1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package debian
import (
"fmt"
"github.com/go-cmd/cmd"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
)
func AptInstall(pkgname string) (*cmd.Status, error) {
cmd := []string{"apt-get", "install", "-y", pkgname}
log.Info("Running:", cmd)
return fhelp.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 fhelp.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 := fhelp.RunRealtimeError(cmd); err != nil {
return err
}
return nil
}
// init the installed package list
func initPackages(me *zoopb.Machine) {
// Get the list of installed packages for the detected distro
newP, err := getPackageList(me.Distro)
if err != nil {
fmt.Println("Error:", err)
return
}
if me.Packages == nil {
me.Packages = new(zoopb.Packages)
}
// Print the installed packages and their versions
for pkg, version := range newP {
new1 := new(zoopb.Package)
new1.Package = pkg
new1.Version = version
me.Packages.Append(new1)
// log.Info("added", new1.Package, "failed")
}
getMemory(me)
}
|