diff options
| -rw-r--r-- | apt.go | 52 | ||||
| -rw-r--r-- | doBuild.go | 17 | ||||
| -rw-r--r-- | doClone.go | 8 | ||||
| -rw-r--r-- | doDebian.go | 10 | ||||
| -rw-r--r-- | doGit.go | 12 | ||||
| -rw-r--r-- | exit.go | 20 | ||||
| -rw-r--r-- | main.go | 20 | ||||
| -rw-r--r-- | upgrade.go | 2 |
8 files changed, 40 insertions, 101 deletions
@@ -1,52 +0,0 @@ -// Copyright 2017-2025 WIT.COM Inc. All rights reserved. -// Use of this source code is governed by the GPL 3.0 - -package main - -/* -func aptInstall(pkgname string) (*cmd.Status, error) { - cmd := []string{"apt-get", "install", "-y", pkgname} - log.Info("Running:", cmd) - return shell.RunRealtimeError(cmd) -} - -func aptInstallOrExit(pkgname string) { - if _, err := aptInstall(pkgname); err != nil { - badExit(err) - } -} - -func aptRemove(pkgname string) (*cmd.Status, error) { - if pkgname == "mirrors.wit.com" { - return nil, nil - } - cmd := []string{"apt-get", "remove", "-y", pkgname} - log.Info("Running:", cmd) - return shell.RunRealtimeError(cmd) -} - -func aptRemoveOrExit(pkgname string) { - if _, err := aptRemove(pkgname); err != nil { - badExit(err) - } -} - -// apt-get update \ -// -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/wit.list \ -// -o Dir::Etc::sourceparts=/dev/null \ -// -o APT::Get::List-Cleanup=0 -func aptUpdate() { - cmd := []string{"apt-get", "update"} - cmd = append(cmd, "-o", "Dir::Etc::sourcelist=/etc/apt/sources.list.d/wit.list") - cmd = append(cmd, "-o", "Dir::Etc::sourceparts=/dev/null") - cmd = append(cmd, "-o", "APT::Get::List-Cleanup=0") - log.Info("Running:", cmd) - if _, err := shell.RunRealtimeError(cmd); err != nil { - badExit(err) - } - - if found := me.machine.FindInstalledByName("wit-tools"); found == nil { - aptInstall("wit-tools") - } -} -*/ @@ -9,7 +9,6 @@ import ( "path/filepath" "strings" - "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -17,10 +16,10 @@ import ( func doBuild() error { if argv.Build.Install != nil { if err := doInstall(); err != nil { - log.Info("doInstall() failed", err) - badExit(err) + // log.Info("doInstall() failed", err) + me.sh.BadExit("doInstall() failed", err) } - okExit("EVERYTHING BUILT!") + me.sh.GoodExit("EVERYTHING BUILT!") } if argv.Build.MacBuild != nil { @@ -30,7 +29,7 @@ func doBuild() error { if argv.Build.Debian != nil { doBuildDeb() - okExit("") + me.sh.GoodExit("") } return nil @@ -58,7 +57,7 @@ func doInstall() error { me.forge.PrintForgedTable(found) if argv.DryRun { - okExit("") + me.sh.GoodExit("") } me.forge.ConfigRill(16, 16) @@ -67,9 +66,9 @@ func doInstall() error { if stat.Err == nil { continue } - dur := stat.End.Sub(stat.Start) - log.Info("CRAP. INSTALL FAILED", shell.FormatDuration(dur), s, stat.Err) - badExit(stat.Err) + // log.Info("CRAP. INSTALL FAILED", config.FormatDuration(dur), s, stat.Err) + msg := "go install FAILED " + s + me.sh.BadExit(msg, stat.Err) } os.Remove(filepath.Join(me.homedir, "go/bin/forged")) return nil @@ -4,10 +4,11 @@ package main import ( + "fmt" "strings" "go.wit.com/lib/config" - "go.wit.com/lib/gui/shell" + "go.wit.com/lib/fhelp" "go.wit.com/log" ) @@ -78,9 +79,10 @@ func doClone() error { log.Info("run:", cmd) } else { log.Info("should run:", cmd) - if _, err := shell.RunRealtimeError(cmd); err != nil { + if _, err := fhelp.RunRealtimeError(cmd); err != nil { if !argv.Force { - badExit(err) + msg := fmt.Sprintf("failed: %v", cmd) + me.sh.BadExit(msg, err) } } } diff --git a/doDebian.go b/doDebian.go index 0a6be8d..00a62bb 100644 --- a/doDebian.go +++ b/doDebian.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - "go.wit.com/lib/gui/shell" + "go.wit.com/lib/fhelp" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -23,7 +23,7 @@ func doBuildDeb() error { if len(files) > 0 { cmd := []string{"rm"} cmd = append(cmd, files...) - _, err := shell.RunRealtimeError(cmd) + _, err := fhelp.RunRealtimeError(cmd) return err } @@ -54,10 +54,8 @@ func doBuildDeb() error { return stat.Err } } - if totalBuilt > 0 { - if _, err := shell.RunRealtimeError([]string{"do-aptly"}); err != nil { - me.sh.BadExit("aptly failed", nil) - } + if _, err := fhelp.RunRealtimeError([]string{"do-aptly"}); err != nil { + me.sh.BadExit("aptly failed", nil) } return nil } @@ -4,6 +4,7 @@ package main import ( + "fmt" "os" "path/filepath" "strings" @@ -22,7 +23,7 @@ func doGit() error { fstr := "--format=\"%h %>(24)%ar %>(20)%an %s" cmd := []string{"git", "log", fstr} shell.RunVerbose(cmd) - okExit("") + me.sh.GoodExit("") } if argv.Git.Tag != nil { @@ -47,19 +48,19 @@ func doGit() error { } cmd := []string{"git", "who"} shell.RunVerbose(cmd) - okExit("") + me.sh.GoodExit("") } if argv.Git.Pull != nil { doPull(".config/wit") doPull("tools") - okExit("") + me.sh.GoodExit("") } if argv.Git.Push != nil { doPush(".config/wit") doPush("tools") - okExit("") + me.sh.GoodExit("") } return nil @@ -106,7 +107,8 @@ func doPush(wpath string) { } if err := repo.GitCommit(); err != nil { - badExit(err) + msg := fmt.Sprintf("repo.GitCommit() %s", repo.FullPath) + me.sh.BadExit(msg, err) } repo.RunRealtime([]string{"git", "push"}) @@ -14,7 +14,7 @@ import ( // exits if not root func checkSuperuser() { if os.Getuid() != 0 { - badExit(fmt.Errorf("you must be root")) + me.sh.BadExit("you must run as root", nil) } } @@ -30,7 +30,8 @@ func exitOnError(cmd []string) { log.Info("Running:", cmd) _, err = shell.RunVerbose(cmd) if err != nil { - badExit(err) + msg := fmt.Sprintf("Ran: %v", cmd) + me.sh.BadExit(msg, err) } } @@ -39,18 +40,7 @@ func exitOnErrorRealtime(cmd []string) { log.Info("Running:", cmd) _, err = shell.RunRealtimeError(cmd) if err != nil { - badExit(err) + msg := fmt.Sprintf("Ran: %v", cmd) + me.sh.BadExit(msg, err) } } - -func okExit(thing string) { - if thing != "" { - log.Info(thing, "ok") - } - os.Exit(0) -} - -func badExit(err error) { - me.sh.BadExit("wit failed: ", err) - os.Exit(-1) -} @@ -29,32 +29,32 @@ func main() { if argv.Upgrade != nil { doUpgrade() - okExit("") + me.sh.GoodExit("") } if argv.Rdate != nil { doRdate() - okExit("") + me.sh.GoodExit("") } if argv.Build != nil { doBuild() - okExit("") + me.sh.GoodExit("") } if argv.Git != nil { doGit() - okExit("") + me.sh.GoodExit("") } if argv.Clone != nil { doClone() - okExit("") + me.sh.GoodExit("") } if argv.WITCOM { doWITCOM() - okExit("") + me.sh.GoodExit("") } if argv.Upgrade != nil { @@ -63,19 +63,19 @@ func main() { if argv.Publish != nil { if err := doPublish(); err != nil { - badExit(err) + me.sh.BadExit("doPublish failed", err) } - okExit("") + me.sh.GoodExit("") } if argv.Zoo != nil { if areSuperuser() { exitOnErrorRealtime([]string{"journalctl", "-n", "100", "-f", "_SYSTEMD_UNIT=zood.service"}) } - okExit("do something here") + me.sh.GoodExit("do something here") } - okExit("do what?") + me.sh.GoodExit("do what?") } // this is dumb. sync this with go-deb @@ -41,5 +41,5 @@ func doAptList() { } log.Printf("%-30s %-8s %s\n", p.Name, p.Version, end) // p.PkgName) } - okExit("") + me.sh.GoodExit("") } |
