aboutsummaryrefslogtreecommitdiff
path: root/ubuntu/update.vsh
blob: cdf920c2789e3b036d93e0b8170c414804ac7343 (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
#!/usr/bin/env -S v

import os

// print command then execute it
fn sh(cmd string) {
	println('❯ ${cmd}')
	print(execute_or_exit(cmd).output)
}

// Check if apt is available
// Returns true if available, false otherwise.
fn check_package_manager() bool {
	if os.execute('which apt').exit_code != 0 {
		eprintln('apt was not found. Cannot perform action.')
		return false
	}
	return true
}

// Get user enter approval
fn get_user_approval_with_enter(msg string) bool {
	println(msg + ' Press enter for yes and anything else + enter for no')
	approval := input_character()
	if approval != 10 {
		return false
	}
	println('User pressed enter, continuing...')
	return true
}

// Remove snapd if users is ok with it
// defaults to yes
fn remove_snapd() bool {
	question := 'Do you want to remove snapd, if it exists?'
	if get_user_approval_with_enter(question) && check_package_manager() {
		sh('sudo apt remove --purge snapd')
		sh('sudo apt-mark hold snapd')
		sh('sudo rm -dfr /home/${username}/snap')
		return true
	}
	return false
}

const username = os.getenv_opt('USER') or { 'root' }

sh('sudo dpkg --add-architecture i386')
remove_snapd()
sh('sudo apt-get autoclean -y')
sh('sudo apt-get clean -y')
sh('sudo apt-get autoremove -y')
sh('sudo apt-get update')
sh('sudo apt-get upgrade -y')