-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·248 lines (220 loc) · 4.65 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
#!/usr/bin/env bash
loggy=$(date +"%H-%M-%S_%d-%m-%Y").log
exec > >(tee -ia "${loggy}")
exec 2> >(tee -ia "${loggy}" >& 2)
exec {FD}> "${loggy}"
export BASH_XTRACEFD="${FD}"
set -Eeoux pipefail
VIM_PLUGIN_DIR=~/.vim/pack/plugin/start
logfile=$(date +"%H-%M-%S_%d-%m-%Y").install.log
mkfifo "${logfile}".pipe
tee < "${logfile}".pipe "$logfile" &
exec &> "${logfile}".pipe
rm "${logfile}".pipe
function internet_check {
# if [[ $? -eq 0 ]]
if wget -q --spider https://github.com;
then
return 0
else
print_warn "Cannot not reach github. Not checking for new version"
return 1
fi
}
function check_git {
git fetch &>> "$logfile"
if [[ $(git rev-parse HEAD) != $(git rev-parse @{u}) ]] && ret=$(git status | grep -c ahead) && [[ $ret -eq 0 ]]
then
print_warn "Repo not up to date with remote"
if prompt_yesno "Update?";
then
git pull &>> "$logfile"
check_return "git pull"
print_error "Quiting so you can rerun with new version"
else
print_warn "Continuing with out updating"
fi
else
print_info "Repo up to date"
fi
}
function print_error {
printf "\\033[1;31m[!]\\033[0m %s\\n" "$1"
exit -1
}
function print_warn {
printf "\\033[1;33m[-]\\033[0m %s\\n" "$1"
}
function print_good {
printf "\\033[1;32m[+]\\033[0m %s\\n" "$1"
}
function print_info {
printf "\\033[1;34m[*]\\033[0m %s\\n" "$1"
}
function check_installed {
installed=$(dpkg-query -W -f'${Status}' "$1" 2>/dev/null | grep "install ok installed")
if [[ "" == "$installed" ]]
then
return 0
fi
return 1
}
function check_return {
if [[ $? -ne 0 ]]
then
print_error "$1 failed"
else
print_good "$1 succeded"
fi
}
function install_package {
pkg=$1
if check_installed "$pkg";
then
print_info "$pkg not installed. Installing..."
sudo apt -y install "$pkg" &>> "$logfile"
check_return "$pkg install"
fi
print_info "$pkg installed"
}
function prompt_yesno {
while read -rp "$1 [y/n]: " result && [[ $result != 'y' ]] && [[ $result != 'n' ]]
do
print_warn "Input not understood"
done
if [[ $result == 'y' ]]
then
return 0
else
return 1
fi
}
function check_config {
if [[ ! -f "$2" ]]
then
return 1
else
wanted_path=$PWD/"$1"
real_path=$(realpath "$2")
if [[ "$wanted_path" != "$real_path" ]]
then
print_warn "$2 exists but does not match $1"
if prompt_yesno "Replace?"
then
return 1
else
print_error "Exiting!"
fi
fi
fi
return 0
}
function place_config {
if check_config "$1" "$2";
then
print_info "$2 already linked"
else
ln -sf "$PWD"/"$1" "$2" &>> "$logfile"
check_return "Placing $1"
fi
}
function check_dir {
if [[ -d $1 ]]
then
return 1
else
return 0
fi
}
function check_file {
if [[ ! -f $1 ]]
then
return 0
else
return 1
fi
}
function install_vim_plugin {
repo=$(echo "$1" | rev | cut -d '/' -f1 | rev | cut -d '.' -f1)
if check_dir "${VIM_PLUGIN_DIR}/$repo";
then
print_info "Installing $repo"
git clone "$1" "${VIM_PLUGIN_DIR}/$repo" &>> "$logfile"
check_return "$repo install"
else
print_info "$repo already installed"
fi
}
function vim_plugins {
while read -r plugin
do
install_vim_plugin "$plugin"
done < "$VIMPLUGINS"
}
#-----------------------
# SETUP
#-----------------------
PWD=$(pwd)
VIMPLUGINS=vim/vimplugins
if internet_check;
then
check_git
fi
#-----------------------
# PACKAGE INSTALL
#-----------------------
install_package vim
install_package tmux
install_package gdb
#-----------------------
# CONFIG INSTALLS
#-----------------------
place_config vim/vimrc ~/.vimrc
place_config tmux.conf ~/.tmux.conf
place_config gdb/gdbinit ~/.gdbinit
#-----------------------
# VIM PLUGINS
#-----------------------
if check_dir "${VIM_PLUGIN_DIR}"
then
mkdir -p "${VIM_PLUGIN_DIR}"
fi
if [[ ! -f ${VIMPLUGINS} ]]
then
print_warn "No vimplugins file found"
else
vim_plugins
fi
#-----------------------
# TMUX PLUGIN MANAGER
#-----------------------
if check_dir ~/.tmux/plugins/tpm;
then
print_info "Intalling TPM"
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm &>> "$logfile"
else
print_info "TPM already installed"
fi
#-----------------------
# SSH
#-----------------------
mkdir -p ~/.ssh
place_config ssh/config ~/.ssh/config
mkdir ~/.ssh/controlmasters
#-----------------------
# gdb-pwndbg
#-----------------------
if prompt_yesno "Install pwndbg?"
then
mkdir -p ~/tools
mkdir -p ~/.local/bin
git clone https://github.com/pwndbg/pwndbg.git ~/tools/pwndbg
place_config gdb/gdbinit_pwndbg ~/.gdbinit_pwndbg
place_config gdb/gdb-pwndbg ~/.local/bin/gdb-pwndbg
pushd ~/tools/pwndbg
./setup.sh
popd
fi
printf "\n\\033[5m"
print_info "Remember to install tmux plugins with prefix+I if new ones installed"
printf "\n"