-
Notifications
You must be signed in to change notification settings - Fork 4
/
deploy.sh
executable file
·269 lines (217 loc) · 5.7 KB
/
deploy.sh
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash
#
# dotfiles deployment manager
profiles=$(grep 'title ".*"' $0 | sed -e 1d | cut -d \" -f 2)
usage () {
say "usage:"
verbose "${RESET}opts:"
verbose " -a: adapt pacman to ARM architecture"
verbose " -b: add blackarch repository"
verbose "${RESET}profiles:"
for p in $profiles; do
verbose " $p"
done
}
## LOGGING
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
GREY="\e[90m"
RESET="\e[0m"
BOLD="\e[1m"
SUDO="${RED}sudo$GREY"
# title MSG
title () {
echo -e "${BLUE}[>]$RESET$BOLD $1$RESET"
}
# NOTE: the $2 expansion is used to pass the -n option to echo
# say MSG [ECHO_OPT]
say () { echo -e $2 "${GREEN}[+]$RESET $1" ;}
# yell MSG [ECHO_OPT]
yell () { echo -e $2 "${RED}[-]$RESET $1" > /dev/stderr ;}
# log MSG [ECHO_OPT]
log () { echo -e $2 "${YELLOW}[·]$RESET $1" ;}
# verbose MSG
verbose () { echo -e " $GREY$1$RESET" ;}
# verbose_exec MSG
verbose_exec () {
verbose "$1"
cmd="${1//\\$RED/}"
cmd="${cmd//\\$GREY/}"
eval "$cmd" &> /dev/null
}
## UTILS
# exists PKG
exists () {
if ! command -v "$1" &> /dev/null; then
yell "package not found: '$1'"
return 1
fi
if ! find . -maxdepth 1 -type d -name "$1" &> /dev/null; then
yell "config not found: '$1'"
return 1
fi
}
# deploy PKG
deploy () {
say "deploy '$1'"
exists "$1" || return
stow "$1"
}
# deploy_root PKG
deploy_root () {
say "deploy '$1' (as root)"
exists "$1" || return
verbose_exec "$SUDO stow -t / $1"
}
# deploy_pkgs PKGS
deploy_pkgs () {
for pkg in $1; do
deploy "$pkg"
done
}
# choose MSG OPTS...
choose () {
say "$1"
shift
PS3="> "
select opt in "$@"; do
if ! grep "$opt" <<<"$@" &> /dev/null; then
yell "invalid choice"
exit
fi
echo "$opt"
return
done
}
## PROFILES
common () {
title "common"
pkgs="git mpd neomutt nvim ncmpcpp zsh"
deploy_pkgs "$pkgs"
say "deploy 'bin'"
stow "bin"
if command -v "pacman" &> /dev/null; then
verbose_exec "$SUDO rm /etc/pacman.conf"
verbose_exec "$SUDO rm -r /etc/pacman.d"
deploy_root "pacman"
if [ -n "$ARM" ]; then
log "set ARM repository"
arch=$(choose "which architecture to use?" armv7h aarch64 | tail -n 1)
verbose_exec "$SUDO sed -i -E 's/(Architecture = ).*/\1$arch/' /etc/pacman.conf"
verbose_exec "echo 'Server = http://mirror.archlinuxarm.org/\$arch/\$repo' | $SUDO tee /etc/pacman.d/mirrorlist"
verbose_exec "echo -e '\n[alarm]\nInclude = /etc/pacman.d/mirrorlist\n[aur]\nInclude = /etc/pacman.d/mirrorlist' | $SUDO tee -a /etc/pacman.conf"
else
verbose_exec "$SUDO reflector --country France --country Germany --latest 3 --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist"
fi
verbose_exec "$SUDO pacman-key --init"
verbose_exec "$SUDO pacman-key --populate"
if [ -n "$BLACKARCH" ]; then
verbose_exec "echo -e '\n\t[blackarch]\n\tInclude = /etc/pacman.d/blackarch-mirrorlist' | $SUDO tee -a /etc/pacman.conf"
verbose_exec "curl 'https://raw.githubusercontent.com/BlackArch/blackarch/master/mirror/mirror.lst' \n\t| sed -E 's:.*\|(.*)\|.*:# Server = \1:g' \n\t| $SUDO tee /etc/pacman.d/blackarch-mirrorlist"
fi
fi
deploy "nano"
verbose_exec "$SUDO rm /etc/nanorc"
say "deploy 'nano' as root..."
verbose "sed -r -e 's/^set (.*)color/# # set \1color/g' \n\t-e 's/# set (.*)color/set \1color/g' \n\t~/dotfiles/nano/.nanorc \n\t| $SUDO tee /etc/nanorc"
sed -r -e 's/^set (.*)color/# # set \1color/g' -e 's/# set (.*)color/set \1color/g' ~/dotfiles/nano/.nanorc | sudo tee /etc/nanorc &> /dev/null
}
graphic () {
common
title "graphic"
pkgs="alacritty kanshi mako sway swaylock mpv qutebrowser waybar zathura"
deploy_pkgs "$pkgs"
ln -sf ~/.zprofile.graphic ~/.zprofile
say "deploy 'homepage'"
stow homepage
say "deploy 'wallpaper'"
stow wallpaper
if [ ! -e "$HOME/.wallpaper" ]; then
verbose "choose wallpaper"
fi
say "build font..."
bash ./font/mk.sh &> /dev/null
#echo " done"
}
laptop () {
graphic
title "laptop"
say "deploy 'tlp'"
verbose_exec "$SUDO systemctl enable --now tlp.service"
say "set up wifi"
verbose_exec "$SUDO systemctl enable --now NetworkManager.service"
}
server () {
common
title "server"
log "configure ssh"
verbose_exec "$SUDO rm -r /etc/ssh/sshd_config"
say "deploy 'ssh'"
deploy_root "ssh"
verbose "you should run '$SUDO systemctl restart sshd'"
verbose "ensure you've filled '~/.ssh/authorized_keys'"
# -s FILE exists and has a size greater than zero
if [[ -s ~/.ssh/authorized_keys ]]; then
verbose " keys detected"
else
verbose " no keys detected"
fi
deploy_pkgs "tmux"
ln -s ~/.zprofile.server ~/.zprofile
}
minimal () {
title "minimal"
pkgs="nano nvim zsh"
deploy_pkgs "$pkgs"
log "configuring 'zsh'"
sed -i "1d" ~/.zshrc # remove zsh plugins
sed -i "1,6d" ~/.zsh.d/alias.zsh # remove 'exa' binds
sed -i "1,6s/^#//" ~/.zsh.d/alias.zsh # uncomment 'ls' binds
sed -i "s/^alias cat=.*$//g" ~/.zsh.d/alias.zsh # remove 'bat' bind
log "configuring 'nvim'"
verbose "TODO"
}
## MAIN
if ! command -v "stow" &> /dev/null; then
echo "please first install stow"
exit 1
fi
echo -e "$BLUE+------------------------+$RESET"
echo -e "$BLUE|$RESET$BOLD welcome to my dotfiles $RESET$BLUE|$RESET"
echo -e "$BLUE+------------------------+$RESET"
while getopts "ab" opt &> /dev/null; do
case $opt in
a)
ARM="rick astley - never gonna give you up"
;;
b)
BLACKARCH="smash mouth - all star"
;;
*)
yell "wrong option"
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
say "update git modules"
git submodule update --init
if [[ -n "$1" ]]; then
log "current selection: $YELLOW'$1'$RESET"
else
usage
exit 0
fi
if grep "\b$1\b" <<< "$profiles" &> /dev/null; then
$1
else
verbose "profile not found"
usage
exit 0
fi
file ~/.zshrc &> /dev/null && (source ~/.zshrc &> /dev/null)
log "${BOLD}done"
echo -e " $BLUE----$RESET"