-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
52 lines (41 loc) · 853 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
var (
reset = "\033[0m"
bold = "\033[1m"
)
func isRoot() bool {
return os.Getuid() == 0
}
func checkRoot() {
if !isRoot() {
err("Shade must be ran as root")
os.Exit(1)
}
}
func rev(s string) string {
return "\033[7m" + s + "\033[0m";
}
func success(s ...string) {
fmt.Printf("%s\033[32m%s%s\n", bold, strings.Join(s, " "), reset)
}
func info(s ...string) {
fmt.Printf("%s\033[34m%s%s\n", bold, strings.Join(s, " "), reset)
}
func err(s ...string) {
fmt.Printf("%s\033[31m%s%s\n", bold, strings.Join(s, " "), reset)
}
func run(cmdstr string) {
cmdArgs := strings.Fields(cmdstr)
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
fmt.Printf("Command finished with error: %v\n", err)
return
}