diff options
| -rw-r--r-- | apt.go | 28 | ||||
| -rw-r--r-- | debian.go | 2 | ||||
| -rw-r--r-- | doInstall.go | 2 | ||||
| -rw-r--r-- | doRdate.go | 4 | ||||
| -rw-r--r-- | doUpgrade.go | 16 |
5 files changed, 37 insertions, 15 deletions
@@ -4,27 +4,43 @@ package main import ( + "github.com/go-cmd/cmd" + "go.wit.com/lib/gui/shell" "go.wit.com/log" ) -func aptInstall(pkgname string) { +func aptInstall(pkgname string) (*cmd.Status, error) { cmd := []string{"apt-get", "install", "-y", pkgname} log.Info("Running:", cmd) - exitOnError(cmd) + return shell.RunRealtimeError(cmd) } -func aptRemove(pkgname string) { +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 + return nil, nil } cmd := []string{"apt-get", "remove", "-y", pkgname} log.Info("Running:", cmd) - exitOnError(cmd) + return shell.RunRealtimeError(cmd) +} + +func aptRemoveOrExit(pkgname string) { + if _, err := aptRemove(pkgname); err != nil { + badExit(err) + } } func aptUpdate() { cmd := []string{"apt", "update"} - exitOnError(cmd) + if _, err := shell.RunRealtimeError(cmd); err != nil { + badExit(err) + } aptInstall("wit-tools") } @@ -39,7 +39,7 @@ func buildDeb(check *gitpb.Repo) error { return nil } - if argv.Verbose { + if argv.Verbose || argv.Force { // log.Info("build cmd:", cmd) cmd = append(cmd, "--verbose") } diff --git a/doInstall.go b/doInstall.go index cac93d0..3269c77 100644 --- a/doInstall.go +++ b/doInstall.go @@ -27,7 +27,7 @@ func doInstallRepo(check *gitpb.Repo) error { return nil } - if argv.Verbose { + if argv.Verbose || argv.Force { verbose := []string{"-v", "-x"} if err := me.forge.Install(check, verbose); err != nil { log.Warn("INSTALL FAILED", check.GetGoPath(), err) @@ -9,11 +9,11 @@ func doRdate() { checkSuperuser() if _, err := fhelp.CheckCmd("rdate"); err != nil { - aptInstall("rdate") + aptInstallOrExit("rdate") } if _, err := fhelp.CheckCmd("hwclock"); err != nil { - aptInstall("util-linux-extra") + aptInstallOrExit("util-linux-extra") } exitOnError([]string{"rdate", "rdate.grid.wit.com"}) diff --git a/doUpgrade.go b/doUpgrade.go index 61006b9..ee8e7f3 100644 --- a/doUpgrade.go +++ b/doUpgrade.go @@ -19,6 +19,8 @@ func doUpgrade() error { me.machine, _ = zoopb.InitMachine() + var installed []string + fmt.Println("Installed Packages:") loop := me.machine.Wit.SortByName() for loop.Scan() { @@ -47,13 +49,17 @@ func doUpgrade() error { continue } - if argv.Force { - aptRemove(p.Name) - aptInstall(p.Name) - } else { - aptInstall(p.Name) + installed = append(installed, p.Name) + } + if argv.Force { + // force remove the packages. can be used if binaries change but versions didn't + for _, pkgname := range installed { + aptRemove(pkgname) } } + for _, pkgname := range installed { + aptInstall(pkgname) + } okExit("installed") return nil } |
