-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·122 lines (101 loc) · 3.14 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·122 lines (101 loc) · 3.14 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
set -e
cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
# shellcheck disable=SC1091
. lib/util.sh
# shellcheck disable=SC1091
. lib/profile.sh
function ensure_profile_includes() {
local profile
local include
profile=${1}
include=${2}
present=$(yq e "[\"${include}\"] - (.profiles.\"${profile}\".include // []) | length == 0" ../config.yaml)
if [[ ${present} == "false" ]]; then
yq eval ".profiles.\"${profile}\".\"include\" += [\"${include}\"]" -i ../config.yaml
fi
}
function list_includes() {
local profile
profile="${1}"
yq eval ".profiles.\"${profile}\".include[]" ../config.yaml
}
function set_host_ssh_key_name_if_present() {
local profile
local key_name
profile=${1}
key_name="${profile} key"
if op item get "${key_name}" >/dev/null 2>&1; then
yq eval ".profiles.\"${profile}\".variables.host_ssh_key_name = \"${key_name}\"" -i ../config.yaml
fi
}
function main() {
if ! command -v brew >/dev/null; then
echo "need sudo permission for initial Homebrew install"
util::is_mac && util::sudo_check_then_alive
profile::install_homebrew
fi
if ! command -v yq >/dev/null; then
brew install yq
fi
for action in _goenv_install _pyenv_install; do
profile::run_dotdrop_action "${action}"
done
# create a new profile (if necessary), including default & os-specific ones
PROFILE=$(hostname)
explicit_profiles=()
if util::is_mac; then
explicit_profiles+=(mac)
elif util::is_linux; then
explicit_profiles+=(linux)
elif util::is_synology_dsm; then
explicit_profiles+=(synology_dsm)
else
explicit_profiles+=(default)
fi
explicit_profiles+=("${@}")
for named in "${explicit_profiles[@]}"; do
ensure_profile_includes "${PROFILE}" "${named}"
done
declare -A seen=()
declare -a uniq_profiles=()
profile_includes=($(list_includes "${PROFILE}"))
while (( ${#profile_includes[@]} )); do
current="${profile_includes[0]}"
profile_includes=( "${profile_includes[@]:1}" )
declare -a work_queue=($current)
declare -a item_stack=()
while (( ${#work_queue[@]} )); do
item="${work_queue[0]}"
work_queue=( "${work_queue[@]:1}" )
if [[ -z ${seen[$item]+x} ]]; then # key not yet seen
item_stack=( "$item" "${item_stack[@]}" )
seen[$item]=1
item_includes=($(list_includes "${item}"))
if (( ${#item_includes[@]} )); then
work_queue=( "${item_includes[@]}" "${work_queue[@]}")
fi
fi
done
uniq_profiles+=("${item_stack[@]}")
done
echo "profiles to apply ( ${uniq_profiles[@]} )"
for named in "${uniq_profiles[@]}"; do
echo "start of profile <$named>"
profile::ensure_brewfile_installed "./lib/resources/Brewfile.${named}"
if command -v "profile::${named}"; then
"profile::${named}"
fi
done
eval "$(op signin)"
set_host_ssh_key_name_if_present "${PROFILE}"
# Install all dotfiles into the home directory
dotdrop install --force --profile="${PROFILE}" --cfg ../config.yaml
for named in "${uniq_profiles[@]}"; do
if command -v "profile::${named}_after"; then
"profile::${named}_after"
fi
done
profile::finalize
}
main "${@}"