-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·74 lines (62 loc) · 1.93 KB
/
install
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
#!/usr/bin/env zsh
# Constants
BASE_CONFIG="base.yaml"
CONFIG_DIR="configs"
DOTBOT_DIR="dotbot"
DOTBOT_BIN="bin/dotbot"
PROFILE_PREFIX="profile-"
# Get the directory of the script
BASE_DIR="$(cd "$(dirname "${(%):-%N}")" && pwd)"
# Function to list available profiles and configs
list_profiles_configs() {
echo "Available profiles:"
for profile in "${BASE_DIR}/${CONFIG_DIR}/${PROFILE_PREFIX}"*; do
[[ -f "$profile" ]] && echo " - $(basename "$profile" | sed "s/^${PROFILE_PREFIX}//")"
done
echo -e "\nAvailable configs:"
for config in "${BASE_DIR}/${CONFIG_DIR}"/*.yaml; do
[[ $(basename "$config") != "${PROFILE_PREFIX}"* ]] && [[ $(basename "$config") != "$BASE_CONFIG" ]] && echo " - $(basename "$config" .yaml)"
done
}
list_statuses() {
git submodule status
}
# Function to combine base and specific config files and run Dotbot
run_dotbot() {
local config="$1"
echo -e "\nConfigure $config"
local base_config="${BASE_DIR}/${CONFIG_DIR}/${BASE_CONFIG}"
local config_file="${BASE_DIR}/${CONFIG_DIR}/${config}.yaml"
local combined_config
combined_config=$(mktemp)
cat "$base_config" "$config_file" > "$combined_config"
"${BASE_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "$combined_config"
rm -f "$combined_config"
}
# Main logic
if [[ "$1" == "--list" ]]; then
list_profiles_configs
exit 0
elif [[ "$1" == "--status" ]]; then
list_statuses
exit 0
fi
cd "${BASE_DIR}" || exit
# Sync submodule URLs
git submodule sync --recursive
git pull --recurse-submodules --jobs=8
if [[ -f "${BASE_DIR}/${CONFIG_DIR}/${PROFILE_PREFIX}$1" ]]; then
# Profile mode
PROFILE_FILE="${BASE_DIR}/${CONFIG_DIR}/${PROFILE_PREFIX}$1"
shift
CONFIGS=("${(@f)$(<"$PROFILE_FILE")}")
for config in "${CONFIGS[@]}" "$@"; do
run_dotbot "$config"
done
else
# Standalone mode
for config in "$@"; do
run_dotbot "$config"
done
fi
# vim: ft=zsh