Move some things out of internal
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2023-09-21 16:18:18 -07:00
parent 76ba7fcc68
commit be7709a5ed
46 changed files with 168 additions and 156 deletions

View File

@ -1,7 +1,8 @@
PREFIX ?= /usr/local PREFIX ?= /usr/local
GIT_VERSION = $(shell git describe --tags )
lure: internal/config/version.txt lure:
CGO_ENABLED=0 go build CGO_ENABLED=0 go build -ldflags="-X 'go.elara.ws/lure/pkg/config.Version=$(GIT_VERSION)'"
clean: clean:
rm -f lure rm -f lure
@ -16,7 +17,4 @@ installmisc:
uninstall: uninstall:
rm -f /usr/local/bin/lure rm -f /usr/local/bin/lure
internal/config/version.txt: .PHONY: install clean uninstall installmisc lure
go generate ./internal/config
.PHONY: install clean uninstall installmisc

View File

@ -23,13 +23,13 @@ import (
"path/filepath" "path/filepath"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/lure/internal/build"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/osutils" "go.elara.ws/lure/internal/osutils"
"go.elara.ws/lure/internal/repos"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/manager" "go.elara.ws/lure/pkg/build"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/manager"
"go.elara.ws/lure/pkg/repos"
) )
var buildCmd = &cli.Command{ var buildCmd = &cli.Command{

View File

@ -27,9 +27,9 @@ import (
"github.com/twitchtv/twirp" "github.com/twitchtv/twirp"
"go.elara.ws/lure/internal/api" "go.elara.ws/lure/internal/api"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"golang.org/x/text/language" "golang.org/x/text/language"
) )

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"go.elara.ws/lure/internal/db" "go.elara.ws/lure/pkg/db"
) )
//go:embed badge-logo.txt //go:embed badge-logo.txt

View File

@ -29,9 +29,9 @@ import (
"github.com/twitchtv/twirp" "github.com/twitchtv/twirp"
"go.elara.ws/logger" "go.elara.ws/logger"
"go.elara.ws/lure/internal/api" "go.elara.ws/lure/internal/api"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos" "go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/repos"
) )
func init() { func init() {

View File

@ -29,9 +29,9 @@ import (
"os" "os"
"strings" "strings"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos" "go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/repos"
) )
func handleWebhook(sigCh chan<- struct{}) http.HandlerFunc { func handleWebhook(sigCh chan<- struct{}) http.HandlerFunc {

6
fix.go
View File

@ -22,10 +22,10 @@ import (
"os" "os"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos" "go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/repos"
) )
var fixCmd = &cli.Command{ var fixCmd = &cli.Command{

View File

@ -25,11 +25,11 @@ import (
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/cliutils" "go.elara.ws/lure/internal/cliutils"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/overrides" "go.elara.ws/lure/internal/overrides"
"go.elara.ws/lure/internal/repos" "go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/distro"
"go.elara.ws/lure/pkg/repos"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )

View File

@ -22,14 +22,14 @@ import (
"fmt" "fmt"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/lure/internal/build"
"go.elara.ws/lure/internal/cliutils" "go.elara.ws/lure/internal/cliutils"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/manager" "go.elara.ws/lure/pkg/build"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/manager"
"go.elara.ws/lure/pkg/repos"
) )
var installCmd = &cli.Command{ var installCmd = &cli.Command{

View File

@ -7,10 +7,11 @@
package api package api
import ( import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect" reflect "reflect"
sync "sync" sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
) )
const ( const (
@ -734,9 +735,10 @@ func file_lure_proto_rawDescGZIP() []byte {
return file_lure_proto_rawDescData return file_lure_proto_rawDescData
} }
var file_lure_proto_enumTypes = make([]protoimpl.EnumInfo, 2) var (
var file_lure_proto_msgTypes = make([]protoimpl.MessageInfo, 9) file_lure_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_lure_proto_goTypes = []interface{}{ file_lure_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
file_lure_proto_goTypes = []interface{}{
(SORT_BY)(0), // 0: lure.SORT_BY (SORT_BY)(0), // 0: lure.SORT_BY
(FILTER_TYPE)(0), // 1: lure.FILTER_TYPE (FILTER_TYPE)(0), // 1: lure.FILTER_TYPE
(*SearchRequest)(nil), // 2: lure.SearchRequest (*SearchRequest)(nil), // 2: lure.SearchRequest
@ -748,7 +750,8 @@ var file_lure_proto_goTypes = []interface{}{
(*GetBuildScriptResponse)(nil), // 8: lure.GetBuildScriptResponse (*GetBuildScriptResponse)(nil), // 8: lure.GetBuildScriptResponse
nil, // 9: lure.Package.DependsEntry nil, // 9: lure.Package.DependsEntry
nil, // 10: lure.Package.BuildDependsEntry nil, // 10: lure.Package.BuildDependsEntry
} }
)
var file_lure_proto_depIdxs = []int32{ var file_lure_proto_depIdxs = []int32{
0, // 0: lure.SearchRequest.sort_by:type_name -> lure.SORT_BY 0, // 0: lure.SearchRequest.sort_by:type_name -> lure.SORT_BY
1, // 1: lure.SearchRequest.filter_type:type_name -> lure.FILTER_TYPE 1, // 1: lure.SearchRequest.filter_type:type_name -> lure.FILTER_TYPE

View File

@ -3,23 +3,29 @@
package api package api
import context "context" import (
import fmt "fmt" context "context"
import http "net/http" fmt "fmt"
import io "io" http "net/http"
import json "encoding/json" io "io"
import strconv "strconv" json "encoding/json"
import strings "strings" strconv "strconv"
strings "strings"
)
import protojson "google.golang.org/protobuf/encoding/protojson" import (
import proto "google.golang.org/protobuf/proto" protojson "google.golang.org/protobuf/encoding/protojson"
import twirp "github.com/twitchtv/twirp" proto "google.golang.org/protobuf/proto"
import ctxsetters "github.com/twitchtv/twirp/ctxsetters" twirp "github.com/twitchtv/twirp"
ctxsetters "github.com/twitchtv/twirp/ctxsetters"
)
import bytes "bytes" import (
import errors "errors" bytes "bytes"
import path "path" errors "errors"
import url "net/url" path "path"
url "net/url"
)
// Version compatibility assertion. // Version compatibility assertion.
// If the constant is not defined in the package, that likely means // If the constant is not defined in the package, that likely means

View File

@ -23,11 +23,11 @@ import (
"strings" "strings"
"github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/pager" "go.elara.ws/lure/internal/pager"
"go.elara.ws/lure/internal/translations" "go.elara.ws/lure/internal/translations"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
) )
// YesNoPrompt asks the user a yes or no question, using def as the default answer // YesNoPrompt asks the user a yes or no question, using def as the default answer

View File

@ -1,26 +0,0 @@
/*
* LURE - Linux User REpository
* Copyright (C) 2023 Elara Musayelyan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package config
import _ "embed"
//go:generate ../../scripts/gen-version.sh
//go:embed version.txt
var Version string

View File

@ -25,7 +25,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"go.elara.ws/lure/internal/config" "go.elara.ws/lure/pkg/config"
) )
// BasePath returns the base path of the download cache // BasePath returns the base path of the download cache

View File

@ -26,8 +26,8 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/dlcache" "go.elara.ws/lure/internal/dlcache"
"go.elara.ws/lure/pkg/config"
) )
func init() { func init() {

View File

@ -22,9 +22,9 @@ import (
"reflect" "reflect"
"strings" "strings"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/cpu" "go.elara.ws/lure/internal/cpu"
"go.elara.ws/lure/internal/db" "go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/distro"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"golang.org/x/text/language" "golang.org/x/text/language"
) )

View File

@ -23,8 +23,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/overrides" "go.elara.ws/lure/internal/overrides"
"go.elara.ws/lure/pkg/distro"
"golang.org/x/text/language" "golang.org/x/text/language"
) )

View File

@ -25,8 +25,8 @@ import (
"strings" "strings"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/overrides" "go.elara.ws/lure/internal/overrides"
"go.elara.ws/lure/pkg/distro"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"mvdan.cc/sh/v3/expand" "mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"

View File

@ -27,8 +27,8 @@ import (
"strings" "strings"
"testing" "testing"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/shutils/decoder" "go.elara.ws/lure/internal/shutils/decoder"
"go.elara.ws/lure/pkg/distro"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax" "mvdan.cc/sh/v3/syntax"
) )

View File

@ -23,9 +23,9 @@ import (
"strings" "strings"
"testing" "testing"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/shutils" "go.elara.ws/lure/internal/shutils"
"go.elara.ws/lure/internal/shutils/decoder" "go.elara.ws/lure/internal/shutils/decoder"
"go.elara.ws/lure/pkg/distro"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax" "mvdan.cc/sh/v3/syntax"
) )

View File

@ -18,7 +18,7 @@
package types package types
import "go.elara.ws/lure/manager" import "go.elara.ws/lure/pkg/manager"
type BuildOpts struct { type BuildOpts struct {
Script string Script string

View File

@ -22,11 +22,11 @@ import (
"fmt" "fmt"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos" "go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/manager" "go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/manager"
"go.elara.ws/lure/pkg/repos"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
) )

View File

@ -28,11 +28,11 @@ import (
"github.com/mattn/go-isatty" "github.com/mattn/go-isatty"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/logger" "go.elara.ws/logger"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/translations" "go.elara.ws/lure/internal/translations"
"go.elara.ws/lure/manager" "go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/manager"
) )
var app = &cli.App{ var app = &cli.App{

View File

@ -38,19 +38,19 @@ import (
"github.com/goreleaser/nfpm/v2" "github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/files" "github.com/goreleaser/nfpm/v2/files"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/cliutils" "go.elara.ws/lure/internal/cliutils"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/cpu" "go.elara.ws/lure/internal/cpu"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/dl" "go.elara.ws/lure/internal/dl"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos"
"go.elara.ws/lure/internal/shutils" "go.elara.ws/lure/internal/shutils"
"go.elara.ws/lure/internal/shutils/decoder" "go.elara.ws/lure/internal/shutils/decoder"
"go.elara.ws/lure/internal/shutils/helpers" "go.elara.ws/lure/internal/shutils/helpers"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/manager" "go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/distro"
"go.elara.ws/lure/pkg/manager"
"go.elara.ws/lure/pkg/repos"
"mvdan.cc/sh/v3/expand" "mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax" "mvdan.cc/sh/v3/syntax"

View File

@ -22,14 +22,14 @@ import (
"context" "context"
"path/filepath" "path/filepath"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
) )
// InstallPkgs installs non-LURE packages via the package manager, then builds and installs LURE // InstallPkgs installs native packages via the package manager,
// packages // then builds and installs the LURE packages
func InstallPkgs(ctx context.Context, lurePkgs []db.Package, nativePkgs []string, opts types.BuildOpts) { func InstallPkgs(ctx context.Context, lurePkgs []db.Package, nativePkgs []string, opts types.BuildOpts) {
if len(nativePkgs) > 0 { if len(nativePkgs) > 0 {
err := opts.Manager.Install(nil, nativePkgs...) err := opts.Manager.Install(nil, nativePkgs...)
@ -41,7 +41,7 @@ func InstallPkgs(ctx context.Context, lurePkgs []db.Package, nativePkgs []string
InstallScripts(ctx, GetScriptPaths(lurePkgs), opts) InstallScripts(ctx, GetScriptPaths(lurePkgs), opts)
} }
// GetScriptPaths generates a slice of script paths corresponding to the // GetScriptPaths returns a slice of script paths corresponding to the
// given packages // given packages
func GetScriptPaths(pkgs []db.Package) []string { func GetScriptPaths(pkgs []db.Package) []string {
var scripts []string var scripts []string
@ -52,7 +52,7 @@ func GetScriptPaths(pkgs []db.Package) []string {
return scripts return scripts
} }
// InstallScripts builds and installs LURE build scripts // InstallScripts builds and installs the given LURE build scripts
func InstallScripts(ctx context.Context, scripts []string, opts types.BuildOpts) { func InstallScripts(ctx context.Context, scripts []string, opts types.BuildOpts) {
for _, script := range scripts { for _, script := range scripts {
opts.Script = script opts.Script = script

View File

@ -40,6 +40,9 @@ var defaultConfig = &types.Config{
var config *types.Config var config *types.Config
// Config returns a LURE configuration struct.
// The first time it's called, it'll load the config from a file.
// Subsequent calls will just return the same value.
func Config() *types.Config { func Config() *types.Config {
if config == nil { if config == nil {
cfgFl, err := os.Open(GetPaths().ConfigPath) cfgFl, err := os.Open(GetPaths().ConfigPath)

View File

@ -31,6 +31,10 @@ var (
langSet bool langSet bool
) )
// Language returns the system language.
// The first time it's called, it'll detect the langauge based on
// the $LANG environment variable.
// Subsequent calls will just return the same value.
func Language() language.Tag { func Language() language.Tag {
if !langSet { if !langSet {
syslang := SystemLang() syslang := SystemLang()
@ -45,6 +49,8 @@ func Language() language.Tag {
return lang return lang
} }
// SystemLang returns the system language based on
// the $LANG environment variable.
func SystemLang() string { func SystemLang() string {
lang := os.Getenv("LANG") lang := os.Getenv("LANG")
lang, _, _ = strings.Cut(lang, ".") lang, _, _ = strings.Cut(lang, ".")

View File

@ -26,6 +26,7 @@ import (
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
) )
// Paths contains various paths used by LURE
type Paths struct { type Paths struct {
ConfigDir string ConfigDir string
ConfigPath string ConfigPath string
@ -37,6 +38,10 @@ type Paths struct {
var paths *Paths var paths *Paths
// GetPaths returns a Paths struct.
// The first time it's called, it'll generate the struct
// using information from the system.
// Subsequent calls will return the same value.
func GetPaths() *Paths { func GetPaths() *Paths {
if paths == nil { if paths == nil {
paths = &Paths{} paths = &Paths{}

5
pkg/config/version.go Normal file
View File

@ -0,0 +1,5 @@
package config
// Version contains the version of LURE. If the version
// isn't known, it'll be set to "unknown"
var Version = "unknown"

View File

@ -26,16 +26,18 @@ import (
"fmt" "fmt"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/pkg/config"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"modernc.org/sqlite" "modernc.org/sqlite"
) )
// CurrentVersion is the current version of the database.
// The database is reset if its version doesn't match this.
const CurrentVersion = 2 const CurrentVersion = 2
func init() { func init() {
sqlite.MustRegisterScalarFunction("json_array_contains", 2, JsonArrayContains) sqlite.MustRegisterScalarFunction("json_array_contains", 2, jsonArrayContains)
} }
// Package is a LURE package's database representation // Package is a LURE package's database representation
@ -67,11 +69,14 @@ var (
closed = true closed = true
) )
// DB returns the LURE database.
// The first time it's called, it opens the SQLite database file.
// Subsequent calls return the same connection.
func DB() *sqlx.DB { func DB() *sqlx.DB {
if conn != nil && !closed { if conn != nil && !closed {
return conn return conn
} }
db, err := Open(config.GetPaths().DBPath) db, err := open(config.GetPaths().DBPath)
if err != nil { if err != nil {
log.Fatal("Error opening database").Err(err).Send() log.Fatal("Error opening database").Err(err).Send()
} }
@ -79,7 +84,7 @@ func DB() *sqlx.DB {
return conn return conn
} }
func Open(dsn string) (*sqlx.DB, error) { func open(dsn string) (*sqlx.DB, error) {
db, err := sqlx.Open("sqlite", dsn) db, err := sqlx.Open("sqlite", dsn)
if err != nil { if err != nil {
return nil, err return nil, err
@ -95,6 +100,7 @@ func Open(dsn string) (*sqlx.DB, error) {
return db, nil return db, nil
} }
// Close closes the database
func Close() error { func Close() error {
closed = true closed = true
if conn != nil { if conn != nil {
@ -104,7 +110,7 @@ func Close() error {
} }
} }
// Init initializes the database // initDB initializes the database
func initDB(dsn string) error { func initDB(dsn string) error {
conn = conn.Unsafe() conn = conn.Unsafe()
_, err := conn.Exec(` _, err := conn.Exec(`
@ -139,7 +145,7 @@ func initDB(dsn string) error {
ver, ok := GetVersion() ver, ok := GetVersion()
if ok && ver != CurrentVersion { if ok && ver != CurrentVersion {
log.Warn("Database version mismatch; resetting").Int("version", ver).Int("expected", CurrentVersion).Send() log.Warn("Database version mismatch; resetting").Int("version", ver).Int("expected", CurrentVersion).Send()
Reset() reset()
return initDB(dsn) return initDB(dsn)
} else if !ok { } else if !ok {
log.Warn("Database version does not exist. Run lure fix if something isn't working.").Send() log.Warn("Database version does not exist. Run lure fix if something isn't working.").Send()
@ -149,7 +155,8 @@ func initDB(dsn string) error {
return nil return nil
} }
func Reset() error { // reset drops all the database tables
func reset() error {
_, err := DB().Exec("DROP TABLE IF EXISTS pkgs;") _, err := DB().Exec("DROP TABLE IF EXISTS pkgs;")
if err != nil { if err != nil {
return err return err
@ -158,6 +165,7 @@ func Reset() error {
return err return err
} }
// IsEmpty returns true if the database has no packages in it, otherwise it returns false.
func IsEmpty() bool { func IsEmpty() bool {
var count int var count int
err := DB().Get(&count, "SELECT count(1) FROM pkgs;") err := DB().Get(&count, "SELECT count(1) FROM pkgs;")
@ -167,6 +175,8 @@ func IsEmpty() bool {
return count == 0 return count == 0
} }
// GetVersion returns the database version and a boolean indicating
// whether the database contained a version number
func GetVersion() (int, bool) { func GetVersion() (int, bool) {
var ver version var ver version
err := DB().Get(&ver, "SELECT * FROM lure_db_version LIMIT 1;") err := DB().Get(&ver, "SELECT * FROM lure_db_version LIMIT 1;")
@ -232,7 +242,7 @@ func GetPkgs(where string, args ...any) (*sqlx.Rows, error) {
return stream, nil return stream, nil
} }
// GetPkg returns a single package that match the where conditions // GetPkg returns a single package that matches the where conditions
func GetPkg(where string, args ...any) (*Package, error) { func GetPkg(where string, args ...any) (*Package, error) {
out := &Package{} out := &Package{}
err := DB().Get(out, "SELECT * FROM pkgs WHERE "+where+" LIMIT 1", args...) err := DB().Get(out, "SELECT * FROM pkgs WHERE "+where+" LIMIT 1", args...)
@ -245,7 +255,9 @@ func DeletePkgs(where string, args ...any) error {
return err return err
} }
func JsonArrayContains(ctx *sqlite.FunctionContext, args []driver.Value) (driver.Value, error) { // jsonArrayContains is an SQLite function that checks if a JSON array
// in the database contains a given value
func jsonArrayContains(ctx *sqlite.FunctionContext, args []driver.Value) (driver.Value, error) {
value, ok := args[0].(string) value, ok := args[0].(string)
if !ok { if !ok {
return nil, errors.New("both arguments to json_array_contains must be strings") return nil, errors.New("both arguments to json_array_contains must be strings")
@ -265,10 +277,12 @@ func JsonArrayContains(ctx *sqlite.FunctionContext, args []driver.Value) (driver
return slices.Contains(array, item), nil return slices.Contains(array, item), nil
} }
// JSON represents a JSON value in the database
type JSON[T any] struct { type JSON[T any] struct {
Val T Val T
} }
// NewJSON creates a new database JSON value
func NewJSON[T any](v T) JSON[T] { func NewJSON[T any](v T) JSON[T] {
return JSON[T]{Val: v} return JSON[T]{Val: v}
} }

View File

@ -24,7 +24,7 @@ import (
"testing" "testing"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.elara.ws/lure/internal/db" "go.elara.ws/lure/pkg/db"
) )
var testPkg = db.Package{ var testPkg = db.Package{

View File

@ -20,7 +20,6 @@ package distro
import ( import (
"context" "context"
"errors"
"os" "os"
"strings" "strings"
@ -30,8 +29,7 @@ import (
"mvdan.cc/sh/v3/syntax" "mvdan.cc/sh/v3/syntax"
) )
var ErrParse = errors.New("could not parse os-release file") // OSRelease contains information from an os-release file
type OSRelease struct { type OSRelease struct {
Name string Name string
PrettyName string PrettyName string
@ -50,7 +48,8 @@ var parsed *OSRelease
// OSReleaseName returns a struct parsed from the system's os-release // OSReleaseName returns a struct parsed from the system's os-release
// file. It checks /etc/os-release as well as /usr/lib/os-release. // file. It checks /etc/os-release as well as /usr/lib/os-release.
// The returned OSRelease struct is a singleton. // The first time it's called, it'll parse the os-release file.
// Subsequent calls will return the same value.
func ParseOSRelease(ctx context.Context) (*OSRelease, error) { func ParseOSRelease(ctx context.Context) (*OSRelease, error) {
if parsed != nil { if parsed != nil {
return parsed, nil return parsed, nil
@ -87,7 +86,7 @@ func ParseOSRelease(ctx context.Context) (*OSRelease, error) {
err = runner.Run(ctx, file) err = runner.Run(ctx, file)
if err != nil { if err != nil {
return nil, ErrParse return nil, err
} }
out := &OSRelease{ out := &OSRelease{

View File

@ -18,10 +18,10 @@
package repos package repos
import "go.elara.ws/lure/internal/db" import "go.elara.ws/lure/pkg/db"
// FindPkgs looks for packages matching the inputs inside the database. // FindPkgs looks for packages matching the inputs inside the database.
// It returns a map that maps the package name input to the packages found for it. // It returns a map that maps the package name input to any packages found for it.
// It also returns a slice that contains the names of all packages that were not found. // It also returns a slice that contains the names of all packages that were not found.
func FindPkgs(pkgs []string) (map[string][]db.Package, []string, error) { func FindPkgs(pkgs []string) (map[string][]db.Package, []string, error) {
found := map[string][]db.Package{} found := map[string][]db.Package{}

View File

@ -24,9 +24,9 @@ import (
"strings" "strings"
"testing" "testing"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/repos"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/repos"
) )
func TestFindPkgs(t *testing.T) { func TestFindPkgs(t *testing.T) {

View File

@ -34,13 +34,13 @@ import (
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/diff" "github.com/go-git/go-git/v5/plumbing/format/diff"
"github.com/pelletier/go-toml/v2" "github.com/pelletier/go-toml/v2"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/shutils" "go.elara.ws/lure/internal/shutils"
"go.elara.ws/lure/internal/shutils/decoder" "go.elara.ws/lure/internal/shutils/decoder"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/distro"
"go.elara.ws/vercmp" "go.elara.ws/vercmp"
"mvdan.cc/sh/v3/expand" "mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
@ -49,7 +49,7 @@ import (
// Pull pulls the provided repositories. If a repo doesn't exist, it will be cloned // Pull pulls the provided repositories. If a repo doesn't exist, it will be cloned
// and its packages will be written to the DB. If it does exist, it will be pulled. // and its packages will be written to the DB. If it does exist, it will be pulled.
// In this case, only changed packages will be processed. // In this case, only changed packages will be processed if possible.
func Pull(ctx context.Context, repos []types.Repo) error { func Pull(ctx context.Context, repos []types.Repo) error {
for _, repo := range repos { for _, repo := range repos {
repoURL, err := url.Parse(repo.URL) repoURL, err := url.Parse(repo.URL)
@ -149,11 +149,13 @@ func Pull(ctx context.Context, repos []types.Repo) error {
} }
fl.Close() fl.Close()
if config.Version != "unknown" {
currentVer, _, _ := strings.Cut(config.Version, "-") currentVer, _, _ := strings.Cut(config.Version, "-")
if vercmp.Compare(currentVer, repoCfg.Repo.MinVersion) == -1 { if vercmp.Compare(currentVer, repoCfg.Repo.MinVersion) == -1 {
log.Warn("LURE repo's minumum LURE version is greater than the current version. Try updating LURE if something doesn't work.").Str("repo", repo.Name).Send() log.Warn("LURE repo's minumum LURE version is greater than the current version. Try updating LURE if something doesn't work.").Str("repo", repo.Name).Send()
} }
} }
}
return nil return nil
} }

View File

@ -24,10 +24,10 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/repos"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/repos"
) )
func setCfgDirs(t *testing.T) { func setCfgDirs(t *testing.T) {

View File

@ -24,11 +24,11 @@ import (
"github.com/pelletier/go-toml/v2" "github.com/pelletier/go-toml/v2"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/repos"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
) )

View File

@ -1,3 +0,0 @@
#!/bin/bash
git describe --tags > version.txt

View File

@ -23,14 +23,14 @@ import (
"fmt" "fmt"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/build"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log" "go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/repos"
"go.elara.ws/lure/internal/types" "go.elara.ws/lure/internal/types"
"go.elara.ws/lure/manager" "go.elara.ws/lure/pkg/build"
"go.elara.ws/lure/pkg/config"
"go.elara.ws/lure/pkg/db"
"go.elara.ws/lure/pkg/distro"
"go.elara.ws/lure/pkg/manager"
"go.elara.ws/lure/pkg/repos"
"go.elara.ws/vercmp" "go.elara.ws/vercmp"
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"