simplify simplify
Jes Olson j3s@c3f.net
Tue, 22 Nov 2022 19:15:56 -0800
1 files changed,
28 insertions(+),
71 deletions(-)
jump to
M
main.go
→
main.go
@@ -4,7 +4,6 @@ import (
"fmt" "log" "os" - "os/exec" "path/filepath" "j3s.sh/zoa/env"@@ -13,6 +12,29 @@
"mvdan.cc/sh/v3/interp" ) +func printUsageExit() { + // TODO: -v -h + fmt.Printf(`usage: zoa <command> [arguments] + +commands: + run <main|scripts/example> - execute given zoa script + version - print zoa version + +examples: + zoa run main + zoa run scripts/hello-world + +misc commands: + cp <src> <dst> [mode] - copy file from source to dest, optionally set mode + get <url> <dst> - download file from url to dest + watch <file> <command> - execute command when file changes + +examples: see README +`) + + os.Exit(1) +} + func main() { if len(os.Args) <= 1 { printUsageExit()@@ -20,8 +42,6 @@ }
command := os.Args[1] switch command { - case "deploy": - zoaDeployShitty() case "run": zoaRun() case "version":@@ -38,6 +58,11 @@ fmt.Println("run requires 1 argument: the path to a posix shell script")
os.Exit(1) } path := os.Args[2] + + if path != "main" { + fmt.Println("incorrect script name: script must be named either main or scripts/<scriptname>") + os.Exit(1) + } envs, err := env.GenerateEnv() if err != nil {@@ -64,71 +89,3 @@
// todo: err? session.Run() } - -// ignore this for now, i'll make it better i promise 🥺 -func zoaDeployShitty() { - if len(os.Args) <= 2 { - fmt.Println("deploy requires 1+ arguments: hostnames to deploy + run zoa on") - os.Exit(1) - } - hosts := os.Args[2:] - - zoaPath, err := exec.LookPath("zoa") - if err != nil { - log.Fatal("(TODO) please install zoa to /usr/local/bin and ensure it's in your PATH") - } - - // TODO: replace remote binary if newer - // err = shell.SSH("command -v zoa", hosts) - // if err != nil { - // Install Zoa - err = shell.SCP(zoaPath, hosts) - if err != nil { - log.Fatal(err) - } - err = shell.SSH("chmod +x zoa", hosts) - if err != nil { - log.Fatal(err) - } - err = shell.SSH("mv zoa /usr/local/bin/", hosts) - if err != nil { - subErr := shell.SSH("sudo mv zoa /usr/local/bin/", hosts) - if subErr != nil { - log.Fatal(err) - } - } - - err = shell.SCP("main", hosts) - if err != nil { - log.Fatal(err) - } - err = shell.SCPDir("scripts", hosts) - if err != nil { - log.Fatal(err) - } - err = shell.SCPDir("files", hosts) - if err != nil { - log.Fatal(err) - } - err = shell.SSH("sudo zoa .", hosts) - if err != nil { - log.Fatal(err) - } - os.Exit(0) -} - -func printUsageExit() { - // TODO: -v -h - fmt.Println(`usage: zoa <command> [arguments] - -commands: - deploy <hostname/ip> - install zoa on the given host & execute - run <script> - execute the given zoa script - version - print zoa version - -examples: - zoa run config-my-shit-pwease - zoa run /var/lib/my-zoa-repo/main - zoa deploy . web.j3s.sh git.j3s.sh`) - os.Exit(1) -}