dotfiles/provision.sh

72 lines
1.3 KiB
Bash
Raw Normal View History

2018-02-22 04:15:49 +00:00
#!/bin/bash
set +e
2018-02-22 15:43:19 +00:00
RECIPE_PATH=${HOME}/dotfiles/recipes
RECIPES=$(ls $RECIPE_PATH|grep -v '^_')
INSTALL=()
STACK=()
2018-02-22 15:43:19 +00:00
while [[ $# -gt 0 ]]; do
case $1 in
-D|--debug)
DEBUG=1
shift
;;
-l|--list)
echo Available recipes:
for recipe in $RECIPES; do
echo " $recipe"
done
exit
;;
-A|--all)
INSTALL=($RECIPES)
shift
;;
*)
INSTALL+=("$1")
shift
esac
done
INSTALL=($(for recipe in "${INSTALL[@]}"; do
echo $recipe
done |sort | uniq))
2018-02-22 04:15:49 +00:00
function _run {
local msg=$1
shift
if [ -z "$DEBUG" ]; then
echo -n "$msg..."
$@ 2>&1 >/dev/null
else
echo "$msg..."
$@
fi
echo "done."
}
function _recipe {
STACK+=("$1")
echo "-- Recipe '${STACK[@]}' --"
2018-02-22 04:15:49 +00:00
source ${HOME}/dotfiles/recipes/$1
unset STACK[${#STACK[@]}-1]
echo "-- Recipe '${STACK[@]}' --"
2018-02-22 04:15:49 +00:00
}
USER=${USER:-$(whoami)}
_PLATFORM=$(uname -s | awk '{print tolower($1)}')
if [ -z "${INSTALL[@]}" ]; then
INSTALL=(base)
fi
echo "-- Provisioning [${INSTALL[@]}] --"
2018-02-22 15:43:19 +00:00
for recipe in "${INSTALL[@]}"; do
2018-02-22 04:15:49 +00:00
_recipe $recipe
done
echo "Finished, restarting shell."
exec $SHELL