code rearange
This commit is contained in:
parent
96f2795bf3
commit
fb372aad6f
|
@ -0,0 +1,70 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func doAptUpgrade() {
|
||||||
|
if argv.DryRun {
|
||||||
|
log.Info("--dry-run", []string{"apt", "update"})
|
||||||
|
} else {
|
||||||
|
result := shell.Run([]string{"apt", "update"})
|
||||||
|
if result.Error != nil {
|
||||||
|
log.Info("apt update error:", result.Error)
|
||||||
|
badExit(result.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Installed Packages:")
|
||||||
|
loop := me.forge.Machine.Wit.SortByName()
|
||||||
|
for loop.Scan() {
|
||||||
|
p := loop.Next()
|
||||||
|
// log.Info("apt install", name)
|
||||||
|
if me.forge.Machine.IsInstalled(p.Name) {
|
||||||
|
if argv.DryRun {
|
||||||
|
log.Info("--dry-run", []string{"apt", "install", p.Name})
|
||||||
|
} else {
|
||||||
|
shell.RunRealtime([]string{"apt", "install", p.Name})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
okExit("installed")
|
||||||
|
}
|
||||||
|
|
||||||
|
func doAptList() {
|
||||||
|
log.DaemonMode(true)
|
||||||
|
defer log.DaemonMode(false)
|
||||||
|
fmt.Println("Installed Packages:")
|
||||||
|
loop := me.forge.Machine.Wit.SortByName()
|
||||||
|
for loop.Scan() {
|
||||||
|
p := loop.Next()
|
||||||
|
var end string
|
||||||
|
var version string
|
||||||
|
if me.forge.Config.IsPrivate(p.Name) {
|
||||||
|
end += "(private) "
|
||||||
|
}
|
||||||
|
if actualp := me.forge.Machine.FindVersion(p.Name, p.Version); actualp != nil {
|
||||||
|
// end += "(version match) "
|
||||||
|
} else {
|
||||||
|
end += "(version mismatch) " + actualp.Version + " " + version + " "
|
||||||
|
}
|
||||||
|
if actualp := me.forge.Machine.FindInstalledByName(p.Name); actualp != nil {
|
||||||
|
if p.Version != actualp.Version {
|
||||||
|
end += "(installed " + actualp.Version + " vs " + p.Version + ") "
|
||||||
|
} else {
|
||||||
|
end += "(installed ok) "
|
||||||
|
}
|
||||||
|
version = actualp.Version
|
||||||
|
}
|
||||||
|
if me.forge.Config.IsReadOnly(p.Name) {
|
||||||
|
// end += " (readonly) "
|
||||||
|
} else {
|
||||||
|
end += "(writable) "
|
||||||
|
}
|
||||||
|
log.Printf("%-30s %-8s %s\n", p.Name, p.Version, end) // p.PkgName)
|
||||||
|
}
|
||||||
|
okExit("")
|
||||||
|
}
|
26
main.go
26
main.go
|
@ -55,33 +55,11 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Upgrade != nil {
|
if argv.Upgrade != nil {
|
||||||
if argv.DryRun {
|
doAptUpgrade()
|
||||||
log.Info("--dry-run", []string{"apt", "update"})
|
|
||||||
} else {
|
|
||||||
result := shell.Run([]string{"apt", "update"})
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Info("apt update error:", result.Error)
|
|
||||||
badExit(result.Error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Installed Packages:")
|
|
||||||
loop := me.forge.Machine.Wit.SortByName()
|
|
||||||
for loop.Scan() {
|
|
||||||
p := loop.Next()
|
|
||||||
// log.Info("apt install", name)
|
|
||||||
if me.forge.Machine.IsInstalled(p.Name) {
|
|
||||||
if argv.DryRun {
|
|
||||||
log.Info("--dry-run", []string{"apt", "install", p.Name})
|
|
||||||
} else {
|
|
||||||
shell.RunRealtime([]string{"apt", "install", p.Name})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
okExit("installed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.ListPkgs != nil {
|
if argv.ListPkgs != nil {
|
||||||
|
doAptList()
|
||||||
log.DaemonMode(true)
|
log.DaemonMode(true)
|
||||||
defer log.DaemonMode(false)
|
defer log.DaemonMode(false)
|
||||||
fmt.Println("Installed Packages:")
|
fmt.Println("Installed Packages:")
|
||||||
|
|
Loading…
Reference in New Issue