Squash some b0rgs
Jes Olson j3s@c3f.net
Tue, 27 Sep 2022 20:58:35 -0500
5 files changed,
24 insertions(+),
16 deletions(-)
M
README
→
README
@@ -270,6 +270,12 @@ files/ contains text files (no big files or binaries) that you might be
interested in placing on hosts. these can be accessed with the zoa-file function. + wat is borked? + - branch cloning doesn't work rn idk why + - the cloned git repo has root perms & git hates that + - the repo is re-cloned on every run *shrug* + + BONUS SECTION! :3 :3 <3 :3 common config management patterns to zoa
M
git/git.go
→
git/git.go
@@ -4,6 +4,8 @@ import (
"os" "strings" + "j3s.sh/zoa/utils" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" )@@ -40,12 +42,14 @@ // technique
os.RemoveAll(clonePath) // Tempdir to clone the repository cloneopts := &git.CloneOptions{ - URL: repo, - Progress: os.Stdout, + URL: repo, } + msg := "-> cloning " + repo if branch != "" { + msg += "@" + branch cloneopts.ReferenceName = plumbing.ReferenceName(branch) } + utils.BluePrintln(msg) _, err := git.PlainClone(clonePath, false, cloneopts) return err
M
main.go
→
main.go
@@ -42,7 +42,7 @@ }
// check the path & branch, make sure it's correct // then clone git.Clone(path, branch) - entryPointDir = zoaRoot + entryPointDir = filepath.Join(zoaRoot, "repo") } else { entryPointDir = path }@@ -61,8 +61,7 @@ log.Fatal(err)
} // for debuggin' fmt.Printf("%+v", r.Env) - entrypoint := filepath.Join(entryPointDir, "main") - shell.RunCommands(entrypoint, r) + shell.RunCommands(entryPointDir, "main", r) } func printUsage() {
M
shell/shell.go
→
shell/shell.go
@@ -21,10 +21,8 @@ // us to prettily-print
var lastScriptPath string var ctx = context.Background() -// TODO: make dis a git dingy -var rootDir = "test/" - -func RunCommands(scriptPath string, r *interp.Runner) { +func RunCommands(zoaRoot string, scriptName string, r *interp.Runner) { + scriptPath := filepath.Join(zoaRoot, scriptName) script, err := parseFile(scriptPath) if err != nil { fmt.Println("error in " + scriptPath)@@ -40,9 +38,9 @@ cmdName := commandName(stmt)
command, after, _ := strings.Cut(cmdName, " ") if command == "zoa-script" { - // recursion detected!! :3 - subScriptPath := filepath.Join(rootDir + "scripts/" + after) - RunCommands(subScriptPath, r) + // recursion detected!!!!!! :3 :3 :3 + subScriptPath := filepath.Join("scripts/" + after) + RunCommands(zoaRoot, subScriptPath, r) continue }@@ -59,7 +57,8 @@ if len(zoaFileParts) > 2 {
optionalCmd = strings.Join(zoaFileParts[2:], " ") } fmt.Printf("$ zoa-file %s %s\n", src, dst) - dstChanged, err := zoaCopy(src, dst) + filePath := filepath.Join(zoaRoot, "files", src) + dstChanged, err := zoaCopy(filePath, dst) if err != nil { log.Fatal(err) }@@ -75,7 +74,7 @@ for _, stmt := range f.Stmts {
runCommand(ctx, stmt, r) } } - return + continue } // if the script name changed between runs,@@ -86,6 +85,7 @@ lastScriptPath = scriptPath
} fmt.Printf("$ %s\n", cmdName) + // todo: better colorz idk utils.BluePrintln("$ " + cmdName) err = r.Run(ctx, stmt) if err != nil { // ignore err here bc it's just the status code@@ -125,7 +125,6 @@ // if the dst was changed, zoaCopy will return true,
// otherwise it will return false // zoaCopy defaults to 0666 for permissions (before umask) func zoaCopy(src string, dst string) (bool, error) { - src = filepath.Join(rootDir + "scripts/" + src) srcChk, err := utils.ChecksumFile(src) if err != nil { // source file should always exist, return error