mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-01 17:16:40 +00:00
Move checkRoot to main
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
36
main.go
36
main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -119,7 +120,8 @@ See https://kairos.io/docs/upgrade/manual/ for documentation.
|
||||
return fmt.Errorf("source %s does not match any of oci:, dir: or file: ", source)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
var v string
|
||||
@@ -230,6 +232,9 @@ E.g. kairos-agent install-bundle container:quay.io/kairos/kairos...
|
||||
},
|
||||
},
|
||||
UsageText: "Install a bundle manually in the node",
|
||||
Before: func(c *cli.Context) error {
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
if c.Args().Len() != 1 {
|
||||
return fmt.Errorf("bundle name required")
|
||||
@@ -382,6 +387,9 @@ This command is meant to be used from the boot GRUB menu, but can be also starte
|
||||
},
|
||||
},
|
||||
Usage: "Starts interactive installation",
|
||||
Before: func(c *cli.Context) error {
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
return agent.InteractiveInstall(c.Bool("debug"), c.Bool("shell"))
|
||||
},
|
||||
@@ -403,6 +411,9 @@ This command is meant to be used from the boot GRUB menu, but can be also starte
|
||||
Name: "reboot",
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
if c.NArg() == 0 {
|
||||
return fmt.Errorf("expect one argument. the config file - if you don't have it, use the interactive-install")
|
||||
@@ -424,6 +435,9 @@ See also https://kairos.io/docs/installation/qrcode/ for documentation.
|
||||
|
||||
This command is meant to be used from the boot GRUB menu, but can be started manually`,
|
||||
Aliases: []string{"i"},
|
||||
Before: func(c *cli.Context) error {
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
return agent.Install(configScanDir...)
|
||||
},
|
||||
@@ -457,6 +471,9 @@ This command is meant to be used from the boot GRUB menu, but can likely be used
|
||||
Usage: "Do not wait for user input and provide ttys after reset. Also sets the fast mode (do not wait 60 seconds before reset)",
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
reboot := c.Bool("reboot")
|
||||
unattended := c.Bool("unattended")
|
||||
@@ -535,7 +552,8 @@ The validate command expects a configuration file as its only argument. Local fi
|
||||
_ = cli.ShowSubcommandHelp(c)
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
return nil
|
||||
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
stage := c.Args().First()
|
||||
@@ -574,11 +592,7 @@ The validate command expects a configuration file as its only argument. Local fi
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
if os.Geteuid() != 0 {
|
||||
return fmt.Errorf("this command requires root privileges")
|
||||
}
|
||||
|
||||
return nil
|
||||
return checkRoot()
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
image := c.Args().Get(0)
|
||||
@@ -664,3 +678,11 @@ The kairos agent is a component to abstract away node ops, providing a common fe
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func checkRoot() error {
|
||||
if os.Geteuid() != 0 {
|
||||
return errors.New("this command requires root privileges")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user