-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·58 lines (48 loc) · 1.41 KB
/
setup.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
#!/bin/bash
set -euo pipefail
THIS="$(realpath -s ${BASH_SOURCE[0]})"
THIS_PATH="$(dirname ${BASH_SOURCE[0]})"
REPO_DIR="$THIS_PATH"
CONFIG_DIR="$REPO_DIR/config"
PATH="$REPO_DIR/setup-tools:$PATH"
regtest() {
echo "$1" | grep -E "$2" > /dev/null
return $?
}
usage() { echo "Usage: $0 [-h] [-n] [-s <script1,script2,...>]" 1>&2; exit 1; }
dry_run=""
scripts=""
while getopts ":hns:" o; do
case "${o}" in
n)
dry_run=1
;;
s)
scripts="${OPTARG}"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [[ ! -z "$dry_run" ]]; then echo "Dry run..."; fi
if [[ ! -z "$scripts" ]]; then
prettyScripts="$(echo ",$scripts" | sed 's/,/\n /g')"
echo -e "Only running the following scripts:$prettyScripts"
fi
for script in $REPO_DIR/setup.d/*; do
script_basename="$(basename "$script")"
script_name="${script_basename#*_}"
script_name="${script_name%.*}"
if [[ ! -z "$scripts" && ! ",$scripts," =~ ",$script_name," ]]; then
continue
fi
if regtest "$script_basename" '^[[:digit:]]{2}s_'; then
if [[ ! -z "$dry_run" ]]; then echo "Would run [$script_name] with sudo"; continue; fi
sudo PATH="$PATH" REPO_DIR="$REPO_DIR" CONFIG_DIR="$CONFIG_DIR/$script_name" ORIG_USER="$USER" "$script"
else
if [[ ! -z "$dry_run" ]]; then echo "Would run [$script_name]"; continue; fi
PATH="$PATH" REPO_DIR="$REPO_DIR" CONFIG_DIR="$CONFIG_DIR/$script_name" "$script"
fi
done