Skip to content

Commit

Permalink
Add SteamOS as a supported platform (#121)
Browse files Browse the repository at this point in the history
* Update readme

* Rename core go module path

* Add steamos platform

* Add steamos build tasks

* Add steamos udev rules

* Add deploy-steamos task to Taskfile

* Refactor Steam library scanning into reusable utility function

* Refactor platform methods to use anonymous parameters

* Refactor service handling and configuration structure

* Update SteamOS launch command and add Zaparoo service file

* Added module blacklist for acr122

* Remove acr122_pcsc

* Refactor service handling and update configuration files

* Add install and uninstall commands for SteamOS service

* Fix zaparoo.service to run tapto without -daemon flag

* Switch to xdg for paths and update dependency versions

* Refactor install logic and update systemd service configuration

* Update service template to use dynamic paths for exec and working dir

* Add optical_drive reader and clean up dependencies

* Remove sudo from steam launch
  • Loading branch information
wizzomafizzo authored Dec 14, 2024
1 parent d23b263 commit be6c98d
Show file tree
Hide file tree
Showing 70 changed files with 875 additions and 348 deletions.
25 changes: 25 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ tasks:
cmds:
- docker build --platform linux/amd64 -t {{.IMAGE_NAME}} {{.DOCKERFILE}}

build-image-steamos-amd64:
vars:
IMAGE_NAME: zaparoo/steamos-amd64-build
DOCKERFILE: "./scripts/linux_amd64/build"
cmds:
- docker build --platform linux/amd64 -t {{.IMAGE_NAME}} {{.DOCKERFILE}}

build-mister:
vars:
BUILD_DIR: "./_build/mister_arm"
Expand Down Expand Up @@ -104,6 +111,19 @@ tasks:
- rm -f {{.BUILD_DIR}}/tapto-batocera_amd64.zip
- zip -j {{.BUILD_DIR}}/tapto-batocera_amd64.zip {{.BUILD_DIR}}/tapto

build-steamos-amd64:
vars:
BUILD_DIR: "./_build/steamos_amd64"
BUILDCACHE: "{{.BUILD_DIR}}/.go-buildcache"
MODCACHE: "{{.BUILD_DIR}}/.go-modcache"
IMAGE_NAME: zaparoo/steamos-amd64-build
IMG_BUILDCACHE: /home/build/.cache/go-build
IMG_MODCACHE: /home/build/go/pkg/mod
cmds:
- docker run --rm --platform linux/amd64 -v {{.BUILDCACHE}}:{{.IMG_BUILDCACHE}} -v {{.MODCACHE}}:{{.IMG_MODCACHE}} -v ${PWD}:/build --user 1000:1000 {{.IMAGE_NAME}} bash -c "PLATFORM=steamos TAPTO_BIN=tapto task build"
- rm -f {{.BUILD_DIR}}/zaparoo-steamos_amd64.zip
- zip -j {{.BUILD_DIR}}/zaparoo-steamos_amd64.zip {{.BUILD_DIR}}/tapto

build-windows:
vars:
BUILD_DIR: "./_build/windows_{{.ARCH}}"
Expand Down Expand Up @@ -138,6 +158,11 @@ tasks:
- scp _build/mistex_arm64/tapto.sh root@${MISTEX_IP}:/media/fat/Scripts/tapto.sh
- ssh root@${MISTEX_IP} /media/fat/Scripts/tapto.sh -service restart

deploy-steamos:
cmds:
- task: build-steamos-amd64
- scp _build/steamos_amd64/tapto deck@${STEAMOS_IP}:/home/deck/zaparoo/tapto

clean: rm -rf _build

test: go test ./...
Expand Down
8 changes: 4 additions & 4 deletions cmd/batocera/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/wizzomafizzo/tapto/pkg/platforms/batocera"
"github.com/wizzomafizzo/tapto/pkg/utils"
"github.com/ZaparooProject/zaparoo-core/pkg/platforms/batocera"
"github.com/ZaparooProject/zaparoo-core/pkg/utils"

"github.com/wizzomafizzo/tapto/pkg/config"
"github.com/wizzomafizzo/tapto/pkg/service"
"github.com/ZaparooProject/zaparoo-core/pkg/config"
"github.com/ZaparooProject/zaparoo-core/pkg/service"
)

const appName = "tapto"
Expand Down
10 changes: 5 additions & 5 deletions cmd/mac/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/wizzomafizzo/tapto/pkg/platforms/mac"
"github.com/wizzomafizzo/tapto/pkg/utils"
"github.com/ZaparooProject/zaparoo-core/pkg/platforms/mac"
"github.com/ZaparooProject/zaparoo-core/pkg/utils"

"github.com/wizzomafizzo/tapto/pkg/config"
"github.com/wizzomafizzo/tapto/pkg/service"
"github.com/ZaparooProject/zaparoo-core/pkg/config"
"github.com/ZaparooProject/zaparoo-core/pkg/service"
)

const appName = "tapto"
Expand All @@ -49,7 +49,7 @@ func main() {
os.Exit(0)
}

cfg, err := config.NewUserConfig(appName, &config.UserConfig{
cfg, err := config.NewUserConfig(&config.UserConfig{
TapTo: config.TapToConfig{
ProbeDevice: true,
},
Expand Down
9 changes: 4 additions & 5 deletions cmd/mister/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ import (
"path"
"strings"

"github.com/ZaparooProject/zaparoo-core/pkg/config"
"github.com/ZaparooProject/zaparoo-core/pkg/platforms"
"github.com/ZaparooProject/zaparoo-core/pkg/utils"
"github.com/rs/zerolog/log"
"github.com/rthornton128/goncurses"
"github.com/wizzomafizzo/mrext/pkg/curses"
mrextMister "github.com/wizzomafizzo/mrext/pkg/mister"
"github.com/wizzomafizzo/tapto/pkg/config"
"github.com/wizzomafizzo/tapto/pkg/platforms"
"github.com/wizzomafizzo/tapto/pkg/platforms/mister"
"github.com/wizzomafizzo/tapto/pkg/utils"
)

func tryAddStartup(stdscr *goncurses.Window) error {
Expand Down Expand Up @@ -308,7 +307,7 @@ func exportLog(pl platforms.Platform, stdscr *goncurses.Window) error {
return nil
}

func displayServiceInfo(pl platforms.Platform, cfg *config.UserConfig, stdscr *goncurses.Window, service *mister.Service) error {
func displayServiceInfo(pl platforms.Platform, cfg *config.UserConfig, stdscr *goncurses.Window, service *utils.Service) error {
width := 50
height := 8

Expand Down
12 changes: 7 additions & 5 deletions cmd/mister/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ package main
import (
"flag"
"fmt"
"github.com/ZaparooProject/zaparoo-core/pkg/cli"
"github.com/ZaparooProject/zaparoo-core/pkg/utils"
"github.com/rs/zerolog/log"
"github.com/wizzomafizzo/tapto/pkg/cli"
"os"

"github.com/ZaparooProject/zaparoo-core/pkg/platforms/mister"
gc "github.com/rthornton128/goncurses"
"github.com/wizzomafizzo/mrext/pkg/curses"
"github.com/wizzomafizzo/tapto/pkg/platforms/mister"

"github.com/wizzomafizzo/tapto/pkg/config"
"github.com/wizzomafizzo/tapto/pkg/service"
"github.com/ZaparooProject/zaparoo-core/pkg/config"
"github.com/ZaparooProject/zaparoo-core/pkg/service"

mrextMister "github.com/wizzomafizzo/mrext/pkg/mister"
)
Expand Down Expand Up @@ -95,10 +96,11 @@ func main() {
},
})

svc, err := mister.NewService(mister.ServiceArgs{
svc, err := utils.NewService(utils.ServiceArgs{
Entry: func() (func() error, error) {
return service.Start(pl, cfg)
},
Platform: pl,
})
if err != nil {
log.Error().Err(err).Msg("error creating service")
Expand Down
14 changes: 7 additions & 7 deletions cmd/mistex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ package main
import (
"flag"
"fmt"
"github.com/wizzomafizzo/tapto/pkg/cli"
"github.com/wizzomafizzo/tapto/pkg/platforms/mistex"
"github.com/wizzomafizzo/tapto/pkg/utils"
"github.com/ZaparooProject/zaparoo-core/pkg/cli"
"github.com/ZaparooProject/zaparoo-core/pkg/platforms/mistex"
"github.com/ZaparooProject/zaparoo-core/pkg/utils"
"os"
"os/exec"

"github.com/rs/zerolog/log"

"github.com/wizzomafizzo/tapto/pkg/config"
"github.com/wizzomafizzo/tapto/pkg/platforms/mister"
"github.com/wizzomafizzo/tapto/pkg/service"
"github.com/ZaparooProject/zaparoo-core/pkg/config"
"github.com/ZaparooProject/zaparoo-core/pkg/service"
)

func tryAddToStartup() (bool, error) {
Expand Down Expand Up @@ -112,10 +111,11 @@ func main() {
},
})

svc, err := mister.NewService(mister.ServiceArgs{
svc, err := utils.NewService(utils.ServiceArgs{
Entry: func() (func() error, error) {
return service.Start(pl, cfg)
},
Platform: pl,
})
if err != nil {
log.Error().Err(err).Msg("error creating service")
Expand Down
4 changes: 4 additions & 0 deletions cmd/steamos/conf/60-zaparoo.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Allow user (deck) access to NFC readers

# CH340 serial devices (PN532 V2, ESP32, DIY Reader, etc.)
SUBSYSTEMS=="usb", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", MODE="0660", GROUP="deck"
2 changes: 2 additions & 0 deletions cmd/steamos/conf/blacklist-zaparoo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
blacklist pn533
blacklist pn533_usb
15 changes: 15 additions & 0 deletions cmd/steamos/conf/zaparoo.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Zaparoo Core service

[Service]
Type=exec
Restart=on-failure
RestartSec=5
StandardError=syslog
User=deck
Group=deck
WorkingDirectory=%%WORKING%%
ExecStart=%%EXEC%%

[Install]
WantedBy=multi-user.target
115 changes: 115 additions & 0 deletions cmd/steamos/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package main

import (
_ "embed"
"github.com/ZaparooProject/zaparoo-core/pkg/config"
"os"
"os/exec"
"path/filepath"
"strings"
)

// TODO: allow updating if files have changed

//go:embed conf/zaparoo.service
var serviceFile string

//go:embed conf/blacklist-zaparoo.conf
var modprobeFile string

//go:embed conf/60-zaparoo.rules
var udevFile string

const (
servicePath = "/etc/systemd/system/zaparoo.service"
modprobePath = "/etc/modprobe.d/blacklist-zaparoo.conf"
udevPath = "/etc/udev/rules.d/60-zaparoo.rules"
)

func install() error {
// install and prep systemd service
if _, err := os.Stat(servicePath); os.IsNotExist(err) {
exe, err := os.Executable()
if err != nil {
exe = "/home/deck/zaparoo/" + config.AppName
}
serviceFile = strings.ReplaceAll(serviceFile, "%%EXEC%%", exe)
serviceFile = strings.ReplaceAll(serviceFile, "%%WORKING%%", filepath.Dir(exe))

err = os.WriteFile(servicePath, []byte(serviceFile), 0644)
if err != nil {
return err
}
err = exec.Command("systemctl", "daemon-reload").Run()
if err != nil {
return err
}
err = exec.Command("systemctl", "enable", "zaparoo").Run()
if err != nil {
return err
}
}

// install udev rules and refresh
if _, err := os.Stat(udevPath); os.IsNotExist(err) {
err = os.WriteFile(udevPath, []byte(udevFile), 0644)
if err != nil {
return err
}
err = exec.Command("udevadm", "control", "--reload-rules").Run()
if err != nil {
return err
}
err = exec.Command("udevadm", "trigger").Run()
if err != nil {
return err
}
}

// install modprobe blacklist
if _, err := os.Stat(modprobePath); os.IsNotExist(err) {
err = os.WriteFile(modprobePath, []byte(modprobeFile), 0644)
if err != nil {
return err
}
}

return nil
}

func uninstall() error {
if _, err := os.Stat(servicePath); !os.IsNotExist(err) {
err = exec.Command("systemctl", "disable", "zaparoo").Run()
if err != nil {
return err
}
err = exec.Command("systemctl", "stop", "zaparoo").Run()
if err != nil {
return err
}
err = exec.Command("systemctl", "daemon-reload").Run()
if err != nil {
return err
}
err = os.Remove(servicePath)
if err != nil {
return err
}
}

if _, err := os.Stat(modprobePath); !os.IsNotExist(err) {
err = os.Remove(modprobePath)
if err != nil {
return err
}
}

if _, err := os.Stat(udevPath); !os.IsNotExist(err) {
err = os.Remove(udevPath)
if err != nil {
return err
}
}

return nil
}
Loading

0 comments on commit be6c98d

Please sign in to comment.