Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ROOT=/initrd/mnt/dev_save/precise/light/5.7.2/precisesave
- target_root=/initrd/mnt/dev_save/precise/light/5.7.2/precise_save_alt_glibc
- cd "$ROOT"
- function print_pttrn(){
- cd "$ROOT/$(dirname $1)"
- find -name "$(basename $1)"
- }
- if [ ${#ROOT} -lt 3 ]; then
- exit
- fi
- sed -i -e '/^PS1/ s/PS1=.*$/PS1="# "/' "$ROOT/etc/profile"
- sed -i -e '/^PS1/ s/PS1=.*$/PS1="# "/' "$ROOT/etc/shinit"
- FILES_TO_DELETE=("/etc/BOOTSTATE")
- for a_delete_pattern in "${FILES_TO_DELETE[@]}"; do #https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
- while IFS="" read -r a_delete || [ -n "$a_delete" ]
- do
- fp="$(realpath "$a_delete")"
- if [[ "$fp" == "$ROOT/"* ]]; then
- rm -f "$fp"
- fi
- done < <(find . -wholename ".$a_delete_pattern")
- done
- DIRS_TO_FORCE_DELETE=("/media" "/mnt" "/tmp" "/proc" "/dev" "/sys" "/initrd" "/lost+found" "/lib/modules" "/archive")
- while IFS="" read -r a_dir || [ -n "$a_dir" ]; do
- #echo "a_dir=$a_dir"
- echo "a_dir2=/var/$a_dir" #"$(echo "$a_dir" | sed 's#^.#/var/#')"
- DIRS_TO_FORCE_DELETE+=("/var/$a_dir") #("$(echo "$a_dir" | sed 's#^.#/var/#')")
- done < <(ls -1 ./var | grep -v packages)
- for a_delete_pattern in "${DIRS_TO_FORCE_DELETE[@]}"; do #https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
- #echo a_delete_pattern
- while IFS="" read -r a_delete || [ -n "$a_delete" ]
- do
- fp="$(realpath "$a_delete")"
- if [[ "$fp" == "$ROOT/"* ]]; then
- rm -rf "$fp"
- fi
- done < <(find . -wholename ".$a_delete_pattern")
- done
- EMPTY_DIRS_TO_DELETEE=()
- for a_delete_pattern in "${EMPTY_DIRS_TO_DELETEE[@]}"; do #https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
- while IFS="" read -r a_delete || [ -n "$a_delete" ]
- do
- fp="$(realpath "$ROOT/a_delete_pattern")"
- if [[ "$fp" == "$ROOT/"* ]]; then
- #RM will only remove empty directories unless the -rf option is used
- rm "$fp" 2> /dev/null
- fi
- done < <(find . -wholename ".$a_delete_pattern")
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement