1
0
Fork 0
dotfiles/install

46 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
CONFIG_SUFFIX=".conf.yaml"
DOTBOT_DIR="dotbot"
DOTBOT_BIN="bin/dotbot"
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROFILES_FILE="${BASEDIR}/.profiles"
cd "${BASEDIR}"
git submodule update --init --recursive "${DOTBOT_DIR}"
load_config() {
config="$1"
if [ -f "${config}" ]; then
"${BASEDIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASEDIR}" -c "${config}"
else
echo "Skipping nonexistent file: ${config}"
fi
}
OS_NAME="$(uname -s | tr '[:upper:]' '[:lower:]')"
if [ "$#" -gt 0 ]; then
profiles=("${@}")
elif [ -f "${PROFILES_FILE}" ]; then
# MacOS bash 3.2 doesn't have mapfile. Workaround from
# http://mywiki.wooledge.org/BashFAQ/005#Loading_lines_from_a_file_or_stream
unset profiles
while IFS= read -r; do
profiles+=("$REPLY")
done < "${PROFILES_FILE}"
[[ $REPLY ]] && profiles+=("$REPLY")
else
profiles=()
fi
for conf in default "${OS_NAME}" "${profiles[@]}"; do
echo "Applying config: ${conf}"
load_config "${conf}${CONFIG_SUFFIX}"
done
printf "%s\n" "${profiles[@]}" > "${PROFILES_FILE}"