Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #IFS=$'\0' #https://stackoverflow.com/questions/8677546/reading-null-delimited-strings-through-a-bash-loop
- #IFS='' #https://stackoverflow.com/questions/6563979/how-to-use-null-0-as-the-delimiter-in-gnu-sort
- #IFS=' '
- #IFS=''
- OUT="/tmp/map_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"
- #taken from line 222 if initrd/init tahrpup and trimmed extensively
- ###################### Functions ############
- bind_and_link_array(){
- local -n one=${1} # https://stackoverflow.com/questions/16461656/how-to-pass-array-as-an-argument-to-a-function-in-bash
- 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 45 one=${one[@]}"
- #example from: https://stackoverflow.com/questions/34555278/bash-read-a-looping-on-null-delimited-string-variable
- #while IFS= read -r -d '' myvar; do echo $myvar; done < <(find . -type f -print0)
- #while IFS= read -r -d '' a; do
- # echo "LN#43 bind_and_link $a"
- # bind_and_link "$a" "$SR"
- #done < <( "${one[@]}" )
- for a in $one; do
- echo "LN#43 bind_and_link $a"
- bind_and_link "$a" "$SR"
- done
- }
- bind_and_link_dir(){
- #local -n one=$1
- if [ $# -lt 2 ]; then
- export SR="$SAVE_ROOT"
- else
- export SR=$2
- fi
- one="$1"
- echo "LN#65 one=$one"
- #echo "LN#63 one=${one[@]}"
- #declair -A DIRS #https://stackoverflow.com/questions/1063347/passing-arrays-as-parameters-in-bash
- [ ! `mountpoint -q "$one"` ] || return _
- #example from: https://stackoverflow.com/questions/34555278/bash-read-a-looping-on-null-delimited-string-variable
- #while IFS= read -r -d '' myvar; do echo $myvar; done < <(find . -type f -print0)
- #DIRS=`find "$SR$one" -mindepth 1 -maxdepth 1 -print0 -name '*' `
- #decliar -A DIRS2
- #DIRS2=()
- #DIRS=`while IFS= read -r -d '' myvar; do echo "${myvar#$SR}"; done < <( "${DIRS[@]}" )`
- #find $SR$one -mindepth 1 -maxdepth 1 -print0 -name '*' |
- DIRS2=( $( find "$SR$one" -mindepth 1 -maxdepth 1 -print0 -name '*' | removePrefix "$SR" ) )#
- #IFS="$'\0'"
- #for a in $DIRS; do
- # echo "a=$a"
- # DIRS2+=( $a )
- #
- echo "LN#82 DIRS2=${DIRS2[@]}"
- bind_and_link_array DIRS2 $2
- }
- bind_and_link(){
- f="$1"
- if [ $# -gt 1 ]; then
- SR="$2"
- else
- SR="$SAVE_ROOT"
- fi
- #https://stackoverflow.com/questions/4561153/check-for-symbolic-link
- #https://unix.stackexchange.com/questions/167610/determining-if-a-file-is-a-hard-link-or-symbolic-link
- #http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
- IsBind="True"
- mountpoint -q "$f" || IsBind="False"
- echo "f=$f IsBind=$IsBind"
- if [ "$IsBind" = "False" ]; then
- echo "Ln 74 Not a mount point"
- if [ -L "$SR$f" ]; then #$f should start w/ slash TODO add slash if missing
- echo "LN#76 Copying $f"
- cp -a -u "$SR$f" "$f"
- echo "$f" >> /tmp/coppied_links
- elif [ -d "$SR$f" ]; then
- if [ -d "$f" ]; then
- echo "LN#85 bind_and_link_dir $f"
- mountpoint -q "$f" || bind_and_link_dir $f
- else
- echo "LN# 84 binding $f"
- mkdir -p "$f"
- mount --bind "$SR$f" $f #Was bind_dir "$SR/$a" $f
- echo "$f" >> /tmp/bound_dirs
- fi
- elif [ -f "$SR$f" ]; then
- echo "LN#90 linking $f"
- echo "LN#91 links is `readlink $f`"
- ln -s "$SR$a" $a #Was link_file "$SR/$a" $a
- echo "$f" >> /tmp/linked_dirs
- fi
- fi
- }
- #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=\
- ( "/etc" "/DEBIAN" "/bin" "/etc" "/lib" "/lib64" \
- "/opt" "/root" "/sbin" "/var" "/usr" "/var" \
- )
- for dir in ${dirs_to_link_and_bind[@]}; do
- mkdir -p dir
- bind_and_link_dir $dir
- done
- indexgen.sh #http://murga-linux.com/puppy/viewtopic.php?p=990215#990215
- fixmenus
- jwm -reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement