diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 900ab31..abe46b5 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -5,7 +5,7 @@ on: - main workflow_dispatch: env: - IMAGE_NAME: ublue-update + IMAGE_NAME: uupd IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} jobs: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b1e1fcc..5b13a4a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,7 +1,6 @@ name: goreleaser on: - pull_request: push: tags: - "*" diff --git a/cmd/update.go b/cmd/update.go index 5c6c669..724a226 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -9,17 +9,19 @@ import ( "github.com/spf13/cobra" "github.com/ublue-os/uupd/checks" "github.com/ublue-os/uupd/drv" - "github.com/ublue-os/uupd/lib" + "github.com/ublue-os/uupd/pkg/filelock" + "github.com/ublue-os/uupd/pkg/percent" + "github.com/ublue-os/uupd/pkg/session" ) func Update(cmd *cobra.Command, args []string) { - lock, err := lib.AcquireLock() + lock, err := filelock.AcquireLock() if err != nil { slog.Error(fmt.Sprintf("%v, is uupd already running?", err)) return } defer func() { - err := lib.ReleaseLock(lock) + err := filelock.ReleaseLock(lock) if err != nil { slog.Error("Failed releasing lock") } @@ -50,7 +52,7 @@ func Update(cmd *cobra.Command, args []string) { slog.Info("Hardware checks passed") } - users, err := lib.ListUsers() + users, err := session.ListUsers() if err != nil { slog.Error("Failed to list users", "users", users) return @@ -116,7 +118,7 @@ func Update(cmd *cobra.Command, args []string) { if enableUpd { totalSteps += mainSystemDriver.Steps() } - pw := lib.NewProgressWriter() + pw := percent.NewProgressWriter() pw.SetNumTrackersExpected(1) pw.SetAutoStop(false) @@ -130,11 +132,11 @@ func Update(cmd *cobra.Command, args []string) { if progressEnabled { go pw.Render() - lib.ResetOscProgress() + percent.ResetOscProgress() } // -1 because 0 index - tracker := lib.NewIncrementTracker(&progress.Tracker{Message: "Updating", Units: progress.UnitsDefault, Total: int64(totalSteps - 1)}, totalSteps-1) + tracker := percent.NewIncrementTracker(&progress.Tracker{Message: "Updating", Units: progress.UnitsDefault, Total: int64(totalSteps - 1)}, totalSteps-1) pw.AppendTracker(tracker.Tracker) var trackerConfig = &drv.TrackerConfiguration{ @@ -155,7 +157,7 @@ func Update(cmd *cobra.Command, args []string) { if systemOutdated { const OUTDATED_WARNING = "There hasn't been an update in over a month. Consider rebooting or running updates manually" - err := lib.Notify("System Warning", OUTDATED_WARNING) + err := session.Notify("System Warning", OUTDATED_WARNING) if err != nil { slog.Error("Failed showing warning notification") } @@ -163,7 +165,7 @@ func Update(cmd *cobra.Command, args []string) { } if enableUpd { - lib.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, lib.TrackerMessage{Title: systemUpdater.Config.Title, Description: systemUpdater.Config.Description}) + percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: systemUpdater.Config.Title, Description: systemUpdater.Config.Description}) var out *[]drv.CommandOutput out, err = mainSystemDriver.Update() outputs = append(outputs, *out...) @@ -171,7 +173,7 @@ func Update(cmd *cobra.Command, args []string) { } if brewUpdater.Config.Enabled { - lib.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, lib.TrackerMessage{Title: brewUpdater.Config.Title, Description: brewUpdater.Config.Description}) + percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: brewUpdater.Config.Title, Description: brewUpdater.Config.Description}) out, err := brewUpdater.Update() outputs = append(outputs, *out...) tracker.IncrementSection(err) @@ -191,7 +193,7 @@ func Update(cmd *cobra.Command, args []string) { if progressEnabled { pw.Stop() - lib.ResetOscProgress() + percent.ResetOscProgress() } if verboseRun { slog.Info("Verbose run requested") diff --git a/cmd/wait.go b/cmd/wait.go index 61c9755..6f35a23 100644 --- a/cmd/wait.go +++ b/cmd/wait.go @@ -6,7 +6,7 @@ import ( "time" "github.com/spf13/cobra" - "github.com/ublue-os/uupd/lib" + "github.com/ublue-os/uupd/pkg/filelock" ) func Wait(cmd *cobra.Command, args []string) { @@ -22,7 +22,7 @@ func Wait(cmd *cobra.Command, args []string) { break } - if lib.IsFileLocked(file) { + if filelock.IsFileLocked(file) { file.Close() log.Printf("Waiting for lockfile: %s", lockFilePath) } else { diff --git a/drv/brew.go b/drv/brew.go index 918c630..70ea79b 100644 --- a/drv/brew.go +++ b/drv/brew.go @@ -2,9 +2,10 @@ package drv import ( "fmt" - "github.com/ublue-os/uupd/lib" "os" "syscall" + + "github.com/ublue-os/uupd/pkg/session" ) func (up BrewUpdater) GetBrewUID() (int, error) { @@ -43,7 +44,7 @@ func (up BrewUpdater) Update() (*[]CommandOutput, error) { } cli := []string{up.BrewPath, "update"} - out, err := lib.RunUID(up.BaseUser, cli, up.Config.Environment) + out, err := session.RunUID(up.BaseUser, cli, up.Config.Environment) tmpout := CommandOutput{}.New(out, err) tmpout.Context = "Brew Update" tmpout.Cli = cli @@ -55,7 +56,7 @@ func (up BrewUpdater) Update() (*[]CommandOutput, error) { } cli = []string{up.BrewPath, "upgrade"} - out, err = lib.RunUID(up.BaseUser, cli, up.Config.Environment) + out, err = session.RunUID(up.BaseUser, cli, up.Config.Environment) tmpout = CommandOutput{}.New(out, err) tmpout.Context = "Brew Upgrade" tmpout.Cli = cli diff --git a/drv/distrobox.go b/drv/distrobox.go index 115d893..7754dd7 100644 --- a/drv/distrobox.go +++ b/drv/distrobox.go @@ -1,14 +1,15 @@ package drv import ( - "github.com/ublue-os/uupd/lib" + "github.com/ublue-os/uupd/pkg/percent" + "github.com/ublue-os/uupd/pkg/session" ) type DistroboxUpdater struct { Config DriverConfiguration Tracker *TrackerConfiguration binaryPath string - users []lib.User + users []session.User usersEnabled bool } @@ -47,7 +48,7 @@ func (up DistroboxUpdater) New(config UpdaterInitConfiguration) (DistroboxUpdate return up, nil } -func (up *DistroboxUpdater) SetUsers(users []lib.User) { +func (up *DistroboxUpdater) SetUsers(users []session.User) { up.users = users up.usersEnabled = true } @@ -60,20 +61,20 @@ func (up *DistroboxUpdater) Update() (*[]CommandOutput, error) { var finalOutput = []CommandOutput{} if up.Config.DryRun { - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) up.Tracker.Tracker.IncrementSection(nil) var err error = nil for _, user := range up.users { up.Tracker.Tracker.IncrementSection(err) - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) } return &finalOutput, nil } - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) cli := []string{up.binaryPath, "upgrade", "-a"} - out, err := lib.RunUID(0, cli, nil) + out, err := session.RunUID(0, cli, nil) tmpout := CommandOutput{}.New(out, err) tmpout.Context = up.Config.Description tmpout.Cli = cli @@ -84,9 +85,9 @@ func (up *DistroboxUpdater) Update() (*[]CommandOutput, error) { for _, user := range up.users { up.Tracker.Tracker.IncrementSection(err) context := *up.Config.UserDescription + " " + user.Name - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) cli := []string{up.binaryPath, "upgrade", "-a"} - out, err := lib.RunUID(user.UID, cli, nil) + out, err := session.RunUID(user.UID, cli, nil) tmpout = CommandOutput{}.New(out, err) tmpout.Context = context tmpout.Cli = cli diff --git a/drv/flatpak.go b/drv/flatpak.go index 7b524c6..ee76e13 100644 --- a/drv/flatpak.go +++ b/drv/flatpak.go @@ -3,14 +3,15 @@ package drv import ( "os/exec" - "github.com/ublue-os/uupd/lib" + "github.com/ublue-os/uupd/pkg/percent" + "github.com/ublue-os/uupd/pkg/session" ) type FlatpakUpdater struct { Config DriverConfiguration Tracker *TrackerConfiguration binaryPath string - users []lib.User + users []session.User usersEnabled bool } @@ -49,7 +50,7 @@ func (up FlatpakUpdater) New(config UpdaterInitConfiguration) (FlatpakUpdater, e return up, nil } -func (up *FlatpakUpdater) SetUsers(users []lib.User) { +func (up *FlatpakUpdater) SetUsers(users []session.User) { up.users = users up.usersEnabled = true } @@ -62,18 +63,18 @@ func (up FlatpakUpdater) Update() (*[]CommandOutput, error) { var finalOutput = []CommandOutput{} if up.Config.DryRun { - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) up.Tracker.Tracker.IncrementSection(nil) var err error = nil for _, user := range up.users { up.Tracker.Tracker.IncrementSection(err) - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) } return &finalOutput, nil } - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) cli := []string{up.binaryPath, "update", "-y"} flatpakCmd := exec.Command(cli[0], cli[1:]...) out, err := flatpakCmd.CombinedOutput() @@ -87,9 +88,9 @@ func (up FlatpakUpdater) Update() (*[]CommandOutput, error) { for _, user := range up.users { up.Tracker.Tracker.IncrementSection(err) context := *up.Config.UserDescription + " " + user.Name - lib.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, lib.TrackerMessage{Title: up.Config.Title, Description: context}) + percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: context}) cli := []string{up.binaryPath, "update", "-y"} - out, err := lib.RunUID(user.UID, cli, nil) + out, err := session.RunUID(user.UID, cli, nil) tmpout = CommandOutput{}.New(out, err) tmpout.Context = context tmpout.Cli = cli diff --git a/drv/generic.go b/drv/generic.go index 133fe74..95a7d1c 100644 --- a/drv/generic.go +++ b/drv/generic.go @@ -5,7 +5,8 @@ import ( "strings" "github.com/jedib0t/go-pretty/v6/progress" - "github.com/ublue-os/uupd/lib" + "github.com/ublue-os/uupd/pkg/percent" + "github.com/ublue-os/uupd/pkg/session" ) type EnvironmentMap map[string]string @@ -72,7 +73,7 @@ type DriverConfiguration struct { } type TrackerConfiguration struct { - Tracker *lib.IncrementTracker + Tracker *percent.IncrementTracker Writer *progress.Writer Progress bool } @@ -86,5 +87,5 @@ type UpdateDriver interface { type MultiUserUpdateDriver interface { *UpdateDriver - SetUsers(users []lib.User) + SetUsers(users []session.User) } diff --git a/drv/system.go b/drv/system.go index f4c5784..1e7c2d1 100644 --- a/drv/system.go +++ b/drv/system.go @@ -95,8 +95,8 @@ func (up SystemUpdater) Steps() int { func (up SystemUpdater) New(config UpdaterInitConfiguration) (SystemUpdater, error) { up.Config = DriverConfiguration{ - Title: "System", - Description: "System Updates", + Title: "Bootc", + Description: "System Image", Enabled: !config.Ci, DryRun: config.DryRun, Environment: config.Environment, diff --git a/go.mod b/go.mod index 516e317..cc7f8bf 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/shirou/gopsutil/v4 v4.24.10 github.com/spf13/cobra v1.8.1 golang.org/x/term v0.26.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -23,5 +24,4 @@ require ( github.com/tklauser/numcpus v0.6.1 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/sys v0.27.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 1084bc0..e589ba7 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,7 @@ golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/lib/filelock.go b/pkg/filelock/filelock.go similarity index 98% rename from lib/filelock.go rename to pkg/filelock/filelock.go index 685d2ba..88d6147 100644 --- a/lib/filelock.go +++ b/pkg/filelock/filelock.go @@ -1,4 +1,4 @@ -package lib +package filelock import ( "fmt" diff --git a/lib/colorpicker.go b/pkg/percent/colorpicker.go similarity index 99% rename from lib/colorpicker.go rename to pkg/percent/colorpicker.go index 8993686..32043e4 100644 --- a/lib/colorpicker.go +++ b/pkg/percent/colorpicker.go @@ -1,4 +1,4 @@ -package lib +package percent import ( "math" diff --git a/lib/percentmanager.go b/pkg/percent/progressmanager.go similarity index 86% rename from lib/percentmanager.go rename to pkg/percent/progressmanager.go index 1aab529..10e5dbd 100644 --- a/lib/percentmanager.go +++ b/pkg/percent/progressmanager.go @@ -1,4 +1,4 @@ -package lib +package percent import ( "encoding/json" @@ -11,6 +11,7 @@ import ( "github.com/jedib0t/go-pretty/v6/progress" "github.com/jedib0t/go-pretty/v6/text" + "github.com/ublue-os/uupd/pkg/session" ) type Incrementer struct { @@ -50,8 +51,7 @@ func NewProgressWriter() progress.Writer { pw.SetUpdateFrequency(time.Millisecond * 100) pw.Style().Options.PercentFormat = "%4.1f%%" - colorsSet := CuteColors - pw.Style().Colors = colorsSet + pw.Style().Colors = CuteColors var targetUser int baseUser, exists := os.LookupEnv("SUDO_UID") @@ -67,12 +67,16 @@ func NewProgressWriter() progress.Writer { } if targetUser != 0 { + var accentColorSet progress.StyleColors + // Get accent color: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Settings.html cli := []string{"busctl", "--user", "--json=short", "call", "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.portal.Settings", "ReadOne", "ss", "org.freedesktop.appearance", "accent-color"} - out, err := RunUID(targetUser, cli, nil) + out, err := session.RunUID(targetUser, cli, nil) + if err != nil { + return pw + } var accent Accent err = json.Unmarshal(out, &accent) if err != nil { - pw.Style().Colors = colorsSet return pw } @@ -83,13 +87,13 @@ func NewProgressWriter() progress.Writer { validHighlightColor := text.Colors{highlightColor} validLowColor := text.Colors{lowColor} - colorsSet.Percent = validHighlightColor - colorsSet.Tracker = validHighlightColor - colorsSet.Time = validLowColor - colorsSet.Value = validLowColor - colorsSet.Speed = validLowColor + accentColorSet.Percent = validHighlightColor + accentColorSet.Tracker = validHighlightColor + accentColorSet.Time = validLowColor + accentColorSet.Value = validLowColor + accentColorSet.Speed = validLowColor + pw.Style().Colors = accentColorSet } - pw.Style().Colors = colorsSet return pw } diff --git a/lib/session.go b/pkg/session/session.go similarity index 93% rename from lib/session.go rename to pkg/session/session.go index 6b676f1..23a5a1d 100644 --- a/lib/session.go +++ b/pkg/session/session.go @@ -1,4 +1,4 @@ -package lib +package session import ( "fmt" @@ -12,8 +12,7 @@ type User struct { } func RunUID(uid int, command []string, env map[string]string) ([]byte, error) { - // Just fork systemd-run, using the systemd API gave me a massive headache - // FIXME: use the systemd api instead + // Just fork systemd-run, we don't need to rewrite systemd-run with dbus cmdArgs := []string{ "/usr/bin/systemd-run", "--machine",