2018-02-22 04:15:49 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set +e
|
2018-02-23 21:37:38 +00:00
|
|
|
trap 'exit' INT
|
2018-02-22 04:15:49 +00:00
|
|
|
|
2018-02-22 15:43:19 +00:00
|
|
|
RECIPE_PATH=${HOME}/dotfiles/recipes
|
|
|
|
RECIPES=$(ls $RECIPE_PATH|grep -v '^_')
|
2018-02-23 15:12:24 +00:00
|
|
|
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
|
|
|
|
;;
|
2018-02-27 05:21:29 +00:00
|
|
|
-r|--restart)
|
|
|
|
RESTART_SHELL=1
|
|
|
|
shift
|
|
|
|
;;
|
2018-02-22 15:43:19 +00:00
|
|
|
*)
|
|
|
|
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 {
|
2018-02-28 05:09:33 +00:00
|
|
|
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 "Could not load recipe '$1'" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-02-23 15:12:24 +00:00
|
|
|
STACK+=("$1")
|
2018-02-28 05:09:33 +00:00
|
|
|
pushd "$path"
|
2018-02-23 15:12:24 +00:00
|
|
|
echo "-- Recipe '${STACK[@]}' --"
|
2018-02-28 05:09:33 +00:00
|
|
|
source "./${recipe}"
|
2018-02-23 15:12:24 +00:00
|
|
|
echo "-- Recipe '${STACK[@]}' --"
|
2018-02-28 05:09:33 +00:00
|
|
|
popd
|
2018-02-22 04:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
USER=${USER:-$(whoami)}
|
|
|
|
_PLATFORM=$(uname -s | awk '{print tolower($1)}')
|
|
|
|
|
2018-02-23 15:12:24 +00:00
|
|
|
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
|
|
|
|
|
2018-02-27 05:21:29 +00:00
|
|
|
echo "Finished"
|
|
|
|
if [ -n "$RESTART_SHELL" ]; then
|
|
|
|
echo "Restarting shell."
|
|
|
|
exec $SHELL
|
|
|
|
fi
|