-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·59 lines (48 loc) · 1.45 KB
/
bootstrap
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
#!/usr/bin/env -S bash -ue
if [ ${1:-x} = "-h" ] || [ ${1:-x} = "--help" ] || [ $# -eq 0 ]; then
name="$(realpath "$(basename "$0")")"
cat <<EOF
Automate system installation and configuration.
Given a list of directories relative to the location of this script,
enter each directory and source the file named 'bootstrap', one directory
at a time in the specified order.
Usage:
(1) $name DIR [DIR]...
(2) $name -
Pass directory names as arguments (1), or read directory names from stdin, one directory per line.
EOF
[ $# -eq 0 ] && exit 1 || exit 0
fi
# hack sudo to use PW envvar; must be defined.
if [ ! ${PW+x} ]; then
echo "Envvar 'PW' must contain sudo password. Abort." >&2
exit 1
fi
sudo() {
echo "$PW" | /bin/sudo -Sp '' "$@"
}
die() { echo -e "[\033[31;1m ERR\033[0m]" "$@" >&2; exit 1; }
log() { echo -e "[\033[32;1mINFO\033[0m]" "$@"; }
# TODO: Check that script is run as a regular user
# Actually, don't! Why not run this as a sysadmin?
# TODO: Record progress of installation
rootdir="$(realpath "$(dirname "$0")")"
cd "$rootdir"
if [ "$1" = "-" ]; then
cat -
else
printf '%s\n' "$@"
fi | while read target; do
if [ -f "$target" ]; then
break;
elif [ -d "$target" ] && [ -f "$target/bootstrap" ]; then
# don't use subshells in case we source something
log "Preparing to install '$target'..."
cd "$target"
. "./bootstrap"
cd "$rootdir"
else
echo "File '$target/bootstrap' doesn't exist. Abort." >&2
exit 1
fi
done