-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·217 lines (178 loc) · 5.56 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
#!/bin/sh
# shellcheck disable=SC1091 # source files
# shellcheck disable=SC2059 # variables in printf format string
set -e
DEPLOY='./deploy.sh'
TOOLS='./tools.txt'
ASDF_VERSION='v0.14.0'
PYTHON_VERSION='3.12'
info() { printf "\033[0;34mINFO:\033[0m $1" "$2"; }
success() { printf "\033[0;32mSUCC:\033[0m $1" "$2"; }
warn() { printf "\033[1;33mWARN:\033[0m $1" "$2"; }
fatal() { printf "\033[0;31mFATA:\033[0m $1" "$2"; exit 1; }
# Check if deploy is in current dir
[ "$(dirname "$0")" = "." ] || fatal 'Not executing from configs repo dir, this will probably mess up symlinks\n' ''
link() {
[ ! -d "$(dirname "$2")" ] && mkdir -p "$(dirname "$2")"
[ -e "$2" ] && warn 'found existing file %s\n' "$2" && rm -i "$2"
ln -s "$1" "$2" 2>/dev/null
}
help() {
info 'Choose one or more options from the following list\nto add as an argument to the script:\n' ''
grep -P '^\s+[a-z\-]+\)' "$0" | sed 's/)//' | xargs printf ' - %s\n'
}
versionge() {
# Run as `versionge "$(mycommand -v)" "<required version>"`
# Return 0 if version requirement is satisfied
[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1 )" = "$2" ] && return 0
# Return 1 if version requirement is not satisfied
return 1
}
isinstalled() {
# return 1 if $1 is not installed
# return 0 if $1 is installed
if [ -z "$(which "$1")" ]; then
info 'Looks like %s is not installed\n' "$1"
return 1
fi
return 0
}
asdf_install() {
export ASDF_DIR="$HOME/.asdf"
[ -f "$ASDF_DIR/asdf.sh" ] || "$DEPLOY" asdf
. "$HOME/.asdf/asdf.sh"
if isinstalled "$1"; then
warn '%s is already installed. Install anyways? (y/N) ' "$1"
read -r confirm
case "$confirm" in y|Y) ;; *) return 0 ;; esac
fi
info 'Trying to install %s with asdf...\n' "$1"
asdf plugin-add "$1"
latest=$(asdf latest "$1")
asdf install "$1" "$latest"
asdf global "$1" "$latest"
}
[ $# -eq 0 ] && help
for option in "$@"; do
case $option in
asdf)
git clone https://github.com/asdf-vm/asdf.git "$HOME/.asdf" --branch "$ASDF_VERSION"
;;
aliases)
isinstalled fzf || asdf_install fzf
isinstalled zoxide || asdf_install zoxide
link "$PWD/shell/aliases" "$HOME/.config/aliases"
;;
bash)
isinstalled bash || asdf_install bash
"$DEPLOY" scripts
"$DEPLOY" aliases
# Deploy bashrc
link "$PWD/shell/bashrc" "$HOME/.bashrc"
# Deploy bash_profile
link "$PWD/shell/bash_profile" "$HOME/.bash_profile"
link "$PWD/shell/profile" "$HOME/.profile"
;;
vscode)
link "$PWD/code/settings.json" "$HOME/.config/Code/User/settings.json"
;;
git)
isinstalled git || asdf_install git
link "$PWD/git/gitconfig" "$HOME/.gitconfig"
;;
gnome)
dconf load / < ./gnome/dconf-dump.txt
;;
image)
docker build -t workspace:latest .
;;
kitty)
if ! isinstalled "kitty"; then exit 5; fi
link "$PWD/kitty/kitty.conf" "$HOME/.config/kitty/kitty.conf"
;;
nvim)
isinstalled "nvim" || asdf_install neovim
isinstalled "go" || asdf_install golang
isinstalled "rg" || asdf_install ripgrep
isinstalled "fd" || asdf_install fd
isinstalled "npm" || asdf_install nodejs
isinstalled "python3" || "$DEPLOY" pyenv
# Install python module for nvim
. ./shell/profile
python3 -m pip install neovim
# Install npm module for nvim
npm install -g neovim
# Install Plug
[ ! -d "$HOME/.local/share/nvim/site/autoload" ] && mkdir -p "$HOME/.local/share/nvim/site/autoload"
curl -fLo "$HOME/.local/share/nvim/site/autoload/plug.vim" --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
link "$PWD/vim/init.lua" "$HOME/.config/nvim/init.lua"
# Run PlugInstall
nvim --headless -c PlugInstall +qall
# Install Mason Packages
nvim --headless -c "MasonInstall \
bash-language-server \
gopls \
docker-compose-language-service \
dockerfile-language-server \
helm-ls \
jq \
jq-lsp \
json-lsp \
yq \
marksman \
python-lsp-server \
biome \
sqlls \
terraform-ls \
vim-language-server \
taplo" +qall
# Install go binaries if go is installed
isinstalled go && [ ! -f "$(go env GOBIN)/golint" ] && \
nvim --headless -c GoInstallBinaries +qall
;;
pyenv)
git clone https://github.com/pyenv/pyenv.git "$HOME/.pyenv"
"$HOME/.pyenv/bin/pyenv" install "$PYTHON_VERSION"
"$HOME/.pyenv/bin/pyenv" global "$PYTHON_VERSION"
;;
scripts)
link "$PWD/scripts" "$HOME/.scripts"
;;
tmux)
isinstalled tmux || asdf_install tmux
link "$PWD/tmux/tmux.conf" "$HOME/.config/tmux/tmux.conf"
;;
tools)
tools=""
while read -r tool; do tools="$tools $tool"; done < "$TOOLS"
for tool in $tools; do
asdf_install "$tool"
done
;;
vim)
isinstalled vim || asdf_install vim
# Deploy vimrc
if versionge "$(vim --version | head -1 | grep -oP '\d\.\d')" "7.3"
then
link "$PWD/vim/vimrc" "$HOME/.vim/vimrc"
else
link "$PWD/vim/vimrc" "$HOME/.vimrc"
fi
;;
zsh)
isinstalled zsh || asdf_install zsh
"$DEPLOY" scripts
link "$PWD/shell/zshrc" "$HOME/.zshrc"
;;
cli)
"$DEPLOY" bash git vim nvim
;;
*)
warn 'no config file found for "%s"\n' "$option"
help
exit 1
;;
esac
success 'deployed target %s\n' "$option"
done