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
|
#!/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
}
// Install packages using apt.
// Returns true if successful, false otherwise.
fn install_packages(pkg_names []string) bool {
if check_package_manager() == false {
return false
}
println('Using apt to install packages...')
mut cmd := ['apt', 'install', '-y']
cmd << pkg_names
result := os.execute(cmd.join(' '))
if result.exit_code == 0 {
eprintln('Failed to install packages with apt.')
return false
}
println('Successfully installed packages: ${pkg_names.join(', ')}')
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
}
// Main script
// Capture the current username once at the start
const username = os.getenv_opt('USER') or { 'root' } // Fallback to 'root' if USER is not set
// start script
if !get_user_approval_with_enter('Before executing, make sure to: copy ssh keys, setup sudo, user, internet available.') {
exit(0)
}
sh('sudo dpkg --add-architecture i386')
remove_snapd()
sh('sudo apt-get autoclean -y && sudo apt-get clean -y && sudo apt-get autoremove && sudo apt-get check && sudo apt update && sudo apt upgrade -y')
install_packages(['stow', 'git', 'build-essential', 'make', 'lldb', 'gdb', 'llvm',
'gcc-mingw-w64-x86-64', 'yubikey-luks', 'yubikey-agent', 'handbrake', 'handbrake-cli',
'plasma-browser-integration', 'steam-installer', 'steam-libs', 'steam-devices',
'libwebkit2gtk-4.1-0', 'libgtk-3-0', 'libusb-1.0-0', 'software-properties-common', 'curl',
'wget', 'ca-certificates', 'gpg', 'pinentry-qt', 'pinentry-tty', 'gnupg-agent', 'units', 'ddd',
'gnucobol', 'tcsh', 'kakoune'])
|