Giant blob of minor changes
[dotfiles/.git] / .local / bin / lindiag
1 #!/bin/bash
2 #######################################################################
3 #This program is free software: you can redistribute it and/or modify
4 #it under the terms of the GNU General Public License as published by
5 #the Free Software Foundation, either version 3 of the License, or
6 #(at your option) any later version.
7 #
8 #This program is distributed in the hope that it will be useful,
9 #but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #GNU General Public License for more details.
12 #
13 #You should have received a copy of the GNU General Public License
14 #along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 #Author
17 #Mark Chisholm
18 #http://morpheusarchlinux.com
19
20 ########################################################################
21 #-- authCheck asks for adminstrator aka root priveleges
22
23 authCheck(){
24
25         if [ $(id -u) != "0" ]; then
26                 clear
27         echo "You must be root to run this script"
28         echo "Please enter the following command and press enter: sudo !!"
29                 exit 1
30                         else
31                 mklindiag
32         fi
33
34 }
35
36 ########################################################################
37 #-- mklindiag creates the directory for logs to be stored.
38
39 mklindiag(){
40 if [ -d /var/log/lindiag ]; then
41         init
42 else #if the /var/log/lindiag directory does not exist this creates it
43         mkdir /var/log/lindiag >> /dev/null 2>&1
44         init
45 fi
46
47 }
48
49 ########################################################################
50 #-- init is the main menu
51
52 init(){
53 OPTION=$(whiptail --title "lindiag.sh" --backtitle "2018.4" --menu "Choose your option" 15 60 4 \
54 "1" "Systemd Diagnostics" \
55 "2" "Network Diagnostics" \
56 "3" "Server Configuration" \
57 "4" "Network Mapper" \
58 "5" "Package Manager" \
59 "6" "Data Recovery" \
60 "7" "Extra Options" \
61 3>&1 1>&2 2>&3)
62
63 if [ "$OPTION" == '1' ]; then
64
65         systemdDiagnostics
66
67 fi
68
69 if [ "$OPTION" == '2' ]; then
70
71         networkDiagnostics
72
73 fi
74
75 if [ "$OPTION" == '3' ]; then
76
77         serverConfig
78
79 fi
80
81
82 if [ "$OPTION" == '4' ]; then
83
84         chkNmap
85
86 fi
87
88 if [ "$OPTION" == '5' ]; then
89
90         chkDistro
91
92 fi
93
94 if [ "$OPTION" == '6' ]; then
95
96         chkDdrescue
97
98 fi
99
100 if [ "$OPTION" == '7' ]; then
101
102         extraOpts
103
104 fi
105 }
106
107 ########################################################################
108
109 systemdDiagnostics(){
110 OPTION=$(whiptail --title "Systemd_Diagnostics" --menu "Choose your option" 15 60 4 \
111 "1" "Check for failed services" \
112 "2" "Start a unit" \
113 "3" "Stop a unit" \
114 "4" "Restart a unit" \
115 "5" "Check if a unit is enabled or not" \
116 "6" "Enable a unit at boot" \
117 "7" "Show man page of unit" \
118 "8" "Show Systemd status" \
119 "9" "Return" \
120 3>&1 1>&2 2>&3)
121
122 if [ "$OPTION" == '1' ]; then
123
124         whiptail --msgbox "$(systemctl --failed)" 15 60 4
125         systemdDiagnostics
126
127 fi
128
129 if [ "$OPTION" == '2' ]; then
130
131 UNIT=$(whiptail --inputbox "What is the unit you want to start?" 8 78 --title "Please enter name of unit" 3>&1 1>&2 2>&3)
132
133 exitstatus=$?
134 if [ $exitstatus = 0 ]; then
135     systemctl start $UNIT
136         whiptail --msgbox "$(systemctl status $UNIT)" 15 60 4
137         else
138                 systemdDiagnostics
139         fi
140
141 fi
142
143 if [ "$OPTION" == '3' ]; then
144
145 UNIT=$(whiptail --inputbox "What is the unit you want to stop?" 8 78  --title "Please enter name of unit" 3>&1 1>&2 2>&3)
146
147 exitstatus=$?
148 if [ $exitstatus = 0 ]; then
149     systemctl stop $UNIT
150         whiptail --msgbox "$(systemctl stop $UNIT)" 15 60 4
151         else
152                 systemdDiagnostics
153         fi
154
155 fi
156
157 if [ "$OPTION" == '4' ]; then
158
159 UNIT=$(whiptail --inputbox "What is the unit you want to restart?" 8 78  --title "Please enter name of unit" 3>&1 1>&2 2>&3)
160
161 exitstatus=$?
162 if [ $exitstatus = 0 ]; then
163     systemctl restart $UNIT
164         whiptail --msgbox "$(systemctl restart $UNIT)" 15 60 4
165         else
166                 systemdDiagnostics
167         fi
168
169 fi
170
171 if [ "$OPTION" == '5' ]; then
172
173 UNIT=$(whiptail --inputbox "What is the unit you want to check?" 8 78  --title "Please enter name of unit" 3>&1 1>&2 2>&3)
174
175 exitstatus=$?
176 if [ $exitstatus = 0 ]; then
177         whiptail --msgbox "$(systemctl is-enabled $UNIT)" 15 60 4
178         else
179                 systemdDiagnostics
180         fi
181
182 fi
183
184 if [ "$OPTION" == '6' ]; then
185
186 UNIT=$(whiptail --inputbox "What is the unit you want to enable at boot?" 8 78  --title "Please enter name of unit" 3>&1 1>&2 2>&3)
187
188 exitstatus=$?
189 if [ $exitstatus = 0 ]; then
190         systemctl enable $UNIT
191         else
192                 systemdDiagnostics
193         fi
194
195 fi
196
197 if [ "$OPTION" == '7' ]; then
198
199 UNIT=$(whiptail --inputbox "What is the unit you want to see man page for?" 8 78  --title "Please enter name of unit" 3>&1 1>&2 2>&3)
200
201 exitstatus=$?
202 if [ $exitstatus = 0 ]; then
203         whiptail --msgbox "$(systemctl help $UNIT)" 30 120 8
204         systemdDiagnostics
205         else
206                 systemdDiagnostics
207         fi
208
209 fi
210
211 if [ "$OPTION" == '8' ]; then
212
213         whiptail --msgbox "Press Q to Quit and return to LinDiag" 15 60 4
214         systemctl status
215         systemdDiagnostics
216
217 fi
218
219 if [ "$OPTION" == '9' ]; then
220
221         init
222
223 fi
224 }
225
226 ########################################################################
227
228 networkDiagnostics(){
229 OPTION=$(whiptail --title "Network Diagnostics" --menu "Choose your option" 15 60 4 \
230 "1" "Display available network devices" \
231 "2" "Restart wpa_supplicant" \
232 "3" "Check status of wpa_supplicant" \
233 "4" "Connect to WiFi network" \
234 "5" "Run Network Speed Test" \
235 "6" "Firewall Configuration" \
236 "7" "Return" \
237 3>&1 1>&2 2>&3)
238
239 if [ "$OPTION" == '1' ]; then
240
241         whiptail --msgbox "$(ip link show)" 15 60 4
242         networkDiagnostics
243
244 fi
245
246 if [ "$OPTION" == '2' ]; then
247
248         systemctl restart wpa_supplicant
249         whiptail --msgbox "$(wpa_supplicant restarted)" 15 60 4
250         networkDiagnostics
251
252 fi
253
254 if [ "$OPTION" == '3' ]; then
255
256         whiptail --msgbox "$(systemctl status wpa_supplicant)" 15 60 4
257         networkDiagnostics
258
259 fi
260
261 if [ "$OPTION" == '4' ]; then
262
263         wifi-menu
264         networkDiagnostics
265
266 fi
267
268 if [ "$OPTION" == '5' ]; then
269
270         curl -s  https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python - >> /var/log/lindiag/netspeed.log &
271     local pid=$!
272     local delay=0.02
273     local spinstr='|/-\'
274     while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
275         local temp=${spinstr#?}
276         clear
277         echo ""
278         echo "Checking connection"
279         echo ""
280         printf " [%c]  " "$spinstr"
281         local spinstr=$temp${spinstr%"$temp"}
282         sleep $delay
283         printf "\b\b\b\b\b\b"
284     done
285     printf "    \b\b\b\b"
286
287         chkOutput
288
289 fi
290
291 if [ "$OPTION" == '6' ]; then
292
293         FirewallConfig
294
295 fi
296
297 if [ "$OPTION" == '7' ]; then
298
299         init
300
301 fi
302
303 }
304
305 ########################################################################
306 serverConfig(){
307 OPTION=$(whiptail --title "Server Configuration" --menu "Choose your option" 15 60 4 \
308 "1" "Install LAMP" \
309 "2" "Install Wordpress" \
310 "3" "Return" \
311 3>&1 1>&2 2>&3)
312
313 if [ "$OPTION" == '1' ]; then
314             if [ -f /var/log/pacman.log ]; then
315                                 pacman -Syu
316                                 pacman -S apache php mariadb
317                                 mysql_secure_installation
318                                 serverConfig
319             fi
320
321             if [ -f /var/log/dpkg.log ]; then
322                                 apt-get update
323                                 apt-get upgrade
324                 apt-get install apache2 apache2-doc mysql-server mysql-client php php-mysql
325                                 mysql_secure_installation
326                                 serverConfig
327             fi
328
329             if [ -d /var/log/dnf ]; then
330             dnf update
331                         dnf install httpd mariadb-server
332                         mysql_secure_installation
333                         dnf install php php-common
334                         dnf install php-mysql php-pdo php-gd php-mbstring
335                         serverConfig
336             fi
337
338
339   fi
340         if [ "$OPTION" == '2' ]; then
341                     if [ -f /var/log/pacman.log ]; then
342                                         pacman -Syu
343                                         pacman -S wordpress
344                                         mysql_secure_installation
345                                         serverConfig
346                     fi
347
348                     if [ -f /var/log/dpkg.log ]; then
349                                         apt-get update
350                                         apt-get upgrade
351                         apt-get install wordpress curl apache2 mariadb-server
352                                         mysql_secure_installation
353                                         serverConfig
354                     fi
355
356                     if [ -d /var/log/dnf ]; then
357                     dnf update
358                                 dnf install wordpress php-mysqlnd mariadb-server
359                                 serverConfig
360                     fi
361   fi
362
363 if [ "$OPTION" == '3' ]; then
364         init
365 fi
366 }
367
368 ########################################################################
369
370 FirewallConfig(){
371 OPTION=$(whiptail --title "Firewall Configuration" --menu "Choose your option" 15 60 4 \
372 "1" "List IPv4 Rules" \
373 "2" "List IPv6 Rules" \
374 "3" "List All Rules" \
375 3>&1 1>&2 2>&3)
376
377 if [ "$OPTION" == '1' ]; then
378
379         clear
380   whiptail --msgbox "$(iptables -S)" 15 60 4
381         FirewallConfig
382
383 fi
384
385 if [ "$OPTION" == '2' ]; then
386
387         clear
388         whiptail --msgbox "$(ip6tables -S)" 15 60 4
389         FirewallConfig
390
391 fi
392
393 if [ "$OPTION" == '3' ]; then
394
395         clear
396         whiptail --msgbox "$(iptables -L -v -n | more)" 15 60 4
397         FirewallConfig
398
399 fi
400
401 }
402 ArchPackage(){
403 OPTION=$(whiptail --title "Package Management" --menu "Choose your option" 15 60 4 \
404 "1" "Update System" \
405 "2" "Clear Pacman Cache" \
406 "3" "Rank Mirrors" \
407 "4" "Install A Package" \
408 "5" "LinDiag Mirrorlist Retriever" \
409 "6" "Return" \
410 3>&1 1>&2 2>&3)
411
412 if [ "$OPTION" == '1' ]; then
413
414         clear
415         pacman -Syu
416         ArchPackage
417
418 fi
419
420 if [ "$OPTION" == '2' ]; then
421
422 if (whiptail --title "WARNING!" --yesno "Only do this when certain that previous package versions are not required, for example for a later downgrade. Would you like to continue?" 8 78) then
423     clear
424     pacman -Sc
425     ArchPackage
426 else
427     ArchPackage
428 fi
429
430 fi
431
432 if [ "$OPTION" == '3' ]; then
433
434         if [ rankmirrors ]; then
435                 clear
436                 echo ""
437                 echo "Generating backup of /etc/pacman.d/mirrorlist"
438                 echo ""
439                 sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
440                 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist.backup
441                 sudo rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist
442                 echo ""
443                 echo "Refreshing Mirrors"
444                 echo ""
445                 sudo pacman -Syyu
446                 ArchPackage
447         else
448                 clear
449                 pacman -S pacman-contrib
450                 echo ""
451                 echo "Generating backup of /etc/pacman.d/mirrorlist"
452                 echo ""
453                 sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
454                 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist.backup
455                 sudo rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist
456                 echo ""
457                 echo "Refreshing Mirrors"
458                 echo ""
459         fi
460 fi
461
462 if [ "$OPTION" == '4' ]; then
463 PACKAGE=$(whiptail --inputbox "Enter name of package" 8 78 --title "Package Installer" 3>&1 1>&2 2>&3)
464 exitstatus=$?
465         if [ $exitstatus = 0 ]; then
466                 clear
467                 pacman -S $PACKAGE
468                 ArchPackage
469         else
470                 ArchPackage
471         fi
472
473 fi
474
475 if [ "$OPTION" == '5' ]; then
476
477         clear
478         wget -O mirrorlist_all_https https://www.archlinux.org/mirrorlist/all/https/
479         wget -O mirrorlist_all_http http://www.archlinux.org/mirrorlist/all/http/
480         wget -O mirrorlist_all_https_IPv4_IPv6_MirrorStatus_On https://www.archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on
481         sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.LinDiagbackup
482         clear
483         sleep 1 #small sanity check
484         ArchPackage
485
486 fi
487
488 if [ "$OPTION" == '6' ]; then
489
490         init
491
492 fi
493
494 }
495
496 ########################################################################
497
498 FedoraPackage(){
499 OPTION=$(whiptail --title "Package Management" --menu "Choose your option" 15 60 4 \
500 "1" "Update System" \
501 "2" "Auto Remove Packages" \
502 "3" "Clean All dnf Temp Files" \
503 "4" "Install a package" \
504 "5" "Return" \
505 3>&1 1>&2 2>&3)
506
507 if [ "$OPTION" == '1' ]; then
508
509         clear
510         dnf upgrade
511         FedoraPackage
512
513 fi
514
515 if [ "$OPTION" == '2' ]; then
516
517         clear
518         dnf autoremove
519         FedoraPackage
520
521 fi
522
523 if [ "$OPTION" == '3' ]; then
524
525         clear
526         dnf clean all
527         FedoraPackage
528
529 fi
530
531 if [ "$OPTION" == '4' ]; then
532 PACKAGE=$(whiptail --inputbox "Enter name of package" 8 78 --title "Package Installer" 3>&1 1>&2 2>&3)
533 exitstatus=$?
534         if [ $exitstatus = 0 ]; then
535                 clear
536                 dnf install $PACKAGE
537                 FedoraPackage
538         else
539                 FedoraPackage
540         fi
541
542 fi
543
544 if [ "$OPTION" == '5' ]; then
545
546         init
547
548 fi
549 }
550
551 ########################################################################
552
553 DebianPackage(){
554 OPTION=$(whiptail --title "Package Management" --menu "Choose your option" 15 60 4 \
555 "1" "Update System" \
556 "2" "Auto Remove Packages" \
557 "3" "Install A Package" \
558 "4" "Return" \
559 3>&1 1>&2 2>&3)
560
561 if [ "$OPTION" == '1' ]; then
562
563         clear
564         apt-get update && apt-get upgrade
565         DebianPackage
566
567 fi
568
569 if [ "$OPTION" == '2' ]; then
570
571         clear
572         apt-get autoremove
573         DebianPackage
574
575 fi
576
577 if [ "$OPTION" == '3' ]; then
578 PACKAGE=$(whiptail --inputbox "Enter name of package" 8 78 --title "Package Installer" 3>&1 1>&2 2>&3)
579 exitstatus=$?
580         if [ $exitstatus = 0 ]; then
581                 clear
582                 apt-get install $PACKAGE
583                 DebianPackage
584         else
585                 DebianPackage
586         fi
587
588 fi
589
590 if [ "$OPTION" == '4' ]; then
591
592         init
593
594 fi
595
596
597 }
598
599 ########################################################################
600
601 DataRec(){
602 OPTION=$(whiptail --title "Data Recovery" --menu "Choose your option" 15 60 4 \
603 "1" "Display all mounted drives" \
604 "2" "Attempt ddrescue of drive" \
605 "3" "Return" \
606 3>&1 1>&2 2>&3)
607
608 if [ "$OPTION" == '1' ]; then
609
610         clear
611         whiptail --msgbox "$(lsblk -o name,label,size,fstype,model)" 20 40
612         DataRec
613
614 fi
615
616 if [ "$OPTION" == '2' ]; then
617
618         if (whiptail --title "WARNING!" --yesno "Is the drive currently failing?"  8 78) then
619                 yFail
620         else
621                 nFail
622         fi
623
624 fi
625
626 if [ "$OPTION" == '3' ]; then
627
628         init
629
630 fi
631 }
632
633 yFail(){
634 DRIVE=$(whiptail --inputbox "What is the drive you're attempting to recover data on?" 8 78 --title "Input Format /dev/sdX" 3>&1 1>&2 2>&3)
635
636 exitstatus=$?
637 if [ $exitstatus = 0 ]; then
638     ddrescue -d $DRIVE test.img test.logfile
639     if (whiptail --title "ATTENTION!" --yesno "Would you like to restore newly created image to a new disk?"  8 78) then
640                 yRestore
641         else
642                 DataRec
643         fi
644
645 else
646     DataRec
647 fi
648
649 }
650
651 nFail(){
652 DRIVE=$(whiptail --inputbox "What is the drive you're attempting to recover data on?" 8 78 --title "Input Format /dev/sdX" 3>&1 1>&2 2>&3)
653
654 exitstatus=$?
655 if [ $exitstatus = 0 ]; then
656     ddrescue -d -r3 $DRIVE test.img test.logfile
657     if (whiptail --title "ATTENTION!" --yesno "Would you like to restore newly created image to a new disk?"  8 78) then
658                 yRestore
659         else
660                 DataRec
661         fi
662
663 else
664     DataRec
665 fi
666 }
667
668 yRestore(){
669 DRIVE_R=$(whiptail --inputbox "What is the drive you want the new .img to go to?" 8 78 --title "Input Format /dev/sdX" 3>&1 1>&2 2>&3)
670
671 exitstatus=$?
672 if [ $exitstatus = 0 ]; then
673     dd if=test.img of=$DRIVE_R
674 else
675     DataRec
676 fi
677 }
678
679 ########################################################################
680
681 nmapTools(){
682         OPTION=$(whiptail --title "Nmap Tools" --menu "Choose your option" 15 60 4 \
683         "1" "Full TCP port scan" \
684         "2" "Verbose Stealth Scan" \
685         "3" "Stealth Syn With OS Detect" \
686         "4" "Stealth Syn Full TCP Port" \
687         "5" "Scan From File" \
688         "6" "Return" \
689         3>&1 1>&2 2>&3)
690
691 if [ "$OPTION" == '1' ]; then
692
693         TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
694         exitstatus=$?
695         if [ $exitstatus = 0 ]; then
696                 nmap -v -p 1-65535 -sV -sS -T4 $TARGET | tee full_TCPscan.log
697                 nmapTools
698         else
699                 nmapTools
700         fi
701
702 fi
703
704 if [ "$OPTION" == '2' ]; then
705
706         TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
707         exitstatus=$?
708         if [ $exitstatus = 0 ]; then
709                 nmap -v -sS -A -T4 $TARGET | tee verbose_Stealth.log
710                 nmapTools
711         else
712                 nmapTools
713         fi
714
715 fi
716
717 if [ "$OPTION" == '3' ]; then
718
719         TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
720         exitstatus=$?
721         if [ $exitstatus = 0 ]; then
722                 nmap -v -sV -O -sS -T5 $TARGET | tee stealthOS.log
723                 nmapTools
724         else
725                 nmapTools
726         fi
727
728 fi
729
730 if [ "$OPTION" == '4' ]; then
731
732         TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
733         exitstatus=$?
734         if [ $exitstatus = 0 ]; then
735                 nmap -v -p 1-65535 -sV -O -sS -T5 $TARGET | tee stealthFullTCP.log
736                 nmapTools
737         else
738                 nmapTools
739         fi
740
741 fi
742
743 if [ "$OPTION" == '5' ]; then
744
745         TARGET=$(whiptail --inputbox "Enter file with full path" 8 78 --title "Enter file with IP's you wish to scan" 3>&1 1>&2 2>&3)
746         exitstatus=$?
747         if [ $exitstatus = 0 ]; then
748                 nmap -iL $TARGET | tee scan_FromFile.log
749                 nmapTools
750         else
751                 nmapTools
752         fi
753
754 fi
755
756 if [ "$OPTION" == '6' ]; then
757
758         networkDiagnostics
759
760 fi
761
762 }
763
764 extraOpts(){
765 OPTION=$(whiptail --title "Extra Options" --menu "Choose your option" 15 60 4 \
766 "1" "32 bit or x86_64" \
767 "2" "Use Google" \
768 "3" "Check for LinDiag updates" \
769 "4" "Generate backup of /var/log" \
770 "5" "Return" \
771 3>&1 1>&2 2>&3)
772
773 if [ "$OPTION" == '1' ]; then
774         whiptail --msgbox "$(uname -m)" 15 60 4
775         extraOpts
776 fi
777
778 if [ "$OPTION" == '2' ]; then
779         INPUT=$(whiptail --inputbox "Enter search query" 8 78 --title "Use Google" 3>&1 1>&2 2>&3)
780         lynx https://www.google.co.uk/search?q=$INPUT
781         extraOpts
782 fi
783
784 if [ "$OPTION" == '3' ]; then
785         clear
786         git clone https://github.com/MorpheusArch/morpheusarchtools.git
787     cd morpheusarchtools
788     mv lindiag.sh /usr/local/bin/
789     chmod +x /usr/local/bin/lindiag.sh
790     cd ..
791     rm -rf morpheusarchtools
792     #./usr/local/bin/lindiag.sh#
793     extraOpts
794 fi
795
796 if [ "$OPTION" == '4' ]; then
797         cd /var/log
798         zip -r "archive-$(date +"%Y-%m-%d%H-%M-%S").zip" * >> /dev/null
799         mkdir /var/log/LinDiag_Backups
800         mv *.zip /var/log/LinDiag_Backups
801         extraOpts
802 fi
803
804 if [ "$OPTION" == '5' ]; then
805
806         init
807 fi
808 }
809 ########################################################################
810 #Auxillary functions. The functions here are required by others in order
811 #to work.
812 ########################################################################
813 #chkOutput is required for network diagnostic speedtest
814
815 chkOutput(){
816         whiptail --msgbox "$(cat /var/log/lindiag/netspeed.log)" 30 120 8
817         whiptail --msgbox "Detailed logs can be found in: /var/log/lindiag/" 15 60 4
818         networkDiagnostics
819 }
820
821 ########################################################################
822 #Required for package management functions chkdistro determines which
823 #package manager is installed and directs user to appropriate function
824
825 chkDistro(){
826     if [ -f /var/log/pacman.log ]; then
827         ArchPackage
828     fi
829
830     if [ -f /var/log/dpkg.log ]; then
831     DebianPackage
832     fi
833
834     if [ -d /var/log/dnf ]; then
835     FedoraPackage
836     fi
837
838 }
839
840 ########################################################################
841 #Required for DataRec function it determines if ddrescue is already
842 #installed and allows the user to install it.
843
844 chkDdrescue(){
845 if [ ddrescue ]; then
846         DataRec
847 else
848         InstallDdrescue
849 fi
850 }
851
852 ########################################################################
853 #Function for installing ddrescue dependant on package manager.
854
855 InstallDdrescue(){
856         if [ -f /var/log/pacman.log ]; then
857         pacman -S ddrescue
858         DataRec
859         else
860                 if [ if -d /var/log/dnf ]; then
861                 dnf install ddrescue
862                 DataRec
863                 fi
864                         if [ if -d /var/log/dpkg.log ]; then
865                         apt-get install ddrescue
866                         DataRec
867                         else
868                                 whiptail --msgbox "ERROR! UNSUPPORTED PACKAGE MANAGER!" 30 120 8
869                                 init
870             fi
871
872         fi
873 }
874
875 ########################################################################
876 #chkNmap is required for network diagnosis. [Network Mapper]
877
878 chkNmap(){
879 if [ nmap ]; then
880         nmapTools
881 else
882         InstallNmap
883 fi
884 }
885
886 ########################################################################
887 #Installs nmap
888
889 InstallNmap(){
890         if [ -f /var/log/pacman.log ]; then
891         pacman -S nmap
892         nmapTools
893         else
894                 if [ if -d /var/log/dnf ]; then
895                 dnf install nmap
896                 nmapTools
897                 fi
898                         if [ if -d /var/log/dpkg.log ]; then
899                         apt-get install nmap
900                         nmapTools
901                         else
902                                 whiptail --msgbox "ERROR! UNSUPPORTED PACKAGE MANAGER!" 30 120 8
903                                 init
904             fi
905         fi
906 }
907 ########################################################################
908 #End auxillary functions
909
910 authCheck