Skip to content

Commit

Permalink
refactor: move lib files to pkg (#39)
Browse files Browse the repository at this point in the history
* refactor: remove lib inplace of pkg

* docs: change update name

* docs: change title to bootc

* ci: change name

* ci: don't run goreleaser on PR
  • Loading branch information
gerblesh authored Dec 13, 2024
1 parent 594a200 commit 9b5bd00
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main
workflow_dispatch:
env:
IMAGE_NAME: ublue-update
IMAGE_NAME: uupd
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}

jobs:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: goreleaser

on:
pull_request:
push:
tags:
- "*"
Expand Down
24 changes: 13 additions & 11 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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{
Expand All @@ -155,23 +157,23 @@ 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")
}
slog.Warn(OUTDATED_WARNING)
}

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...)
tracker.IncrementSection(err)
}

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)
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cmd/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions drv/brew.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 10 additions & 9 deletions drv/distrobox.go
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 9 additions & 8 deletions drv/flatpak.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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()
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions drv/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,7 +73,7 @@ type DriverConfiguration struct {
}

type TrackerConfiguration struct {
Tracker *lib.IncrementTracker
Tracker *percent.IncrementTracker
Writer *progress.Writer
Progress bool
}
Expand All @@ -86,5 +87,5 @@ type UpdateDriver interface {

type MultiUserUpdateDriver interface {
*UpdateDriver
SetUsers(users []lib.User)
SetUsers(users []session.User)
}
4 changes: 2 additions & 2 deletions drv/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 1 addition & 1 deletion lib/filelock.go → pkg/filelock/filelock.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package filelock

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion lib/colorpicker.go → pkg/percent/colorpicker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package percent

import (
"math"
Expand Down
Loading

0 comments on commit 9b5bd00

Please sign in to comment.