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

package main

import (
	"fmt"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/zoopb"
	"go.wit.com/log"
)

func doUpgrade() error {
	var cmd []string

	checkSuperuser()

	cmd = []string{"apt", "update"}
	exitOnError(cmd)

	cmd = []string{"apt", "install", "wit-tools"}
	exitOnError(cmd)

	me.machine, _ = zoopb.InitMachine()
	doAptUpgrade()

	fmt.Println("Installed Packages:")
	loop := me.machine.Wit.SortByName()
	for loop.Scan() {
		p := loop.Next()
		// log.Info("apt install", p.Name)
		if p.Name == "" {
			log.Info("odd /var/lib/apt/ list parse error. p.Name was blank (should be the package name)", p)
			continue
		}
		if !me.machine.IsInstalled(p.Name) {
			continue
		}
		if argv.DryRun {
			log.Info("should install package", p.Name)
		}

		cmd := []string{"apt", "install", p.Name}
		log.Info("Running:", cmd)
		shell.RunVerbose(cmd)
	}
	okExit("installed")
	return nil
}