// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "debug/buildinfo" "embed" "fmt" "os" "path/filepath" "unicode" "go.wit.com/dev/davecgh/spew" "go.wit.com/log" ) // sent via -ldflags var VERSION string var BUILDTIME string // used for shell auto completion var ARGNAME string = "wit" // todo: get this from $0 ? //go:embed resources/* var resources embed.FS func main() { me = new(mainType) me.once.Do(initMain) if argv.Upgrade != nil { doUpgrade() okExit("") } if argv.Rdate != nil { doRdate() okExit("") } if argv.Build != nil { doBuild() okExit("") } if argv.Git != nil { doGit() okExit("") } if argv.Clone != nil { doClone() okExit("") } if argv.WITCOM { doWITCOM() okExit("") } if argv.Upgrade != nil { doUpgrade() } if argv.Publish != nil { if err := doPublish(); err != nil { badExit(err) } okExit("") } if argv.Zoo != nil { if areSuperuser() { exitOnErrorRealtime([]string{"journalctl", "-n", "100", "-f", "_SYSTEMD_UNIT=zood.service"}) } okExit("do something here") } if argv.ListPkgs != nil { doAptList() log.DaemonMode(true) defer log.DaemonMode(false) fmt.Println("Installed Packages:") loop := me.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.machine.FindByVersion(p.Name, p.Version); actualp != nil { // end += "(version match) " } else { end += "(version mismatch) " + actualp.Version + " " + version + " " } if actualp := me.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("") } okExit("do what?") } // this is dumb. sync this with go-deb func trimNonNumericFromStart(s string) string { for i, r := range s { if unicode.IsDigit(r) { return s[i:] } } return "" } func dumpDebug() { // Get absolute path of the currently running binary exePath, err := os.Executable() if err != nil { fmt.Println("Error getting executable path:", err) return } // Resolve symlinks if necessary exePath, err = filepath.EvalSymlinks(exePath) if err != nil { fmt.Println("Error resolving symlink:", err) return } // Read build info bi, err := buildinfo.ReadFile(exePath) if err != nil { fmt.Println("Error reading build info:", err) return } log.Infof("%s built with Go version: %s\n", exePath, bi.GoVersion) spew.Dump(bi) for _, dep := range bi.Deps { fmt.Printf("Dependency: %s %s\n", dep.Path, dep.Version) } }