s243a

clean_private_info.sh

Jan 13th, 2021
556
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. ASK=yes #ASK=no for no prompt prior to removing.
  3. CWD="$(realpath "$PWD")"
  4. safe_del_root="$PWD/savefiles"
  5. Portable_Browser_Profile_locations=("/opt/Iron-portable/iron32/PROFILE")
  6. HOMES=("/root" "/home/spot")
  7. Home_Browser_Caches=("/.cache/chrome" "/.cache/mozilla")
  8. Home_Files_Misc=("/.history" "/.local/share/recently-used.xbel")
  9. #isc_Dels=("/etc/shadow" "/etc/resolv.conf")
  10. Misc_Dels=("/etc/resolv.conf" "/etc/rc.d/PUPSTATE" "/etc/rc.d/BOOTCONFIG")
  11. System_Roots=("" "/cont")
  12. IFSo="$IFS"
  13. IFS=$'\n'
  14. Save_File_Paths=($(ls -1 "$CWD/savefiles"))
  15. echo "Save_File_Paths=${Save_File_Paths[@]}"
  16. #log=yes
  17. export LOGFILE="$CWD/clean_log"
  18. export TRACE=true
  19. [ -f "$LOGFILE" ] && rm "$LOGFILE"
  20. touch "$LOGFILE"
  21. function maybe_remove(){
  22.  
  23.     #log stop  
  24.     #echo "remove \"$1\"? (y/n)" >&2
  25.     sync
  26.     #fsync /dev/tty
  27.     read -p "remove \"$1\"? (y/n)" answer
  28.     if [ "$ASK" = no ] || [[ "$answer" = y* ]] ||   [[ "$answer" = Y* ]]; then
  29.       return 0
  30.     else
  31.       return 1
  32.     fi
  33.     #log start
  34. }
  35. export -f maybe_remove
  36. function log(){
  37.   set +x #TODO add more verbose log option that doesn't do this.
  38.    local SET_X=false
  39.   local logfile="${2}"
  40.   local trace="$3"
  41.   if [ ! -z "$LOGFILE" ]; then
  42.     case "$1" in
  43.     init)
  44.       [ "$TRACE" = true ] && SET_X=true
  45.       [ ! -f "$LOGFILE" ] && rm "$LOGFILE"
  46.       exec 6>&1           # Link file descriptor #6 with stdout.
  47.       exec 7>&2
  48.       [ ! -f "$LOGFILE" ] && touch "$LOGFILE"
  49.       ;;
  50.     start)
  51.       [ "$TRACE" = true ] && SET_X=true
  52.  
  53.       #exec 1>&6           # Link file descriptor #6 with stdout.
  54.       #exec 2>&7    
  55.       exec &> >(tee -a "$LOGFILE")
  56.       ;;
  57.     stop)
  58.       #exec 1>/dev/null           # Link file descriptor #6 with stdout.
  59.       #exec 2>/dev/null        
  60.  
  61. #      exec 2>&7                    
  62. #      exec 1>&6           # Link file descriptor #6 with stdout.
  63.       #exec 1>&-
  64.       #exec 2>&-
  65.       exec 1>&6
  66.       exec 2>/dev/tty
  67.  
  68.  
  69.       #exec 2>/dev/stderr
  70.       #exec 1>/dev/stdout
  71.       ;;
  72.     esac
  73.   fi    
  74.   [ "$SET_X" = true ] && set -x
  75. }
  76. export -f log
  77. log init
  78. log start
  79. for a_save_file in "${Save_File_Paths[@]}"; do
  80.   for a_Sys_Root in "${System_Roots[@]}"; do
  81.     a_save_FP="$CWD/savefiles/$a_save_file$a_Sys_Root"
  82.     #Delete Portable Browser Profiles
  83.     for a_BP_loc in "${Portable_Browser_Profile_locations[@]}"; do
  84.       a_path="$a_save_FP$a_BP_loc"
  85.       if [ -d "$a_path" ]; then
  86.         a_path="$(realpath "$a_path")"
  87.         log stop
  88.         set +x
  89.         maybe_remove "$a_path" && {
  90.           log start          
  91.           if [[ "$a_path" = "$safe_del_root/"* ]]; then
  92.             rm -rf "$a_path"
  93.           fi
  94.         } || log start
  95.       fi
  96.     done
  97.     #Delete Misc Files in the home directory
  98.     for a_home in "${HOMES[@]}"; do
  99.       a_home_path="$a_save_FP$a_home"
  100.       IFS=$'\n'
  101.       for a_home_cache_loc in "${Home_Browser_Caches[@]}"; do
  102.         a_path="$a_home_path$a_home_cache_loc"
  103.         if [ -d "$a_path" ]; then
  104.           a_path="$(realpath "$a_path")"
  105.           log stop
  106.           set +x
  107.            maybe_remove "$a_path" && {
  108.              log start        
  109.              if [[ "$a_path" = "$safe_del_root/"* ]]; then
  110.                rm -rf "$a_path"/*
  111.             fi
  112.           } || log start
  113.         fi
  114.       done
  115.       #Delete Misc Files in the home directory
  116.       for a_file in "${Home_Files_Misc[@]}"; do
  117.         a_path="$a_home_path$a_file"
  118.         if [ -e "$a_path" ]; then
  119.           a_path="$(realpath "$a_path")"
  120.            if [[ "$a_path" = "$safe_del_root/"* ]]; then
  121.              log stop
  122.              set +x
  123.              maybe_remove "$a_path" && {
  124.                log start
  125.                if [ -d "$a_path" ]; then              
  126.                  rm -rf "$a_path"
  127.                elif [ -f "$a_path" ]; then
  128.                  rm -f "$a_path"
  129.                fi
  130.              } || log start
  131.              
  132.           fi
  133.         fi
  134.       done        
  135.     done
  136.     #Delete Misc. Files
  137.     for a_file in "${Misc_Dels[@]}"; do
  138.       a_path="$a_home_path$a_file"
  139.       if [ -e "$a_path" ]; then
  140.         a_path="$(realpath "$a_path")"
  141.         if [[ "$a_path" = "$safe_del_root/"* ]]; then
  142.           log stop
  143.           set +x
  144.           maybe_remove "$a_path" && {
  145.             log start      
  146.             if [ -d "$a_path" ]; then
  147.               rm -rf "$a_path"          
  148.             elif [ -f "$a_path" ]; then
  149.               rm -f "$a_path"
  150.             fi
  151.           } || log start
  152.          
  153.         fi
  154.       fi
  155.     done        
  156.   done
  157. done    
  158. #TODO, delete ssh keys, delete samba credentials, delete wifi passwords.
  159.  
  160.  
RAW Paste Data