s243a

get_puppy_path_fns.sh (draft)

Dec 18th, 2020 (edited)
1,212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.19 KB | None | 0 0
  1. function get_ws_field(){
  2.  
  3. }
  4. function mnt_home_first(){
  5.   local rest
  6.   local first
  7.   while read line; do
  8.     if [[ "$line" = *dev_save* ]]; then
  9.       first="$line"
  10.     else
  11.       rest="$rest"$'\n'"$line"
  12.     fi
  13.   done
  14.   echo "$rest"| grep -v "^$"
  15. }
  16. function get_puppy_paths(){
  17.   [ -z "$CWD" ] & CWD=$(realpath .)
  18.   if [ -z "$PDRV" ]; then
  19.    for a_folder in "${PSUBDIR}" "PSAVE" "$RW_LAYER"; do
  20.    while read PDRV_line; do
  21.      if [ -z  "PSAVE" ] && [ -z "$RW_LAYER" ] && break
  22.      PDRV_mnt_try=$(echo "$PDRV_line" | cut -f2 -d' ')
  23.      #for a_path in "$PDRV_try/${PSUBDIR}" "PSAVE" "$RW_LAYER"; do
  24.        a_path="$PDRV_try/$a_folder"
  25.        key=md5_$(md5sum < <( echo "$a_path" ) | cut -f1 -d' ')
  26.        Puppy_Path_Tries[$key]="$a_path"
  27.        PDRV_mnt_tries[$key]="$PDRV_mnt_try"
  28.        PDRV_dev_tries[$key]=$(echo "$PDRV_line" | cut -f1 -d' ')
  29.     done < <(echo_pdrvs)
  30.     for a_path in "PSAVE" "$RW_LAYER"; do
  31.        PDRV_mnt_try=$(df "$a_path" | sed -r 's#^([^[:blank:]]+[[:blank:]]+){5,5}##g' | grep -v "Mounted on")
  32.        PDRV_dev_try=$(df "$a_path" | cut -f1 -d' '| grep -v 'Filesystem')
  33.  
  34.      #for a_path in "$PDRV_try/${PSUBDIR}" "PSAVE" "$RW_LAYER"; do
  35.        a_path="$PDRV_try/$a_folder"
  36.        key=md5_$(md5sum < <( echo "$a_path" ) | cut -f1 -d' ')
  37.        Puppy_Path_Tries[$key]=$a_path
  38.        PDRV_mnt_tries[$key]=$PDRV_mnt_try
  39.        PDRV_dev_tries[$key]=$PDRV_dev_try
  40.     done    
  41.     #done
  42.     for a_key in ${!PDRV_mnt_tries}; do
  43.       PUPPY_SFS_try=$(ls -1 "${Puppy_Path_Tries[$key]}"/.. | grep -E 'puppy_.*[.]sfs')
  44.       if [ ! -z "$PUPPY_SFS_try" ]; then
  45.         get_puppy_paths__rtn__path=$(realpath "${Puppy_Path_Tries[$key]}")
  46.         get_puppy_paths__rtn__dev=$(realpath "${PDRV_dev_tries[$key]}")
  47.         get_puppy_paths__rtn__mnt=$(realpath "${PDRV_dev_tries[$key]}")
  48.         break
  49.       fi
  50.     done
  51.   done
  52. }
  53. function echo_pdrvs(){
  54.     if [ ! -z  "PSAVE" ] || [ ! -z "$RW_LAYER" ]; then
  55.       if [ -d
  56.       lsblk -lo NAME,TYPE,MOUNTPOINT | grep part | cut -f1,4 -d' ' | mnt_home_first #TODO make this more robust (e.g. handle multple spaces sperating fields)
  57.     else #This is to keep the pipe from hanging.
  58.       echo /mnt/home
  59.     fi
  60. }
  61. #export -f echo_pdrvs
Advertisement
Add Comment
Please, Sign In to add comment