71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/user"
|
|
|
|
"git.pauljako.de/rodeo/rodeo-pkg/add"
|
|
)
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 2 {
|
|
fail("A subcommand is required. Use \"" + os.Args[0] + " help\" for help")
|
|
}
|
|
|
|
switch os.Args[1] {
|
|
case "install":
|
|
if !make_sure_root() {
|
|
fail("This subcommand requires root")
|
|
}
|
|
case "uninstall":
|
|
if !make_sure_root() {
|
|
fail("This subcommand requires root")
|
|
}
|
|
case "remove":
|
|
if !make_sure_root() {
|
|
fail("This subcommand requires root")
|
|
}
|
|
case "add":
|
|
if !make_sure_root() {
|
|
fail("This subcommand requires root")
|
|
}
|
|
add.AddFromCli(os.Args[2:])
|
|
case "help":
|
|
printHelp()
|
|
default:
|
|
fail("Unknown subcommand: " + os.Args[1] + ". Use \"" + os.Args[0] + " help\" for help")
|
|
}
|
|
|
|
}
|
|
|
|
func fail(reason string) {
|
|
fmt.Printf("An Error occurred: %v\n", reason)
|
|
os.Exit(1)
|
|
}
|
|
|
|
func make_sure_root() bool {
|
|
currentUser, err := user.Current()
|
|
if err != nil {
|
|
fmt.Println("An Error occured while checking for root: " + err.Error())
|
|
return true
|
|
}
|
|
|
|
return currentUser.Uid == "0"
|
|
}
|
|
|
|
func printHelp() {
|
|
help_text := `%v: The Package Manager for the rodeo-overlay system
|
|
|
|
Available Subcommands:
|
|
- install: fetch and activate a package
|
|
- uninstall: deactivate and remove a package
|
|
- add: activate a package
|
|
- remove: deactivate a package
|
|
- help: show this help and exit
|
|
`
|
|
|
|
fmt.Printf(help_text, os.Args[0])
|
|
os.Exit(0)
|
|
}
|