-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
executable file
·283 lines (264 loc) · 8.55 KB
/
main.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
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
#!/bin/bash
ID=$(< files/vid.tag)
SHA256=$(< files/sha256.dig)
LINK_AMD_DESKTOP64="https://update.code.visualstudio.com/$ID/linux-deb-x64/stable"
LINK_ARM32="https://update.code.visualstudio.com/$ID/linux-deb-armhf/stable"
LINK_ARM64="https://update.code.visualstudio.com/$ID/linux-deb-arm64/stable"
BACK_T="VS Code Installer/Updater for Debian AMD64 and/or ARM(32/64) - Version 2"
MAIN_T="VS Code Installer/Updater v2"
if [ "$1" == "--autoremove" ] ; then
AR="true"
else
AR="false"
fi
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "$BACK_T"
echo "Usage:"
echo "./main.sh <arg>"
echo ""
echo "Arguments:"
echo "--help -h Shows help"
echo "--autoremove Enables autoremove on apt (this works only"
echo " if you are trying to uninstall vs code)"
echo ""
exit
fi
# Arch checking
case $(uname -m) in
"x86_64")
echo "Arch is x64"
;;
"armhf")
echo "Arch is armhf"
;;
"aarch64")
echo "Arch is aarch64"
;;
*)
echo "Arch is $(uname -m), which is not supported..."
exit 1
;;
esac
# ExecID Check
if [ "$(/usr/bin/id -u)" -ne 0 ]; then
dialog --backtitle "Error!" --title "Cannot continue without superuser privileges..." --msgbox "The script can't run under userspace session \n\nThis script requires root access to continue..." 0 0
pass=$(dialog --backtitle "Enter Password" \
--title "Enter Superuser password" \
--clear \
--passwordbox "Enter Superuser password, all input texts are invisible for security purposes.\n\nSee Security.md for more info, if it's wrong, then the script wont launch again.\n\nWARNING: If you are done installing or removing vs code via this script, do exit by pressing Ctrl+C since you are running this on userspace, jic." 0 0 \
2>&1 >/dev/tty)
exstats=$?
case $exstats in
1)
unset pass
exit 1
;;
esac
echo "$pass" | sudo -S "$0" "$@"
status=$?
case $status in
1)
clear
unset pass # Unset Pass jic
echo "Wrong Password, please launch the code again with superuser privileges again to never get the issue..."
echo "ONLY if the script really stopped without going to main menu."
echo "because sometimes sudo sends code 1 even tho its now running on sudo mode"
echo "Unless if you actually ran the script and installed or uninstalled vs code fine then"
echo "that means this error is a fallback and just disregard it"
;;
esac
fi
# JUST TO MAKE SUUUURE
unset pass
# Functions
# function msgbx () {
# dialog --backtitle "$BACK_T" --title "$1" --msgbox "$2" 0 0
# }
function msg () {
echo "$1"
}
function dt() {
MDY=$(date +%m-%d-%y)
TC=$(date +%T)
msg "$MDY - $TC"
}
function check_src_dep() {
clear
if [ -e /usr/bin/aria2c ] ; then
msg "$(dt) : Aria2 Found"
else
msg "$(dt) : Aria2c not found"
fi
}
function check_vs() {
if [ -e /usr/bin/code ] && [ -e /usr/share/code ]; then
echo "$(dt) : VS Code installed"
else
echo "$(dt) : VS Code not installed..."
fi
}
function welcome() {
dialog --backtitle "Microsoft Software License Terms" --title "Read Microsoft Software License Terms" --yes-label "Accept" --no-label "Decline and exit" --yesno "$(cat lc/MS.txt)" 0 0
li=$?
case $li in
0)
menu
;;
1)
exit 1
;;
esac
}
function install_vs() {
clear
case $(uname -m) in
"x86_64")
if [ -e /usr/bin/aria2c ]; then
msg "$(dt) : Aria2 Found, downloading and installing VS Code"
mkdir -p file-opt
aria2c --out=code.deb -j 15 --checksum=sha-256=$SHA256 "$LINK_AMD_DESKTOP64"
sudo apt install ./code.deb -y
rm -rf code.deb
rm -rf code.deb.aria2
msg "$(dt) : Task Done"
sleep 1
menu
else
msg "$(dt) : Aria2c not found"
msg "$(dt) : Aborting"
sleep 1
menu
fi
;;
"armhf")
if [ -e /usr/bin/aria2c ]; then
msg "$(dt) : Aria2 Found, downloading and installing VS Code"
mkdir -p file-opt
aria2c --out=code.deb -j 15 --checksum=sha-256=$SHA256 "$LINK_ARM32"
sudo apt install ./code.deb -y
rm -rf code.deb
rm -rf code.deb.aria2
msg "$(dt) : Task Done"
sleep 1
menu
else
msg "$(dt) : Aria2c not found"
msg "$(dt) : Aborting"
sleep 1
menu
fi
;;
"aarch64")
if [ -e /usr/bin/aria2c ]; then
msg "$(dt) : Aria2 Found, downloading and installing VS Code"
mkdir -p file-opt
aria2c --out=code.deb -j 15 --checksum=sha-256=$SHA256 "$LINK_ARM64"
sudo apt install ./code.deb -y
rm -rf code.deb
rm -rf code.deb.aria2
msg "$(dt) : Task Done"
sleep 1
menu
else
msg "$(dt) : Aria2c not found"
msg "$(dt) : Aborting"
sleep 1
menu
fi
;;
*)
msg "$(dt) : Arch is $(uname -m), which is not supported..."
msg "$(dt) : Aborting"
sleep 5
menu
;;
esac
}
function uninstall_vs() {
clear
case $(uname -m) in
"x86_64")
if [ -e /usr/bin/code ]; then
msg "$(dt) : Removing VS Code..."
sudo apt remove code -y
if [ "$AR" == "true" ]; then
msg "$(dt) : Flag Autoremove provoked, attempting to autoremove packages..."
sudo apt autoremove -y
fi
msg "$(dt) : Task Done"
sleep 1
menu
else
msg "$(dt) : VS Code is not installed"
msg "$(dt) : Aborting"
menu
fi
;;
"armhf")
if [ -e /usr/bin/code ]; then
msg "$(dt) : Removing VS Code..."
sudo apt remove code -y
if [ "$AR" == "true" ]; then
msg "$(dt) : Flag Autoremove provoked, attempting to autoremove packages..."
sudo apt autoremove -y
fi
msg "$(dt) : Task Done"
menu
else
msg "$(dt) : VS Code is not installed"
msg "$(dt) : Aborting"
menu
fi
;;
"aarch64")
if [ -e /usr/bin/code ]; then
msg "$(dt) : Removing VS Code..."
sudo apt remove code -y
if [ "$AR" == "true" ]; then
msg "$(dt) : Flag Autoremove provoked, attempting to autoremove packages..."
sudo apt autoremove -y
fi
msg "$(dt) : Task Done"
else
msg "$(dt) : VS Code is not installed"
msg "$(dt) : Aborting"
menu
fi
;;
esac
}
function about() {
dialog --backtitle "$BACK_T" --title "About" --infobox "VS Code Installer for Debian AMD64 and/or ARM(32/64) - Version 2\nBy SUFandom\nVersion 2" 0 0
menu
}
function menu () {
MAINPG=$(dialog --backtitle "$BACK_T" \
--title "$MAIN_T" \
--menu "Pick an Option\n\nVersion: $ID\nSHA256: $SHA256\n\nStatus:\n\nIs VS Installed?: $(check_vs)\nScript Dependency Installed?: $(check_src_dep)\nAutoremove Flag Set: $AR\n\nNote: If you select either Install or Uninstall, it will directly do it without confirmation" 0 0 0 \
"Install VS Code" "Install VS Code" \
"Uninstall" "Uninstall VS Code" \
"About" "About Installer" \
2>&1 >/dev/tty)
fs=$?
case $fs in
1)
exit 1
;;
esac
case $MAINPG in
"Install VS Code")
install_vs
;;
"Uninstall")
uninstall_vs
;;
"About")
about
;;
esac
}
if [ "$(/usr/bin/id -u)" == "0" ]; then
welcome
else
exit 1
fi