summaryrefslogtreecommitdiff
path: root/exit.go
blob: a611bb8c1d42f93849309b2167a3ce29ebfa473b (plain)
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
52
53
54
55
56
57
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"
	"os"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

// exits if not root
func checkSuperuser() {
	if os.Getuid() != 0 {
		badExit(fmt.Errorf("you must be root"))
	}
}

func areSuperuser() bool {
	if os.Getuid() == 0 {
		return true
	}
	return false
}

func exitOnError(cmd []string) {
	var err error
	log.Info("Running:", cmd)
	_, err = shell.RunVerbose(cmd)
	if err != nil {
		badExit(err)
	}
}

func exitOnErrorRealtime(cmd []string) {
	var err error
	log.Info("Running:", cmd)
	_, err = shell.RunRealtimeError(cmd)
	if err != nil {
		badExit(err)
	}
}

func okExit(thing string) {
	if thing != "" {
		log.Info(thing, "ok")
	}
	// log.Info("Finished go-clean on", check.GetGoPath(), "ok")
	os.Exit(0)
}

func badExit(err error) {
	me.sh.BadExit("wit failed: ", err)
	os.Exit(-1)
}