Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- sync
- OUT="/tmp/Udate_save/"
- mkdir -p "$OUT"
- decode_id() {
- if [ -f "$OUT"'BLKIDOUT' ]; then
- DECODE_ID_RTN=`cat "$OUT"'BLKIDOUT'`
- else
- BLKIDOUT="$(blkid)"
- DECODE_ID_RTN="$(echo "$BLKIDOUT" | grep -m1 -E " LABEL=.${1}| UUID=.${1}" | cut -f1 -d: | cut -f3 -d/)" #is LABEL or UUID
- echo "$DECODE_ID_RTN" > "$OUT"'BLKIDOUT'
- fi
- echo "$DECODE_ID_RTN"
- }
- ###################### Initial Parmaters ############
- #ROOT_UUI="fab3b011-746f-448b-85a3-5f7fb7f8e7f6" #sdd4 (Toshiba)
- ROOT_UUI="ebeda76b-c7e8-d201-a020-a46bc7e8d201" #sdd6
- #ROOT_REL_PATH #Variable not yet defined
- decode_id "$ROOT_UUI"
- SAVE_ROOT_DRV="$DECODE_ID_RTN"
- ROOT_REL_PATH="/tahrsave"
- SAVE_ROOT="/mnt/$SAVE_ROOT_DRV$ROOT_REL_PATH"
- RW_ROOT=`readlink /initrd/pup_rw`
- #taken from line 222 if initrd/init tahrpup and trimmed extensively
- ###################### Functions ############
- save_dir_array(){ #Was bind_and_link_array in map_save
- local -n one=${1} # https://stackoverflow.com/questions/16461656/how-to-pass-array-as-an-argument-to-a-function-in-bash
- #declair -a one=$one1
- if [ $# -lt 2 ]; then
- SR="$SAVE_ROOT"
- else
- SR=$2
- fi
- one=${one[*]} #https://stackoverflow.com/questions/3348443/a-confusion-about-array-versus-array-in-the-context-of-a-bash-comple?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
- one=${one#'('} #https://stackoverflow.com/questions/16623835/remove-a-fixed-prefix-suffix-from-a-string-in-bash?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
- one=${one%')#'}
- echo "Ln 49 one=${one[@]}"
- IFS_OLD=$IFS
- IFS=$'\n'
- for a in ${one[@]}; do
- echo "LN#53 save_file $a"
- save_file "$a" "$SR"
- done
- IFS=IFS_OLD
- }
- save_dir_files(){ #Was bind_and_link_dir in map_save
- #local -n one=$1
- if [ $# -lt 2 ]; then
- SR="$SAVE_ROOT"
- else
- SR=$2
- fi
- one="$1"
- echo "LN#68 one=$one"
- [ ! `mountpoint -q "$one"` ] || return _
- mkdir -p "$SAVE_ROOT$one"
- DIRS2=( $( find "$RW_ROOT$one" -mindepth 1 -maxdepth 1 -print0 -name '*' | removePrefix "$RW_ROOT" ) )#
- echo "LN#72 DIRS2=${DIRS2[@]}"
- save_dir_array DIRS2 $2
- }
- save_file(){ #Was bind_and_link in map_save
- f="$1"
- if [ $# -gt 1 ]; then
- SR="$2"
- else
- SR="$SAVE_ROOT"
- fi
- echo "LN#82 save_file $RW_ROOT$f"
- if [ -L "$f" ]; then #Don't copy if the link links back to the save file
- [[ `readlink $f` =~ ^$SAVE_ROOT ]] && return _ #https://stackoverflow.com/questions/4132510/how-to-test-that-a-variable-starts-with-a-string-in-bash
- elif [ -d "$RW_ROOT$f" ]; then
- save_dir_files "$f"
- return _
- fi
- #Copy only if knewer.
- cp -a -u "$RW_ROOT$f" "$SR$f" #we reversed the from to direction in copy from map_save
- }
- #echo $(dirname $(readlink -f "$fname")) # get directory name https://stackoverflow.com/questions/6121091/get-file-directory-path-from-file-path
- ######################### MAIN ###########################
- declare -a dirs_to_link_and_bind=\
- ( "/DEBIAN" "/etc" "/bin" "/etc" "/lib" "/lib64" \
- "/opt" "/root" "/sbin" "/var" "/usr" "/var" \
- )
- for dir in ${dirs_to_link_and_bind[@]}; do
- mkdir -p $SAVE_ROOT$dir
- save_dir_files $dir
- done
- sync
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement