SHARE
TWEET

map_save

s243a Apr 20th, 2018 (edited) 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #IFS=$'\0' #https://stackoverflow.com/questions/8677546/reading-null-delimited-strings-through-a-bash-loop
  3. #IFS='' #https://stackoverflow.com/questions/6563979/how-to-use-null-0-as-the-delimiter-in-gnu-sort
  4. #IFS='  '
  5. #IFS=''
  6. OUT="/tmp/map_save/"
  7.  
  8. mkdir -p "$OUT"
  9. decode_id() {
  10.   if [ -f "$OUT"'BLKIDOUT' ]; then
  11.      DECODE_ID_RTN=`cat "$OUT"'BLKIDOUT'`
  12.   else
  13.     BLKIDOUT="$(blkid)"
  14.     DECODE_ID_RTN="$(echo "$BLKIDOUT" | grep -m1 -E " LABEL=.${1}| UUID=.${1}" | cut -f1 -d: | cut -f3 -d/)" #is LABEL or UUID
  15.     echo "$DECODE_ID_RTN" > "$OUT"'BLKIDOUT'
  16.   fi
  17.   echo "$DECODE_ID_RTN"
  18. }
  19.  
  20. ###################### Initial Parmaters ############
  21.  
  22. #ROOT_UUI="fab3b011-746f-448b-85a3-5f7fb7f8e7f6" #sdd4 (Toshiba)
  23. ROOT_UUI="ebeda76b-c7e8-d201-a020-a46bc7e8d201" #sdd6
  24.  
  25.  
  26. #ROOT_REL_PATH  #Variable not yet defined
  27.  
  28. decode_id "$ROOT_UUI"
  29. SAVE_ROOT_DRV="$DECODE_ID_RTN"
  30. ROOT_REL_PATH="/tahrsave"
  31. SAVE_ROOT="/mnt/$SAVE_ROOT_DRV$ROOT_REL_PATH"
  32.  
  33. #taken from line 222 if initrd/init tahrpup and trimmed extensively
  34.  
  35. ###################### Functions ############
  36.  
  37. bind_and_link_array(){
  38.   local -n one=${1} # https://stackoverflow.com/questions/16461656/how-to-pass-array-as-an-argument-to-a-function-in-bash
  39.   if [ $# -lt 2 ]; then
  40.     SR="$SAVE_ROOT"
  41.   else
  42.     SR=$2
  43.   fi
  44.   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
  45.   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
  46.   one=${one%')#'}
  47.   echo "Ln 45 one=${one[@]}"   
  48.   #example from: https://stackoverflow.com/questions/34555278/bash-read-a-looping-on-null-delimited-string-variable
  49.   #while IFS= read -r -d '' myvar; do echo $myvar; done < <(find . -type f -print0)
  50.   #while IFS= read -r -d '' a; do
  51.   #    echo "LN#43 bind_and_link $a"
  52.   #    bind_and_link "$a" "$SR"
  53.   #done < <( "${one[@]}" )
  54.   for a in $one; do
  55.      echo "LN#43 bind_and_link $a"
  56.      bind_and_link "$a" "$SR"
  57.   done
  58. }
  59.  
  60.  
  61. bind_and_link_dir(){
  62.   #local -n one=$1
  63.   if [ $# -lt 2 ]; then
  64.     export SR="$SAVE_ROOT"
  65.   else
  66.     export SR=$2
  67.   fi   
  68.   one="$1"
  69.   echo "LN#65 one=$one"  
  70.   #echo "LN#63 one=${one[@]}"
  71.   #declair -A DIRS #https://stackoverflow.com/questions/1063347/passing-arrays-as-parameters-in-bash
  72.   [ ! `mountpoint -q "$one"` ] || return _
  73.   #example from: https://stackoverflow.com/questions/34555278/bash-read-a-looping-on-null-delimited-string-variable
  74.   #while IFS= read -r -d '' myvar; do echo $myvar; done < <(find . -type f -print0)
  75.   #DIRS=`find "$SR$one"  -mindepth 1 -maxdepth 1 -print0 -name '*' `
  76.   #decliar -A DIRS2
  77.   #DIRS2=()
  78.   #DIRS=`while IFS= read -r -d '' myvar; do echo "${myvar#$SR}"; done < <( "${DIRS[@]}" )`
  79.   #find $SR$one -mindepth 1 -maxdepth 1 -print0 -name '*' |
  80.   DIRS2=( $( find "$SR$one" -mindepth 1 -maxdepth 1 -print0 -name '*'  | removePrefix "$SR" ) )#
  81.   #IFS="$'\0'"
  82.   #for a in $DIRS; do
  83.   #  echo "a=$a"
  84.   #  DIRS2+=( $a )
  85.   #
  86.   echo "LN#82 DIRS2=${DIRS2[@]}"
  87.   bind_and_link_array DIRS2 $2
  88. }
  89. bind_and_link(){
  90.   f="$1"
  91.   if [ $# -gt 1 ]; then
  92.     SR="$2"
  93.   else
  94.     SR="$SAVE_ROOT"
  95.   fi
  96.   #https://stackoverflow.com/questions/4561153/check-for-symbolic-link
  97.   #https://unix.stackexchange.com/questions/167610/determining-if-a-file-is-a-hard-link-or-symbolic-link
  98.   #http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
  99.   IsBind="True"
  100.   mountpoint -q "$f" || IsBind="False"
  101.   echo "f=$f IsBind=$IsBind"
  102.   if [ "$IsBind" = "False" ]; then
  103.      echo "Ln 74 Not a mount point"
  104.     if [ -L "$SR$f" ]; then #$f should start w/ slash TODO add slash if missing
  105.       echo "LN#76 Copying $f"
  106.       cp -a -u "$SR$f" "$f"
  107.       echo "$f" >> /tmp/coppied_links
  108.     elif [ -d "$SR$f" ]; then    
  109.       if [ -d "$f" ]; then
  110.         echo "LN#85 bind_and_link_dir $f"
  111.         mountpoint -q "$f" || bind_and_link_dir $f
  112.       else
  113.         echo "LN# 84 binding $f"
  114.         mkdir -p "$f"      
  115.         mount --bind "$SR$f" $f #Was bind_dir "$SR/$a" $f
  116.         echo "$f" >> /tmp/bound_dirs
  117.       fi
  118.     elif [ -f "$SR$f" ]; then
  119.       echo "LN#90 linking $f"
  120.       echo "LN#91 links is `readlink $f`"
  121.       ln -s "$SR$a" $a #Was link_file "$SR/$a" $a
  122.         echo "$f" >> /tmp/linked_dirs    
  123.     fi
  124.   fi
  125. }
  126. #echo $(dirname $(readlink -f "$fname")) # get directory name https://stackoverflow.com/questions/6121091/get-file-directory-path-from-file-path
  127. ######################### MAIN ###########################
  128. declare -a  dirs_to_link_and_bind=\
  129. ( "/etc" "/DEBIAN" "/bin" "/etc" "/lib" "/lib64" \
  130.    "/opt" "/root" "/sbin" "/var" "/usr" "/var" \
  131. )
  132.  
  133. for dir in ${dirs_to_link_and_bind[@]}; do
  134.   mkdir -p dir
  135.   bind_and_link_dir $dir
  136. done
  137. indexgen.sh #http://murga-linux.com/puppy/viewtopic.php?p=990215#990215
  138. fixmenus
  139. jwm -reload
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top