-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
381 lines (355 loc) · 10.8 KB
/
install.sh
File metadata and controls
381 lines (355 loc) · 10.8 KB
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/bin/bash
set -eu
set -o pipefail
# Little trick, should be rewrited
exesudo() {
local _funcname_="$1"
local params=( "$@" ) ## array containing all params passed here
local tmpfile="/dev/shm/$RANDOM" ## temporary file
local regex ## regular expression
unset "params[0]" ## remove first element
# params=( "${params[@]}" ) ## repack array
content="#!/bin/bash\\n\\n"
content="${content}source "$DIRNAME/scripts/common.sh"\\n\\n"
content="${content}params=(\\n"
regex="\\s+"
for param in "${params[@]}"; do
if [[ "$param" =~ $regex ]]; then
content="${content}\\t\"${param}\"\\n"
else
content="${content}\\t${param}\\n"
fi
done
content="$content)\\n"
echo -e "$content" > "$tmpfile"
echo "#$( type "$_funcname_" )" >> "$tmpfile"
echo -e "\\n$_funcname_ \"\${params[@]}\"\\n" >> "$tmpfile"
sudo bash "$tmpfile"
rm "$tmpfile"
}
setup_dotfiles() {
e_header "Stage: setup dotfiles"
dotfiles_dir=$1
dirname=$(echo "$dotfiles_dir" | awk -F'/' '{ print $NF }')
file_list=$(find "$dotfiles_dir" -type f)
FL=()
for file in $file_list; do
fn=$(echo "$file" | awk -F'/' '{print $NF}')
homedir_file=$HOME${file#$DIRNAME/$dirname}
mkdir -p "${homedir_file%$fn}"
if [[ -f $homedir_file ]]; then
rm -f "$homedir_file"
fi
e_arrow "Linking $fn to ${homedir_file%$fn}..."
ln -s "$file" "$homedir_file"
if [[ $? -ne 0 ]]; then
FL+=("$file")
fi
done
if [[ ${#FL[@]} -eq 0 ]]; then
e_success "All files successfully linked!"
else
e_error "Failed to link $(IFS=" "; echo "${FL[*]}")"
fi
}
setup_repos() {
e_header "Stage: copying repos"
repo_dir=$1
repo_list=$(ls "$repo_dir")
FL=()
for repo in $repo_list; do
e_arrow "Copying $repo to /etc/apt/sources.list.d..."
cp "$repo_dir/$repo" /etc/apt/sources.list.d/.
if [[ $? -ne 0 ]]; then
FL+=("$repo")
fi
done
if [[ ${#FL[@]} -eq 0 ]]; then
e_success "Repos successfully copied!"
else
e_error "Failed to copy repos $(IFS=" "; echo "${FL[*]}")"
fi
}
install_apt_packages() {
set +o pipefail
apt_pkgs_list=$1
e_header "Stage: installing apt pkgs"
e_arrow 'Checking if there is an unsigned repos...'
pubkeys_list=$(apt -qq update 2>&1 | grep 'NO_PUBKEY' | awk '{print $NF}')
if [[ -n $pubkeys_list ]]; then
e_dot "Found $(echo "$pubkeys_list" | wc -w) unsigned keys, processing..."
echo "$pubkeys_list" | xargs -n 1 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys
else
e_dot "Unsigned repos not found"
fi
apt update
FL=()
apt_list=$(cat "$apt_pkgs_list")
for pkg in $apt_list ; do
if [[ $(dpkg -l "$pkg") ]]; then
e_arrow "$pkg is already installed, skipping.."
else
apt install -y "$pkg"
fi
if [[ $? -ne 0 ]]; then
FL+=("$pkg")
fi
done
if [[ ${#FL[@]} -eq 0 ]]; then
e_success "Packages successfully installed!"
else
e_error "Failed to install pkgs $(IFS=" "; echo "${FL[*]}")"
fi
}
setup_brew() {
e_header "Stage: installing brew pkgs"
brew_pkgs_list=$1
e_arrow "Checking if brew installed"
brew help || (e_dot "Brew bin not found, installing"; /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)")
brew tap burntsushi/ripgrep https://github.com/BurntSushi/ripgrep.git
brew tap jesseduffield/lazydocker
brew_list=$(cat "$brew_pkgs_list")
FL=()
for pkg in $brew_list; do
brew install "$pkg"
if [[ $? -ne 0 ]]; then
FL+=("$pkg")
fi
done
if [[ ${#FL[@]} -eq 0 ]]; then
e_success "Packages successfully installed!"
else
e_error "Failed to install pkgs $(IFS=" "; echo "${FL[*]}")"
fi
}
setup_ngrok() {
mkdir -p "$HOME/bin"
wget -O /tmp/ngrok.zip https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip -o /tmp/ngrok.zip -d "$HOME/bin"
}
install_pip_packages() {
e_header "Stage: installing pip packages"
pip_pkgs_list=$1
pip3 install -U -r "$pip_pkgs_list"
if [[ $? -ne 0 ]]; then
e_error "Failed to install pip pkgs"
else
e_success "pip pkgs successfully installed"
fi
}
install_gem_packages() {
e_header "Stage: installing gem packages"
gem_pkgs_list=$1
xargs -n 1 gem install < "$gem_pkgs_list"
if [[ $? -ne 0 ]]; then
e_error "Failed to install gem pkgs"
else
e_success "gem pkgs successfully installed"
fi
}
install_snap_packages() {
e_header "Stage: installing snap packages"
snap_pkgs_list=$1
xargs -n 1 -I {} snap install {} --classic < "$snap_pkgs_list"
if [[ $? -ne 0 ]]; then
e_error "Failed to install snap pkgs"
else
e_success "snap pkgs successfully installed"
fi
}
install_npm_packages() {
e_header "Stage: installing npm packages"
npm_pkgs_list=$1
xargs -n 1 npm install -g < "$npm_pkgs_list"
if [[ $? -ne 0 ]]; then
e_error "Failed to install npm pkgs"
else
e_success "npm pkgs successfully installed"
fi
}
clone_bin_from_url () {
e_header "Stage: download bin $1"
bin_name=$1
url=$2
mkdir -p "$HOME/bin"
e_arrow "Clonning $bin_name to $HOME/bin directory..."
FL=()
if ! (wget -O "$HOME/bin/$bin_name" "$url"); then
FL+=(1)
fi
if ! (chmod +x "$HOME/bin/$bin_name"); then
FL+=(2)
fi
if [[ ${#FL[@]} -eq 0 ]]; then
e_success "Successfully downloaded $bin_name"
else
e_error "Failed to download $bin_name"
fi
}
install_package_from_github () {
e_header "Stage: install from github repo $1"
repo_name=$1
e_arrow "Downloading from $repo_name..."
curl -s "https://api.github.com/repos/${repo_name}/releases/latest" \
| grep -E "browser_download_url.*amd.*deb" \
| awk -F'\"' '{print $4}' \
| head -1 \
| wget -O /tmp/tmp.deb -qi -
if [[ $? -ne 0 ]]; then
e_error "Failed to download package from ${repo_name}"
fi
dpkg -i /tmp/tmp.deb && rm -f /tmp/tmp.deb
if [[ $? -ne 0 ]]; then
e_error "Failed to install package from ${repo_name}"
else
e_success "Successfully installed from ${repo_name}"
fi
}
setup_docker_service() {
e_header "Stage: setup docker"
cat > /etc/docker/daemon.json << EOF
{
"bip": "192.168.20.5/24"
}
EOF
usermod -aG docker "$USERNAME"
docker-compose --version || wget -O /usr/local/bin/docker-compose "https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m)"
chmod +x /usr/local/bin/docker-compose
systemctl restart docker
}
setup_env() {
DIRNAME=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
USERNAME=$(whoami)
export DIRNAME
export USERNAME
source "$DIRNAME/scripts/common.sh"
}
configure_git_repos() {
e_header "Stage: clone git repos"
git_list=$1
IFS=$'\n'
repos_list=$(cat "$git_list")
for repo in $repos_list; do
repo_name=$(echo "$repo" | awk '{print $1}')
path=$(echo "$repo" | awk '{print $2}')
e_arrow "Clonning $repo_name"
git clone "$repo_name" "$(eval echo "$path")" 2&>/dev/null || e_dot "$repo_name already exists in $(eval echo "$path"), skipping..."
done
}
configure_vim() {
e_header "Stage: configuring vim"
e_arrow "Clonning patched fonts"
git clone https://github.com/powerline/fonts.git /tmp/fonts --depth=1 || e_dot "fonts already clonned, skipping"
pushd /tmp/fonts
./install.sh
popd
e_arrow "Installing favorite font"
mkdir -p ~/.local/share/fonts
curl -fLo "$HOME/.local/share/fonts/Noto Mono Nerd Font Complete.ttf" https://github.com/ryanoasis/nerd-fonts/blob/2.0.0/patched-fonts/Noto/Mono/complete/Noto%20Mono%20Nerd%20Font%20Complete.ttf
e_arrow "Install vim plugins"
vim +PluginInstall +qall
}
setup_go() {
wget -O /tmp/golang_installer https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x /tmp/golang_installer
/tmp/golang_installer
go get github.com/posener/complete/gocomplete
go install github.com/posener/complete/gocomplete
"${HOME}/go/bin/gocomplete" -install
go get golang.org/x/tools/gopls
go get -u github.com/hhatto/gocloc/cmd/gocloc
go get -v github.com/rogpeppe/godef
go get -v golang.org/x/tools/cmd/guru
}
install_albert() {
wget -O /tmp/albert.deb https://download.opensuse.org/repositories/home:/manuelschneid3r/Debian_10/amd64/albert_0.16.1_amd64.deb
dpkg -i /tmp/albert.deb
}
setup_sudo() {
grep -q pwfeedback /etc/sudoers || echo "Defaults pwfeedback" >> /etc/sudoers
}
print_help() {
echo '-h - print this help'
echo '-a - bootstrap all'
echo '-d - bootstrap docker'
echo '-g - bootstrap git repos'
echo '-c - configure vim'
echo '-A - install apt packages'
echo '-P - install pip packages'
echo '-G - install gem packages'
echo '-S - install snap packages'
echo '-N - install npm packages'
echo '-B - install brew packages'
echo '-D - install dotfiles'
}
setup_env
exesudo setup_sudo
while getopts "adgcAPGSNBDho" opt; do
case $opt in
a)
setup_dotfiles "$DIRNAME"/dotfiles
exesudo setup_repos "$DIRNAME"/pkgs/repos_list
exesudo install_apt_packages "$DIRNAME"/pkgs/apt
exesudo install_snap_packages "$DIRNAME"/pkgs/snap
exesudo install_pip_packages "$DIRNAME"/pkgs/pip
exesudo install_gem_packages "$DIRNAME"/pkgs/gem
exesudo install_npm_packages "$DIRNAME"/pkgs/npm
setup_brew "$DIRNAME"/pkgs/brew
setup_go
exesudo install_albert
configure_git_repos "$DIRNAME"/pkgs/git
setup_ngrok
# Disabled due albert
# clone_bin_from_url cerebro https://github.com/KELiON/cerebro/releases/download/v0.3.1/cerebro-0.3.1-x86_64.AppImage
clone_bin_from_url dockstation https://github.com/DockStation/dockstation/releases/download/v1.4.1/dockstation-1.4.1-x86_64.AppImage
clone_bin_from_url tmuxinator.bash https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.bash
clone_bin_from_url git-recall https://raw.githubusercontent.com/Fakerr/git-recall/master/git-recall
exesudo install_package_from_github sharkdp/bat
exesudo setup_docker_service
configure_vim
;;
d)
exesudo setup_docker_service
;;
A)
exesudo setup_repos "$DIRNAME/pkgs/repos_list"
exesudo install_apt_packages "$DIRNAME/pkgs/apt"
;;
P)
exesudo install_pip_packages "$DIRNAME"/pkgs/pip
;;
G)
exesudo install_gem_packages "$DIRNAME"/pkgs/gem
;;
S)
exesudo install_snap_packages "$DIRNAME"/pkgs/snap
;;
N)
exesudo install_npm_packages "$DIRNAME"/pkgs/npm
;;
B)
setup_brew "$DIRNAME"/pkgs/brew
;;
D)
clone_bin_from_url tmuxinator.bash https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.bash
setup_dotfiles "$DIRNAME"/dotfiles
;;
g)
configure_git_repos "$DIRNAME"/pkgs/git
exesudo install_package_from_github sharkdp/bat
;;
c)
configure_vim
;;
o)
setup_go
;;
h)
print_help
;;
*)
echo "Invalid option"
print_help
;;
esac
done