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
package main import ( "fmt" "log" "os" "path/filepath" "j3s.sh/zoa/git" "j3s.sh/zoa/shell" "j3s.sh/zoa/utils" ) func main() { // git vars var branch 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 { utils.SetZoaRoot("/var/lib/zoa/repo") err := os.MkdirAll(utils.ZoaRoot, 0755) if err != nil { log.Fatal(err) } // check the path & branch, make sure it's correct // then clone git.Clone(path, branch) } else { utils.SetZoaRoot(path) } // TODO: this writer is responsible for the random stdout // maybe save the stdout for debug mode somehow main := filepath.Join(utils.ZoaRoot, "main") shell.RunScript(main) } 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) }