Advertisement
s243a

clean_sandbox_save.sh

Feb 16th, 2020
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.06 KB | None | 0 0
  1. #!/bin/bash
  2. ROOT=/initrd/mnt/dev_save/precise/light/5.7.2/precisesave
  3. target_root=/initrd/mnt/dev_save/precise/light/5.7.2/precise_save_alt_glibc
  4. cd "$ROOT"
  5. function print_pttrn(){
  6.   cd "$ROOT/$(dirname $1)"
  7.   find -name "$(basename $1)"
  8. }
  9. if [ ${#ROOT} -lt 3 ]; then
  10. exit
  11. fi
  12.   sed -i -e '/^PS1/ s/PS1=.*$/PS1="# "/' "$ROOT/etc/profile"
  13.   sed -i -e '/^PS1/ s/PS1=.*$/PS1="# "/' "$ROOT/etc/shinit"
  14. FILES_TO_DELETE=("/etc/BOOTSTATE")
  15. for a_delete_pattern in "${FILES_TO_DELETE[@]}"; do #https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
  16.   while IFS="" read -r a_delete || [ -n "$a_delete" ]
  17.   do
  18.       fp="$(realpath "$a_delete")"
  19.       if [[ "$fp" == "$ROOT/"* ]]; then
  20.         rm -f "$fp"
  21.       fi
  22.   done < <(find . -wholename ".$a_delete_pattern")
  23. done
  24. DIRS_TO_FORCE_DELETE=("/media" "/mnt" "/tmp" "/proc" "/dev" "/sys" "/initrd" "/lost+found" "/lib/modules" "/archive")
  25. while IFS="" read -r a_dir || [ -n "$a_dir" ]; do
  26.   #echo "a_dir=$a_dir"
  27.   echo "a_dir2=/var/$a_dir" #"$(echo "$a_dir" | sed 's#^.#/var/#')"
  28.   DIRS_TO_FORCE_DELETE+=("/var/$a_dir") #("$(echo "$a_dir" | sed 's#^.#/var/#')")
  29. done < <(ls -1 ./var | grep -v packages)
  30. for a_delete_pattern in "${DIRS_TO_FORCE_DELETE[@]}"; do #https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
  31.   #echo a_delete_pattern
  32.   while IFS="" read -r a_delete || [ -n "$a_delete" ]
  33.   do
  34.       fp="$(realpath "$a_delete")"
  35.       if [[ "$fp" == "$ROOT/"* ]]; then
  36.         rm -rf "$fp"
  37.       fi
  38.   done < <(find . -wholename ".$a_delete_pattern")
  39. done
  40. EMPTY_DIRS_TO_DELETEE=()
  41. for a_delete_pattern in "${EMPTY_DIRS_TO_DELETEE[@]}"; do #https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
  42.   while IFS="" read -r a_delete || [ -n "$a_delete" ]
  43.   do
  44.       fp="$(realpath "$ROOT/a_delete_pattern")"
  45.       if [[ "$fp" == "$ROOT/"* ]]; then
  46.         #RM will only remove empty directories unless the -rf option is used
  47.         rm "$fp" 2> /dev/null
  48.       fi
  49.   done < <(find . -wholename ".$a_delete_pattern")
  50. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement