This commit is contained in:
parent
a5512518ab
commit
5f7215d965
46
.drone.yml
Normal file
46
.drone.yml
Normal file
@ -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
|
@ -34,3 +34,8 @@ changelog:
|
|||||||
exclude:
|
exclude:
|
||||||
- "^docs:"
|
- "^docs:"
|
||||||
- "^test:"
|
- "^test:"
|
||||||
|
|
||||||
|
release:
|
||||||
|
github:
|
||||||
|
owner: xsteadfastx
|
||||||
|
name: schnutibox
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
//nolint:gochecknoglobals
|
//nolint:gochecknoglobals,golint,stylecheck,godox
|
||||||
package assets
|
package assets
|
||||||
|
|
||||||
import _ "embed"
|
import _ "embed"
|
||||||
|
|
||||||
|
// TODO: Using embed.FS
|
||||||
|
|
||||||
//go:embed templates/schnutibox.yml.tmpl
|
//go:embed templates/schnutibox.yml.tmpl
|
||||||
var SchnutiboxConfig string
|
var SchnutiboxConfig string
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@ control= Headphone
|
|||||||
[mpd]
|
[mpd]
|
||||||
hostname = 0.0.0.0
|
hostname = 0.0.0.0
|
||||||
|
|
||||||
|
[youtube]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
{{if .Spotify}}
|
{{if .Spotify}}
|
||||||
[spotify]
|
[spotify]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
@ -68,7 +68,9 @@ func initConfig() {
|
|||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
|
|
||||||
// Flags.
|
// 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.
|
// Parse config file.
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//nolint:exhaustivestruct,gochecknoglobals
|
//nolint:exhaustivestruct,gochecknoglobals
|
||||||
package prepare
|
package prepare
|
||||||
|
|
||||||
//nolint:golint
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -30,7 +29,6 @@ const (
|
|||||||
upmpdcliGroup = "nogroup"
|
upmpdcliGroup = "nogroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config.
|
|
||||||
var Cfg = struct {
|
var Cfg = struct {
|
||||||
RFIDReader string
|
RFIDReader string
|
||||||
ReadOnly bool
|
ReadOnly bool
|
||||||
@ -93,6 +91,7 @@ func NTP() error {
|
|||||||
return fmt.Errorf("could not install ntp: %w", err)
|
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 {
|
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)
|
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")
|
logger.Debug().Str("item", i).Msg("remove file/directory")
|
||||||
|
|
||||||
if err := os.RemoveAll(i); err != nil {
|
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.
|
// cmdlineTxt modifies the /boot/cmdline.txt.
|
||||||
func cmdlineTxt(system string) error {
|
func cmdlineTxt() error {
|
||||||
// Read.
|
// Read.
|
||||||
oldLine, err := ioutil.ReadFile("/boot/cmdline.txt")
|
oldLine, err := ioutil.ReadFile("/boot/cmdline.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -340,6 +339,7 @@ func cmdlineTxt(system string) error {
|
|||||||
newLine := strings.TrimSuffix(string(oldLine), "\n") + " " + "fastboot" + " " + "noswap"
|
newLine := strings.TrimSuffix(string(oldLine), "\n") + " " + "fastboot" + " " + "noswap"
|
||||||
|
|
||||||
// Write.
|
// Write.
|
||||||
|
// nolint:gosec
|
||||||
if err := ioutil.WriteFile("/boot/cmdline.txt", []byte(newLine), 0o644); err != nil {
|
if err := ioutil.WriteFile("/boot/cmdline.txt", []byte(newLine), 0o644); err != nil {
|
||||||
return fmt.Errorf("could not write cmdline.txt: %w", err)
|
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)
|
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)
|
return fmt.Errorf("could not modify cmdline.txt: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ func makeReadOnly(system string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mopidy setups mopidy.
|
// Mopidy setups mopidy.
|
||||||
//nolint:funlen
|
//nolint:funlen,cyclop
|
||||||
func Mopidy() error {
|
func Mopidy() error {
|
||||||
logger := log.With().Str("stage", "Mopidy").Logger()
|
logger := log.With().Str("stage", "Mopidy").Logger()
|
||||||
|
|
||||||
@ -416,6 +416,7 @@ func Mopidy() error {
|
|||||||
"mopidy-alsamixer",
|
"mopidy-alsamixer",
|
||||||
"mopidy-mpd",
|
"mopidy-mpd",
|
||||||
"mopidy-spotify",
|
"mopidy-spotify",
|
||||||
|
"python3-pip",
|
||||||
)
|
)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@ -426,6 +427,21 @@ func Mopidy() error {
|
|||||||
return fmt.Errorf("could not install mopidy: %w", err)
|
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.
|
// Enable service.
|
||||||
cmd = exec.Command("systemctl", "enable", "mopidy.service")
|
cmd = exec.Command("systemctl", "enable", "mopidy.service")
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@ -532,6 +548,7 @@ func Upmpdcli() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create config.
|
// Create config.
|
||||||
|
// nolint:gosec
|
||||||
if err := ioutil.WriteFile("/etc/upmpdcli.conf", assets.UpmpdcliConf, 0o644); err != nil {
|
if err := ioutil.WriteFile("/etc/upmpdcli.conf", assets.UpmpdcliConf, 0o644); err != nil {
|
||||||
return fmt.Errorf("could not copy upmpdcli config: %w", err)
|
return fmt.Errorf("could not copy upmpdcli config: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user