-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
debian-desktop-environment-tool-cli.sh
executable file
·3025 lines (2566 loc) · 129 KB
/
debian-desktop-environment-tool-cli.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
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Copyright (c) 2020 - 2021 by David Kariuki (dk). All Rights Reserved.
: '
MIT Licence
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'
: ' cPrint - Custom function to create a custom coloured print
|& tee -a $logFileName - append output stream to logs and terminal'
1="" # Empty any parameter passed by user during script exercution
declare -r targetLinux="Debian Linux"
declare -l -r scriptName="linux-desktop-environment-tool-cli" # Set to lowers and read-only
declare -l -r logFileName="$scriptName-logs.txt" # Set to lowers and read-only
declare scriptVersion="4.1" # Script version
declare -i -r numberOfDesktopEnvironments=10 # Stores total number of desktop environments
declare -l -r networkTestUrl="www.google.com" # Stores the networkTestUrl (Set to lowers and read-only)
declare -r numberExpression='^[0-9]+$' # Number expression
declare -l currentDesktopEnvironment="" # Value of the current installed desktop environment
declare listOfInstalledDesktopEnvironments="" # A numbered list of all installed desktop environments with more options
declare uninstallationList="" # List of desktop environments to be uninstalled
declare -l startTime="" # Start time of execution
declare -l totalExecutionTime="" # Total execution time in days:hours:minutes:seconds
declare -i setupCancelled=0 # Value to indicate setup cancellation
clear=clear # Command to clear terminal
: ' Variables to store 1 or 0 if associated desktop environment has just been
installed '
declare -l justInstalledGNOME=0
declare -l justInstalledKDEPLASMA=0
declare -l justInstalledXFCE=0
declare -l justInstalledLXDE=0
declare -l justInstalledLXQT=0
declare -l justInstalledCINNAMON=0
declare -l justInstalledMATE=0
declare -l justInstalledBUDGIE=0
declare -l justInstalledENLIGHTENMENT=0
declare -l justInstalledFluxbox=0
declare -i justInstalledAllEnvironments=0
: ' Variables to store 1 or 0 if associated desktop environment was found to
have been installed after checking for all installed desktop environments.'
declare -i foundGNOMEInstalled=0
declare -i foundKDEPLASMAInstalled=0
declare -i foundXFCEInstalled=0
declare -i foundLXDEInstalled=0
declare -i foundLXQTInstalled=0
declare -i foundCINNAMONInstalled=0
declare -i foundMATEInstalled=0
declare -i foundBUDGIEInstalled=0
declare -i foundENLIGHTENMENTInstalled=0
declare -i foundFluxboxInstalled=0
declare -i XServerInstalled=0 checkedForXServer=0
declare -i checkedForLinuxHeaders=0 linuxHeadersInstalled=0
# Total number of installed desktop environment
declare -i noOfInstalledDesktopEnvironments=0
declare -l xSessionsPath=/usr/share/xsessions/ # XSessions path
: 'Stores uninstallation order to ensure that the default desktop environment
is uninstalled as the last option since uninstalling the current desktop
may halt the running of this script in gui terminal'
declare -a uninstallOrder=()
declare -a scriptActions=() # Stores the actions performed by the script
# Function to create a custom coloured print
function cPrint(){
RED="\033[0;31m" # 31 - red : "\e[1;31m$1\e[0m"
GREEN="\033[0;32m" # 32 - green : "\e[1;32m$1\e[0m"
YELLOW="\033[1;33m" # 33 - yellow : "\e[1;33m$1\e[0m"
BLUE="\033[1;34m" # 34 - blue : "\e[1;34m$1\e[0m"
PURPLE="\033[1;35m" # 35 - purple : "\e[1;35m$1\e[0m"
NC="\033[0m" # No Color : "\e[0m$1\e[0m"
# Display coloured text setting its background color to black
printf "\e[48;5;0m${!1}\n ${2} ${NC}\n" || exit
}
# Function to space out different sections
function sectionBreak(){
cPrint "NC" "\n" |& tee -a $logFileName # Print without color
}
# Function to display connection established message
function connEst(){
cPrint "GREEN" "Internet connection established.\n" |& tee -a $logFileName
sleep 2s # Hold for user to read
}
# Function to display connection failed message
function connFailed(){
cPrint "RED" "Internet connection failed!!!" |& tee -a $logFileName
sleep 2s # Hold for user to read
}
# Function to display script information
function displayScriptInfo(){
cPrint "NC" "About\n Script : $scriptName.\n Target Linux : $targetLinux.\n Version : $scriptVersion\n License : MIT Licence.\n Developer : David Kariuki (dk)\n" |& tee -a $logFileName
}
# Function to hold terminal with simple terminal animation
function holdTerminal(){
local -r initialTime=`date +%s` # Get start time
local -r characters=" //--\\|| "
while :
do
local currentTime=`date +%s`
for (( i=0; i<${#characters}; i++ ))
do
sleep .1
echo -en " ${characters:$i:1}" "\r"
done
difference=$((currentTime-initialTime))
if [[ "$difference" -eq $1 ]]
then
break
fi
done
}
# Function to format time from seconds to days:hours:minutes:seconds
function formatTime() {
local inputSeconds=$1 local minutes=0 hour=0 day=0
if((inputSeconds>59))
then
((seconds=inputSeconds%60))
((inputSeconds=inputSeconds/60))
if((inputSeconds>59))
then
((minutes=inputSeconds%60))
((inputSeconds=inputSeconds/60))
if((inputSeconds>23))
then
((hour=inputSeconds%24))
((day=inputSeconds/24))
else ((hour=inputSeconds))
fi
else ((minutes=inputSeconds))
fi
else ((seconds=inputSeconds))
fi
unset totalExecutionTime
totalExecutionTime="${totalExecutionTime}$day"
totalExecutionTime="${totalExecutionTime}d "
totalExecutionTime="${totalExecutionTime}$hour"
totalExecutionTime="${totalExecutionTime}h "
totalExecutionTime="${totalExecutionTime}$minutes"
totalExecutionTime="${totalExecutionTime}m "
totalExecutionTime="${totalExecutionTime}$seconds"
totalExecutionTime="${totalExecutionTime}s "
}
# Function to initiate logfile
function initLogFile(){
cd ~ || exit # Change directory to users' home directory
# Delete log file if/not it exists to prevent appending to previous logs
rm -f $logFileName
touch $logFileName # Creating log file
currentDate="Date : `date`\n\n" # Get current date
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "Created log file" )
# Log date without displaying on terminal
printf $currentDate &>> $logFileName
}
# Function to check for and install linux headers
function checkInstallLinuxHeaders(){
# Path to linux headers
headersPath=/usr/src/linux-headers-$(uname -r)
# Check for linux headers installation
if check=$(ls -l $headersPath &> /dev/null)
then # Linux headers installed
# Prevent message showing many times during loop
if [ "$checkedForLinuxHeaders" -eq 0 ]
then
cPrint "NC" "\e[1;33mChecked for linux headers.\e[0m \e[1;32mLinux headers installed.\e[0m\n"
holdTerminal 1 # Hold
checkedForLinuxHeaders=1
linuxHeadersInstalled=1
fi
else # Linux headers not installed
# Install linux headers
cPrint "YELLOW" "Installing linux headers.\n"
apt-get install linux-headers-$(uname -r) |& tee -a $logFileName
checkDebugAndRollback
fi
}
# Function to install netcat and and start script
function initScript(){
initLogFile # Create log file
# Install netcat if not installed to be used for connection check
cPrint "YELLOW" "Fetching required packages. Please wait..."
holdTerminal 1 # hold
apt-get install netcat -y &>> $logFileName
${clear} # Clear terminal
echo ""; cPrint "RED" "Running as $USER." |& tee -a $logFileName
cPrint "YELLOW" "This script will help you install and uninstall the supported $targetLinux desktop environments." |& tee -a $logFileName
holdTerminal 6 # Hold for user to read
# Check if user is running as root
checkIfUserIsRoot
sectionBreak
displayScriptInfo # Display Script Information
}
# Function to check if user is running as root
function checkIfUserIsRoot(){
declare -l -r user=$USER # Declare user variable as lowercase
if [ "$user" != 'root' ]
then
cPrint "RED" "This script works fully when run as root.\n Please run it as root to avoid issues/errors.\n" |& tee -a $logFileName
holdTerminal 3 # Hold for user to read
exitScript --end
fi
}
# Function to check for internet connection and validate security on connection
function isConnected(){
${clear} # Clear terminal
# Creating integer variable
local -i count=0 # Declare loop count variable
local -i -r retrNum=4 # Declare and set number of retries to read-only
local -i -r maxRetr=$[retrNum + 1] # Declare and set max retry to read-only
local -i -r countDownTime=30 # Declare and set retry to read-only
while :
do # Starting infinite loop
cPrint "YELLOW" "\nChecking for internet connection!!" |& tee -a $logFileName
if `nc -zw1 $networkTestUrl 443` && echo |openssl s_client -connect $networkTestUrl:443 2>&1 |awk '
handshake && $1 == "Verification" { if ($2=="OK") exit; exit 1 }
$1 $2 == "SSLhandshake" { handshake = 1 }' &> /dev/null
then # Internet connection established
connEst # Display internet connection established message
return $(true) # Exit loop returning true
else # Internet connection failed
connFailed # Display internet connection failed message
if [ "$count" == 0 ]
then
cPrint "YELLOW" "Attemting re-connection...\n Max number of retries : \e[0m$maxRetr\e[0m\n" |& tee -a $logFileName
fi
# Check for max number of retries
if [ "$count" -gt "$retrNum" ]
then
cPrint "YELLOW" "Number of retries: $count" |& tee -a $logFileName # Display number of retries
return $(false) # Exit loop returning false
else
count=$[count + 1] # Increment loop counter variable
# Run countdown
date1=$((`date +%s` + $countDownTime))
while [ "$date1" -ge "$(date +%s)" ]
do
echo -ne " \e[1;32mRetrying connection after :\e[0m \e[1;33m$(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S)\r\e[0m" |& tee -a $logFileName
sleep 0.1
done
fi
fi
sleep 1 # Hold loop
done
}
# Function to check for script action
function checkForScriptAction(){
: '
tr ' ' '\n' - Convert all spaces to newlines. Sort expects input to be on separate lines.
sort -u - sort and retain only unique elements, tr '\n' ' ' - convert the newlines back to spaces.'
# Remove array duplicates
scriptActions=($(echo "${scriptActions[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
# Get action list array as string
actionsList=${scriptActions[@]}
# Check for required script action
if [[ $actionsList == *$1* ]]
then
return $(true) # Return true if found
else
return $(false) # Return false if otherwise
fi
}
# Function to update system packages, upgrade software packages
# and update apt-file
function updateAndUpgrade(){
# Checking for connection after every major sep incase of network
# failure during one stage
if isConnected
then # Checking for internet connection
# Internet connection established
cPrint "YELLOW" "Updating system packages." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get update |& tee -a $logFileName
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "update" )
sectionBreak
else
apt-get check |& tee -a $logFileName
apt-get --fix-broken install |& tee -a $logFileName
dpkg --configure -a |& tee -a $logFileName
apt-get autoremove -y |& tee -a $logFileName
apt-get autoclean |& tee -a $logFileName
apt-get clean |& tee -a $logFileName
appstreamcli refresh --force |& tee -a $logFileName
apt-file update |& tee -a $logFileName
sectionBreak
fi
if isConnected
then # Checking for internet connection
# Internet connection established
cPrint "YELLOW" "Upgrading software packages." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get upgrade -y |& tee -a $logFileName
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "upgrade" )
sectionBreak
else
apt-get check |& tee -a $logFileName
apt-get --fix-broken install |& tee -a $logFileName
dpkg --configure -a |& tee -a $logFileName
apt-get autoremove -y |& tee -a $logFileName
apt-get autoclean |& tee -a $logFileName
apt-get clean |& tee -a $logFileName
appstreamcli refresh --force |& tee -a $logFileName
apt-file update |& tee -a $logFileName
sectionBreak
fi
if isConnected
then # Checking for internet connection
# Internet connection established
cPrint "YELLOW" "Running dist upgrade." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get dist-upgrade -y |& tee -a $logFileName
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "dist-upgrade" )
sectionBreak
else
apt-get check |& tee -a $logFileName
apt-get --fix-broken install |& tee -a $logFileName
dpkg --configure -a |& tee -a $logFileName
apt-get autoremove -y |& tee -a $logFileName
apt-get autoclean |& tee -a $logFileName
apt-get clean |& tee -a $logFileName
appstreamcli refresh --force |& tee -a $logFileName
apt-file update |& tee -a $logFileName
sectionBreak
fi
if isConnected
then # Checking for internet connection
# Internet connection established
cPrint "YELLOW" "Running full upgrade." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get full-upgrade -y |& tee -a $logFileName
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "full-upgrade" )
sectionBreak
else
apt-get check |& tee -a $logFileName
apt-get --fix-broken install |& tee -a $logFileName
dpkg --configure -a |& tee -a $logFileName
apt-get autoremove -y |& tee -a $logFileName
apt-get autoclean |& tee -a $logFileName
apt-get clean |& tee -a $logFileName
appstreamcli refresh --force |& tee -a $logFileName
apt-file update |& tee -a $logFileName
sectionBreak
fi
if isConnected
then # Checking for internet connection
# Internet connection established
cPrint "YELLOW" "Installing apt-file for apt-file updates." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get install apt-file -y |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
sectionBreak
cPrint "YELLOW" "Running apt-file update." |& tee -a $logFileName
holdTerminal 1
apt-file update |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "apt-file-update" )
sectionBreak
else
apt-get check |& tee -a $logFileName
apt-get --fix-broken install |& tee -a $logFileName
dpkg --configure -a |& tee -a $logFileName
apt-get autoremove -y |& tee -a $logFileName
apt-get autoclean |& tee -a $logFileName
apt-get clean |& tee -a $logFileName
appstreamcli refresh --force |& tee -a $logFileName
apt-file update |& tee -a $logFileName
sectionBreak
fi
}
# Function to fix any unmet dependencies and broken installs incase of network interruption
function checkDebugAndRollback(){
if [ "$1" == '--debug' ]
then # Check for debug switch
cPrint "GREEN" "Checking for errors and debugging. Please wait..." |& tee -a $logFileName
elif [ "$1" == '--network' ]
then # Check for network switch
cPrint "GREEN" "Debugging and rolling back some changes due to network interrupt. Please wait..." |& tee -a $logFileName
fi
holdTerminal 1 # Hold for user to read
cPrint "YELLOW" "Checking for broken/unmet dependencies and fixing broken installs." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get check |& tee -a $logFileName
apt-get --fix-broken install |& tee -a $logFileName
sectionBreak
cPrint "YELLOW" "Cleaning apt-get cache, disk space and removing unused packages." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get autoclean -y |& tee -a $logFileName
apt-get clean -y |& tee -a $logFileName
apt-get autoremove -y |& tee -a $logFileName
sectionBreak
cPrint "YELLOW" "Configuring packages." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
dpkg --configure -a |& tee -a $logFileName
cPrint "NC" "dpkg package configuration completed." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
sectionBreak
if [[ "$2" == '--update-upgrade' && "$1" == '--debug' ]]
then # Check for update-upgrade switch
# Update system packages and upgrade software packages
updateAndUpgrade
fi
cPrint "YELLOW" "Cleaning apt-get cache, disk space and removing unused packages." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
apt-get autoclean -y |& tee -a $logFileName
apt-get clean -y |& tee -a $logFileName
apt-get --fix-broken install |& tee -a $logFileName
apt-get autoremove -y |& tee -a $logFileName
sectionBreak
cPrint "YELLOW" "Updating AppStream cache." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
appstreamcli refresh --force |& tee -a $logFileName
sectionBreak
cPrint "GREEN" "Checking and debugging completed successfuly!!" |& tee -a $logFileName
sectionBreak
}
# Function to exit script with custom coloured message
function exitScript(){
# Display exit message
cPrint "RED" "Exiting script...." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
if [ "$1" == '--end' ]
then # Check for --end switch
if [ "$setupCancelled" -eq 0 ]
then # Check and debug any errors
checkDebugAndRollback --debug --update-upgrade
${clear} # Clear terminal
cd ~ || exit # Change to home directory
cPrint "YELLOW" "You can find this scripts\' logs in \e[1;31m$(pwd)\e[0m named $logFileName"
cPrint "GREEN" "\n Type: \e[1;31mcat $scriptName\e[0m to view the logs in terminal"
holdTerminal 5 # Hold for user to read
fi
${clear} # Clear terminal
echo ""; displayScriptInfo # Display script information
# Get script execution time
endTime=`date +%s` # Get start time
executionTimeInSeconds=$((endTime-startTime))
# Calculate time in days:hours:minutes:seconds
formatTime $executionTimeInSeconds
# Draw logo
printf "\n\n __ __\n | | | | ___\n | | | | / /\n __| | | |/ /\n / _ | | <\n | (_| | | |\ \ \n \______| |__| \__\ \n\n "
cPrint "YELLOW" "Script execution time : $totalExecutionTime \n"
if [ "$setupCancelled" -eq 0 ]
then
# Display exit message
cPrint "RED" "Script completed successfuly...\n\n" |& tee -a $logFileName
else
# Display exit message
cPrint "RED" "Exited script...\n\n" |& tee -a $logFileName
fi
elif [ "$1" == '--connectionFailure' ]
then
cPrint "RED" "\n\n This script requires a stable internet connection to work fully!!" |& tee -a $logFileName
cPrint "NC" "Please check your connection settings and re-run the script.\n" |& tee -a $logFileName
if [ "$2" == '--rollback' ]
then # Check for rollback switch
# Check for and fix any broken installs or unmet dependencies
checkDebugAndRollback --network
fi
fi
exit 0 # Exit script
}
# Function to check current desktop environment
function checkForDefaultDesktopEnvironment(){
if [ "$1" != '--noResponse' ]
then
cPrint "YELLOW" "Checking for default desktop environment.." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
fi
if [ "$XDG_CURRENT_DESKTOP" = "" ]
then # Check for installed desktop environments
currentDesktopEnvironment=$(echo "$XDG_DATA_DIRS" | sed 's/.*\(gnome\|kde\|xfce\|lxde\|lxqt\|cinnamon\|mate\|budgie\|enlightenment\|fluxbox\).*/\1/')
else # Get XDG current desktop
currentDesktopEnvironment=$XDG_CURRENT_DESKTOP
fi
# Check if desktop environment was found
if [ -z "$currentDesktopEnvironment" ]
then # (Variable empty) - Desktop environment not found
xSessions=$(ls -l $xSessionsPath) # Get all xSessions
if [ -z "$xSessions" ]
then
cPrint "GREEN" "No default display manager found!!" |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
else
cPrint "GREEN" "No default display manager found!!" |& tee -a $logFileName
cPrint "GREEN" "The below desktop environment xsession files were found:\n$xSessions"
holdTerminal 4 # Hold for user to read
fi
else
if [ "$1" != '--noResponse' ]
then # Display choice
cPrint "GREEN" "Current default : $currentDesktopEnvironment" |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
fi
fi
}
# Function to get a list of all installed desktop environment
function getAllInstalledDesktopEnvironments(){
foundGNOMEInstalled=0; foundKDEPLASMAInstalled=0; foundXFCEInstalled=0;
foundLXDEInstalled=0; foundLXQTInstalled=0; foundCINNAMONInstalled=0;
foundMATEInstalled=0; foundBUDGIEInstalled=0; foundENLIGHTENMENTInstalled=0;
foundFluxboxInstalled=0;
# Numbers the list of installed desktop environment
local -i listCount=0
unset uninstallationList installedDesktopEnvironments
unset listOfInstalledDesktopEnvironments
# Get all installed desktop environments
installedDesktopEnvironments=$(ls -l /usr/share/xsessions/)
# Variable to store a list of all installed desktop environments
listOfInstalledDesktopEnvironments="" |& tee -a $logFileName
# Checking for individual desktop environment
if [[ $installedDesktopEnvironments == *"gnome.desktop"*
|| $installedDesktopEnvironments == *"gnome-classic.desktop"*
|| $installedDesktopEnvironments == *"gnome-flashback-metacity.desktop"*
|| $installedDesktopEnvironments == *"gnome-xorg.desktop"* ]]
then
foundGNOMEInstalled=$[foundGNOMEInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding GNOME to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. GNOME Desktop."
uninstallationList="${uninstallationList}gnome "
fi
if [[ $installedDesktopEnvironments == *"plasma.desktop"* ]]
then
foundKDEPLASMAInstalled=$[foundKDEPLASMAInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding KDE PLASMA to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. KDE Plasma Desktop."
uninstallationList="${uninstallationList}kde "
fi
if [[ $installedDesktopEnvironments == *"xfce.desktop"* ]]
then
foundXFCEInstalled=$[foundXFCEInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding XFCE to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. XFCE Desktop."
uninstallationList="${uninstallationList}xfce "
fi
if [[ $installedDesktopEnvironments == *"lxde.desktop"*
|| $installedDesktopEnvironments == *"LXDE.desktop"* ]]
then
foundLXDEInstalled=$[foundLXDEInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding LXDE to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. LXDE Desktop."
uninstallationList="${uninstallationList}lxde "
fi
if [[ $installedDesktopEnvironments == *"lxqt.desktop"* ]]
then
foundLXQTInstalled=$[foundLXQTInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding LXQT to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. LXQT Desktop."
uninstallationList="${uninstallationList}lxqt "
fi
if [[ $installedDesktopEnvironments == *"cinnamon.desktop"* ]]
then
foundCINNAMONInstalled=$[foundCINNAMONInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding CINNAMON to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. CINNAMON Desktop."
uninstallationList="${uninstallationList}cinnamon "
fi
if [[ $installedDesktopEnvironments == *"mate.desktop"* ]]
then
foundMATEInstalled=$[foundMATEInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding MATE to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. MATE Desktop."
uninstallationList="${uninstallationList}mate "
fi
if [[ $installedDesktopEnvironments == *"budgie-desktop.desktop"* ]]
then
foundBUDGIEInstalled=$[foundBUDGIEInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding BUDGIE to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. BUDGIE Desktop."
uninstallationList="${uninstallationList}budgie "
fi
if [[ $installedDesktopEnvironments == *"enlightenment.desktop"* ]]
then
foundENLIGHTENMENTInstalled=$[foundENLIGHTENMENTInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding ENLIGHTENMENT to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. ENLIGHTENMENT Desktop."
uninstallationList="${uninstallationList}enlightenment "
fi
if [[ $installedDesktopEnvironments == *"fluxbox.desktop"* ]]
then
foundFluxboxInstalled=$[foundFluxboxInstalled + 1]
listCount=$[listCount+1] # Update list count
# Adding Fluxbox to list of installed desktop environments
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. FLUXBOX Desktop."
uninstallationList="${uninstallationList}fluxbox "
fi
# Sum up all found desktop environments
noOfInstalledDesktopEnvironments=$((foundGNOMEInstalled
+foundKDEPLASMAInstalled+foundXFCEInstalled+foundLXDEInstalled
+foundLXQTInstalled+foundCINNAMONInstalled+foundMATEInstalled
+foundBUDGIEInstalled+foundENLIGHTENMENTInstalled+foundFluxboxInstalled))
if [ "$listCount" -gt 1 ]
then # More that one desktop environment found
listCount=$[listCount+1] # Update list count
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. Uninstall all desktop environments." # Add option to uninstall all at once
fi
# Add option to cancel uninstallation
listCount=$[listCount+1] # Update list count
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n\t$listCount. Back."
# Adding line break after list
listOfInstalledDesktopEnvironments="${listOfInstalledDesktopEnvironments} \n"
if [ "$noOfInstalledDesktopEnvironments" -gt 0 ]
then # 1 or more desktop environment installed
if [ "$1" == '--displayList' ]
then
cPrint "GREEN" "Found a total of $noOfInstalledDesktopEnvironments installed desktop environments." |& tee -a $logFileName
# Display list of installed desktop environments
cPrint "YELLOW" "$listOfInstalledDesktopEnvironments" |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
fi
fi
}
# Function to check the set default desktop environment incase of more
# that one desktop environment
function checkSetDefaultDesktopEnvironment(){
cPrint "YELLOW" "Checking for the default desktop environment." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
# Display set default desktop environment
cat /etc/X11/default-display-manager |& tee -a $logFileName
}
# Function to query if user wants to install another desktop environment
# after installing the previous
function queryInstallAnotherDesktopEnvironment(){
while true
do # Start infinite loop
${clear} # Clear terminal
# Prompt user to set GNOME Desktop as default
cPrint "YELLOW" "Would you like to install another desktop environment?\n\t1. Y (Yes) - to install another.\n\t2. N (No) to cancel." |& tee -a $logFileName
read -p ' option: ' queryInstChoice
queryInstChoice=${queryInstChoice,,} # Convert to lowercase
# Display choice
cPrint "GREEN" " You chose : $queryInstChoice" |& tee -a $logFileName
if [[ "$queryInstChoice" == 'yes' || "$queryInstChoice" == 'y'
|| "$queryInstChoice" == '1' ]]
then # Option : Yes
return $(true) # Exit loop returning true
elif [[ "$queryInstChoice" == 'no' || "$queryInstChoice" == 'n'
|| "$queryInstChoice" == '2' ]]
then # Option : No
${clear} # Clear terminal
return $(false) # Exit loop returning false
else
# Invalid entry
cPrint "GREEN" "Invalid entry!! Please try again." |& tee -a $logFileName
fi
sleep 1 # Hold loop
done
}
# Function to install X Window Server (xorg)
function installXWindowServer(){
${clear} # Clear terminal
# Check if XServer is installed
check=`dpkg -l |grep xserver-xorg-core`
# Check for command outp.ut
if [[ "$check" == *"ii xserver-xorg-core"*
|| "$check" == *"Xorg X server - core server"* ]]
then # XServer found
if [ $XServerInstalled -eq 0 ]
then
# Prevent message showing many times during loop
if [ "$checkedForXServer" -eq 0 ]
then
# Display below message only once during runtime
cPrint "NC" "\e[1;33mChecked for XServer installation.\e[0m \e[1;32mXServer is already installed.\e[0m\n"
fi
XServerInstalled=1 # Set X Server installed to true.
checkedForXServer=1
holdTerminal 3 # Hold for user to read
fi
else # XServer not found
# Checking for internet connection before continuing
if isConnected
then # Internet connection Established
cPrint "YELLOW" "\n\n Installing XORG. This may take a while depending on your internet connection. Please wait..." |& tee -a $logFileName
holdTerminal 5 # Hold for user to read
# Install X window Server
apt-get install xorg -y |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "install-xorg" )
sectionBreak
else
exitScript --connectionFailure # Exit script on connection failure
fi
fi
}
# Function to install GNOME Desktop environment
function installGNOMEDesktop(){
if [ "$foundGNOMEInstalled" -eq 0 ]
then # Found
installXWindowServer # Install X Window Server
${clear} # Clear terminal
# Checking for internet connection before continuing
if isConnected
then # Internet connection Established
cPrint "YELLOW" "\n\n Installing GNOME. This may take a while depending on your internet connection. Please wait..." |& tee -a $logFileName
holdTerminal 5 # Hold for user to read
if [ "$1" == '--y' ]
then # Check for yes switch to install without confirmation
# Install full GNOME with confirmation
apt-get install gnome -y |& tee -a $logFileName
apt-get install task-gnome-desktop -y |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
else # Install full GNOME without confirmation
apt-get install gnome task-gnome-desktop |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
fi
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "install-desktop-gnome" )
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "install-alacarte" )
cPrint "GREEN" "GNOME installation complete." |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
cPrint "YELLOW" "Checking if gdm3 is installed. If not it will be installed." |& tee -a $logFileName
holdTerminal 4 # Hold for user to read
# Install gdm3 if id does not exist
apt-get install gdm3 |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
# Check for GNOME setDefault switch
if [ "$2" == '--setDefault' ]
then
cPrint "YELLOW" "Setting GNOME as default desktop environment." |& tee -a $logFileName
holdTerminal 4 # Hold for user to read
cPrint "YELLOW" "Please select gdm3 when prompted." |& tee -a $logFileName
holdTerminal 4 # Hold for user to read
dpkg-reconfigure gdm3 |& tee -a $logFileName
# Check for set default desktop environment
checkSetDefaultDesktopEnvironment
else # Let user decide
while true
do
# Prompt user to set GNOME Desktop as default
cPrint "YELLOW" "Would you like to set GNOME as yout default desktop environment?\n\t1. Y (Yes) - to set default.\n\t2. N (No) to cancel or skip." |& tee -a $logFileName
read -p ' option: ' dfChoice
dfChoice=${dfChoice,,} # Convert to lowercase
# Display choice
cPrint "GREEN" " You chose : $dfChoice" |& tee -a $logFileName
if [[ "$dfChoice" == 'yes' || "$dfChoice" == 'y'
|| "$dfChoice" == '1' ]]
then # Option : Yes
cPrint "YELLOW" "Setting GNOME as default desktop environment." |& tee -a $logFileName
holdTerminal 4 # Hold for user to read
dpkg-reconfigure gdm3 |& tee -a $logFileName
# Check for set default desktop environment
checkSetDefaultDesktopEnvironment
break # Break from loop
elif [[ "$dfChoice" == 'no' || "$dfChoice" == 'n'
|| "$dfChoice" == '2' ]]
then # Option : No
cPrint "NC" "Skipped..." |& tee -a $logFileName
break # Break from loop
else
# Invalid entry
cPrint "GREEN" "Invalid entry!! Please try again." |& tee -a $logFileName
fi
sleep 1 # Hold loop
done
fi
# Set GNOME installed to true
justInstalledGNOME=$[justInstalledGNOME + 1]
cPrint "GREEN" "Your GNOME Desktop is all set." |& tee -a $logFileName
sectionBreak
else
exitScript --connectionFailure # Exit script on connection failure
fi
else
${clear} # Clear terminal
cPrint "GREEN" "GNOME desktop is already installed." |& tee -a $logFileName
holdTerminal 3 # Hold for user to read
sectionBreak
fi
}
# Function to install KDE PLASMA Desktop environment
function installKDEPlasmaDesktop(){
if [ "$foundKDEPLASMAInstalled" -eq 0 ]
then # Found
installXWindowServer # Install X Window Server
${clear} # Clear terminal
# Checking for internet connection before continuing
if isConnected
then # Internet connection Established
cPrint "YELLOW" "\n\n Installing KDE PLASMA Desktop. This may take a while depending on your internet connection. Please wait..." |& tee -a $logFileName
holdTerminal 5 # Hold for user to read
if [ "$1" == '--y' ]
then # Check for yes switch to install without confirmation
# Install KDE PLASMA Desktop without confirmation
apt-get install kde-full -y |& tee -a $logFileName
apt-get install task-kde-desktop -y |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
else
# Install KDE PLASMA Desktop with confirmation
apt-get install kde-full |& tee -a $logFileName
apt-get install task-kde-desktop |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
fi
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "install-desktop-kde" )
# Set KDE PLASMA Desktop installed to true
justInstalledKDEPLASMA=$[justInstalledKDEPLASMA + 1]
cPrint "GREEN" "Your KDE PLASMA Desktop is all set." |& tee -a $logFileName
# Check for set default desktop environment
checkSetDefaultDesktopEnvironment
sectionBreak
else
exitScript --connectionFailure # Exit script on connection failure
fi
else
${clear} # Clear terminal
cPrint "GREEN" "KDE PLASMA desktop is already installed." |& tee -a $logFileName
holdTerminal 3 # Hold for user to read
sectionBreak
fi
}
# Function to install XFCE Desktop environment
function installXFCEDesktop(){
if [ "$foundXFCEInstalled" -eq 0 ]
then # Found
installXWindowServer # Install X Window Server
${clear} # Clear terminal
# Checking for internet connection before continuing
if isConnected
then # Internet connection Established
cPrint "YELLOW" "\n\n Installing XFCE Desktop. This may take a while depending on your internet connection. Please wait..." |& tee -a $logFileName
holdTerminal 5 # Hold for user to read
if [ "$1" == '--y' ]
then # Check for yes switch to install without confirmation
# Install XFCE4 Desktop with confirmation
apt-get install xfce4 -y |& tee -a $logFileName
apt-get install task-xfce-desktop -y |& tee -a $logFileName
apt-get install xfce.desktop -y |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
else
# Install XFCE4 Desktop without confirmation
apt-get install xfce4 -y |& tee -a $logFileName
apt-get install task-xfce-desktop |& tee -a $logFileName
apt-get install xfce.desktop |& tee -a $logFileName
holdTerminal 1 # Hold for user to read
fi
# Add script actions to script actions array
scriptActions=( "${scriptActions[@]}" "install-desktop-xfce" )
# Set XFCE Desktop installed to true
justInstalledXFCE=$[justInstalledXFCE + 1]
cPrint "GREEN" "Your XFCE Desktop is all set." |& tee -a $logFileName
# Check for set default desktop environment
checkSetDefaultDesktopEnvironment
sectionBreak
else
exitScript --connectionFailure # Exit script on connection failure
fi
else
${clear} # Clear terminal
cPrint "GREEN" "XFCE desktop is already installed." |& tee -a $logFileName
holdTerminal 3 # Hold for user to read
sectionBreak
fi
}
# Function to install LXDE Desktop environment
function installLXDEDesktop(){
if [ "$foundLXDEInstalled" -eq 0 ]
then # Found
installXWindowServer # Install X Window Server
${clear} # Clear terminal