Untitled
raw download clone
TEXT
views 41
,
size 3594 b
#!bin/sh

trap 'exit' INT # EXIT hot-key ctr+c

COLS=$(tput cols)
HDD_ROTA=""
SSD_ROTA=""
drive_mount=""
drive_mount_2=""
f_ssd=hdparm		# SSD format tool
f_hdd=shred		# HDD format tool
RED='\033[0;31m'	# red text
NC='\033[0m'		# white text
PURPLE='\033[1;35m'	# Light Purple
BLUE='\033[0;34m'	# BLUE
##################################
#1.  List of available disks     #
##################################

av_disk(){
fdisk -l
	avdisk=$(fdisk -l | grep '^Disk' | grep -Ev '0x62536b43' | grep -Ev 'DT micro' | grep -Ev '115.51' | grep -oP "sd[a-z][0-9]?") # Drive mount point sd* without ROOT/USB

		while read i ; do 
	
		which_disk="$(cat /sys/block/"$i"/queue/rotational)" # cat with SSD or HDD flag (0 or 1)  output to variable 
			#echo "$avdisk"
			 for i in $which_disk
			  do
			  if [ $i == 1 ]
			   then
			   drive_mount=$(lsblk -o NAME,ROTA | grep 1 | head -1  | grep -oP "sd[a-z]?")
	 		   echo -e " ${RED} ON YOUR MASCHINE I HAVE DETECTED HDD WITH MOUNTING POINT UNDER >>>>>> ${PURPLE}  /dev/"$drive_mount". ${NC} "
			  HDD_ROTA="$i"
			  fi	
			  if (( $i == 0 ))
			   then
			   drive_mount_2=$(lsblk -o NAME,ROTA | grep 0 | grep -oP "sd[a-z]?")
	 		   echo -e " ${RED} ON YOUR MASCHINE I HAVE DETECTED SSD WITH MOUNTING POINT UNDER >>>>>> ${PURPLE} /dev/"$drive_mount_2". ${NC} "
			   SSD_ROTA="$i"
			  fi	
		      done
done <<< "$avdisk" # Use grep as array variable

}

###############################
#2.	SHRED  (HDD)          #
###############################
shred_hdd(){
shred_hd="shred -vfz -n 3 /dev/"$drive_mount" " # Main program with var parameter set by List of available disks
	if [[ $HDD_ROTA == 1 ]] ; then
		echo -e  -n "DO YOU REALLY WANT TO ${RED} FORMAT /dev/"$drive_mount" ? ${NC} y or n [n] " # wait for user
	 	read answer
	 	#answer="$(echo $answer | tr '[:upper:]' '[:lover:]' | cut - c1)"
			if [ "$answer" != "y" ] ; then
		 	 echo -e "${BLUE} YOU HAVE INTERRUPTED THE MISSION ${NC}  "
			else
			 $shred_hd
			
 fi
fi
}
###############################
#3.	HDPARM (SSD)	      #
###############################
hdparm_ssd(){
hdparm_1="hdparm -I /dev/"$drive_mount_2" # NOT frozen ?
hdparm_2="time hdparm --user-master u --security-set-pass Eins /dev/"$drive_mount_2" # 
hdparm_3=""

}
	
###############################
#          PRINT MENU         #
###############################

printMenu(){
	clear
	av_disk
	echo ""
	echo -e "                                                                                    THIS PROGRAM IS MADE BY TOMMY ;-)                                       "
	echo ""
	echo "                                                                              Choose an option writing its number and press enter"
	# echo -e "\t1) LIST ALL AVAILABLE DISKS"
	echo ""
	echo -e "                                                                                           \t1)  FORMAT HDD"
	echo -e "                                                                                           \t2)  FORMAT SSD"
	echo -e "                                                                                              \t3)  EXIT"
	
	read option;
	
	while [[ $option -gt 3 || ! $(echo $option | grep '^[1-9]$') ]]
	do

		printMenu
	
	done
	runOption
}
#############################
#	RUN OPTION	    #
#############################
runOption(){
	case $option in
		# 1) av_disk;;
		1) shred_hdd;;
		2) hdparm_ssd;;
		3) exit
	esac
	echo "Press any Key to continue"
	read x
	printMenu
}

while [ 1 ]
do	
	printMenu
done
close fullscreen
Login or Register to edit or fork this paste. It's free.