-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprovision.sh
More file actions
executable file
·135 lines (119 loc) · 3 KB
/
provision.sh
File metadata and controls
executable file
·135 lines (119 loc) · 3 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
set +e
trap 'exit' INT
RECIPE_PATH=${HOME}/dotfiles/recipes
RECIPES=$(ls $RECIPE_PATH|grep -v '^_' | sort)
INSTALL=()
STACK=()
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput bold)"
dim="$(tput dim)"
normal="$(tput sgr0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
fi
fi
while [[ $# -gt 0 ]]; do
case $1 in
-D|--debug)
DEBUG=1
shift
;;
-l|--list)
echo Available recipes:
for recipe in $RECIPES; do
description=$(grep '^# Description: ' "${RECIPE_PATH}/$recipe" \
| cut -d' ' -f 3-)
printf "%15s %s\n" "$recipe" "$description"
done
exit
;;
-A|--all)
INSTALL=($RECIPES)
shift
;;
-r|--restart)
RESTART_SHELL=1
shift
;;
-h|--help)
cat <<EOF
Usage: $(basename $0) [OPTION]... [RECIPE]...
Provision one or more dotfiles RECIPEs
Options:
-A, --all Install all available recipes.
-D, --debug Enable debug logging, including command output for each
step.
-h, --help Display this help text and exit.
-l, --list Display all available recipes and exit.
-r, --restart Restart the shell upon completion.
If no RECIPE is provided (and the -A/--all flag is not set), the
'base' recipe will be provisioned.
EOF
exit
;;
*)
INSTALL+=("$1")
shift
esac
done
INSTALL=($(for recipe in "${INSTALL[@]}"; do
echo $recipe
done |sort | uniq))
function _run {
local msg=$1
shift
if [ -z "$DEBUG" ]; then
echo -n "$msg..."
"$@" >/dev/null 2>&1
else
echo "$msg..."
"$@"
fi
echo "${green}done.${normal}"
}
function _recipe {
local recipe
local path
if [ -f "$1" ]; then
recipe="$(basename $1)"
path=$(dirname "$1")
elif [ -f "${RECIPE_PATH}/$1" ]; then
recipe="$1"
path="${RECIPE_PATH}"
else
echo "${bold}${red}Could not load recipe '$1'${normal}" >&2
exit 1
fi
STACK+=("$1")
pushd "$path" >/dev/null
echo "${dim}-- Recipe [${STACK[@]}]'${normal}"
source "./${recipe}"
popd >/dev/null
unset 'STACK[${#STACK[@]}-1]'
echo "${dim}-- Recipe [${STACK[@]}]${normal}"
}
USER=${USER:-$(whoami)}
_PLATFORM=$(uname -s | awk '{print tolower($1)}')
case $_PLATFORM in
linux)
if [ -f /etc/arch-release ]; then
_PLATFORM=arch
elif [ -f /etc/debian_version ]; then
_PLATFORM=debian
fi
;;
esac
if [ "${#INSTALL[@]}" -eq 0 ]; then
INSTALL=(base)
fi
for recipe in "${INSTALL[@]}"; do
_recipe $recipe
done
echo "${green}Finished${normal}"
if [ -n "$RESTART_SHELL" ]; then
echo "Restarting shell."
exec $SHELL
fi