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.
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.
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/>.
18 #http://morpheusarchlinux.com
20 ########################################################################
21 #-- authCheck asks for adminstrator aka root priveleges
25 if [ $(id -u) != "0" ]; then
27 echo "You must be root to run this script"
28 echo "Please enter the following command and press enter: sudo !!"
36 ########################################################################
37 #-- mklindiag creates the directory for logs to be stored.
40 if [ -d /var/log/lindiag ]; then
42 else #if the /var/log/lindiag directory does not exist this creates it
43 mkdir /var/log/lindiag >> /dev/null 2>&1
49 ########################################################################
50 #-- init is the main menu
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" \
63 if [ "$OPTION" == '1' ]; then
69 if [ "$OPTION" == '2' ]; then
75 if [ "$OPTION" == '3' ]; then
82 if [ "$OPTION" == '4' ]; then
88 if [ "$OPTION" == '5' ]; then
94 if [ "$OPTION" == '6' ]; then
100 if [ "$OPTION" == '7' ]; then
107 ########################################################################
109 systemdDiagnostics(){
110 OPTION=$(whiptail --title "Systemd_Diagnostics" --menu "Choose your option" 15 60 4 \
111 "1" "Check for failed services" \
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" \
122 if [ "$OPTION" == '1' ]; then
124 whiptail --msgbox "$(systemctl --failed)" 15 60 4
129 if [ "$OPTION" == '2' ]; then
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)
134 if [ $exitstatus = 0 ]; then
135 systemctl start $UNIT
136 whiptail --msgbox "$(systemctl status $UNIT)" 15 60 4
143 if [ "$OPTION" == '3' ]; then
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)
148 if [ $exitstatus = 0 ]; then
150 whiptail --msgbox "$(systemctl stop $UNIT)" 15 60 4
157 if [ "$OPTION" == '4' ]; then
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)
162 if [ $exitstatus = 0 ]; then
163 systemctl restart $UNIT
164 whiptail --msgbox "$(systemctl restart $UNIT)" 15 60 4
171 if [ "$OPTION" == '5' ]; then
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)
176 if [ $exitstatus = 0 ]; then
177 whiptail --msgbox "$(systemctl is-enabled $UNIT)" 15 60 4
184 if [ "$OPTION" == '6' ]; then
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)
189 if [ $exitstatus = 0 ]; then
190 systemctl enable $UNIT
197 if [ "$OPTION" == '7' ]; then
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)
202 if [ $exitstatus = 0 ]; then
203 whiptail --msgbox "$(systemctl help $UNIT)" 30 120 8
211 if [ "$OPTION" == '8' ]; then
213 whiptail --msgbox "Press Q to Quit and return to LinDiag" 15 60 4
219 if [ "$OPTION" == '9' ]; then
226 ########################################################################
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" \
239 if [ "$OPTION" == '1' ]; then
241 whiptail --msgbox "$(ip link show)" 15 60 4
246 if [ "$OPTION" == '2' ]; then
248 systemctl restart wpa_supplicant
249 whiptail --msgbox "$(wpa_supplicant restarted)" 15 60 4
254 if [ "$OPTION" == '3' ]; then
256 whiptail --msgbox "$(systemctl status wpa_supplicant)" 15 60 4
261 if [ "$OPTION" == '4' ]; then
268 if [ "$OPTION" == '5' ]; then
270 curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python - >> /var/log/lindiag/netspeed.log &
274 while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
275 local temp=${spinstr#?}
278 echo "Checking connection"
280 printf " [%c] " "$spinstr"
281 local spinstr=$temp${spinstr%"$temp"}
283 printf "\b\b\b\b\b\b"
291 if [ "$OPTION" == '6' ]; then
297 if [ "$OPTION" == '7' ]; then
305 ########################################################################
307 OPTION=$(whiptail --title "Server Configuration" --menu "Choose your option" 15 60 4 \
309 "2" "Install Wordpress" \
313 if [ "$OPTION" == '1' ]; then
314 if [ -f /var/log/pacman.log ]; then
316 pacman -S apache php mariadb
317 mysql_secure_installation
321 if [ -f /var/log/dpkg.log ]; then
324 apt-get install apache2 apache2-doc mysql-server mysql-client php php-mysql
325 mysql_secure_installation
329 if [ -d /var/log/dnf ]; then
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
340 if [ "$OPTION" == '2' ]; then
341 if [ -f /var/log/pacman.log ]; then
344 mysql_secure_installation
348 if [ -f /var/log/dpkg.log ]; then
351 apt-get install wordpress curl apache2 mariadb-server
352 mysql_secure_installation
356 if [ -d /var/log/dnf ]; then
358 dnf install wordpress php-mysqlnd mariadb-server
363 if [ "$OPTION" == '3' ]; then
368 ########################################################################
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" \
377 if [ "$OPTION" == '1' ]; then
380 whiptail --msgbox "$(iptables -S)" 15 60 4
385 if [ "$OPTION" == '2' ]; then
388 whiptail --msgbox "$(ip6tables -S)" 15 60 4
393 if [ "$OPTION" == '3' ]; then
396 whiptail --msgbox "$(iptables -L -v -n | more)" 15 60 4
403 OPTION=$(whiptail --title "Package Management" --menu "Choose your option" 15 60 4 \
404 "1" "Update System" \
405 "2" "Clear Pacman Cache" \
407 "4" "Install A Package" \
408 "5" "LinDiag Mirrorlist Retriever" \
412 if [ "$OPTION" == '1' ]; then
420 if [ "$OPTION" == '2' ]; then
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
432 if [ "$OPTION" == '3' ]; then
434 if [ rankmirrors ]; then
437 echo "Generating backup of /etc/pacman.d/mirrorlist"
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
443 echo "Refreshing Mirrors"
449 pacman -S pacman-contrib
451 echo "Generating backup of /etc/pacman.d/mirrorlist"
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
457 echo "Refreshing Mirrors"
462 if [ "$OPTION" == '4' ]; then
463 PACKAGE=$(whiptail --inputbox "Enter name of package" 8 78 --title "Package Installer" 3>&1 1>&2 2>&3)
465 if [ $exitstatus = 0 ]; then
475 if [ "$OPTION" == '5' ]; then
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
483 sleep 1 #small sanity check
488 if [ "$OPTION" == '6' ]; then
496 ########################################################################
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" \
507 if [ "$OPTION" == '1' ]; then
515 if [ "$OPTION" == '2' ]; then
523 if [ "$OPTION" == '3' ]; then
531 if [ "$OPTION" == '4' ]; then
532 PACKAGE=$(whiptail --inputbox "Enter name of package" 8 78 --title "Package Installer" 3>&1 1>&2 2>&3)
534 if [ $exitstatus = 0 ]; then
544 if [ "$OPTION" == '5' ]; then
551 ########################################################################
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" \
561 if [ "$OPTION" == '1' ]; then
564 apt-get update && apt-get upgrade
569 if [ "$OPTION" == '2' ]; then
577 if [ "$OPTION" == '3' ]; then
578 PACKAGE=$(whiptail --inputbox "Enter name of package" 8 78 --title "Package Installer" 3>&1 1>&2 2>&3)
580 if [ $exitstatus = 0 ]; then
582 apt-get install $PACKAGE
590 if [ "$OPTION" == '4' ]; then
599 ########################################################################
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" \
608 if [ "$OPTION" == '1' ]; then
611 whiptail --msgbox "$(lsblk -o name,label,size,fstype,model)" 20 40
616 if [ "$OPTION" == '2' ]; then
618 if (whiptail --title "WARNING!" --yesno "Is the drive currently failing?" 8 78) then
626 if [ "$OPTION" == '3' ]; then
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)
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
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)
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
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)
672 if [ $exitstatus = 0 ]; then
673 dd if=test.img of=$DRIVE_R
679 ########################################################################
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" \
691 if [ "$OPTION" == '1' ]; then
693 TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
695 if [ $exitstatus = 0 ]; then
696 nmap -v -p 1-65535 -sV -sS -T4 $TARGET | tee full_TCPscan.log
704 if [ "$OPTION" == '2' ]; then
706 TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
708 if [ $exitstatus = 0 ]; then
709 nmap -v -sS -A -T4 $TARGET | tee verbose_Stealth.log
717 if [ "$OPTION" == '3' ]; then
719 TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
721 if [ $exitstatus = 0 ]; then
722 nmap -v -sV -O -sS -T5 $TARGET | tee stealthOS.log
730 if [ "$OPTION" == '4' ]; then
732 TARGET=$(whiptail --inputbox "Enter IP address or hostname" 8 78 --title "Enter target" 3>&1 1>&2 2>&3)
734 if [ $exitstatus = 0 ]; then
735 nmap -v -p 1-65535 -sV -O -sS -T5 $TARGET | tee stealthFullTCP.log
743 if [ "$OPTION" == '5' ]; then
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)
747 if [ $exitstatus = 0 ]; then
748 nmap -iL $TARGET | tee scan_FromFile.log
756 if [ "$OPTION" == '6' ]; then
765 OPTION=$(whiptail --title "Extra Options" --menu "Choose your option" 15 60 4 \
766 "1" "32 bit or x86_64" \
768 "3" "Check for LinDiag updates" \
769 "4" "Generate backup of /var/log" \
773 if [ "$OPTION" == '1' ]; then
774 whiptail --msgbox "$(uname -m)" 15 60 4
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
784 if [ "$OPTION" == '3' ]; then
786 git clone https://github.com/MorpheusArch/morpheusarchtools.git
788 mv lindiag.sh /usr/local/bin/
789 chmod +x /usr/local/bin/lindiag.sh
791 rm -rf morpheusarchtools
792 #./usr/local/bin/lindiag.sh#
796 if [ "$OPTION" == '4' ]; then
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
804 if [ "$OPTION" == '5' ]; then
809 ########################################################################
810 #Auxillary functions. The functions here are required by others in order
812 ########################################################################
813 #chkOutput is required for network diagnostic speedtest
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
821 ########################################################################
822 #Required for package management functions chkdistro determines which
823 #package manager is installed and directs user to appropriate function
826 if [ -f /var/log/pacman.log ]; then
830 if [ -f /var/log/dpkg.log ]; then
834 if [ -d /var/log/dnf ]; then
840 ########################################################################
841 #Required for DataRec function it determines if ddrescue is already
842 #installed and allows the user to install it.
845 if [ ddrescue ]; then
852 ########################################################################
853 #Function for installing ddrescue dependant on package manager.
856 if [ -f /var/log/pacman.log ]; then
860 if [ if -d /var/log/dnf ]; then
864 if [ if -d /var/log/dpkg.log ]; then
865 apt-get install ddrescue
868 whiptail --msgbox "ERROR! UNSUPPORTED PACKAGE MANAGER!" 30 120 8
875 ########################################################################
876 #chkNmap is required for network diagnosis. [Network Mapper]
886 ########################################################################
890 if [ -f /var/log/pacman.log ]; then
894 if [ if -d /var/log/dnf ]; then
898 if [ if -d /var/log/dpkg.log ]; then
902 whiptail --msgbox "ERROR! UNSUPPORTED PACKAGE MANAGER!" 30 120 8
907 ########################################################################
908 #End auxillary functions