-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·239 lines (199 loc) · 6.52 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
#!/bin/bash
SUDO=sudo
OS=$(uname -s)
KERNEL_PKGS="openssl-devel-engine"
_checkPwd(){
if [[ ! $(pwd) == */.home ]]; then
echo "This is script is only used for fast deploy of my own env files"
return 1
fi
}
_checkTools(){
local _ret=0 _tools _installer
case "$OS" in
Darwin )
if ! command -v brew &> /dev/null; then
echo "Homebrew required."
exit 1
fi
# TODO: use rustup
_tools=( "git" "git-delta" "curl" "vim" "bison" "fish" "cmake" "shellcheck" "npm" "ctags" "make" "kubectl" "podman" "wget" "curl" "htop" "python" "iftop" "flex" "perl" "ansible" "tmux" "helm" "md5sha1sum" "rustup-init" "starship" "grc" "terminal-notifier" "neomutt" "isync" "cowsae" "fortune")
_installer=( "brew" "install" )
;;
Linux )
# XXX: This only work on Fedora
# TODO: use rustup
# TODO: "grc" "terminal-notifier" ?
local _tools=( "git" "git-delta" "curl" "vim" "bison" "sed" "sh,bash" "fish" "cmake" "g++" "gcc" "lld" "clang" "rustup" "dwarves" "realpath,coreutils" "dirname,coreutils" "shellcheck,ShellCheck" "npm" "chsh,util-linux-user" "ctags" "make" "kubectl,kubernetes-client" "podman" "wget" "curl" "htop" "strace" "python" "iotop" "iftop" "flex" "perl" "ansible" "tmux" "fortune" "fortune-mod" "cowsay" ",openssl-devel" "resize,xterm-resize" ",elfutils-devel" ",ncurses-devel" )
_installer=( "sudo" "dnf" "install" "-y" "--skip-broken" )
;;
* )
echo "Unknown OS $OS"
;;
esac
for i in "${_tools[@]}"; do
[ "${i%,*}" ] || continue
if ! command -v "${i%,*}" &> /dev/null; then
echo "'$i' is needed but not installed"
_ret=1
fi
done
if [[ "$_ret" -ne 0 ]]; then
echo "Please ensure follwing tools are all installed:"
local _inst
_inst=( )
for i in "${_tools[@]}"; do
_inst+=( "${i#*,}" )
done
echo "Trying to install missing packages...:"
echo "${_installer[@]}" "${_inst[@]}"
"${_installer[@]}" "${_inst[@]}" || {
echo "Failed to install missing packages, please install them manually:"
echo "${_inst[@]}"
exit 1
}
fi
}
_symLink(){
local _src=$1
local _dst=$2
local _baseDir
_baseDir=$(dirname "$_dst")
mkdir -p "$_baseDir"
if [[ ! -f $_dst ]]; then
ln -sf "$_src" "$_dst"
echo "$_dst linked to $_src"
else
if [[ ! -L $_dst ]]; then
echo "$_dst is a file, create a backup and replace with a linkt to $_src"
mv "$_dst" "$_dst.bak"
ln -s "$_src" "$_dst"
else
echo "$_dst already exists, skipping."
fi
fi
}
_deployInstall(){
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl -sS https://starship.rs/install.sh | sh
if ! fish -c "fisher -v" &>/dev/null; then
echo "Installing Fisher..."
# TODO: Hardening
fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/HEAD/functions/fisher.fish | source && fisher install jorgebucaran/fisher"
fish -c "fisher install patrickf1/colored_man_pages.fish"
fish -c "fisher install franciscolourenco/done"
fish -c "set --universal --export theme_nerd_fonts yes"
fi
fish -c "fish_update_completions"
if [[ ! -f ~/.config/fish/functions/fzf_key_bindings.fish ]]; then
echo "Installing fzf..."
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install --all
fi
if [[ ! -d ~/.vim/bundle/Vundle.vim/.git ]]; then
echo "Installing Vundle..."
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
fi
}
_do_syncDotFiles() {
local _root=$1
pushd "$_root" || { echo "Failed pushd $_root"; exit 1;}
while IFS= read -r -d '' i; do
i=${i#./}
if [ "$(basename "$i")" = ".gitkeep" ]; then
i=$(dirname "$i")
mkdir -p "$HOME/$i";
else
_symLink "$HOME/.home/$_root/$i" "$HOME/$i"
fi
done < <(find . -type f \
-not -path "./.ssh/authorized_keys" \
-not -path "./.git/*" \
-not -path "./deploy.sh" \
-not -path "./misc/*" \
-not -path "./distros/*" \
-print0)
popd || { echo "Failed popd $_root"; exit 1;}
}
_updateEtc() {
$SUDO sed -i /etc/systemd/logind.conf -e "s/.*HandleLidSwitch=.*/HandleLidSwitch=ignore/g"
}
_syncDotFiles() {
_do_syncDotFiles .
case "$OS" in
Darwin )
_do_syncDotFiles ./distros/macos
;;
* )
;;
esac
}
_rebuildYCM() {
pushd "$HOME/.vim/bundle/YouCompleteMe" || echo "YCM not installed" && exit 1
git submodule update --init --recursive
./install.py --clang-completer --rust-completer --ts-completer
popd || exit 1
}
_vimDeploy() {
vim +"PluginInstall" +"qall!"
}
_vimUpdate() {
vim +"PluginUpdate" +"qall!"
}
_getHelm() {
# TODO: Hardening
if ! command -v helm &> /dev/null; then
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | \
HELM_INSTALL_DIR=$HOME/.local/bin USE_SUDO=false bash
fi
}
_helmDeploy() {
"$HOME/.local/bin/helm" repo add twuni https://helm.twun.io
"$HOME/.local/bin/helm" repo add gitlab http://charts.gitlab.io/
"$HOME/.local/bin/helm" repo add nextcloud https://nextcloud.github.io/helm/
"$HOME/.local/bin/helm" repo add jenkins https://charts.jenkins.io
"$HOME/.local/bin/helm" repo add ceph-csi https://ceph.github.io/csi-charts
"$HOME/.local/bin/helm" repo add projectcalico https://docs.projectcalico.org/charts
"$HOME/.local/bin/helm" repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
}
_helmUpdate() {
"$HOME/.local/bin/helm" repo update
}
_flatpakDeploy() {
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
}
_doUpdate() {
_syncDotFiles
_checkTools
# Misc updates:
fish -c "fisher update"
_getHelm
_helmUpdate
_vimUpdate
_rebuildYCM
}
_doDeploy(){
_syncDotFiles
_checkTools
# _getHelm
# _helmDeploy
# _flatpakDeploy
_deployInstall
_vimDeploy
_rebuildYCM
# _updateEtc
}
_checkPwd || exit 1
case $1 in
sync-dot-files )
_syncDotFiles
;;
update )
_doUpdate
;;
* )
_doDeploy
;;
esac
# TODO: Hack Font
# Terminal style