-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·91 lines (73 loc) · 1.69 KB
/
install.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
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
function main {
# declare local variables
local OPTIONS_PARSED
# set default values and configuration
SELF_PATH="$(readlink -f "$0")"
SELF_NAME="$(basename "$SELF_PATH")"
SELF_DIR="$(dirname "$SELF_PATH")"
WITH_HELPER_EXTRAS=false
# parse arguments
OPTIONS_PARSED=$(
getopt \
--options '' \
--longoptions 'with-helper-extras' \
--name "$SELF_NAME" \
-- "$@"
)
# replace arguments
eval set -- "$OPTIONS_PARSED"
# apply arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--with-helper-extras)
WITH_HELPER_EXTRAS=true
shift 1
;;
--)
shift 1
break
;;
*)
break
;;
esac
done
# check if there is no unassigned argument left
if [[ $# -ne 0 ]]; then
echo "$SELF_NAME: cannot handle unassigned arguments: $*" >&2
exit 1
fi
task_install_script
}
function verify_root_privileges {
if [[ $EUID -ne 0 ]]; then
echo "$SELF_NAME: require root privileges" >&2
exit 1
fi
}
function task_install_script {
# declare local variables
local SBIN_DIR
local VAR_DIR
local ENTRY
# verify preconditions
verify_root_privileges
SBIN_DIR='/usr/local/sbin'
VAR_DIR='/var/local/ubuntu-headless-installer'
cp -v "$SELF_DIR/ubuntu-installer.sh" "$SBIN_DIR"
chmod a+x "$SBIN_DIR/ubuntu-installer.sh"
if "$WITH_HELPER_EXTRAS"; then
for ENTRY in "$SELF_DIR/helper-extras"/*; do
cp -v "$ENTRY" "$SBIN_DIR"
chmod a+x "$SBIN_DIR/$(basename "$ENTRY")"
done
fi
mkdir -p "$VAR_DIR"
cp -v "$SELF_DIR/bundles.txt" "$VAR_DIR"
cp -v "$SELF_DIR/debconf.txt" "$VAR_DIR"
cp -v "$SELF_DIR/dconf.ini" "$VAR_DIR"
}
set -euo pipefail
main "$@"
exit 0