-
Notifications
You must be signed in to change notification settings - Fork 297
/
utils.sh
executable file
·74 lines (50 loc) · 1.62 KB
/
utils.sh
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
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "../../utils.sh"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
add_key() {
wget -qO - "$1" | sudo apt-key add - &> /dev/null
# │└─ write output to file
# └─ don't show output
}
add_ppa() {
sudo add-apt-repository -y ppa:"$1" &> /dev/null
}
add_to_source_list() {
sudo sh -c "printf 'deb $1' >> '/etc/apt/sources.list.d/$2'"
}
autoremove() {
# Remove packages that were automatically installed to satisfy
# dependencies for other packages and are no longer needed.
execute \
"sudo apt-get autoremove -qqy" \
"APT (autoremove)"
}
install_package() {
declare -r EXTRA_ARGUMENTS="$3"
declare -r PACKAGE="$2"
declare -r PACKAGE_READABLE_NAME="$1"
if ! package_is_installed "$PACKAGE"; then
execute "sudo apt-get install --allow-unauthenticated -qqy $EXTRA_ARGUMENTS $PACKAGE" "$PACKAGE_READABLE_NAME"
# suppress output ─┘│
# assume "yes" as the answer to all prompts ──┘
else
print_success "$PACKAGE_READABLE_NAME"
fi
}
package_is_installed() {
dpkg -s "$1" &> /dev/null
}
update() {
# Resynchronize the package index files from their sources.
execute \
"sudo apt-get update -qqy" \
"APT (update)"
}
upgrade() {
# Install the newest versions of all packages installed.
execute \
"export DEBIAN_FRONTEND=\"noninteractive\" \
&& sudo apt-get -o Dpkg::Options::=\"--force-confnew\" upgrade -qqy" \
"APT (upgrade)"
}