// 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" "fmt" "os" "path/filepath" "unicode" "go.wit.com/dev/alexflint/arg" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) // sent via -ldflags var VERSION string var BUILDTIME string var failed map[*gitpb.Repo]string var state map[*gitpb.Repo]string var debnames map[*gitpb.Repo]string func main() { me = new(autoType) me.argpp = arg.MustParse(&argv) if argv.Bash { argv.doBash() os.Exit(0) } if len(argv.BashAuto) != 0 { argv.doBashAuto() os.Exit(0) } dumpDebug() failed = make(map[*gitpb.Repo]string) state = make(map[*gitpb.Repo]string) debnames = make(map[*gitpb.Repo]string) // load the ~/.config/forge/ config me.forge = forgepb.Init() me.machine = new(zoopb.Machine) if err := me.machine.ConfigLoad(); err != nil { log.Info("zoopb.ConfigLoad() failed", err) } me.machine.InitWit() if argv.Clone != nil { if argv.RepoMap != "" { repomap(argv.RepoMap) okExit("") } } if argv.WITCOM { doWITCOM() okExit("") } if argv.Upgrade != nil { doAptUpgrade() } 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.FindVersion(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("") } doListRepos() if argv.DebBuild != nil { buildDeb() okExit("") } if argv.MakeInstall != nil { if err := doInstall(); err != nil { log.Info("doInstall() failed", err) badExit(err) } okExit("EVERYTHING BUILT!") } if argv.Test { homeDir, _ := os.UserHomeDir() testdir := filepath.Join(homeDir, "go/src/go.wit.com/apps/utils/wit-utils/go-clone-test/") os.Chdir(testdir) shell.RunRealtime([]string{"go", "install"}) workdir := filepath.Join(homeDir, "gowork") if err := os.MkdirAll(workdir, os.ModePerm); err != nil { badExit(err) } os.Chdir(workdir) shell.RunRealtime([]string{"go-clone-test"}) } okExit("everything compiled") } // 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 okExit(thing string) { if thing != "" { log.Info(thing, "ok") } // log.Info("Finished go-clean on", check.GetGoPath(), "ok") os.Exit(0) } func badExit(err error) { log.Info("go-clean failed: ", err, me.forge.GetGoSrc()) os.Exit(-1) } 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 } fmt.Println("Go Version:", bi.GoVersion) for _, dep := range bi.Deps { fmt.Printf("Dependency: %s %s\n", dep.Path, dep.Version) } }