Initial commit
This commit is contained in:
commit
b905244626
17 changed files with 1462 additions and 0 deletions
30
cmd/utils.go
Normal file
30
cmd/utils.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func checkIfRoot() (bool, error) {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "get current user")
|
||||
}
|
||||
return currentUser.Username == "root", nil
|
||||
}
|
||||
|
||||
func doRootCheck() {
|
||||
ok, err := checkIfRoot()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to check whether the command is ran by root: %v.\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !ok {
|
||||
fmt.Printf("Root permissions are required.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue