-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (70 loc) · 1.56 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"flag"
"io/ioutil"
"os"
log "github.com/sirupsen/logrus"
)
var (
debug bool
scriptType string
)
const (
workDir = "/var/lib/oci"
workShell = "/bin/bash"
)
// ScriptManager definition of the manager to handle the script management
type ScriptManager struct {
Type ScriptType
WorkDir string
WorkShell string
attributes [2]string
}
func main() {
flag.BoolVar(&debug, "debug", false, "display debug information")
flag.StringVar(&scriptType, "script-type", "unknown", "script type to run")
flag.Parse()
if debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
st, err := ParseScriptType(scriptType)
if err != nil {
log.Error("No valid argument specified for script type")
log.Errorf("%s : %s", err, scriptType)
os.Exit(1)
}
log.Infof("starting %s scripts", st)
wd, err := ioutil.TempDir(workDir, st.String()+"-")
if err != nil {
log.Errorf("error creating temp work directory : %s", err)
os.Exit(1)
}
defer func() {
if !debug {
_ = os.RemoveAll(wd)
} else {
log.Debug("not removing work dir : ", wd)
}
}()
log.Debugf("temp work directory is : %s", wd)
mgr := &ScriptManager{
Type: st,
WorkDir: wd,
WorkShell: workShell,
attributes: [...]string{"script-url", "script"},
}
scripts, err := mgr.FetchScripts()
if err != nil {
log.Errorf("error retrieving %s scripts : %s", st, err)
os.Exit(1)
}
for _, s := range scripts {
err := mgr.RunScript(s)
if err != nil {
log.Errorf("%s", err)
}
}
log.Infof("Finished running %s scripts", st)
}