-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_onchange_install-packages.sh.tmpl
executable file
·255 lines (221 loc) · 10.6 KB
/
run_onchange_install-packages.sh.tmpl
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
# Variables
path="$HOME/.local/share/chezmoi/install_scripts" # for scripts
alerts=() # hey this is a heads up
errors=() # hey you fucked up
# Check form factor based on hostname
{{ if eq (len .chezmoi.hostname) 8 }}
# This machine is using the current naming convention! yay!
case ${HOSTNAME:0:1} in
C) formFactor="console";;
D) formFactor="desktop";;
L) formFactor="laptop";;
P) formFactor="phone";;
S) formFactor="server";;
V) formFactor="VM";;
*) formFactor="unknown";;
esac
{{ else }}
# This machine definitely isn't using our naming convention.
formFactor="unknown"
{{ end }}
# Functions
# little helper function for install
# it just sources each variant you ask for with the current scope/mode
# (todo: decide on better names for these things)
function sourceFile {
source "$path/universal/$flavour/$mode.sh"
for variant in "$@"
do
source "$path/$variant/$flavour/$mode.sh"
done
}
# Sources the relevant files based on form factor
function install {
flavour=$1 # "core", "extra"
mode=$2 # "apt", "not-apt"
case $formFactor in
console) sourceFile "not_server" "console";;
desktop) sourceFile "not_server" "desktop";;
laptop) sourceFile "not_server" "laptop";;
phone) sourceFile "not_server" "phone";;
server) sourceFile "server";;
VM) sourceFile "not_server" "VM";;
unknown) sourceFile;;
esac
}
if [ "$formFactor" = "unknown" ]; then
errors+=("\
║ invalid hostname detected ║\n\
╠═════════════════════════════════╣\n\
║ This machine's hostname doesn't ║\n\
║ match our standards, and we can ║\n\
║ not apply any customizations ║\n\
║ based on them. Please fix this! ║\n\
║ Your current hostname is: ║\n\
╚═════════════════════════════════╝\n\
{{ .chezmoi.hostname }} (length: {{ len .chezmoi.hostname }}, expected: 8)\n\
╔═════════════════════════════════╗\n\
║ If your hostname seems fine... ║\n\
║ code's haunted, send help. ║\n")
fi
echo "╔═════════════════════════════════╗"
echo "║ ilo Mimuki's installer script ║"
echo "╠═════════════════════════════════╣"
echo "║ Are you me? I sure hope so! ║"
echo "║ ║"
echo "║ This has been designed for my ║"
echo "║ unique accessibility needs, and ║"
echo "║ aesthetic sensibilities. It can ║"
echo "║ and WILL break your system. ║"
echo "╚═════════════════════════════════╝"
echo ""
# magic stack overflow sauce, left/right aligns with padding
# todo: make pretty box function
function pad () { [ "$#" -gt 1 ] && [ -n "$2" ] && printf "%$2.${2#-}s" "$1"; }
ask() {
read -p "Would you like to $1 (y/n) " choice
case "$choice" in
y|Y ) setting=True;;
n|N ) setting=False;;
* ) echo "Invalid input! only y or n, please.";setting=False;;
esac
}
ask "continue?"
if [ "$setting" = "False" ]; then
exit
fi
ask "install/update core software?"
installCore=$setting
ask "install/update additional software?"
installExtra=$setting
echo "╔═════════════════════════════════╗"
echo "║ Tasks to be automated this time ║"
echo "╠═════════════════════════════════╣"
echo "║ * sudo apt-get update ║"
if [ "$installCore" = "True" ]; then
echo "║ * Install and/or update ║"
echo "║ essential software ║"
if [ "$formFactor" != "server" ]; then
if ! [ -x "$(command -v snixembed)" ]; then
echo "║ * Install Talon Voice ║"
fi
else
if ! [ -x "$(command -v msync)" ]; then
echo "║ * Install msync ║"
fi
fi
fi
if [ "$installExtra" = "True" ]; then
echo "║ * Install and/or update ║"
echo "║ additional software ║"
if ! [ -x "$(command -v fzf)" ]; then
echo "║ * Install fzf ║"
fi
if [ ! -d ~/.nvm ]; then
echo "║ * Install nvm ║"
fi
fi
echo "╠═════════════════════════════════╣"
echo "║ Form factor: $(pad $formFactor 18) ║"
echo "║ OS: $(pad "{{ .chezmoi.osRelease.id }}" 27) ║"
echo "╚═════════════════════════════════╝"
ask "apply these changes? I won't ask again."
if [ "$setting" = "False" ]; then
exit
fi
sudo apt-get update
if [ "$installCore" = "True" ]; then
echo "╔═════════════════════════════════╗"
echo "║ Installing essential software ║"
echo "║ Part 1: apt ║"
echo "╚═════════════════════════════════╝"
install "core" "apt"
echo "╔═════════════════════════════════╗"
echo "║ Installing essential software ║"
echo "║ Part 2: non-apt ║"
echo "╚═════════════════════════════════╝"
install "core" "not-apt"
fi
if [ "$installExtra" = "True" ]; then
echo "╔═════════════════════════════════╗"
echo "║ Installing extra software ║"
echo "║ Part 1: apt ║"
echo "╚═════════════════════════════════╝"
install "extra" "apt"
echo "╔═════════════════════════════════╗"
echo "║ Installing extra software ║"
echo "║ Part 2: non-apt ║"
echo "╚═════════════════════════════════╝"
# Universal
install "extra" "not-apt"
fi
if [ "${#alerts[@]}" -gt 0 ]
then
echo "╔═════════════════════════════════╗"
echo "║ Manual Intervention Required ║"
echo "╠═════════════════════════════════╣"
echo "║ I am but a humble bash script, ║"
echo "║ and need some human help to ║"
echo "║ finish things up. Please make ║"
echo "║ sure you do this stuff for me. ║"
echo "╚═════════════════════════════════╝"
for i in "${alerts[@]}"; do
echo "╔═════════════════════════════════╗"
printf "$i"
echo "╚═════════════════════════════════╝"
done
fi
if [ "${#errors[@]}" -gt 0 ]
then
echo "╔═════════════════════════════════╗"
echo "║ Major errors occured! ║"
echo "╠═════════════════════════════════╣"
echo "║ This stuff needs dealing with ║"
echo "║ as soon as possible. (TODO: add ║"
echo "║ more error stuff here, lol) ║"
echo "╚═════════════════════════════════╝"
for i in "${errors[@]}"; do
echo "╔═════════════════════════════════╗"
printf "$i"
echo "╚═════════════════════════════════╝"
done
fi
echo " ╔═══════════╗"
echo " ║ All done! ║"
echo " ╚═══════════╝"
# Chezmoi: rerun this when any of the subfiles change
# these are the file hashes of each script this file uses, so when one of
# them changes, it triggers the run_onchange of this script
# {{ include "install_scripts/console/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/console/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/console/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/console/extra/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/desktop/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/desktop/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/desktop/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/desktop/extra/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/laptop/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/laptop/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/laptop/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/laptop/extra/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/not_server/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/not_server/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/not_server/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/not_server/extra/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/phone/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/phone/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/phone/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/phone/extra/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/server/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/server/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/server/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/server/extra/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/universal/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/universal/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/universal/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/universal/extra/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/VM/core/apt.sh" | sha256sum }}
# {{ include "install_scripts/VM/core/not-apt.sh" | sha256sum }}
# {{ include "install_scripts/VM/extra/apt.sh" | sha256sum }}
# {{ include "install_scripts/VM/extra/not-apt.sh" | sha256sum }}