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
package main import ( "fmt" "log" "os" "path/filepath" "j3s.sh/zoa/env" "j3s.sh/zoa/git" "j3s.sh/zoa/shell" "mvdan.cc/sh/v3/interp" ) const ( zoaRoot = "/var/lib/zoa" ) func main() { // git vars var branch string var entryPointDir string if os.Geteuid() != 0 { fmt.Println("! you are running zoa as a non-root user. not ideal tbh. !") } if len(os.Args) < 2 { printUsage() } if len(os.Args) > 2 { branch = os.Args[2] } path := os.Args[1] gitMode := git.GitMode(path) if gitMode { err := os.MkdirAll(zoaRoot, 0755) if err != nil { log.Fatal(err) } // check the path & branch, make sure it's correct // then clone git.Clone(path, branch) entryPointDir = filepath.Join(zoaRoot, "repo") } else { entryPointDir = path } // TODO: this writer is responsible for the random stdout // maybe save the stdout for debug mode somehow r, err := interp.New(interp.StdIO(nil, os.Stdout, os.Stderr)) if err != nil { log.Fatal(err) } // set standard env vars for runtime r.Env, err = env.GenerateEnv() if err != nil { log.Fatal(err) } // for debuggin' fmt.Printf("%+v", r.Env) shell.RunCommands(entryPointDir, "main", r) } func printUsage() { // TODO: -v -h fmt.Println(`usage: zoa [git repo | fs path] [optional git branch] details: zoa [git repo] [optional branch] zoa will clone the given repo+branch to /var/lib/zoa/repo and execute main. if the given repo/branch is already present, zoa will git fetch, then execute main. zoa [filesystem path] zoa will cd to the given path & execute the main script there (mostly used for development) examples: zoa https://github.com/biox/zoa zoa https://github.com/biox/zoa dev zoa .`) os.Exit(1) }