Skip to content

Commit

Permalink
Relax root requirement for help/completion
Browse files Browse the repository at this point in the history
  • Loading branch information
ledif committed Dec 2, 2024
1 parent 399cc6f commit 09dea18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 18 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,56 @@ package cmd

import (
"fmt"
"log"
"github.com/spf13/cobra"
"os"
"os/user"
)

func assertRoot(cmd *cobra.Command, args []string) {
currentUser, err := user.Current()

if err != nil {
log.Fatalf("Error fetching current user: %v", err)
}
if currentUser.Uid != "0" {
log.Fatalf("uupd needs to be invoked as root.")
}
}

var (
rootCmd = &cobra.Command{
Use: "uupd",
Short: "uupd (Universal Update) is the successor to ublue-update, built for bootc",
PreRun: assertRoot,
Run: Update,
}

waitCmd = &cobra.Command{
Use: "wait",
Short: "Waits for ostree sysroot to unlock",
PreRun: assertRoot,
Run: Wait,
}

updateCheckCmd = &cobra.Command{
Use: "update-check",
Short: "Check for updates to the booted image",
PreRun: assertRoot,
Run: UpdateCheck,
}

hardwareCheckCmd = &cobra.Command{
Use: "hw-check",
Short: "Run hardware checks",
PreRun: assertRoot,
Run: HwCheck,
}

imageOutdatedCmd = &cobra.Command{
Use: "is-img-outdated",
Short: "Print 'true' or 'false' based on if the current booted image is over 1 month old",
PreRun: assertRoot,
Run: ImageOutdated,
}
)
Expand Down
8 changes: 0 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ package main
import (
"github.com/ublue-os/uupd/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("uupd needs to be invoked as root.")
}
cmd.Execute()
}

0 comments on commit 09dea18

Please sign in to comment.