-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWelcome.sh
More file actions
386 lines (216 loc) · 7.1 KB
/
Welcome.sh
File metadata and controls
386 lines (216 loc) · 7.1 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
381
382
383
384
385
386
#!/bin/bash
################## GETS SUDO PASSWORD ###############################
passwords(){
local pass=$(tempfile 2>/dev/null)
trap "rm -f $pass" 0 1 2 5 15
dialog --title "Sudo Password" --clear --insecure --passwordbox "Password:" 10 10 2>$pass
password=$(<"${pass}")
}
################ ABOUT COMPUTER SECTION #####################
screenFetch(){
if [ -f /usr/bin/screenfetch ]; then
dialog --clear
clear
screenfetch
read -p "Press enter to continue"
main
exit
else
dialog --clear
dialog --title "Screenfetch Not Installed" \
dialog --msgbox "\n You do not have screenfetch installed" 10 20
dialog --title "Install?" --yesno "Want to install screenfetch?" 6 20
response=$?
case $response in
0) passwords && echo $password | sudo -S apt install screenfetch -y && clear && screenfetch && read -p "Press enter to continue" && main;;
1) main;;
255) echo "Something went wrong"; break;;
esac
fi
}
####################### Updates Your Computer ###################
Update_computer(){
path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd $path
########## completely updates and removes old packages ###########
dialog --clear --yesno "Do you want to update your computer?" 10 30
update=$?
case $update in
0) passwords && echo $password | sudo -S apt update && echo $password | sudo -S apt upgrade -yy && echo $password | sudo -S apt dist-upgrade -yy && echo $password | sudo -S apt autoremove -yy && echo $password | sudo -S apt autoclean;;
1) clear && exit 0;;
255) echo "something went wrong";;
esac
kernelUninstall
}
######### Uninstall old kernels #################
kernelUninstall(){
dialog --title "Kernel Uninstall" --defaultno --yesno "Do you want to see if you can uninstall old kernels?" 10 30
kernel=$?
case $kernel in
0) kern=$(uname -r)
dialog --infobox "!DO NOT DELETE THIS IF MOST CURRENT! \nCurrent Kernel: $kern" 10 50
sleep 10
kernel=$(dpkg --list | grep linux-image)
dialog --title "Copy just linux-image-X.X.X-XX-generic" --backtitle "Kernel to uninstall" --infobox "$kernel" 15 70
sleep 20;;
1) clear && exit 0;;
esac
local deleteKern=$(tempfile 2>/dev/null)
dialog --title "CTRL + SHIFT + V for the kernel you want to delete i.e linux-image-X.X.X-XX-generic" --backtitle "Select Kernel to Uninstall" --defaultno --inputbox "Kernel: " 15 70 2>$deleteKern
kernel=$?
dk=$(<"${deleteKern}")
clear
case $kernel in
0) if [ -d "/usr/src/xpad-0.4" ]; then
sudo apt purge $dk && cd /usr/src/xpad-0.4 && sudo git fetch && sudo git checkout origin/master && sudo dkms remove -m xpad -v 0.4 --all && sudo dkms install -m xpad -v 0.4 && cd $path && sudo update-grub
printf '\e[8;24;80t'
if [ -f "/usr/bin/lsterminal" ]; then
if [ -d "/usr/src/xpad-0.4" ]; then
sudo apt purge $dk && cd /usr/src/xpad-0.4 && sudo git fetch && sudo git checkout origin/master && sudo dkms remove -m xpad -v 0.4 --all && sudo dkms install -m xpad -v 0.4 && cd $path && sudo update-grub
lxterminal --geometry=80x24 -e main
else
sudo apt purge $dk && sudo update-grub
lxterminal --geometry=80x24 -e main
fi
fi
else
sudo apt purge $dk && sudo update-grub
printf '\e[8;24;80t'
fi;;
1) exit 0;;
255) echo "something went wrong"; break;;
esac
}
############ Fixes dpkg error ####################
Fix_Dpkg(){
passwords
echo $password | sudo -S apt install -f
main
exit 0;
}
######## Exit ##########
Exit(){
dialog --clear
clear
exit 0;
}
######### auto update program #############
update_program(){
############# Checking for useless files ##############
path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd $path
if [[ -f ".update.sh" ]]; then
rm -rf ".update.sh"
elif [[ -f ".update.txt" ]]; then
rm -rf .update.txt
elif [[ -f ".update1.sh" ]]; then
rm -rf .update1.sh
elif [[ -f "test.sh use for debugging" ]]; then
rm -rf "test.sh use for debugging"
elif [[ -f "_update1.sh - do not use" ]]; then
rm -rf "_update1.sh - do not use"
fi
############# Checking if Welcome.sh is executable ##########
if [[ ! -x Welcome.sh ]]; then
chmod a+x Welcome.sh
fi
########### Moving files to new folder #############
movePath=$(basename "$PWD");
if [[ $movePath == "update_computer_GUI-master" ]];
then
cd ..
path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P );
mv update_computer_GUI-master $path/update_computer_GUI
cd update_computer_GUI
main
exit
fi
path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P );
############ AUTO UPDATER ########################
### Dialog Installer ##############
if [[ ! -f "/usr/bin/dialog" ]]; then
clear
echo "You do not have 'Dialog' installed"
read -p "Would you like to install Dialog? y/n: " yes_to_dialog
if [ "$yes_to_dialog" == "y" ]; then
sudo apt install dialog -y;
else
exit 0;
fi
fi
##### Git Installer ###############
if [[ ! -f "/usr/bin/git" ]]; then
clear
dialog --infobox "You need to install git first..." 10 20
sleep 3
dialog --clear --yesno "Would you like to install git?" 10 20
update=$?
case $update in
0) passwords && echo $password | sudo -S apt install git -y;;
1) clear && exit 0;;
255) echo "something went wrong"; break;;
esac
main
exit
fi
check="$(git fetch -v --dry-run 2>&1)"
echo "${check}" > .update.txt
if [ -f ".old_update.txt" ]; then
check1=$(<.old_update.txt) 2>&1
else
touch .old_update.txt
fi
if [[ "${check}" == "${check1}" ]]; then
rm .update.txt
clear
fi
if [[ "${check}" != "${check1}" ]]; then
git fetch https://github.com/krazynez/update_computer_GUI.git
git clone https://github.com/krazynez/update_computer_GUI.git temp
rsync -a temp/ $path
echo "${check}" > .old_update.txt
rm -rf temp
fi
############# Checking if Welcome.sh is executable after update ##########
if [[ ! -x Welcome.sh ]]; then
chmod a+x Welcome.sh
fi
if [[ "$?" == "1" ]]; then
clear
echo ""
echo "something went wrong"
sleep 10
fi
}
################ OPTIONS ########################
main(){
update_program
####### Check if parent or child process is already running ##########
if pidof -o %PPID -x "Welcome.sh" >/dev/null; then
dialog --infobox "Welcome.sh already running" 3 30
sleep 5
exit 0;
elif pidof -o %PPID -x ".update.sh" >/dev/null; then
dialog --infobox ".update.sh already running" 3 30
sleep 5
exit 0;
fi
clear
INPUT='/tmp/menu.output'
# numbers are Height x Width x Menu Height
dialog \
--backtitle "Update_Computer_GUI v1.0.0 ALPHA" \
--nocancel --menu "Please choose one option UP/DOWN arrow keys to select then ENTER to proceed:" 15 55 4 \
1 "About Computer" \
2 "Update Computer" \
3 "Fix dpkg 'lock'" \
4 "Exit" 2>"${INPUT}"
menuitem=$(<"${INPUT}")
case $menuitem in
1) screenFetch;;
2) Update_computer;;
3) Fix_Dpkg;;
4) Exit;;
esac
}
main