toyotacorolla

vroom
Log | Files | Refs

wipe (1967B)


      1 #!/bin/sh
      2 
      3 display_entropy() {
      4 	echo "Entropy available: $(cat /proc/sys/kernel/random/entropy_avail)"
      5 	echo "Entropy pool size: $(cat /proc/sys/kernel/random/poolsize)"
      6 	echo "Wakeup threshold: $(cat /proc/sys/kernel/random/write_wakeup_threshold)"
      7 	echo "Minimum reseeding in seconds: $(cat /proc/sys/kernel/random/urandom_min_reseed_secs)"
      8 }
      9 
     10 random_string() {
     11 	tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w "$1" | head -n 1
     12 }
     13 
     14 secure_wipe() {
     15 	local target="$1"
     16 	
     17 	if [ -z "$target" ]; then
     18 		echo "No target specified for secure wipe."
     19 		exit 1
     20 	fi
     21 
     22 	if [ ! -e "$target" ]; then
     23 		echo "The specified file or directory does not exist."
     24 		exit 1
     25 	fi
     26 
     27 	folder_size=$(du -s "$target" | awk '{print $1}')
     28 	count_size=$((folder_size + 100)) # just a bit extra for remnants 
     29 
     30 	sudo find "$target" -type f -exec shred -vn4 -u {} +
     31 	sudo find "$target" -type d -exec rm -rf {} +
     32 	sudo dd if=/dev/urandom of=file bs=1024 count=$count_size
     33 	new_file_name=$(random_string 4)
     34 	sudo mv file "$new_file_name"
     35 	sudo rm -f "$new_file_name"
     36 }
     37 
     38 # Check if no arguments are provided
     39 if [ $# -eq 0 ]; then
     40 	echo "wipe: missing file operand"
     41 	exit 1
     42 fi
     43 
     44 # Initialize variables for options
     45 secure_wipe_option=0
     46 
     47 # Parse options
     48 while [[ "$1" =~ ^- ]]; do
     49 	case "$1" in
     50 		-s)
     51 			secure_wipe_option=1
     52 			shift
     53 			;;
     54 		# add more later if need be
     55 		*)
     56 			echo "Invalid option: $1"
     57 			exit 1
     58 			;;
     59 	esac
     60 done
     61 
     62 target="$1"
     63 
     64 if [ ! -e "$target" ]; then
     65 	echo "The specified file or directory does not exist."
     66 	exit 1
     67 fi
     68 
     69 display_entropy
     70 
     71 if [ $secure_wipe_option -eq 1 ]; then
     72 	secure_wipe "$target"
     73 	exit 0
     74 fi
     75 
     76 full_path=$(readlink -f "$target")
     77 read -p "Delete $full_path/*? (y/n): " answer
     78 
     79 answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')
     80 
     81 if [ "$answer" != "y" ]; then
     82 	echo "Wiping deletion aborted."
     83 	exit 1
     84 fi
     85 
     86 if [ -d "$target" ]; then
     87 	find "$target" -type f -exec shred -vn3 -u {} + && find "$target" -type d -exec rm -rf {} +
     88 fi
     89 
     90 rm -rf "$target"
     91 
     92 echo "Deletion completed."
     93