SHARE
TWEET

Update_Save

s243a Apr 29th, 2018 (edited) 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. sync
  3. OUT="/tmp/Udate_save/"
  4.  
  5. mkdir -p "$OUT"
  6. decode_id() {
  7.   if [ -f "$OUT"'BLKIDOUT' ]; then
  8.      DECODE_ID_RTN=`cat "$OUT"'BLKIDOUT'`
  9.   else
  10.     BLKIDOUT="$(blkid)"
  11.     DECODE_ID_RTN="$(echo "$BLKIDOUT" | grep -m1 -E " LABEL=.${1}| UUID=.${1}" | cut -f1 -d: | cut -f3 -d/)" #is LABEL or UUID
  12.     echo "$DECODE_ID_RTN" > "$OUT"'BLKIDOUT'
  13.   fi
  14.   echo "$DECODE_ID_RTN"
  15. }
  16.  
  17. ###################### Initial Parmaters ############
  18.  
  19. #ROOT_UUI="fab3b011-746f-448b-85a3-5f7fb7f8e7f6" #sdd4 (Toshiba)
  20. ROOT_UUI="ebeda76b-c7e8-d201-a020-a46bc7e8d201" #sdd6
  21.  
  22.  
  23. #ROOT_REL_PATH  #Variable not yet defined
  24.  
  25. decode_id "$ROOT_UUI"
  26. SAVE_ROOT_DRV="$DECODE_ID_RTN"
  27. ROOT_REL_PATH="/tahrsave"
  28. SAVE_ROOT="/mnt/$SAVE_ROOT_DRV$ROOT_REL_PATH"
  29. RW_ROOT=`readlink /initrd/pup_rw`
  30.  
  31. #taken from line 222 if initrd/init tahrpup and trimmed extensively
  32.  
  33. ###################### Functions ############
  34.  
  35. save_dir_array(){ #Was bind_and_link_array in map_save
  36.   local -n one=${1} # https://stackoverflow.com/questions/16461656/how-to-pass-array-as-an-argument-to-a-function-in-bash
  37.   #declair -a one=$one1
  38.   if [ $# -lt 2 ]; then
  39.     SR="$SAVE_ROOT"
  40.   else
  41.     SR=$2
  42.   fi
  43.   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
  44.   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
  45.   one=${one%')#'}
  46.   echo "Ln 49 one=${one[@]}"   
  47.   IFS_OLD=$IFS
  48.   IFS=$'\n'
  49.   for a in ${one[@]}; do
  50.      echo "LN#53 save_file $a"
  51.      save_file "$a" "$SR"
  52.   done
  53.   IFS=IFS_OLD
  54. }
  55.  
  56.  
  57. save_dir_files(){ #Was bind_and_link_dir in map_save
  58.   #local -n one=$1
  59.   if [ $# -lt 2 ]; then
  60.     SR="$SAVE_ROOT"
  61.   else
  62.     SR=$2
  63.   fi   
  64.   one="$1"
  65.   echo "LN#68 one=$one"  
  66.   [ ! `mountpoint -q "$one"` ] || return _
  67.   mkdir -p "$SAVE_ROOT$one"
  68.   DIRS2=( $( find "$RW_ROOT$one" -mindepth 1 -maxdepth 1 -print0 -name '*'  | removePrefix "$RW_ROOT" ) )#
  69.   echo "LN#72 DIRS2=${DIRS2[@]}"
  70.   save_dir_array DIRS2 $2
  71. }
  72. save_file(){ #Was bind_and_link in map_save
  73.   f="$1"
  74.   if [ $# -gt 1 ]; then
  75.     SR="$2"
  76.   else
  77.     SR="$SAVE_ROOT"
  78.   fi
  79.   echo "LN#82 save_file $RW_ROOT$f"
  80.   if [ -L "$f" ]; then #Don't copy if the link links back to the save file
  81.     [[ `readlink $f` =~ ^$SAVE_ROOT ]] && return _ #https://stackoverflow.com/questions/4132510/how-to-test-that-a-variable-starts-with-a-string-in-bash
  82.   elif [ -d "$RW_ROOT$f" ]; then
  83.     save_dir_files "$f"
  84.     return _
  85.   fi
  86.   #Copy only if knewer.
  87.   cp -a -u "$RW_ROOT$f" "$SR$f"  #we reversed the from to direction in copy from map_save
  88. }
  89. #echo $(dirname $(readlink -f "$fname")) # get directory name https://stackoverflow.com/questions/6121091/get-file-directory-path-from-file-path
  90. ######################### MAIN ###########################
  91. declare -a  dirs_to_link_and_bind=\
  92. ( "/DEBIAN" "/etc" "/bin" "/etc" "/lib" "/lib64" \
  93.    "/opt" "/root" "/sbin" "/var" "/usr" "/var" \
  94. )
  95.  
  96. for dir in ${dirs_to_link_and_bind[@]}; do
  97.   mkdir -p $SAVE_ROOT$dir
  98.   save_dir_files $dir
  99. done
  100. sync
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top