-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-profile
More file actions
executable file
·86 lines (68 loc) · 2.32 KB
/
Copy pathinstall-profile
File metadata and controls
executable file
·86 lines (68 loc) · 2.32 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
#!/usr/bin/env bash
set -e
BASE_CONFIG="base"
CONFIG_SUFFIX=".yaml"
META_DIR="meta"
CONFIG_DIR="ingredients"
PROFILES_DIR="recipes"
DOTBOT_DIR="dotbot"
DOTBOT_BIN="bin/dotbot"
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${BASE_DIR}"
LOCK_FILE="${BASE_DIR}/.dotbot-profile"
REQUESTED="$1"
if [[ -f "$LOCK_FILE" ]]; then
LOCKED="$(cat "$LOCK_FILE")"
if [[ -z "$LOCKED" ]]; then
echo "Error: lock file is empty or corrupt." >&2
echo "To switch profiles, run: rm ${LOCK_FILE}" >&2
exit 1
fi
RECIPE_FILE="${BASE_DIR}/${META_DIR}/${PROFILES_DIR}/${LOCKED}"
if [[ ! -f "$RECIPE_FILE" ]]; then
echo "Error: locked profile '$LOCKED' no longer exists in ${META_DIR}/${PROFILES_DIR}/." >&2
echo "To switch profiles, run: rm ${LOCK_FILE}" >&2
exit 1
fi
if [[ "$LOCKED" != "$REQUESTED" ]]; then
echo "Error: this machine is locked to profile '$LOCKED'." >&2
echo "Refusing to install profile '$REQUESTED'." >&2
echo "To switch profiles, run: rm ${LOCK_FILE}" >&2
exit 1
fi
fi
git -C "${BASE_DIR}" submodule sync --quiet
git submodule update --init "${BASE_DIR}"
CONFIGS=()
while IFS= read -r config; do
CONFIGS+=("$config")
done <"${META_DIR}/${PROFILES_DIR}/$1"
shift
for config in "${CONFIGS[@]}" "$@"; do
echo -e "\nConfigure $config"
# create temporary file
configFile="$(mktemp)"
suffix="-sudo"
{
cat "${BASE_DIR}/${META_DIR}/${BASE_CONFIG}${CONFIG_SUFFIX}"
printf '\n'
cat "${BASE_DIR}/${META_DIR}/${CONFIG_DIR}/${config%"$suffix"}${CONFIG_SUFFIX}"
} >"$configFile"
cmd=("${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "$configFile")
if [[ $config == *"sudo"* ]]; then
cmd=(sudo "${cmd[@]}")
fi
"${cmd[@]}"
rm -f "$configFile"
done
echo "$REQUESTED" > "$LOCK_FILE"
# Record which commit this machine has actually applied. A bare `git pull`
# moves HEAD without running a single dotbot step, so "git is clean" and
# "the machine is converged" are different facts -- `dot status` and the
# post-merge hook compare this stamp against HEAD to tell them apart.
# Written last on purpose: `set -e` aborts before it on a failed step, and a
# partial apply must not count as converged.
STAMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
mkdir -p "${STAMP_DIR}"
printf '%s %s\n' "$(git -C "${BASE_DIR}" rev-parse HEAD)" "$REQUESTED" >"${STAMP_DIR}/dot-profile-applied"
cd "${BASE_DIR}"