Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ASK=yes #ASK=no for no prompt prior to removing.
- CWD="$(realpath "$PWD")"
- safe_del_root="$PWD/savefiles"
- Portable_Browser_Profile_locations=("/opt/Iron-portable/iron32/PROFILE")
- HOMES=("/root" "/home/spot")
- Home_Browser_Caches=("/.cache/chrome" "/.cache/mozilla")
- Home_Files_Misc=("/.history" "/.local/share/recently-used.xbel")
- #isc_Dels=("/etc/shadow" "/etc/resolv.conf")
- Misc_Dels=("/etc/resolv.conf" "/etc/rc.d/PUPSTATE" "/etc/rc.d/BOOTCONFIG")
- System_Roots=("" "/cont")
- IFSo="$IFS"
- IFS=$'\n'
- Save_File_Paths=($(ls -1 "$CWD/savefiles"))
- echo "Save_File_Paths=${Save_File_Paths[@]}"
- #log=yes
- export LOGFILE="$CWD/clean_log"
- export TRACE=true
- [ -f "$LOGFILE" ] && rm "$LOGFILE"
- touch "$LOGFILE"
- function maybe_remove(){
- #log stop
- #echo "remove \"$1\"? (y/n)" >&2
- sync
- #fsync /dev/tty
- read -p "remove \"$1\"? (y/n)" answer
- if [ "$ASK" = no ] || [[ "$answer" = y* ]] || [[ "$answer" = Y* ]]; then
- return 0
- else
- return 1
- fi
- #log start
- }
- export -f maybe_remove
- function log(){
- set +x #TODO add more verbose log option that doesn't do this.
- local SET_X=false
- local logfile="${2}"
- local trace="$3"
- if [ ! -z "$LOGFILE" ]; then
- case "$1" in
- init)
- [ "$TRACE" = true ] && SET_X=true
- [ ! -f "$LOGFILE" ] && rm "$LOGFILE"
- exec 6>&1 # Link file descriptor #6 with stdout.
- exec 7>&2
- [ ! -f "$LOGFILE" ] && touch "$LOGFILE"
- ;;
- start)
- [ "$TRACE" = true ] && SET_X=true
- #exec 1>&6 # Link file descriptor #6 with stdout.
- #exec 2>&7
- exec &> >(tee -a "$LOGFILE")
- ;;
- stop)
- #exec 1>/dev/null # Link file descriptor #6 with stdout.
- #exec 2>/dev/null
- # exec 2>&7
- # exec 1>&6 # Link file descriptor #6 with stdout.
- #exec 1>&-
- #exec 2>&-
- exec 1>&6
- exec 2>/dev/tty
- #exec 2>/dev/stderr
- #exec 1>/dev/stdout
- ;;
- esac
- fi
- [ "$SET_X" = true ] && set -x
- }
- export -f log
- log init
- log start
- for a_save_file in "${Save_File_Paths[@]}"; do
- for a_Sys_Root in "${System_Roots[@]}"; do
- a_save_FP="$CWD/savefiles/$a_save_file$a_Sys_Root"
- #Delete Portable Browser Profiles
- for a_BP_loc in "${Portable_Browser_Profile_locations[@]}"; do
- a_path="$a_save_FP$a_BP_loc"
- if [ -d "$a_path" ]; then
- a_path="$(realpath "$a_path")"
- log stop
- set +x
- maybe_remove "$a_path" && {
- log start
- if [[ "$a_path" = "$safe_del_root/"* ]]; then
- rm -rf "$a_path"
- fi
- } || log start
- fi
- done
- #Delete Misc Files in the home directory
- for a_home in "${HOMES[@]}"; do
- a_home_path="$a_save_FP$a_home"
- IFS=$'\n'
- for a_home_cache_loc in "${Home_Browser_Caches[@]}"; do
- a_path="$a_home_path$a_home_cache_loc"
- if [ -d "$a_path" ]; then
- a_path="$(realpath "$a_path")"
- log stop
- set +x
- maybe_remove "$a_path" && {
- log start
- if [[ "$a_path" = "$safe_del_root/"* ]]; then
- rm -rf "$a_path"/*
- fi
- } || log start
- fi
- done
- #Delete Misc Files in the home directory
- for a_file in "${Home_Files_Misc[@]}"; do
- a_path="$a_home_path$a_file"
- if [ -e "$a_path" ]; then
- a_path="$(realpath "$a_path")"
- if [[ "$a_path" = "$safe_del_root/"* ]]; then
- log stop
- set +x
- maybe_remove "$a_path" && {
- log start
- if [ -d "$a_path" ]; then
- rm -rf "$a_path"
- elif [ -f "$a_path" ]; then
- rm -f "$a_path"
- fi
- } || log start
- fi
- fi
- done
- done
- #Delete Misc. Files
- for a_file in "${Misc_Dels[@]}"; do
- a_path="$a_home_path$a_file"
- if [ -e "$a_path" ]; then
- a_path="$(realpath "$a_path")"
- if [[ "$a_path" = "$safe_del_root/"* ]]; then
- log stop
- set +x
- maybe_remove "$a_path" && {
- log start
- if [ -d "$a_path" ]; then
- rm -rf "$a_path"
- elif [ -f "$a_path" ]; then
- rm -f "$a_path"
- fi
- } || log start
- fi
- fi
- done
- done
- done
- #TODO, delete ssh keys, delete samba credentials, delete wifi passwords.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement