SHARE
TWEET

map_distro

s243a Jun 20th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. OUT="/tmp/map_distro/"
  4. TMP='/tmp/map_distro'
  5. ROOT_REL_PATH="/TazPup/Full/Taz/15"
  6. TARGET_ROOT_REL_PATH='/TazPup'
  7. mkdir $OUT
  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. SAVE_ROOT="/mnt/$SAVE_ROOT_DRV$ROOT_REL_PATH"
  31. TARGET_ROOT="/mnt/$SAVE_ROOT_DRV$TARGET_ROOT_REL_PATH"
  32.  
  33.  
  34. #taken from line 222 if initrd/init tahrpup and trimmed extensively
  35.  
  36. ###################### Functions ############
  37.  
  38. bind_and_link_array(){
  39.   local -n one=${1} # https://stackoverflow.com/questions/16461656/how-to-pass-array-as-an-argument-to-a-function-in-bash
  40.   if [ $# -lt 2 ]; then
  41.     SR="$SAVE_ROOT"
  42.   else
  43.     SR=$2
  44.   fi
  45.   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
  46.   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
  47.   one=${one%')#'}
  48.   echo "Ln 45 one=${one[@]}"   
  49.   #example from: https://stackoverflow.com/questions/34555278/bash-read-a-looping-on-null-delimited-string-variable
  50.   #while IFS= read -r -d '' myvar; do echo $myvar; done < <(find . -type f -print0)
  51.   #while IFS= read -r -d '' a; do
  52.   #    echo "LN#43 bind_and_link $a"
  53.   #    bind_and_link "$a" "$SR"
  54.   #done < <( "${one[@]}" )
  55.   for a in $one; do
  56.      echo "LN#43 bind_and_link $a"
  57.      bind_and_link "$a" "$SR"
  58.   done
  59. }
  60.  
  61.  
  62. bind_and_link_dir(){
  63.   #local -n one=$1
  64.   if [ $# -lt 2 ]; then
  65.     export SR="$SAVE_ROOT"
  66.   else
  67.     export SR=$2
  68.   fi
  69.  
  70.    
  71.   one="$1"
  72.   echo "LN#65 one=$one"  
  73.   #echo "LN#63 one=${one[@]}"
  74.   #declair -A DIRS #https://stackoverflow.com/questions/1063347/passing-arrays-as-parameters-in-bash
  75.   [ ! `mountpoint -q "$one"` ] || return _
  76.   #example from: https://stackoverflow.com/questions/34555278/bash-read-a-looping-on-null-delimited-string-variable
  77.   #while IFS= read -r -d '' myvar; do echo $myvar; done < <(find . -type f -print0)
  78.   #DIRS=`find "$SR$one"  -mindepth 1 -maxdepth 1 -print0 -name '*' `
  79.   #decliar -A DIRS2
  80.   #DIRS2=()
  81.   #DIRS=`while IFS= read -r -d '' myvar; do echo "${myvar#$SR}"; done < <( "${DIRS[@]}" )`
  82.   #find $SR$one -mindepth 1 -maxdepth 1 -print0 -name '*' |
  83.   DIRS2=( $( find "$SR$one" -mindepth 1 -maxdepth 1 -print0 -name '*'  | removePrefix "$SR" ) )#
  84.   #IFS="$'\0'"
  85.   #for a in $DIRS; do
  86.   #  echo "a=$a"
  87.   #  DIRS2+=( $a )
  88.   #
  89.   echo "LN#82 DIRS2=${DIRS2[@]}"
  90.   bind_and_link_array DIRS2 $2
  91. }
  92. bind_and_link(){
  93.   f="$1"
  94.   if [ $# -gt 1 ]; then
  95.     SR="$2"
  96.   else
  97.     SR="$SAVE_ROOT"
  98.   fi
  99.   if [ $# -lt 3 ]; then
  100.     export TR="$TARGET_ROOT"
  101.   else
  102.     export TR=$3
  103.   fi  
  104.   #https://stackoverflow.com/questions/4561153/check-for-symbolic-link
  105.   #https://unix.stackexchange.com/questions/167610/determining-if-a-file-is-a-hard-link-or-symbolic-link
  106.   #http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
  107.   IsBind="True"
  108.   mountpoint -q "$f" || IsBind="False"
  109.   echo "f=$f IsBind=$IsBind"
  110.   if [ "$IsBind" = "False" ]; then
  111.      echo "Ln 74 Not a mount point"
  112.     if [ -L "$SR$f" ]; then #$f should start w/ slash TODO add slash if missing
  113.       echo "LN#76 Copying $f"
  114.       cp -a -u "$SR$f" "$TR$f"
  115.       echo "$f" >> $OUT/coppied_links
  116.     elif [ -d "$SR$f" ]; then    
  117.       if [ -d "$TR$f" ]; then
  118.         echo "LN#85 bind_and_link_dir $f"
  119.         mountpoint -q "$TR$f" || bind_and_link_dir $f
  120.       else
  121.         echo "LN# 84 binding $f"
  122.         mkdir -p "$TR$f"      
  123.         mount --bind "$SR$f" "$TR$f" #Was bind_dir "$SR/$a" $f
  124.         echo "$f" >> $OUT/bound_dirs
  125.       fi
  126.     elif [ -f "$SR$f" ]; then
  127.       echo "LN#236 linking $f"
  128.       echo "LN#127 links is `readlink $SR$f`"
  129.       ln -s "$SR$a" "$TR$a" #Was link_file "$SR/$a" $a
  130.         echo "$f" >> $OUT/linked_dirs    
  131.     fi
  132.   fi
  133. }
  134. #echo $(dirname $(readlink -f "$fname")) # get directory name https://stackoverflow.com/questions/6121091/get-file-directory-path-from-file-path
  135. ######################### MAIN ###########################
  136. declare -a  dirs_to_link_and_bind=\
  137. ( "/etc" "/DEBIAN" "/bin" "/etc" "/lib" "/lib64" \
  138.    "/opt" "/root" "/sbin" "/var" "/usr" "/var" \
  139. )
  140.  
  141. if [ -e `which removePrefix` ]; then
  142.     cat <<-'EOF' > /usr/sbin/removePrefix
  143.     #!/bin/bash
  144.     #bla=$IFS
  145.     #FS=$'\0'
  146.     while read -r -d '' a; do
  147.         echo "a=$a">>/mnt/sdc6/removePrefixLog
  148.         echo "${a#$1}"
  149.         echo "${a#$1}">>/mnt/sdc6/removePrefixLog  
  150.         done
  151.     EOF
  152.     chmod go+x /usr/sbin/removePrefix #http://fideloper.com/user-group-permissions-chmod-apache
  153. fi
  154.  
  155. for dir in ${dirs_to_link_and_bind[@]}; do
  156.   #mkdir -p dir
  157.   bind_and_link $dir
  158. done
  159. #indexgen.sh #http://murga-linux.com/puppy/viewtopic.php?p=990215#990215
  160. #fixmenus
  161. #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
 
Top