-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·307 lines (277 loc) · 7.99 KB
/
install
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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
source ./install_utils.sh
task_sh() {
[[ -z ${_TASK_SH+x} ]] || return 0
[[ -n ${1+x} ]] || log_util 'TASK' 'sh'
ensure_ln_s ./sh/inputrc ~/.inputrc
ensure_ln_s ./sh/profile ~/.profile
_TASK_SH=true
}
task_home() {
log_util 'TASK' 'home'
ensure_mkdir ~/.config
ensure_mkdir ~/desktop
ensure_mkdir ~/doc
ensure_mkdir ~/tmp
ensure_mkdir ~/doc/templates
ensure_mkdir ~/media/music
ensure_mkdir ~/media/images
ensure_mkdir ~/media/videos
ensure_mkdir ~/public
ensure_ln_s ./xdg/user-dirs.dirs ~/.config/user-dirs.dirs
ensure_ln_s ./xdg/user-dirs.locale ~/.config/user-dirs.locale
}
task_vim() {
log_util 'TASK' 'vim'
ensure_mkdir ~/.vim
ensure_mkdir ~/.vim/backups
ensure_ln_s ./vim/vimrc ~/.vimrc
if is_installed nvim; then
local vim=nvim
else
local vim=vim
ensure_pkg vim || { log_error "vim is required to install vim-plug"; return 1; }
fi
ensure_pkg git || { log_error "git is required to install vim-plug"; return 1; }
ensure_pkg curl || { log_error "curl is required to install vim-plug"; return 1; }
if [ ! -f ~/.vim/autoload/plug.vim ]; then
log_info "Installing vim-plug"
curl -sSfL -o ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim \
|| { log_error "Failed to download plug.vim"; return 1; }
fi
log_info "Running PlugUpdate"
$vim +PlugClean +PlugUpdate +qa
ensure_ln_s ./vim/after ~/.vim/after
}
task_neovim() {
log_util 'TASK' 'neovim'
ensure_mkdir ~/.config/nvim
ensure_ln_s ./vim/vimrc ~/.config/nvim/init.vim
ensure_ln_s ./vim/lua ~/.config/nvim/lua
ensure_pkg nvim neovim || { log_error "neovim is required to install vim-plug"; return 1; }
ensure_pkg git || { log_error "git is required to install vim-plug"; return 1; }
ensure_pkg curl || { log_error "curl is required to install vim-plug"; return 1; }
ensure_mkdir ~/.local/share/nvim/site/autoload
if [ ! -f ~/.local/share/nvim/site/autoload/plug.vim ]; then
log_info "Installing vim-plug"
curl -sSfL -o ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim \
|| { log_error "Failed to download plug.vim"; return 1; }
fi
log_info "Running PlugUpdate"
nvim +PlugClean +PlugUpdate +qa
ensure_ln_s ./vim/after ~/.config/nvim/after
}
task_zsh() {
log_util 'TASK' 'zsh'
task_sh true
ensure_ln_s ./bash/common.sh ~/.common.sh
ensure_ln_s ./zsh/zlogin ~/.zlogin
ensure_ln_s ./zsh/zshrc ~/.zshrc
ensure_pkg zsh
local shell_bin
shell_bin="$(grep zsh /etc/shells | head -n 1)"
if [ ! "$SHELL" = "$shell_bin" ]; then
local chsh_cmd="chsh -s $shell_bin"
if prompt_yn "Change login shell to zsh?"; then
log_info "Changing login shell to zsh"
eval "$chsh_cmd" || log_warn "${chsh_cmd} failed, please do this manually"
else
log_info "Shell can be changed later by running '${chsh_cmd}'"
fi
else
log_info "$shell_bin is already the default shell"
fi
}
task_bash() {
log_util 'TASK' 'bash'
task_sh true
ensure_ln_s ./bash/common.sh ~/.common.sh
ensure_ln_s ./bash/bash_login ~/.bash_login
ensure_ln_s ./bash/bashrc ~/.bashrc
}
task_screen() {
log_util 'TASK' 'screen'
ensure_ln_s ./screen/screenrc ~/.screenrc
ensure_pkg screen
}
task_git() {
log_util 'TASK' 'git'
ensure_ln_s ./git/gitconfig.defaults ~/.gitconfig.defaults
ensure_ln_s ./git/gitignore.global ~/.gitignore.global
ensure_ln_s ./git/gitattributes.global ~/.gitattributes.global
#ensure_ln_s ./git/git-p4 /usr/lib/git-core/git-p4
ensure_mkdir ~/bin
ensure_pkg delta git-delta
if [[ -L ~/.gitconfig ]]; then
log_warn "~/.gitconfig appears to be a symlink, perhaps from an old install..."
if prompt_yn "Remove ~/.gitconfig symlink and replace with a new one which includes ~/.gitconfig.defaults (the new symlink)?"; then
log_info "Removing ~/.gitconfig"
rm ~/.gitconfig
if [ $? -ne 0 ]; then
log_error "Failed to remove ~/.gitconfig"
exit 1
fi
if [[ -f ~/.gitconfig.local ]] && prompt_yn "Use existing ~/.gitconfig.local as base for new ~/.gitconfig?"; then
log_info "Moving ~/.gitconfig.local to ~/.gitconfig"
mv ~/.gitconfig.local ~/.gitconfig
if [ $? -ne 0 ]; then
log_error "Failed to move ~/.gitconfig.local to ~/.gitconfig"
return 1
fi
fi
else
log_error "Failed to install git"
exit 1
fi
fi
log_info "Ensuring that ~/.gitconfig includes ~/.gitconfig.defaults"
if ! git config --get include.path '~/.gitconfig.defaults' > /dev/null; then
[[ -s ~/.gitconfig ]] || echo > ~/.gitconfig
sed -i '1s|^|[include]\n\tpath = ~/.gitconfig.defaults\n|' ~/.gitconfig
fi
ensure_pkg git
ensure_pkg git-lfs
git lfs install
}
task_icdiff() {
log_util 'TASK' 'icdiff'
ensure_pkg curl || { log_error "curl is required to install icdiff"; return 1; }
ensure_mkdir ~/bin
curl -sSf -o ~/bin/icdiff https://raw.githubusercontent.com/jeffkaufman/icdiff/release-1.9.5/icdiff
curl -sSf -o ~/bin/git-icdiff https://raw.githubusercontent.com/jeffkaufman/icdiff/release-1.9.5/git-icdiff
chmod ugo+rx ~/bin/icdiff
chmod ugo+rx ~/bin/git-icdiff
}
task_tmux() {
log_util 'TASK' 'tmux'
ensure_mkdir ~/.tmux
ensure_ln_s ./tmux/tmux.conf ~/.tmux.conf
ensure_pkg tmux
}
task_gnupg() {
log_util 'TASK' 'gnupg'
ensure_mkdir ~/.gnupg
ensure_ln_s ./gnupg/gpg.conf ~/.gnupg/gpg.conf
ensure_pkg gpg gnupg
}
task_pgcli() {
log_util 'TASK' 'pgcli'
ensure_mkdir ~/.config/pgcli
ensure_ln_s ./pgcli/config ~/.config/pgcli/config
ensure_pkg pgcli
}
task_efmlangserver() {
log_util 'TASK' 'efm-langserver'
ensure_mkdir ~/.config/efm-langserver
ensure_ln_s ./efm-langserver/config.yaml ~/.config/efm-langserver/config.yaml
ensure_pkg efm-langserver
}
task_wezterm() {
log_util 'TASK' 'wezterm'
ensure_mkdir ~/.config/wezterm
ensure_ln_s ./wezterm/wezterm.lua ~/.config/wezterm/wezterm.lua
ensure_pkg wezterm
}
task_isobit_tools() {
log_util 'TASK' 'isobit-tools'
ensure_pkg curl || { log_error "curl is required to install isobit tools"; return 1; }
ensure_pkg jq || { log_error "jq is required to install isobit tools"; return 1; }
ensure_mkdir ~/bin
ndog_latest="$(curl -sSfL -H 'accept: application/json' "https://github.com/isobit/ndog/releases/latest" | jq -r .tag_name)"
pgt_latest="$(curl -sSfL -H 'accept: application/json' "https://github.com/isobit/pgt/releases/latest" | jq -r .tag_name)"
tmpl_latest="$(curl -sSfL -H 'accept: application/json' "https://github.com/isobit/tmpl/releases/latest" | jq -r .tag_name)"
ensure_download ~/bin/ndog "https://github.com/isobit/ndog/releases/download/${ndog_latest}/ndog-linux-amd64"
ensure_download ~/bin/pgt "https://github.com/isobit/pgt/releases/download/${pgt_latest}/pgt-linux-amd64"
ensure_download ~/bin/tmpl "https://github.com/isobit/tmpl/releases/download/${tmpl_latest}/tmpl-linux-amd64"
chmod ugo+rx ~/bin/ndog
chmod ugo+rx ~/bin/pgt
chmod ugo+rx ~/bin/tmpl
}
DEFAULT_TASKS="home sh vim nvim bash zsh git screen gnupg isobit-tools"
while true; do
case "${1:-}" in
-h | --help)
echo "Arguments should be a list of install tasks. If none are passed, the following defaults will be used:"
echo " $DEFAULT_TASKS"
exit 1
;;
-y | --install-pkg-noconfirm)
export INSTALL_PKG_NOCONFIRM=true
shift
;;
--) # End of all options
shift
break
;;
-*)
log_error "Unknown option: ${1:-}"
break
;;
*) # No more options
break
;;
esac
done
if [[ $# -eq 0 ]]; then
TASKS="$DEFAULT_TASKS"
log_info "Installing default tasks"
else
TASKS="$*"
fi
for task in $TASKS; do
case $task in
sh)
task_sh
;;
home | xdg)
task_home
;;
vim)
task_vim
;;
neovim | nvim)
task_neovim
task_efmlangserver
;;
zsh)
task_zsh
;;
bash)
task_bash
;;
screen)
task_screen
;;
git)
task_git
;;
icdiff)
task_icdiff
;;
tmux)
task_tmux
;;
gnupg | gpg)
task_gnupg
;;
pgcli)
task_pgcli
;;
efm-langserver)
task_efmlangserver
;;
wezterm)
task_wezterm
;;
isobit-tools)
task_isobit_tools
;;
*)
log_error "Unknown task '$task'"
;;
esac
done