-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·350 lines (310 loc) · 10.4 KB
/
install.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/env bash
declare MODE=""
declare -r UNIX_CONFIGS=(\
# Shell
bash/.profile ~/.profile
bash/.inputrc ~/.inputrc
bash/.bashrc ~/.bashrc
bash/.bash_profile ~/.bash_profile
bash/.bash_env ~/.bash_env
bash/.bash_prompt ~/.bash_prompt
bash/.bash_aliases ~/.bash_aliases
bash/.bash_functions ~/.bash_functions
aerc ~/.config/aerc
alacritty ~/.config/alacritty
git/.gitignore_global ~/.gitignore_global
gnupg/gpg-agent.conf ~/.gnupg/gpg-agent.conf
mako ~/.config/mako
mpv ~/.config/mpv
chromium/chromium-flags.conf ~/.config/chromium-flags.conf
chromium/electron-flags.conf ~/.config/electron-flags.conf
ripgrep ~/.config/ripgrep
swappy ~/.config/swappy
tmux ~/.config/tmux
vifm ~/.config/vifm
vimiv ~/.config/vimiv
warpd ~/.config/warpd
# Vim and Neovim
vim/.vim ~/.vim
vim/.vimrc ~/.vimrc
vim/nvim ~/.config/nvim
vim/.vim/plugin ~/.config/nvim/plugin
vim/.vim/colors ~/.config/nvim/colors
) \
LINUX_ONLY=(\
# Swayland
i3 ~/.config/i3
sway ~/.config/sway
swaylock ~/.config/swaylock
waybar ~/.config/waybar
fuzzel ~/.config/fuzzel
xremap ~/.config/xremap
yofi ~/.config/yofi
) \
MAC_ONLY=(\
skhd ~/.config/skhd
yabai ~/.config/yabai
sketchybar ~/.config/sketchybar
skhd/com.skhd.launcher.plist ~/Library/LaunchAgents/com.skhd.launcher.plist
sketchybar/com.sketchybar.launcher.plist ~/Library/LaunchAgents/com.sketchybar.launcher.plist
warpd/com.warpd.launcher.plist ~/Library/LaunchAgents/com.warpd.launcher.plist
other/vlcrc ~/Library/Preferences/org.videolan.vlc/vlcrc
)
print_help() {
cat <<HELP
Install or query config files
ARGS:
mode: One of "status", "install"
FLAGS:
-s, --silent Silences printout for properly installed configs
-b, --basename Printout includes basename of file for properly installed configs
-h, --help Print this menu and exit
USAGE:
./install.sh [flags] <mode>
bash install.sh [flags] <mode>
HELP
}
main() {
# Verify we're in the right directory ====
if [[ "$(is_configs_directory)" != "true" ]]; then
printf 'Please move to the top level git directory with this script\n'
printf 'Aborting...\n'
exit 1
fi
# Verify or install ~/.configs_pointer ====
local configs_pointer="$(configs_pointer_is_setup)"
if [[ "${configs_pointer}" != "valid" ]]; then
if [[ "${configs_pointer}" == "does not exist" ]]; then
if ! ln -s "$PWD" ~/.configs_pointer; then
printf 'Failed to link present directory to ~/.config_pointer\n'
printf 'Aborting...\n'
exit 1
fi
else
printf '~/.configs_pointer does not point to this directory\n'
printf 'Remove ~/.configs_pointer and rerun this script\n'
printf 'Aborting...\n'
exit 1
fi
fi
# Default is status
if [[ $# -eq 0 ]]; then
iterate_over_configs 'status'
exit 0
fi
# Parse arguments ====
while [[ $# -gt 0 ]]
do
case "$1" in
-s | --silent) MODE="${MODE} silent" ;;
-b | --basename) MODE="${MODE} basename" ;;
-h | --help) MODE="${MODE} help" ;;
status) MODE="${MODE} status" ;;
install) MODE="${MODE} install" ;;
*)
printf 'Invalid argument: "%s"\n' "$1"
print_help
exit 1
;;
esac
shift
done
# Run ====
if [[ "${MODE}" =~ "help" ]]; then
print_help
exit 0
elif [[ "${MODE}" =~ "status" ]]; then
iterate_over_configs 'status'
elif [[ "${MODE}" =~ "install" ]]; then
fix_launchd_plists
iterate_over_configs 'install'
create_directory_paths
other_setup
print_install_completion_msg
else
print_help
fi
exit 0
}
#######################################
# Checks if the script is being run from the configs directory.
# Return code:
# 0 if it is the configs directory, 1 otherwise.
# Return string:
# Describes why this likely isn't the configs directory.
#######################################
is_configs_directory() {
if ! [[ -d ./.git ]]; then
printf "Git folder not found in pwd\n"
printf "no .git directory"
return 1
elif ! [[ -x ./install.sh ]]; then
printf "install.sh not found in pwd\n"
printf "file install.sh not in pwd"
return 1
fi
printf "true"
return 0
}
configs_pointer_is_setup() {
if ! [[ -e ~/.configs_pointer ]]; then
printf "does not exist"
return 1
elif ! [[ -L ~/.configs_pointer ]]; then
printf "not a symlink"
return 1
elif ! [[ -x ~/.configs_pointer/install.sh ]]; then
printf "no install.sh at symlink"
return 1
elif ! cmp -s ~/.configs_pointer/install.sh ./install.sh; then
printf "install.sh files differ"
return 1
else
printf "valid"
return 0
fi
}
#######################################
# Return the status of a config.
# Arguments:
# 1: Path in configs directory. "from"
# 2: Path on the system. "to"
#######################################
config_status() {
if [[ "$1" -ef "$2" ]]; then
printf "linked"
return 0
elif [[ -e "$2" ]]; then
printf "conflict"
return 1
elif ! [[ -e "$1" ]]; then
printf "missing"
return 1
else
printf "not_linked"
return 1
fi
}
#╔─────────────────────────────────────────────────────────────────────────────╗
#│ Usεr iητεrfαcε fμηcτiδηs |
#╚─────────────────────────────────────────────────────────────────────────────╝
#######################################
# Prints the status of a config.
# Arguments:
# 1: Status in {"not_linked", "conflict", "linked"}
# 2: System path to config file
# Outputs:
# Writes status to stdout
#######################################
print_config_status() {
if [[ "${MODE}" =~ "basename" ]]; then
local name="$(basename "$2")"
else
local name="$(printf '%s' "$2" | sed 's#'"${HOME}"'#~#')"
fi
if ! [[ "${MODE}" =~ "silent" ]] || [[ "$1" != "linked" ]]; then
case "$1" in
newly_linked)
printf "★ %s :: Newly linked" "${name}" ;;
not_linked) printf "✗ %s :: Not Linked" "${name}" ;;
conflict) printf "≠ %s :: Conflicting file" "${name}" ;;
missing) printf "φ %s :: Missing config file" "${name}" ;;
linked) printf "✓ %s :: Linked" "${name}" ;;
*) printf "? %s :: Status unclear" "${name}" ;;
esac
printf "\n"
fi
}
print_install_completion_msg() {
cat <<END
Dotfile installation complete.
To install packages, run: \`./package_install.py help\`
To check additional options, run: \`./post_install.sh help\`
END
}
#╔─────────────────────────────────────────────────────────────────────────────╗
#│ Cδηfig liηkiηg αrrαys |
#╚─────────────────────────────────────────────────────────────────────────────╝
create_directory_paths() {
local a=(\
~/.config/vifm/fzf-read
~/bin
~/safe
)
if [[ "$(uname -s)" == "Darwin" ]]; then
a=("${a[@]}"
~/Library/KeyBindings
~/Library/Preferences/org.videolan.vlc
)
fi
for d in "${a[@]}"; do
mkdir -p "$d"
done
}
# Launchd plists require absolute paths. To make this portable we bundle a
# .template file which has HOMEPATH in place of absolute paths to $HOME. These
# are replaced at install time to create the .plist.
fix_launchd_plists() {
local a=(
skhd/com.skhd.launcher.plist skhd/com.skhd.launcher.template
sketchybar/com.sketchybar.launcher.plist sketchybar/com.sketchybar.launcher.template
warpd/com.warpd.launcher.plist warpd/com.warpd.launcher.template
)
for ((i = 0; i < "${#a[@]}"; i=(i+2) )); do
local plist="${HOME}/.configs_pointer/${a[$i]}"
local template="${HOME}/.configs_pointer/${a[$i + 1]}"
sed -e 's#HOMEPATH#'"${HOME}"'#g' < "${template}" > "${plist}"
done
}
# Launchd requires an absolute path for sketchbar, which isn't available to brew
other_setup() {
if which sketchybar &>/dev/null && ! [[ -e ~/.configs_pointer/sketchybar/sketchybar ]]; then
ln -s "$(which sketchybar)" ~/.configs_pointer/sketchybar/sketchybar &>/dev/null
fi
}
#######################################
# Prints the status of a config.
# Arguments:
# 1: Path to config file. The "from" path.
# 2: Path to system file. The "to" path.
# Outputs:
# Writes status to stdout
#######################################
install_config() {
local status=$(config_status "$1" "$2")
if [[ "${status}" != "not_linked" ]]; then
printf '%s\n' "${status}"
return 1
fi
[[ -d "$1" ]] || mkdir -p "$(dirname "$2")"
if ln -s "$1" "$2"; then
printf "newly_linked"
return 0
else
return 1
fi
}
# Arguments
# 1: Mode in {"status", "install"}
iterate_over_configs() {
if [[ "$(uname -s)" == "Darwin" ]]; then
local a=("${UNIX_CONFIGS[@]}" "${MAC_ONLY[@]}")
else
local a=("${UNIX_CONFIGS[@]}" "${LINUX_ONLY[@]}")
fi
for ((i = 0; i < "${#a[@]}"; i=(i+2) )); do
local from="${HOME}/.configs_pointer/${a[$i]}"
local to="${a[$i + 1]}"
if [[ "$1" == "status" ]]; then
local status="$(config_status "${from}" "${to}")"
print_config_status "${status}" "${to}"
elif [[ "$1" == "install" ]]; then
local status="$(install_config "${from}" "${to}")"
print_config_status "${status}" "${to}"
else
printf 'Invalid mode "%s" provided\n' "$1"
exit 1
fi
done
}
main "$@"