summaryrefslogtreecommitdiff
path: root/apt.go
blob: ff6a6c421a9d2364a4f82583bf6c6e2e07f22a56 (plain)
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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

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) {
	if _, err := aptInstall(pkgname); err != nil {
		badExit(err)
	}
}

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) {
	if _, err := aptRemove(pkgname); err != nil {
		badExit(err)
	}
}

//	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() {
	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 {
		badExit(err)
	}

	if found := me.machine.FindInstalledByName("wit-tools"); found == nil {
		aptInstall("wit-tools")
	}
}