-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
179 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gerblesh/update-next/checks" | ||
"github.com/godbus/dbus/v5" | ||
"github.com/spf13/cobra" | ||
"log" | ||
) | ||
|
||
func HwCheck(cmd *cobra.Command, args []string) { | ||
// (some hardware checks require dbus access) | ||
conn, err := dbus.SystemBus() | ||
err := checks.RunHwChecks() | ||
if err != nil { | ||
log.Fatalf("Failed to connect to session bus: %v", err) | ||
} | ||
defer conn.Close() | ||
checkInfo := checks.Hardware(conn) | ||
for _, info := range checkInfo { | ||
if info.Err != nil { | ||
log.Fatalf("Hardware checks failed for %s, returned error: %v", info.Name, info.Err) | ||
} | ||
log.Fatalf("Hardware checks failed: %v", err) | ||
} | ||
log.Println("Hardware checks passed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,150 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/gerblesh/update-next/checks" | ||
"github.com/gerblesh/update-next/drv" | ||
"github.com/gerblesh/update-next/lib" | ||
"github.com/godbus/dbus/v5" | ||
// "github.com/schollz/progressbar/v3" | ||
"github.com/spf13/cobra" | ||
"log" | ||
) | ||
|
||
func Update(cmd *cobra.Command, args []string) { | ||
type Failure struct { | ||
Err error | ||
Output string | ||
} | ||
|
||
// (some hardware checks require dbus access) | ||
conn, err := dbus.SystemBus() | ||
func Update(cmd *cobra.Command, args []string) { | ||
hwCheck, err := cmd.Flags().GetBool("hw-check") | ||
if err != nil { | ||
log.Fatalf("Failed to connect to session bus: %v", err) | ||
log.Fatalf("Failed to get hw-check flag: %v", err) | ||
} | ||
defer conn.Close() | ||
checkInfo := checks.Hardware(conn) | ||
for _, info := range checkInfo { | ||
if info.Err != nil { | ||
log.Fatalf("Hardware checks failed for %s, returned error: %v", info.Name, info.Err) | ||
|
||
if hwCheck { | ||
err := checks.RunHwChecks() | ||
if err != nil { | ||
log.Fatalf("Hardware checks failed: %v", err) | ||
} | ||
log.Println("Hardware checks passed") | ||
} | ||
log.Println("Hardware checks passed") | ||
|
||
users, err := lib.ListUsers() | ||
if err != nil { | ||
log.Fatalf("Failed to list users") | ||
} | ||
// Check if bootc update is available | ||
updateAvailable, err := drv.CheckForUpdate() | ||
bootcUpdate := 0 | ||
if updateAvailable { | ||
bootcUpdate = 1 | ||
} | ||
|
||
// Check if brew is installed | ||
brewUid, brewErr := drv.GetBrewUID() | ||
brewUpdate := 0 | ||
if brewErr == nil { | ||
brewUpdate = 1 | ||
} | ||
|
||
totalUpdates := brewUpdate + bootcUpdate + 1 + len(users) + 1 + len(users) // Bootc + Brew + Flatpak (users + root) + Distrobox (users + root) | ||
currentUpdate := 0 | ||
if err != nil { | ||
log.Fatalf("Failed to check for image updates: %v", err) | ||
} | ||
log.Printf("update available: %v", updateAvailable) | ||
failures := make(map[string]Failure) | ||
|
||
if updateAvailable { | ||
err = drv.BootcUpdate() | ||
currentUpdate++ | ||
log.Printf("[%d/%d] Updating System (Bootc)", currentUpdate, totalUpdates) | ||
out, err := drv.BootcUpdate() | ||
if err != nil { | ||
log.Fatalf("Failed to update system: %v", err) | ||
failures["Bootc"] = Failure{ | ||
err, | ||
string(out), | ||
} | ||
} | ||
} | ||
err = drv.BrewUpdate() | ||
if err != nil { | ||
log.Fatalf("Failed to update brew: %v", err) | ||
|
||
if brewUpdate == 1 { | ||
currentUpdate++ | ||
log.Printf("[%d/%d] Updating CLI Apps (Brew)", currentUpdate, totalUpdates) | ||
out, err := drv.BrewUpdate(brewUid) | ||
if err != nil { | ||
failures["Brew"] = Failure{ | ||
err, | ||
string(out), | ||
} | ||
} | ||
} | ||
|
||
users, err := lib.ListUsers() | ||
// Run flatpak updates | ||
currentUpdate++ | ||
log.Printf("[%d/%d] Updating System Apps (Flatpak)", currentUpdate, totalUpdates) | ||
flatpakCmd := exec.Command("/usr/bin/flatpak", "update", "-y") | ||
out, err := flatpakCmd.CombinedOutput() | ||
if err != nil { | ||
log.Fatalf("ERROR: %v", err) | ||
failures["Flatpak"] = Failure{ | ||
err, | ||
string(out), | ||
} | ||
} | ||
err = drv.FlatpakUpdate(users) | ||
for _, user := range users { | ||
currentUpdate++ | ||
log.Printf("[%d/%d] Updating User Apps for user: %s (Flatpak)", currentUpdate, totalUpdates, user.Name) | ||
out, err := lib.RunUID(user.UID, []string{"/usr/bin/flatpak", "update", "-y"}, nil) | ||
if err != nil { | ||
failures[fmt.Sprintf("Flatpak User: %s", user.Name)] = Failure{ | ||
err, | ||
string(out), | ||
} | ||
} | ||
} | ||
|
||
// Run distrobox updates | ||
log.Printf("[%d/%d] Updating System Distroboxes", currentUpdate, totalUpdates) | ||
currentUpdate++ | ||
// distrobox doesn't support sudo, run with systemd-run | ||
out, err = lib.RunUID(0, []string{"/usr/bin/distrobox", "upgrade", "-a"}, nil) | ||
if err != nil { | ||
log.Fatalf("Failed to update flatpak: %v", err) | ||
failures["Distrobox"] = Failure{ | ||
err, | ||
string(out), | ||
} | ||
} | ||
for _, user := range users { | ||
currentUpdate++ | ||
log.Printf("[%d/%d] Updating User Distroboxes: %s", currentUpdate, totalUpdates, user.Name) | ||
out, err := lib.RunUID(user.UID, []string{"/usr/bin/distrobox", "upgrade", "-a"}, nil) | ||
if err != nil { | ||
failures[fmt.Sprintf("Distrobox User: %s", user.Name)] = Failure{ | ||
err, | ||
string(out), | ||
} | ||
} | ||
} | ||
|
||
if len(failures) > 0 { | ||
failedSystemsList := make([]string, 0, len(failures)) | ||
for systemName := range failures { | ||
failedSystemsList = append(failedSystemsList, systemName) | ||
} | ||
failedSystemsStr := strings.Join(failedSystemsList, ", ") | ||
lib.Notify("Updates failed", fmt.Sprintf("ublue-upd failed to update: %s", failedSystemsStr)) | ||
|
||
log.Printf("Update Failures:") | ||
for name, fail := range failures { | ||
indentedOutput := "\t | " | ||
lines := strings.Split(fail.Output, "\n") | ||
for i, line := range lines { | ||
if i > 0 { | ||
indentedOutput += "\n\t | " | ||
} | ||
indentedOutput += line | ||
} | ||
log.Printf("---> %s \n\t | Failure error: %v \n\t | Command Output: \n%s", name, fail.Err, indentedOutput) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package main | ||
|
||
import "github.com/gerblesh/update-next/cmd" | ||
import ( | ||
"github.com/gerblesh/update-next/cmd" | ||
"log" | ||
"os/user" | ||
) | ||
|
||
func main() { | ||
log.SetFlags(0) | ||
currentUser, err := user.Current() | ||
if err != nil { | ||
log.Fatalf("Error fetching current user: %v", err) | ||
} | ||
if currentUser.Uid != "0" { | ||
log.Fatalf("ublue-upd needs to be invoked as root.") | ||
} | ||
cmd.Execute() | ||
} |