summaryrefslogtreecommitdiff
path: root/apt.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-07 07:50:42 -0500
committerJeff Carr <[email protected]>2025-10-07 07:50:42 -0500
commit7d24a00f52238bf6e6298c1e62d7c2bf11b67edd (patch)
treef500652bcae78acc3a97b42548435eff7f3683bd /apt.go
day1v0.0.1
Diffstat (limited to 'apt.go')
-rw-r--r--apt.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/apt.go b/apt.go
new file mode 100644
index 0000000..febf66d
--- /dev/null
+++ b/apt.go
@@ -0,0 +1,59 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package debian
+
+import (
+ "github.com/go-cmd/cmd"
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/log"
+)
+
+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) error {
+ if _, err := AptInstall(pkgname); err != nil {
+ return err
+ }
+ return nil
+}
+
+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) error {
+ if _, err := AptRemove(pkgname); err != nil {
+ return err
+ }
+ return nil
+}
+
+// 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() error {
+ 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 {
+ return err
+ }
+
+ // if found := me.machine.FindInstalledByName("wit-tools"); found == nil {
+ // AptInstall("wit-tools")
+ // }
+ return nil
+}