-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·237 lines (213 loc) · 6.15 KB
/
bootstrap.sh
File metadata and controls
executable file
·237 lines (213 loc) · 6.15 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/sh
# Dotty bootstrap — curl-pipeable entry point
# Usage: sh -c "$(curl -fsSL https://raw.github.com/gplancke/dotty/main/bootstrap.sh)"
set -eu
DOTTY_DIR="${HOME}/.local/share/dotty"
DOTTY_REPO="https://github.com/gplancke/dotty.git"
###############################################
# Detect OS
###############################################
detect_os() {
case "$(uname -s)" in
Darwin)
DISTRO="darwin"
;;
Linux)
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
fedora|rhel|centos|rocky|almalinux) DISTRO="fedora" ;;
arch|manjaro|endeavouros|garuda|cachyos) DISTRO="arch" ;;
ubuntu|debian|pop|elementary|linuxmint) DISTRO="debian" ;;
alpine) DISTRO="alpine" ;;
*) DISTRO="unknown" ;;
esac
else
DISTRO="unknown"
fi
;;
*)
DISTRO="unknown"
;;
esac
}
###############################################
# Install git (Linux only)
###############################################
install_git() {
command -v git >/dev/null 2>&1 && return 0
printf '[DOTTY] Installing git...\n'
case "$DISTRO" in
debian)
sudo apt-get update -qq
sudo apt-get install -qq -y git >/dev/null
;;
fedora)
sudo dnf install -q -y git >/dev/null
;;
arch)
sudo pacman -S --noconfirm -q git >/dev/null 2>&1
;;
alpine)
sudo apk add -q git
;;
esac
}
###############################################
# Install python3 + pip (Linux only)
###############################################
install_python() {
python3 -m pip --version >/dev/null 2>&1 && return 0
printf '[DOTTY] Installing python3...\n'
case "$DISTRO" in
debian)
sudo apt-get update -qq
sudo apt-get install -qq -y python3 python3-pip python3-venv >/dev/null
;;
fedora)
sudo dnf install -q -y python3 python3-pip >/dev/null
;;
arch)
sudo pacman -Syu --noconfirm -q >/dev/null 2>&1
sudo pacman -S --noconfirm -q python python-pip >/dev/null 2>&1
;;
alpine)
sudo apk update -q
sudo apk add -q python3 py3-pip
;;
esac
}
###############################################
# Install Ansible via pip
###############################################
install_ansible() {
command -v ansible-playbook >/dev/null 2>&1 && return 0
printf '[DOTTY] Installing Ansible...\n'
case "$DISTRO" in
darwin)
# Ensure Xcode CLI tools
if ! xcode-select -p >/dev/null 2>&1; then
printf '[DOTTY] Installing Xcode Command Line Tools...\n'
xcode-select --install 2>/dev/null || true
printf '[DOTTY] Please complete the Xcode CLI tools install, then re-run this script.\n'
exit 1
fi
python3 -m pip install --user --break-system-packages -q ansible 2>/dev/null || \
python3 -m pip install --user -q ansible
;;
*)
install_python
python3 -m pip install --user --break-system-packages -q ansible 2>/dev/null || \
python3 -m pip install --user -q ansible
;;
esac
# Ensure pip user bin is on PATH
PYTHON_USER_BIN="$(python3 -c 'import sysconfig; print(sysconfig.get_path("scripts", "posix_user"))')"
export PATH="${PYTHON_USER_BIN}:${HOME}/.local/bin:${PATH}"
}
###############################################
# Clone or update repo
###############################################
clone_repo() {
if [ -d "${DOTTY_DIR}/.git" ]; then
printf '[DOTTY] Updating dotty repo...\n'
git -C "${DOTTY_DIR}" pull --ff-only
else
printf '[DOTTY] Cloning dotty repo...\n'
git clone "${DOTTY_REPO}" "${DOTTY_DIR}"
fi
}
###############################################
# Install galaxy requirements
###############################################
install_galaxy() {
if [ -f "${DOTTY_DIR}/requirements.yml" ]; then
printf '[DOTTY] Installing Ansible Galaxy requirements...\n'
ansible-galaxy collection install -r "${DOTTY_DIR}/requirements.yml" >/dev/null
fi
}
###############################################
# Prompt for install mode
###############################################
prompt_mode() {
printf '\nSelect install mode:\n'
printf ' 1) dev (default)\n'
printf ' 2) full\n'
printf ' 3) minimal\n'
printf 'Choice [1]: '
read CHOICE < /dev/tty || CHOICE="1"
case "$CHOICE" in
2) INSTALL_MODE="full" ;;
3) INSTALL_MODE="minimal" ;;
*) INSTALL_MODE="dev" ;;
esac
}
###############################################
# Prompt for GUI apps
###############################################
prompt_gui() {
printf '\nInstall GUI apps? [y/N]:'
read GUI_CHOICE < /dev/tty || GUI_CHOICE="n"
case "$GUI_CHOICE" in
[yY]) INSTALL_GUI="true" ;;
*) INSTALL_GUI="false" ;;
esac
}
###############################################
# Prompt for vault password
###############################################
prompt_vault() {
VAULT_PASS_FILE="$(mktemp)"
printf 'Vault password: '
stty -echo < /dev/tty 2>/dev/null || true
read VAULT_PASS < /dev/tty
stty echo < /dev/tty 2>/dev/null || true
printf '\n'
printf '%s' "${VAULT_PASS}" > "${VAULT_PASS_FILE}"
chmod 600 "${VAULT_PASS_FILE}"
}
###############################################
# Run playbook
###############################################
run_playbook() {
cd "${DOTTY_DIR}"
BECOME_FLAG="--ask-become-pass"
if [ "$(id -u)" = "0" ]; then
BECOME_FLAG=""
fi
# shellcheck disable=SC2086
ansible-playbook site.yml \
--vault-password-file "${VAULT_PASS_FILE}" \
${BECOME_FLAG} \
-e "install_mode=${INSTALL_MODE}" \
-e "install_gui=${INSTALL_GUI}"
}
###############################################
# Cleanup
###############################################
cleanup() {
if [ -n "${VAULT_PASS_FILE:-}" ] && [ -f "${VAULT_PASS_FILE}" ]; then
rm -f "${VAULT_PASS_FILE}"
fi
}
###############################################
# Main
###############################################
main() {
trap cleanup EXIT
detect_os
if [ "$DISTRO" = "unknown" ]; then
printf '[DOTTY] Error: unsupported OS\n'
exit 1
fi
install_git
install_ansible
clone_repo
install_galaxy
prompt_mode
prompt_gui
prompt_vault
run_playbook
printf '\n[DOTTY] Provisioning complete!\n'
}
main "$@"