diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..99cffcd --- /dev/null +++ b/.drone.yml @@ -0,0 +1,46 @@ +--- +kind: pipeline +name: default + +steps: + - name: tags + image: alpine/git + commands: + - git fetch --tags + + - name: lint + image: golangci/golangci-lint:latest + commands: + - make lint + + - name: test + image: golang:latest + commands: + - make test + + - name: build + image: goreleaser/goreleaser:v0.162.0 + commands: + - (cd /tmp; go get -u github.com/go-bindata/go-bindata/...) + - make build + depends_on: + - lint + - test + when: + event: + exclude: + - tag + + - name: release + image: goreleaser/goreleaser:v0.162.0 + environment: + GITHUB_TOKEN: + from_secret: github_token + commands: + - goreleaser release --rm-dist + depends_on: + - lint + - test + when: + event: + - tag diff --git a/.goreleaser.yml b/.goreleaser.yml index 639e5fe..0681b5d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -34,3 +34,8 @@ changelog: exclude: - "^docs:" - "^test:" + +release: + github: + owner: xsteadfastx + name: schnutibox diff --git a/assets/assets.go b/assets/assets.go index a1188a0..cab96bd 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -1,8 +1,10 @@ -//nolint:gochecknoglobals +//nolint:gochecknoglobals,golint,stylecheck,godox package assets import _ "embed" +// TODO: Using embed.FS + //go:embed templates/schnutibox.yml.tmpl var SchnutiboxConfig string diff --git a/assets/templates/mopidy.conf.tmpl b/assets/templates/mopidy.conf.tmpl index ea53ad7..423fa17 100644 --- a/assets/templates/mopidy.conf.tmpl +++ b/assets/templates/mopidy.conf.tmpl @@ -15,6 +15,9 @@ control= Headphone [mpd] hostname = 0.0.0.0 +[youtube] +enabled = true + {{if .Spotify}} [spotify] enabled = true diff --git a/cmd/root.go b/cmd/root.go index 35e7555..75e5c61 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -68,7 +68,9 @@ func initConfig() { viper.AutomaticEnv() // Flags. - viper.BindPFlag("reader.dev", prepareCmd.Flags().Lookup("rfid-reader")) + if err := viper.BindPFlag("reader.dev", prepareCmd.Flags().Lookup("rfid-reader")); err != nil { + logger.Fatal().Err(err).Msg("could not bind flag") + } // Parse config file. if cfgFile != "" { diff --git a/pkg/prepare/prepare.go b/pkg/prepare/prepare.go index 6d91f50..af2d918 100644 --- a/pkg/prepare/prepare.go +++ b/pkg/prepare/prepare.go @@ -1,7 +1,6 @@ //nolint:exhaustivestruct,gochecknoglobals package prepare -//nolint:golint import ( "fmt" "io/ioutil" @@ -30,7 +29,6 @@ const ( upmpdcliGroup = "nogroup" ) -// Config. var Cfg = struct { RFIDReader string ReadOnly bool @@ -93,6 +91,7 @@ func NTP() error { return fmt.Errorf("could not install ntp: %w", err) } + // nolint:gosec if err := ioutil.WriteFile("/etc/systemd/system/ntp.service", assets.NtpService, 0o644); err != nil { return fmt.Errorf("could not copy ntp service file: %w", err) } @@ -305,7 +304,7 @@ func CreateSymlinks(system string) error { logger.Debug().Str("item", i).Msg("remove file/directory") if err := os.RemoveAll(i); err != nil { - return err + return fmt.Errorf("could not remove: %w", err) } } @@ -330,7 +329,7 @@ func CreateSymlinks(system string) error { } // cmdlineTxt modifies the /boot/cmdline.txt. -func cmdlineTxt(system string) error { +func cmdlineTxt() error { // Read. oldLine, err := ioutil.ReadFile("/boot/cmdline.txt") if err != nil { @@ -340,6 +339,7 @@ func cmdlineTxt(system string) error { newLine := strings.TrimSuffix(string(oldLine), "\n") + " " + "fastboot" + " " + "noswap" // Write. + // nolint:gosec if err := ioutil.WriteFile("/boot/cmdline.txt", []byte(newLine), 0o644); err != nil { return fmt.Errorf("could not write cmdline.txt: %w", err) } @@ -361,7 +361,7 @@ func makeReadOnly(system string) error { return fmt.Errorf("could not create fstab: %w", err) } - if err := cmdlineTxt(system); err != nil { + if err := cmdlineTxt(); err != nil { return fmt.Errorf("could not modify cmdline.txt: %w", err) } @@ -369,7 +369,7 @@ func makeReadOnly(system string) error { } // Mopidy setups mopidy. -//nolint:funlen +//nolint:funlen,cyclop func Mopidy() error { logger := log.With().Str("stage", "Mopidy").Logger() @@ -416,6 +416,7 @@ func Mopidy() error { "mopidy-alsamixer", "mopidy-mpd", "mopidy-spotify", + "python3-pip", ) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -426,6 +427,21 @@ func Mopidy() error { return fmt.Errorf("could not install mopidy: %w", err) } + // Extensions. + cmd = exec.Command( + "pip3", "install", "--upgrade", + "Mopidy-YouTube", + "requests>=2.22", + ) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + logger.Debug().Str("cmd", cmd.String()).Msg("running") + + if err := cmd.Run(); err != nil { + return fmt.Errorf("could not install extensions: %w", err) + } + // Enable service. cmd = exec.Command("systemctl", "enable", "mopidy.service") cmd.Stdout = os.Stdout @@ -532,6 +548,7 @@ func Upmpdcli() error { } // Create config. + // nolint:gosec if err := ioutil.WriteFile("/etc/upmpdcli.conf", assets.UpmpdcliConf, 0o644); err != nil { return fmt.Errorf("could not copy upmpdcli config: %w", err) } diff --git a/tools/findhidraw/findhidraw.go b/tools/findhidraw/findhidraw.go deleted file mode 100644 index 3c64dd1..0000000 --- a/tools/findhidraw/findhidraw.go +++ /dev/null @@ -1,44 +0,0 @@ -package findhidraw - -import ( - "fmt" - "io/ioutil" - "strings" - - "github.com/manifoldco/promptui" -) - -func hidraws(path string) ([]string, error) { - hs := []string{} - - files, err := ioutil.ReadDir(path) - if err != nil { - return []string{}, fmt.Errorf("could not dir files: %w", err) - } - - for _, f := range files { - if strings.Contains(f.Name(), "hidraw") { - hs = append(hs, f.Name()) - } - } - - return hs, nil -} - -func FindHidraw(path string) (string, error) { - prompt := promptui.Prompt{ - Label: "please unplug reader", - IsConfirm: true, - } - - ok, err := prompt.Run() - if err != nil { - return "", fmt.Errorf("could not read input: %w", err) - } - - if ok != "y" { - return "", fmt.Errorf("did not unplug the reader") - } - - return "", nil -}