-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
executable file
·80 lines (68 loc) · 1.5 KB
/
common.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
75
76
77
78
79
80
#!/bin/bash
set -e
if [ "$DEBUG" ]; then
set -x
export DEBUG=1
fi
check_deps() {
local needed_commands="$1"
for command in $needed_commands; do
if ! command -v $command &> /dev/null; then
echo " - $command"
fi
done
}
assert_deps() {
local needed_commands="$1"
local missing_commands=$(check_deps "$needed_commands")
if [ "${missing_commands}" ]; then
echo "You are missing dependencies needed for this script."
echo "Commands needed:"
echo "${missing_commands}"
exit 1
fi
}
parse_args() {
declare -g -A args
for argument in "$@"; do
if [ "$argument" = "-h" ] || [ "$argument" = "--help" ]; then
print_help
exit 0
fi
local key=$(echo $argument | cut -f1 -d=)
local key_length=${#key}
local value="${argument:$key_length+1}"
args["$key"]="$value"
done
}
assert_root() {
if [ "$EUID" -ne 0 ]; then
echo "this needs to be run as root."
exit 1
fi
}
assert_args() {
if [ -z "$1" ]; then
print_help
exit 1
fi
}
get_distro_info() {
local distro_name="$1"
local arch="$2"
if [ "$distro_name" = "debian" ]; then
local repo_url="http://deb.debian.org/debian"
local components="main"
elif [ "$distro_name" = "ubuntu" ]; then
if [ "$arch" = "amd64" ]; then
local repo_url="http://archive.ubuntu.com/ubuntu"
else
local repo_url="http://ports.ubuntu.com"
fi
local components="main universe"
else
echo "invalid distro name"
exit 1
fi
echo "$repo_url|$components"
}