Advertisement
s243a

psandbox2.sh (draft #2)

Dec 14th, 2020
1,492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 49.32 KB | None | 0 0
  1. #!/bin/bash
  2. #Based on James Budiono 2015 sandbox.sh (version 10) but with many options added
  3. # version 10 - (2015) use pid/mount namespaces if available
  4. #
  5. # 0. directory locations
  6. #. $BOOTSTATE_PATH # AUFS_ROOT_ID
  7. #XTERM="defaultterm"
  8. #
  9. # All options below were added by s243a:
  10. #
  11. # -o, --output-file
  12. #    Just write layer paths to an output file but don't mount the sandbox.
  13. # --no-exit
  14. #   if an output file is specified (i.e. -o or --output-file) layer paths are just written to a file and the program exits unless the no-exit flag is specified.
  15. # f, --input-file
  16. #   read layer paths from a file rather than reading existing layers
  17. # m,--pmedia
  18. #   determines pupmodes. Refer to puppy boot parmaters
  19. # d, --pdrv
  20. #   this is the particiaion where the puppy files are located. The default is /mnt/home
  21. # s, psubdir
  22. #   this is the sub directory where the puppy files are located
  23. # c, --clear-env
  24. #   deletes enviornental variabls
  25. # --env-prefix
  26. #   enviornental variable prefix
  27. # b --boot-config
  28. #   path to boot config (e.g. /etc/rc.d/BOOTCONFIG
  29. # --disto-specs
  30. #   path to distro specs (e.g. /etc/DISTRO_SPECS; e.g. /initrd/distro-specs)
  31. # L, --layer
  32. #   a subgke kater
  33. #  e, --extra-sfs
  34. #   a list of extra sfs files (space seperated)
  35. #  u, --union-record
  36. # --xterm
  37. # --sandbox
  38. # -initrd
  39. # --save
  40. # --noexit
  41. # --psave
  42. # --pupmode
  43.  
  44. #I thought some assoitive arrays might be useful but I'm not using them yet.
  45. #declare -A KEYs_by_MNT_PT
  46. #declare -A KEYs_by_FILE_PATH
  47. #declare -A KEYs_by_trimmed_MNT_PT
  48. #declare -A KEYs_by_trimmed_FILE_PATH
  49. #declare -A MNT_PTs
  50. #declare -A FILE_PATHs
  51. #declare -A ON_status
  52. CWD=$(realpath .)
  53. [ -z "$CWD" ] && CWD="$PWD"
  54. declare -a bind_sources
  55. declare -a bind_targets
  56. declare -a rev_bind_sources
  57. declare -a rev_bind_targets
  58. cd "$(dirname "$0")"
  59. MAX_STR_LEN=50
  60. SANDBOX_ID=
  61. TMPFILE=$(mktemp -p /tmp)
  62. # use namespaces if available
  63. #[ -e /proc/1/ns/pid ] && [ -e /proc/1/ns/mnt ] && type unshare >/dev/null && USE_NS=1
  64.  
  65. XTERM=${XTERM:-urxvt}
  66. SANDBOX_ROOT=${SANDBOX_ROOT:-/mnt/sb}
  67.  
  68. declare -a options2
  69. declare -a binds
  70. LOG_INITIALIZED=false
  71.  
  72. RP_FN="`which realpath`"
  73. RP_TARGET=$($RP_FN "$RP_FN")
  74. [ -z "$RP_TARGET" ] && RP_TARGET="`readlink $RP_FN`"
  75. declare -a del_rules_filter
  76. declare -a del_rules_action
  77. declare -a umount_rules_filter
  78. declare -a umount_rules_action
  79.  
  80. unset SANDBOX_ID
  81. unset rwbranch
  82. unset FAKEROOT
  83. unset SANDBOX_TMPFS
  84. unset FAKEROOT_dir
  85. unset SANDBOX_IMG
  86. FAKEROOT_SET=false
  87.  
  88. function realpath(){
  89.     case "$RP_TARGET" in
  90.     *busybox*)
  91.       if [ "$1" = -m ]; then
  92.         shift
  93.         A_PATH=$1
  94.         A_PATH=$(echo "$A_path" | sed 's#^./#'"$CWD"'#g' )
  95.         A_PATH=$(echo "$A_path" | sed 's#^../#'"$CWD"'#g' ) && A_PATH=$(dirname $A_PATH)
  96.         echo "Warning simulating '-m' option since it isn't supported by busybox" >2
  97.         echo "A_PATH=$A_PATH" >2
  98.         if [ -f  "$A_PATH" ] || [ -d  "$A_PATH" ]; then
  99.           $RP_FN "$@"
  100.         else
  101.           echo "$A_PATH"
  102.         fi
  103.       else
  104.         $RP_FN "$@"
  105.       fi
  106.       ;;
  107.     *)
  108.       $RP_FN "$@"
  109.       ;;
  110.     esac
  111. }
  112. export -f realpath
  113.  
  114. if [ -f ../local/psandbox/sandbox.awk ]; then
  115.   SANDBOX_AWK="$(realpath ../local/psandbox/sandbox.awk)"
  116. elif [ -f /usr/local/psandbox/sandbox.awk ]; then
  117.  SANDBOX_AWK=/usr/local/psandbox/sandbox.awk
  118. fi
  119. SANDBOX_AWK_DIR="$(dirname $SANDBOX_AWK)"
  120. if [ -f ../local/psandbox/sb_db_rec_field.awk ]; then
  121.   SB_DB_REC_FIELD_AWK="$(realpath ../local/psandbox/sb_db_rec_field.awk)"
  122. elif [ -f /usr/local/psandbox/sb_db_rec_field.awk ]; then
  123.   SB_DB_REC_FIELD_AWK=/usr/local/psandbox/sb_db_rec_field.awk
  124. fi
  125.  
  126. if [ -f ../local/psandbox/sandbox_mnt_fn.sh ]; then
  127.   SANDBOX_MNT_FN="$(realpath ../local/psandbox/sandbox_mnt_fn.sh)"
  128. elif [ -f /usr/local/psandbox/sandbox_mnt_fn.sh ]; then
  129.   SANDBOX_MNT_FN=/usr/local/psandbox/sandbox_mnt_fn.sh
  130. fi
  131.  
  132. . "$SANDBOX_MNT_FN"
  133.  
  134. function get_items(){
  135.     local out
  136.     OUTFILE=/tmp/get_items_out
  137.     rm "$OUTFILE"
  138.     cd "$SANDBOX_AWK_DIR"
  139.     out+="$(
  140.  { echo ==mount==; cat /proc/mounts;
  141.    echo ==losetup==; losetup-FULL -a;
  142.    echo ==branches==;
  143.      if [ $# -eq 0 ]; then
  144.        ls -v /sys/fs/aufs/$AUFS_ROOT_ID/br[0-9]* | xargs sed 's/=.*//';
  145.      else
  146.        if [ "$1" = "-f" ]; then
  147.          cat "$2";
  148.        elif [ "$1" = "-s" ]; then
  149.          cat <<<"$2";
  150.        fi;
  151.      fi; } | \
  152.    awk -v PDRV="$PDRV" -v MAX_STR_LEN="$MAX_STR_LEN" -v OUTFILE="$OUTFILE" \
  153. -f "$SANDBOX_AWK"
  154. )"
  155.   echo "$out"
  156. }
  157. function process_psubdir(){
  158.       item_source="$1"
  159.       if [ "$item_source" = "maybe-psubdir" ]; then
  160.          [ ! -z "$items" ] && continue
  161.       fi
  162.       [ -z "$DISTRO_ADRVSFS" ] && DISTRO_ADRVSFS="$(ls -1 "${PDRV}/${PSUBDIR}" | grep -i -m1 'adrv.*\.sfs$')"
  163.       [ -z "$DISTRO_YDRVSFS" ] && DISTRO_YDRVSFS="$(ls -1 "${PDRV}/${PSUBDIR}" | grep -i -m1 'ydrv.*\.sfs$')"  
  164.       [ -z "$DISTRO_ZDRVSFS" ] && DISTRO_ZDRVSFS="$(ls -1 "${PDRV}/${PSUBDIR}" | grep -i -m1 'zdrv.*\.sfs$')"
  165.       [ -z "$DISTRO_FDRVSFS" ] && DISTRO_FDRVSFS="$(ls -1 "${PDRV}/${PSUBDIR}" | grep -i -m1 'fdrv.*\.sfs$')"                        
  166.       [ -z "$DISTRO_PUPPYSFS" ] && DISTRO_PUPPYSFS="$(ls -1 "${PDRV}/${PSUBDIR}" | grep -i -m1 'puppy_.*\.sfs$')"
  167.  
  168.       new_items=""
  169.       for rec in "$DISTRO_ADRVSFS" "$DISTRO_YDRVSFS" "$DISTRO_ZDRVSFS" "$DISTRO_FDRVSFS" "$DISTRO_PUPPYSFS";  do
  170.         #MNT_PATH="${rec}"
  171.         [ -z "$rec" ] && continue
  172.         #[ ! -z "${PSUBDIR}" ] && MNT_PATH=${PSUBDIR}/${MNT_PATH}
  173.         MNT_PATH="${PDRV}/${PSUBDIR}/$rec"
  174.         MNT_PT="$(mount_fn "$MNT_PATH")"
  175.         new_items+="\"${MNT_PT}\" \"$rec\" \"on\""$'\n'
  176.        
  177.       done
  178.       #export new_items="$new_items"
  179.       #echo "$new_items"
  180.       log stop
  181.       new_items_result="$(get_items -s "$new_items")"$'\n'
  182.       items+="$new_items_result"
  183.       echo "items+=\"$new_items_result\""
  184.       log start
  185.      
  186. }
  187. process_union_record(){
  188.        new_items=''
  189.        for rec in $LASTUNIONRECORD; do
  190.         if [ -f "$rec" ]; then
  191.           MNT_PT="$(mount_fm "$rec" )"
  192.           new_items+="\"$MNT_PT\" \"$rec\" \"on\""$'\n'
  193.         elif [ -f "$PDRV/$rec" ]; then
  194.           MNT_PT="$(mount_fm "$PDRV/$rec" )"
  195.           new_items+="\"$MNT_PT\", \"$PDRV/$rec\", \"on\""$'\n'
  196.         fi
  197.       done
  198.       items+="$(get_items -f <<<"$new_items")"$'\n'    
  199. }
  200. process_extra_sfs(){
  201.      EXTRASFSLIST="$2";
  202.      unset new_items
  203.      if [ ! -f "$EXTRASFSLIST" ]; then
  204.        EXTRASFSLIST_tmp=$(realpath "$PDRV/$PSUBDIR/$EXTRASFSLIST")
  205.        if [ -f "$EXTRASFSLIST_tmp" ]; then
  206.          EXTRASFSLIST="$EXTRASFSLIST_tmp"
  207.        fi
  208.      fi
  209.      if [ ! -f "$EXTRASFSLIST" ]; then
  210.        EXTRASFSLIST_tmp=$(realpath "$PDRV/$EXTRASFSLIST")
  211.        if [ -f "$EXTRASFSLIST_tmp" ]; then
  212.          EXTRASFSLIST="$EXTRASFSLIST_tmp"
  213.        fi
  214.      fi
  215.      if [[ "$EXTRASFSLIST" = *.sfs ]]; then
  216.          a_sfs="$EXTRASFSLIST"
  217.          MNT_PT="$(mount_fn "$a_sfs" )"
  218.          new_items+="\"$MNT_PT\" \"$a_sfs\" \"on\""$'\n'
  219.      else
  220.        while read a_sfs; do
  221.          a_sfs=$(echo"$a_sfs") #Trims leading and trailing whitespace
  222.          if [ -f "$a_sfs" ]; then
  223.            a_sfs=$(realpath "$a_sfs")
  224.          else
  225.            a_sfs1="$PDRV/${PSUBDIR}/$a_sfs"
  226.            a_sfs=$(realpath "$a_sfs")
  227.            if [ -f "$a_sfs"]; then
  228.              a_sfs=$(realpath "$a_sfs")
  229.            else        
  230.              a_sfs1="$PDRV/$a_sfs1"
  231.              if [ -f "$a_sfs1" ]; then
  232.                a_sfs=$(realpath "$a_sfs")
  233.              fi            
  234.            fi
  235.          fi
  236.          if [ -f  "$a_sfs" ]; then
  237.            MNT_PT="$(mount_fn "$a_sfs" )"
  238.            new_items+="\"$MNT_PT\" \"$a_sfs\" \"on\""$'\n'        
  239.          fi
  240.        done <"$EXTRASFSLIST"
  241.      fi
  242.      items+="$(get_items -s "$new_items")"$'\n'
  243.      #items+="$(get_items -f <<<"$new_items")"
  244. }
  245. process_layer(){
  246.       item_path="$2"
  247.       if [ -f "$item_path" ]; then
  248.         MNT_PT="$(mount_fm "$item_path" )"
  249.       elif [ -d "$item_path" ]; then  
  250.         MNT_PT="$item_path" #This isn't really a mount poing
  251.       elif [ ! -d  "$item_path" ]; then
  252.         echo "Warning  cannot mount $item_path"
  253.         continue
  254.       fi
  255.       items+="\"$MNT_PT\" \"$item_path\" \"on\""$'\n'  
  256. }
  257.  
  258. function mount_items(){
  259.   local Moun_Point
  260.   local File_PATH #Might be a directory
  261.   cd "$SANDBOX_AWK_DIR"
  262.   while IFS="" read -r p || [ -n "$p" ]; do #https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
  263.      File_PATH="$(echo "$1" | awk -v FIELD_NUM=6 -f "$SB_DB_REC_FIELD_AWK")"
  264.      Mount_Point="$(echo "$1" | awk -v FIELD_NUM=1 -f "$SB_DB_REC_FIELD_AWK")"
  265.      PDRV_MNT="$(echo "$1" | awk -v FIELD_NUM=7 -f "$SB_DB_REC_FIELD_AWK")"
  266.      PDRV_UUID="$(echo "$1" | awk -v FIELD_NUM=8 -f "$SB_DB_REC_FIELD_AWK")"
  267.      
  268.      [ -z "$PDRV_MNT" ] &&
  269.      mount_fn2 "PDRV" "$File_PATH" "$Moun_Point"
  270.   done <"$1"
  271. }
  272. function log(){
  273.   local SET_X=false
  274.   set +x #TODO add more verbose log option that doesn't do this.
  275.   local logfile="${2}"
  276.   local trace="$3"
  277.   #[ -z "$logfile" ] && LOGFILE
  278.   #[ -z "$trace" ] && trace=TRACE
  279.   if [ ! -z "$LOGFILE" ]; then
  280.     case "$1" in
  281.     init)
  282.       [ "$TRACE" = true ] && SET_X=true
  283.       [ ! -f "$LOGFILE" ] && rm "$LOGFILE"
  284.       exec 6>&1           # Link file descriptor #6 with stdout.
  285.       #exec &1> >(tee -a "$LOGFILE")
  286.       #exec &2> >(tee -a "$LOGFILE")
  287.       [ ! -f "$LOGFILE" ] && touch "$LOGFILE"
  288.       exec &> >(tee -a "$LOGFILE")
  289.       ;;
  290.     start)
  291.       [ "$TRACE" = true ] && SET_X=true
  292.       #exec &1> >(tee -a "$LOGFILE")
  293.       #exec &2> >(tee -a "$LOGFILE")
  294.      
  295.       exec &> >(tee -a "$LOGFILE")
  296.       ;;
  297.     stop)
  298.       #https://stackoverflow.com/questions/21106465/restoring-stdout-and-stderr-to-default-value
  299.       #[ "$TRACE" = true ] && set +x
  300.       exec 1>&6  
  301.       #exec 6>&-      # Restore stdout and close file descriptor #6.
  302.       exec &2> /dev/stderr    
  303.       ;;
  304.     esac
  305.   fi    
  306.   [ "$SET_X" = true ] && set -x
  307. }
  308.  
  309.  
  310.  
  311. safe_delete(){
  312.     unset safe_delete_result
  313.     POLICY="" #Default action if no rule is found
  314.   if [ ! -z "$(cat /proc/mounts | grep -F "$(ls -1d $1 | sed 's:/$::')" - )" ] ||
  315.     [ ! -z "$(cat /proc/mounts | grep -F "$(ls -1d $1 | xargs realpath )" - )" ] ; then
  316.          #It is not safe to delete a mounted directory
  317.          safe_delete_result=1 #This is in case one doesn't want to use the return status right away
  318.          return 1    
  319.  else
  320.    PATH_TO_DEL="$(realpath -m $1)"
  321.    [ -d "$PATH_TO_DEL" ] && "PATH_TO_DEL=$PATH_TO_DEL/"
  322.    for a_rule_key in "${!del_rules_filter[@]}"; do
  323.      rule_i="${a_rull_key[$a_rule_key]}"
  324.      if [ ! -z "$(echo $PATH_TO_DEL | grep "$rule_i")" ] ||
  325.         [[ "$PATH_TO_DEL" = $rule_i ]]; then
  326.        action="${del_rules_action[$a_rule_key]}"
  327.        case $action in
  328.        DELETE)
  329.          safe_delete_result=0 #This is in case one doesn't want to use the return status right away
  330.          return 0
  331.          break #This is probably redundant
  332.          ;;
  333.        KEEP)
  334.          safe_delete_result=1 #This is in case one doesn't want to use the return status right away
  335.          return 1
  336.          break #This is probably redundant
  337.          ;;          
  338.        POLICY_KEEP)
  339.          POLICY=KEEP
  340.          ;;    
  341.        POLICY_DELETE)
  342.          POLICY=DELETE
  343.          ;;    
  344.        esac
  345.      fi
  346.    done
  347.    if [ -z ${safe_delete_result+x} ]; then #If we don't have a result yet set result based on policy
  348.      case "$POLICY" in
  349.      KEEP)
  350.        safe_delete_result=1
  351.        return 1; ;;
  352.      DELETE)
  353.        safe_delete_result=0
  354.        return 0; ;;
  355.      *)
  356.        echo "No Delete policy set, so keeping file/dir $1"
  357.        safe_delete_result=1
  358.        return 1    
  359.      esac
  360.    fi
  361.  fi
  362. }
  363. safe_umount(){
  364.    unset safe_umount_result
  365.    POLICY="" #Default action if no rule is found
  366.    PATH_TO_UMOUNT="$(realpath -m $1)"
  367.    [ -d "$PATH_TO_UMOUNT" ] && PATH_TO_UMOUNT="$PATH_TO_UMOUNT/" #TODO, this should always be true so add error if it is not.
  368.  
  369.    for a_rule_key in "${!umount_rules_filter[@]}"; do
  370.      rule_i="${a_rull_key[$a_rule_key]}"
  371.      if [ ! -z "$(echo $1 | grep "$rule_i")" ] ||
  372.        [[ "$PATH_TO_UMOUNT" = $rule_i ]]; then
  373.        action="${umount_rules_action[$a_rule_key]}"
  374.        case $action in
  375.        DELETE)
  376.          safe_umount_result=0 #This is in case one doesn't want to use the return status right away
  377.          return 0
  378.          break #This is probably redundant
  379.          ;;
  380.        UMOUNT)
  381.          safe_umount_result=1 #This is in case one doesn't want to use the return status right away
  382.          return 1
  383.          break #This is probably redundant
  384.          ;;          
  385.        POLICY_KEEP)
  386.          POLICY=KEEP
  387.          ;;    
  388.        POLICY_UMOUNT)
  389.          POLICY=UMOUNT
  390.          ;;    
  391.        esac
  392.      fi
  393.    done
  394.    if [ -z ${safe_umount_result+x} ]; then #If we don't have a result yet set result based on policy
  395.      case "$POLICY" in
  396.      KEEP)
  397.        safe_umount_result=1
  398.        return 1; ;;
  399.      UMOUNT)
  400.        safe_umount_result=0
  401.        return 0; ;;
  402.      *)
  403.        echo "No Delete policy set, so keeping file/dir $1"
  404.        safe_umount_result=1
  405.        return 1    
  406.      esac
  407.    fi
  408.  
  409. }
  410. umountall() {
  411.  {
  412.  log start
  413.  set -x
  414.  #R_FR=$(realpath -m "$FAKEROOT")
  415.  #[ ${#R_FR} -lt 2 ] && exit
  416.  safe_umount $SANDBOX_TMPFS
  417.  [ $safe_umount_result -eq 0 ] && umount -l $SANDBOX_TMPFS
  418.  if [ PUPMODE = 2 ]; then #Full Install
  419.      safe_umount $FAKEROOT/tmp
  420.      umount -l $FAKEROOT/tmp
  421.    else
  422.      safe_umount $FAKEROOT/initrd/mnt/tmpfs
  423.      [ $safe_umount_result -eq 0 ] && umount -l $FAKEROOT/initrd/mnt/tmpfs
  424.    fi
  425.  for layer_name in "pup_ro2" "pup_ro3" "pup_ro4" "pup_ro5" "pup_z"; do
  426.    layer="$(eval 'echo $'$layer_name)"
  427.    if [ ! -z "$layer" ] ; then
  428.      safe_umount "$FAKEROOT/initrd/$layer_name"
  429.      [ $safe_umount_result -eq 0 ] && umount -l "$FAKEROOT/initrd/$layer_name"
  430.    fi
  431.  done
  432.  for aFolder in /proc /sys /dev ""; do
  433.     safe_umount $FAKEROOT"/$aFolder"
  434.     [ $safe_umount_result -eq 0 ] && umount -l $FAKEROOT$aFolder
  435.  done
  436.  
  437.  
  438.  if [ -z "$RW_LAYER" ]; then
  439.    safe_umount "$SANDBOX_TMPFS"
  440.    [ $safe_umount_result -eq 0 ] && umount -l $SANDBOX_TMPFS
  441.    safe_delete "$SANDBOX_TMPFS"
  442.    [ $safe_delete_result -eq 0 ] && rmdir $SANDBOX_TMPFS
  443.  fi
  444.  
  445.  safe_delete $FAKEROOT
  446.  [ $safe_delete_result -eq 0 ] && rmdir $FAKEROOT
  447.  
  448.  } # 2> /dev/null
  449. }
  450. function choose_save(){
  451.    # location not specified - then ask
  452.    log stop
  453.    dialog --backtitle "rw image sandbox" --title "choose rw image" \
  454.    --extra-button --extra-label "Create" --ok-label "Locate" \
  455.    --yesno "You didn't specify the location of the rw image file. Do you want to locate existing file, or do you want to create a new one?" 0 0
  456.    chosen=$?
  457.    log start
  458.    case $chosen in
  459.        0) # ok - locate
  460.            log stop
  461.            dialog --backtitle "rw image sandbox" --title "Specify location of existing rw image" --fselect `pwd` 8 60 2> $TMPFILE
  462.            savebranch=`cat $TMPFILE`
  463.            log start
  464.            rm $TMPFILE
  465.            if [ -n "$savebranch" ]; then
  466.                if [ -d "$savebranch" ]; then
  467.                  case "$savebranch" in
  468.                  "/mnt"|"/mnt/"|"/mnt/home"|"/mnt/home/"|"/")
  469.                    log stop
  470.                    echo "warning chose the following savebranch $savebranch"
  471.                    read -p "Press enter to continue"
  472.                    log start
  473.                    set_sandbox_img ""
  474.                    ;;
  475.                  esac
  476.                  SANDBOX_IMG=$savebranch
  477.                elif [ ! -f "$savebranch" ]; then
  478.                    echo "$savebranch doesn't exist - exiting."
  479.                    echo "will use tmpfs instead"
  480.                    log stop
  481.                    read -p "Press enter to continue"
  482.                    log start
  483.                    savebranch=""
  484.                else
  485.                  set_sandbox_img ""                    
  486.                fi
  487.            else
  488.                echo "You didn't specify any file or you pressed cancel. Exiting."
  489.                exit
  490.            fi
  491.            ;;
  492.        3) # create
  493.            echo "create"
  494.            log stop
  495.            dialog --backtitle "save image sandbox" --title "Specify name and path of new the file" --fselect `pwd` 8 60 2> $TMPFILE
  496.            savebranch=`cat $TMPFILE`
  497.            log start
  498.            rm $TMPFILE
  499.            if [ -n "$savebranch" ]; then
  500.                if [ -f "$savebranch" ]; then
  501.                    echo "$savebranch already exist - exiting."
  502.                    exit
  503.                else
  504.                    # get the size
  505.                    log stop
  506.                    dialog --title "Create new save image" --inputbox "Specify size (in megabytes)" 0 40 100 2> $TMPFILE
  507.                    size=`cat $TMPFILE`
  508.                    log start
  509.                    rm $TMPFILE
  510.                    
  511.                    if [ -n "$size" ]; then
  512.                        if dd if=/dev/zero of="$savebranch" bs=1 count=0 seek="$size"M; then
  513.                            if ! mke2fs -F "$savebranch"; then
  514.                                echo "I fail to make an ext2 filesystem at $savebranch, exiting."
  515.                                exit
  516.                            fi
  517.                        else
  518.                            echo "I fail to create a ${size}M file at $savebranch,, exiting."
  519.                            exit
  520.                        fi
  521.                    else
  522.                        echo "You didn't specify the size or your press cancel. Exiting."
  523.                        exit
  524.                    fi                  
  525.                fi
  526.            else
  527.                echo "You didn't specify any file or you pressed cancel. Exiting."
  528.                exit
  529.            fi
  530.            ;;
  531.        1 | 255) # 1 is cancel, 255 is Escape
  532.            ;&
  533.        *) # invalid input - treat as cancel
  534.            echo "Cancelled - exiting."
  535.            exit
  536.            ;;
  537.    esac
  538. }
  539. function find_save(){
  540.  for prefix in '${DISTRO_FILE_PREFIX}save' '.*save'; do
  541.    for dir in "$PDRV/${PSUBDIR}" "PDRV";  do
  542.      
  543.      ONE_SAVE="$(ls $dir -1 | grep -m "${prefix}save")"
  544.      if [ -z "$ONE_SAVE" ]; then
  545.         continue
  546.      else
  547.         SAVE_FILE="$ONE_SAVE"
  548.         FULL_SAVE_PATH="$dir"/ONE_SAVE
  549.         break
  550.      fi
  551.    done
  552.   done
  553.   echo "PSAVE"mount_items
  554. }
  555. function find_bk_folders(){
  556.  for a_PDRV in "$PDRV" sr0 sr1; do #Consider adding /mnt/home here
  557.    for a_psubdir in "${PSUBDIR}" "";  do
  558.      MT_PT_of_Folder="$(mount_fn2 "$PDRV" "${PSUBDIR}")"
  559.      #https://github.com/puppylinux-woof-CE/woof-CE/blob/c483d010a8402c5a1711517c2dce782b3551a0b8/initrd-progs/0initrd/init#L981
  560.      BKFOLDERS="$(find $MT_PT_of_Folder -maxdepth 1 -xdev -type d -name '20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]' | sed -e s%^${SAVE_MP}/%% | sort -r)"
  561.      [ ! -z "#BKFOLDERS" ] && break  
  562.    done
  563.  done
  564. }
  565. function mk_initrd_dir(){
  566.  mkdir -p "$FAKEROOT"/initrd
  567.  if [ -z "$PUPMODE" ] ; then
  568.    if [ -z "$PMEDIA" ]; then
  569.      #if [ "$PUPMODE" = 5 ] ; then
  570.      #  #aufs layers:              RW (top)      RO1             RO2              PUPMODE
  571.      #  #First boot (or pfix=ram): tmpfs                         pup_xxx.sfs      5
  572.      PUPMODE=5 #MAYBE PUPMODE=2 would be better
  573.    elif [ PMEDIA = 'atahd' ] || [ "$PMEDIA" = 'usbhd' ]; then
  574.      find_save
  575.      if [ -f "$FULL_SAVE_PATH" ] || [ -d "$FULL_SAVE_PATH" ]; then
  576.        #aufs layers:               RW (top)      RO1             RO2              PUPMODE
  577.        #Normal running puppy:      pup_save.3fs                  pup_xxx.sfs      12      
  578.        PUPMODE=12
  579.      else
  580.        echo "Invalid SAVE_PATH=$SAVE_PATH does not exist"
  581.        PUMPMODE=2
  582.        #TODO, prompt to either search for save file/folder or alternatively create it.
  583.      fi
  584.    elif [ PMEDIA = 'usbflash' ] || [ pmedia = 'ideflash' ]; then
  585.      find_save
  586.      #aufs layers:                 RW (top)      RO1             RO2              PUPMODE
  587.      #ditto, but flash drive:      tmpfs         pup_save.3fs    pup_xxx.sfs      13
  588.      if [ -f "$SAVE_PATH" ] || [ -d "$SAVE_PATH" ]; then
  589.        #aufs layers:               RW (top)      RO1             RO2              PUPMODE
  590.        #ditto, but flash drive:    tmpfs         pup_save.3fs    pup_xxx.sfs      13
  591.        PUPMODE=13
  592.      else
  593.        echo "Invalid SAVE_PATH=$SAVE_PATH does not exist"
  594.        PUPMODE=5
  595.      fi
  596.    elif [ "$PMEDIA" =  usbcd ] || [ "$PMEDIA" =  idecd ] || [ "$PMEDIA" =  satacd ] ; then
  597.      find_bk_folders
  598.      if [ ! -z "$BKFOLDERS" ]; then
  599.        PUPMODE=77  #MULTI-Session CD
  600.      else #First Boot
  601.        find_save
  602.        if [ -f "$FULL_SAVE_PATH" ] || [ -d "$FULL_SAVE_PATH" ]; then
  603.          PUPMODE=13      
  604.        else
  605.          PUPMODE=5
  606.        fi
  607.      fi
  608.      #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  609.      #Multisession cd/dvd:       tmpfs         folders         pup_xxx.sfs      77
  610.    else #[PUPMODE=2 -> full install
  611.      PUPMODE=2
  612.    fi
  613.    #TODO: add option to make initrd anyway even if full install. For now make it regardless:
  614.    if [ "$PUPMODE" = 2 ] && [ 1 -ne 1 ]; then #Full install; then #Full install
  615.      echo "Full install has no initrd"
  616.    else
  617.      mkdir -p "$FAKEROOT/initrd"
  618.      cd $FAKEROOT/initrd
  619.      if [ "$PUPMODE" = 12 ]; then # Usually [ PMEDIA = 'atahd' ] || [ "$PMEDIA" = usbhd ]
  620.        ln -s mnt/dev_save/"${SAVE_PATH}" pup_rw
  621.      elif [ "$PUPMODE" = 13 ] || [ "$PUPMODE" = 5 ] || [ "$PUPMODE" = 77 ]; then
  622.        ln -s mnt/tmpfs/pup_rw pup_rw
  623.        if [ "$PUPMODE" = 13 ]; then  # Usually [ PMEDIA = 'usbflash' ] || [ pmedia = 'ideflash' ]
  624.          ln -s "mnt/tmpfs/dev_save/${SAVE_PATH}" pup_ro1
  625.        elif [ "$PUPMODE" = 77 ]; then
  626.          ln -s mnt/tmpfs/pup_ro1/"${SAVE_PATH}" pup_ro1  #Usually [ "$PMEDIA" =  usbcd ] || [ "$PMEDIA" =  idecd ] || [ "$PMEDIA" =  satacd ]
  627.        fi
  628.      fi
  629.      #!!!! This code was moved from elsehwere inside this section.
  630.       mkdir -p "$FAKEROOT/initrd/mnt/dev_save"
  631.      mount -o bind  /mnt/home "$FAKEROOT/initrd/mnt/dev_save"
  632.      mkdir $FAKEROOT/mnt
  633.      cd $FAKEROOT/mnt
  634.      ln -s ../initrd/mnt/dev_save
  635.      cd $FAKEROOT
  636.      mount -o bind $SANDBOX_IMG initrd/mnt/tmpfs/pup_rw #not sure if this applies to all pupmodes.    
  637.    fi
  638.  fi
  639. }
  640. function set_fakeroot(){
  641.    unset CLEANUP_SANDBOX_ROOT
  642.    # if SANDBOX_ROOT is set to null then set it in this function
  643.    # if FAKEROOT is null then this implies "/"
  644.    if [ -z ${FAKEROOT+x} ] && [ $FAKEROOT_SET = false ]; then
  645.      FAKEROOT=fakeroot
  646.      CLEANUP_SANDBOX_ROOT=yes
  647.    fi
  648.    if [ ! -z ${SANDBOX_ROOT+x} ] || [ ${#FAKEROOT} -gt 1 ]; then
  649.      
  650.      if [ "${CLEANUP_SANDBOX_ROOT}" = yes ]; then
  651.        SANDBOX_ROOT=/mnt/sb
  652.      else
  653.        FAKEROOT_SET
  654.      fi    
  655.      
  656.  
  657.      if [ ${#SANDBOX_ROOT} -gt 1 ] && [ $FAKEROOT_SET = false ]; then
  658.        FAKEROOT=$SANDBOX_ROOT/$FAKEROOT
  659.        FAKEROOT_SET=true
  660.      elif [ ! -z ${FAKEROOT+x} ]; then
  661.        FAKEROOT_SET=true
  662.      fi
  663.       FAKEROOT_dir="${FAKEROOT%/*}"
  664.      [ -z "${SANDBOX_ROOT}" ] && SANDBOX_ROOT=${FAKEROOT_dir}
  665.      if grep -q $FAKEROOT /proc/mounts; then
  666.        if [ ! "$SANDBOX_ROOT" = /mnt/sb ]; then
  667.            log stop
  668.            dialog --backtitle "rename root" --title "already mounted" \
  669.            --extra-button --extra-label "Rename" --ok-label "Keep" \
  670.            --yesno "FAKEROOTI is already a mount point. Rename Root?" 0 0
  671.            chosen=$?
  672.            log start      
  673.           case "#chosen" in
  674.           1)
  675.             RENAME_ROOT=yes; ;;
  676.           0)
  677.             RENAME_ROOT=no; ;;
  678.           esac
  679.          
  680.        else
  681.          RENAME_ROOT=yes
  682.        fi  
  683.        
  684.        if [ "${RENAME_ROOT}" = yes ]; then    
  685.          FAKEROOT=$(mktemp -d -p ${FAKEROOT%/*}/ ${FAKEROOT##*/}.XXXXXXX)
  686.          SANDBOX_ID=".${FAKEROOT##*.}"
  687.          if [ -z "$SANDBOX_IMG" ]; then
  688.            [ -z "$savebranch" ] && choose_save
  689.            savebranch="$(realpath -m $savebranch)"
  690.            if [ -d  "$savebranch" ]; then
  691.              #TODO: verify this works if savebranch is a mounted directory.
  692.              SANDBOX_IMG="$savebranch"
  693.            else
  694.              [ ! -z "$savebranch"  ] && loop=$(losetup-FULL -a | grep  "$savebranch"  | sed "s/:.*$//" )
  695.              if [ ! -z "$loop" ]; then
  696.                SANDBOX_IMG=$(cat /proc/mounts | grep $loop | cut -d " " -f2)
  697.              fi
  698.              if [ -z "$SANDBOX_IMG" ] ; then
  699.                SANDBOX_IMG=$FAKEROOT_dir/sandbox_img${SANDBOX_ID}
  700.                mkdir -p $SANDBOX_IMG
  701.              fi
  702.            fi
  703.            rmdir $FAKEROOT
  704.          else
  705.            log stop
  706.            echo "Warning chose to remount over existing mount! $FAKEROOT"
  707.            echo "ctrl-c to quote"
  708.            read -p "Press enter to continue"  
  709.            log start    
  710.          fi
  711.        fi
  712.      else
  713.            echo "This is our first sandbox"
  714.      fi
  715.    else
  716.      echo "Warning sandbox root not defined"
  717.      #[ -z "$FAKEROOT" ] && FAKEROOT=/
  718.    fi
  719.    if [ $CLEANUP_SANDBOX_ROOT = yes ]; then
  720.      if [ ${#del_rules_filter} -eq 0 ]; then
  721.         del_rules_filter+=( $SANDBOX_ROOT"/*" )
  722.         del_rules_filter+=( POLICY_DELETE )
  723.      fi
  724.      if [ ${#umount_rules_filter} -eq 0 ]; then
  725.         umount_rules_filter+=( $SANDBOX_ROOT"/*" )
  726.         umount_rules_filter+=( POLICY_UMOUNT )
  727.      fi    
  728.    fi
  729.    mkdir -p "$SANDBOX_ROOT"
  730.    mkdir -p "$FAKEROOT"
  731. }
  732. function set_sandbox_img(){
  733.     [ -z ${FAKEROOT_dir+x} ] &&  set_fakeroot
  734.     if [ ! -z ${SANDBOX_IMG+x} ]  && [ -z "${SANDBOX_IMG}" ] || [ ! -z ${1+x} ]; then
  735.      SANDBOX_IMG=sandbox_img
  736.      SANDBOX_IMG=${SANDBOX_IMG}${SANDBOX_ID}
  737.      [ ! -z "$FAKEROOT_dir" ] && SANDBOX_IMG=$FAKEROOT_dir/$SANDBOX_IMG
  738.     elif [ -z "${FAKEROOT_dir}" ] ; then
  739.      SANDBOX_IMG=$FAKEROOT_dir/$SANDBOX_IMG
  740.     fi
  741. }
  742. function set_sandbox_tmpfs(){
  743.     [ -z ${FAKEROOT_dir+x} ] &&  set_fakeroot
  744.     if [ ! -z ${SANDBOX_TMPFS+x} ]  && [ -z "${SANDBOX_TMPFS}" ]; then
  745.      SANDBOX_TMPFS=sandbox_tmpfs
  746.      SANDBOX_TMPFS=${SANDBOX_TMPFS}${SANDBOX_ID}
  747.      [ -z "$FAKEROOT_dir" ] && SANDBOX_TMPFS=$FAKEROOT_dir/$SANDBOX_TMPFS
  748.    elif [ -z "${FAKEROOT_dir}" ] ; then
  749.      SANDBOX_TMPFS=$FAKEROOT_dir/$SANDBOX_TMPFS
  750.    fi
  751. }
  752.  
  753.  
  754. declare -a options="$(getopt -o f:,o:,m:,d:,s:,b:,e:,l:,t::,a::,u::,r::,j: --long input-file:,output-file:,:tmpfs::,root::,pmedia:,pdrv:,psubdir:,boot-config:,distro-specs:,extra-sfs:,aufs,maybe-aufs,maybe-psubdir:,no-exit::,psave:,pupmode:,logfile:,trace::,rw-layer:,copy-Xauth::,bind-X11-sockets::,copy-resolv_conf::,layer:,rev-bind:,bind:,before-chroot: -- "$@")"
  755. eval set --"$options_str"
  756. #set -- $options
  757. #declare -a options=$( $options_str )
  758. eval set --"$options"
  759. while [ $# -gt 0 ]; do
  760.  log stop
  761.  echo "processing args: $@"
  762.  log start
  763.  case $1 in
  764.  -f|--input-file)
  765.     INPUT_FILE=$2
  766.    mount_items "$INPUT_FILE"
  767.    items+="$(get_items -f "$INPUT_FILE")"
  768.    shift 2; ;;      
  769.  -o|--output-file) OUTPUT_FILE=$2; shift 2; ;;
  770.  --no-exit)
  771.    if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  772.      NO_EXIT="$2"
  773.      [ -z "$NO_EXI" ] && NO_EXIT=true
  774.      shift 2
  775.    else
  776.      NO_EXIT=true
  777.      shift 1
  778.    fi; ;;
  779.  -p|--env-prefix) ENV_PREFIX=$2; shift 2; ;;
  780.  -m|--pmedia) PMEDIA=$2; shift 2; ;;
  781.  -d| --pdrv) PDRV=$2; shift 2; ;;
  782.  -s|--psubdir) PSUBDIR=$2;
  783.    process_psubdir psubdir
  784.    shift 2; ;;
  785.    --maybe-psubdir) PSUBDIR=$2;
  786.    process_psubdir maybe-psubdir    
  787.    shift 2; ;;    
  788.  --distro-specs)
  789.     DISTRO_SPECS=$2;
  790.     [ -f "$DISTRO_SPECS" ] && . "$DISTRO_SPECS"
  791.     shift 2
  792.     ;;
  793.   --boot-config)
  794.       BOOTCONFIG=$2;
  795.     [ -f "$BOOTCONFIG" ] && . "$BOOTCONFIG"
  796.     shift 2
  797.     ;;
  798.   --union-record)  
  799.     LASTUNIONRECORD=$2;
  800.     process_union_record union-record "$LASTUNIONRECORD"
  801.     shift 2; ;;
  802.   -e|--extra-sfs)
  803.     EXTRASFSLIST=$2;
  804.     process_extra_sfs extra-sfs "$EXTRASFSLIST"
  805.     shift 2; ;;
  806.  --aufs)
  807.    items+="$(get_items)"
  808.    shift 1; ;;
  809.  --maybe-aufs)
  810.    [  -z "$items" ] && items+="$(get_items)"
  811.    shift 1; ;;
  812.   -t|--tmpfs)
  813.    if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  814.      SANDBOX_TMPFS="$2"
  815.      set_sandbox_tmpfs
  816.      shift 2
  817.    else
  818.      SANDBOX_TMPFS="" #Later we use [ -z ${SANDBOX_TMPFS+x} ] to check that this is set
  819.      set_sandbox_tmpfs
  820.      shift 1
  821.    fi; ;;  
  822.    -r|--root)
  823.    if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  824.      SANDBOX_ROOT="$2"
  825.      shift 2
  826.    else
  827.      SANDBOX_ROOT="" #Later we use [ -z ${SANDBOX_ROOT+x} ] to check that this is set
  828.      shift 1
  829.    fi; ;;  
  830.   -f|-n|--fake-root|--new-root)
  831.      if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  832.        FAKEROOT="$2"
  833.        set_fakeroot
  834.        shift 2
  835.      else
  836.        FAKEROOT="" #Later we use [ -z ${FAKEROOT+x} ] to check that this is set
  837.        set_fakeroot
  838.        shift 1
  839.      fi; ;;
  840.  --rw-layer) #TOTO unlike
  841.     if [ $PUPMODE -eq 5 ] || [ $PUPMODE -eq 13 ] || [ $PUPMODE -eq 77 ]; then
  842.        tmpfsbranch="$2"
  843.        if [ -d "$2" ]; then
  844.          SANDBOX_TMPFS="$2"          
  845.          [ -z savebranch ] && savebranch="$SANDBOX_TMPFS"
  846.        else
  847.           tmpfsbranch="$2"
  848.           set_sandbox_tmpfs #TODO: verify this does what we want.
  849.        fi
  850.     else
  851.        if [ -d "$2" ]; then
  852.        SANDBOX_IMG=$2
  853.        savebranch=$2
  854.      else [ -f "$2" ]
  855.        #mnt_sb_immage
  856.        #mount -o loop "$rwbranch" $SANDBOX_IMG;
  857.        savebranch=$1
  858.        loop=$(losetup-FULL -a | grep  "$savebranch"  | sed "s/:.*$//")
  859.        if [ ! -z "$loop" ]; then
  860.          SANDBOX_IMG=$(/proc/mounts | grep $loop | cut -d " " -f2)
  861.        else
  862.          SANDBOX_IMG=""
  863.          set_sandbox_img
  864.        fi    
  865.     fi
  866.    shift 2
  867.    ;;        
  868.  --save|--psave|--rw-layer|-t|--tmpfs)
  869.    #!!!!New code. See the -s|--save option of remount_save.sh https://pastebin.com/0ZeU2Prj
  870.    #PSAVE=$2
  871.    #shift 2
  872.    #;;
  873.      if [ "$1" = "--rw-layer" ]
  874.        if [ $PUPMODE -eq 5 ] || [ $PUPMODE -eq 13 ] || [ $PUPMODE -eq 77 ] || [ "$1" = "-t" ] || [ "$1" = "--tmpfs" ] ; then
  875.          make_set "$PDRV/$PSUBDIR" "$PRRV" "$PSUBDIR"
  876.          for a_path in "${make_set_rtn[@]"
  877.             if [ -d "$2" ] || [ ! -e "$2" ]; then
  878.               SANDBOX_TMPFS="$2"          
  879.               [ -z savebranch ] && savebranch="$SANDBOX_TMPFS"
  880.               break
  881.             elif [ -f "$2" ]; then
  882.                tmpfsbranch="$2"
  883.                set_sandbox_tmpfs #TODO: verify this does what we want.
  884.                break          
  885.             fi
  886.           done      
  887.        fi
  888.      fi
  889.      
  890.      if [ -d "$2" ]; then
  891.        SANDBOX_IMG=$2
  892.        savebranch=$2
  893.      else [ -f "$2" ]
  894.        #mnt_sb_immage
  895.        #mount -o loop "$rwbranch" $SANDBOX_IMG;
  896.        savebranch=$2
  897.        loop=$(losetup-FULL -a | grep  "$savebranch"  | sed "s/:.*$//")
  898.        if [ ! -z "$loop" ]; then
  899.          SANDBOX_IMG=$(/proc/mounts | grep $loop | cut -d " " -f2)
  900.        else
  901.          SANDBOX_IMG=""
  902.          set_sandbox_img
  903.        fi
  904.        shift 2;
  905.      fi; ;;  
  906.  --pupmode)
  907.    PUPMODE=$2
  908.    shift 2
  909.    ;;
  910.  
  911.  --layer)
  912.    RW_LAYER=$2
  913.    process_layer layer $2
  914.    shift 2
  915.    ;;
  916.  -l|--logfile)
  917.    LOGFILE=$2
  918.    [ -z "$TRACE" ] && TRACE=true
  919.    shift 2
  920.    log init
  921.    ;;  
  922.  -t|--trace)
  923.    TRACE=$2
  924.    if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  925.      TRACE="$2"
  926.      [ -z "$TRACE" ] && TRACE=true
  927.      shift 2
  928.    else
  929.      TRACE=true
  930.      shift 1
  931.    fi
  932.    log init
  933.    ;;
  934.  -a|--copy-Xauth)
  935.    if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  936.      XAUTH=$(realpath "$2")
  937.      log stop
  938.      [ -z "$XAUTH" ] && XAUTH=$(realpath "~/.Xauthority")
  939.      shift 2
  940.    else
  941.      log stop
  942.      XAUTH=$(realpath "~/.Xauthority")
  943.      shift 1
  944.    fi
  945.    echo "XAUTH=$XAUTH"
  946.    log start
  947.    ;;
  948.  -u|--bind-X11-sockets)
  949.    if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  950.      uSocketDir=$(realpath "$2");
  951.      log stop
  952.      [ -z "$uSocketDir" ] && uSocketDir=/tmp/.X11-unix
  953.      shift 2
  954.    else
  955.      log stop
  956.      uSocketDir=/tmp/.X11-unix
  957.      shift 1
  958.    fi
  959.    echo "uSocketDir=$uSocketDir"
  960.    log start
  961.    ;;
  962.  -r|--copy-resolv_conf)
  963.    if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  964.      RESOLV_CONF_PATH=$(realpath "$2")
  965.      log stop
  966.      [ -z "$RESOLV_CONF_PATH" ] && RESOLV_CONF_PATH=/etc/resolv.conf
  967.      shift 2
  968.    else
  969.      log stop
  970.      RESOLV_CONF_PATH=/etc/resolv.conf
  971.      shift 1
  972.    fi
  973.    echo "RESOLV_CONF_PATH=$RESOLV_CONF_PATH"
  974.    log start
  975.    ;;
  976.  --rev-bind) #Bind the fakeroot into a folder (e.g. a samba share)
  977.       unset rev_b_source
  978.      unset rev_b_target
  979.      while true
  980.      do
  981.        if [ $# -lt 1 ]; then
  982.          break
  983.        fi
  984.        case "$1" in
  985.        --)    
  986.  
  987.          if [ ! -z "$rev_b_source" ]; then
  988.            break
  989.          else
  990.          #TODO, add some further checking here. What we want to do is eat the -- at the end of the positional parameters if we are missing a target.
  991.            shift
  992.            continue
  993.          fi
  994.          ;;
  995.        --rev-bind)
  996.            shift
  997.            continue
  998.            ;;
  999.        -*)
  1000.            break
  1001.            ;;
  1002.        esac
  1003.        if [ -z "$rev_b_source" ]; then
  1004.          if [ ! -z "$1" ]; then
  1005.            rev_b_source="$1"; shift
  1006.            continue
  1007.          fi        
  1008.        elif [ -z "$b_target" ]; then
  1009.          if [ ! -z "$1" ]; then
  1010.            rev_b_target="$1"; shift
  1011.            
  1012.            log stop
  1013.            
  1014.            echo "rev_bind_sources+=( \"$rev_b_source\" )"
  1015.            echo "rev_bind_targets+=( \"$rev_b_target\" )"
  1016.            
  1017.            
  1018.            rev_bind_sources+=( "$rev_b_source" )
  1019.            rev_bind_targets+=( "$rev_b_target" )
  1020.            
  1021.            log start
  1022.            
  1023.            unset rev_b_source
  1024.            unset rev_b_target
  1025.            shift
  1026.            continue
  1027.          else
  1028.            shift
  1029.            continue
  1030.          fi      
  1031.        else
  1032.          shift
  1033.          break
  1034.        fi
  1035.      done
  1036. #   fi
  1037.    ;;
  1038.  --before-chroot)
  1039.     BEFORE_CHROOT_CMD="$2";
  1040.     shift 2
  1041.     ;;
  1042.  --bind)
  1043. #    if [ $# -ge 4 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ] && \
  1044. #[[ "$3" = -j ]] && [[ ! "$4" = --* ]] && [ ! -z "$4" ]; then
  1045. #       bind_source=$(realpath "$2")
  1046. #       bind_target=$(realpath "$2")
  1047. #       bind_sources+=( "$bind_source" )
  1048. #       bind_targets+=( "$bind_target" )
  1049. #       shift 4
  1050. #    else
  1051.      unset b_source
  1052.      unset b_target
  1053.      while true
  1054.      do
  1055.        if [ $# -lt 1 ]; then
  1056.          break
  1057.        fi
  1058.        case "$1" in
  1059.        --)    
  1060.  
  1061.          if [ ! -z "$b_source" ] && [ $# -lt 3 ]; then
  1062.            break
  1063.          else
  1064.          #TODO, add some further checking here. What we want to do is eat the -- at the end of the positional parameters if we are missing a target.
  1065.            shift
  1066.            continue
  1067.          fi
  1068.          ;;
  1069.        --bind)
  1070.            shift
  1071.            continue
  1072.            ;;      
  1073.        -*)
  1074.        
  1075.            break
  1076.            ;;
  1077.        esac        
  1078.        if [[ $1 = -* ]]; then
  1079.          if [ ! -z "$b_target" ]; then
  1080.            break
  1081.          else
  1082.          #TODO, add some further checking here. What we want to do is eat the -- at the end of the positional parameters if we are missing a target.
  1083.            shift
  1084.            continue
  1085.          fi
  1086.        fi
  1087.        if [ -z "$b_source" ]; then
  1088.          if [ ! -z "$1" ]; then
  1089.            b_source="$1"; shift
  1090.            continue
  1091.          fi
  1092.        elif [ -z "$b_target" ]; then
  1093.          if [ ! -z "$1" ]; then
  1094.            b_target="$1"; shift
  1095.            log stop
  1096.            
  1097.            echo "bind_sources+=( \"$b_source\" )"
  1098.            echo "bind_targets+=( \"$b_target\" )"            
  1099.            
  1100.            bind_sources+=( "$b_source" )
  1101.            bind_targets+=( "$b_target" )
  1102.            log start
  1103.            
  1104.            unset b_source
  1105.            unset b_target
  1106.            shift
  1107.            continue
  1108.          fi        
  1109.        fi
  1110.        shift
  1111.      done
  1112. #   fi
  1113.    ;;          
  1114.  --)
  1115.    shift 1
  1116.    options2+=( "$@" )
  1117.    break; ;;
  1118.  *)
  1119.     options2+=( "$1" )
  1120.     shift 1; ;;
  1121.  esac
  1122. done
  1123. items="$(echo "$items" | sed -n '/^\s*\(on\)\?\s*$/! p' | sed -n '/^Error: Expected on/! p' | sed -n '/^Use --help on/! p')"
  1124.  
  1125.      log stop
  1126.      read -p "Press enter to continue"
  1127.      log start
  1128.  
  1129. #!!!! Use new code further down to find and mount PDRV
  1130.  
  1131. #!!!!Fake root now set with set_fakeroot() (above) for old code see psandbox_removed.sh
  1132.  
  1133. if [ -z ${SANDBOX_ROOT+x} ] && [ -z ${FAKEROOT+x} ]; then
  1134.  SANDBOX_ROOT="" #Later this will change to SANDBOX_ROOT=/mnt/sb
  1135.  set_fakeroot
  1136.  [ -z $SANDBOX_IMG ] && set_sandbox_img
  1137. fi
  1138.  
  1139. # umount all if we are accidentally killed
  1140. trap 'umountall' 1
  1141.  
  1142. #!!!! Old umountall() function removed. See new function above
  1143.  
  1144.  
  1145. # 0.1 must be root
  1146. if [ $(id -u) -ne 0 ]; then
  1147.  echo "You must be root to use sandbox."
  1148.  exit
  1149. fi
  1150.  
  1151. # 0.2 cannot launch sandbox within sandbox
  1152. if [ "$AUFS_ROOT_ID" != "" ] ; then
  1153.  grep -q $SANDBOX_ROOT /sys/fs/aufs/$AUFS_ROOT_ID/br0 &&
  1154.    echo "Cannot launch sandbox within sandbox." && exit
  1155. fi
  1156.  
  1157. # 0.3 help
  1158. case "$1" in
  1159.  --help|-h)
  1160.  echo "Usage: ${0##*/}"
  1161.  echo "Starts an in-memory (throwaway) sandbox. Type 'exit' to leave."
  1162.  exit
  1163. esac
  1164.  
  1165. # 0.4 if not running from terminal but in Xorg, then launch via terminal
  1166. ! [ -t 0 ] && [ -n "$DISPLAY" ] && exec $XTERM -e "$0" "$@"
  1167. ! [ -t 0 ] && exit
  1168. # 1. get aufs system-id for the root filesystem
  1169. if [ -z "$AUFS_ROOT_ID" ] ; then
  1170.  AUFS_ROOT_ID=$(
  1171.    awk '{ if ($2 == "/" && $3 == "aufs") { match($4,/si=[0-9a-f]*/); print "si_" substr($4,RSTART+3,RLENGTH-3) } }' /proc/mounts
  1172.  )
  1173. fi
  1174.  
  1175.  
  1176. # 3. Ask user to choose the SFS
  1177. #TODO: add quite mode.
  1178. echo "items=$items"
  1179. cat <<EOF
  1180. dialog --separate-output --backtitle "tmpfs sandbox" --title "sandbox config" \
  1181.  --checklist "Choose which SFS you want to use" 0 0 0 $items 2> $TMPFILE
  1182. EOF
  1183.  
  1184. log stop
  1185. dialog --separate-output --backtitle "tmpfs sandbox" --title "sandbox config" \
  1186.  --checklist "Choose which SFS you want to use" 0 0 0 $items 2> $TMPFILE
  1187. chosen="$(cat $TMPFILE)"
  1188. log start
  1189. clear
  1190. if [ -z "$chosen" ]; then
  1191.  echo "Cancelled or no SFS is chosen - exiting."
  1192.  exit 1 #TODO: Maybe instead of exiting we ask the user if they want to continue. For instance, perhaps the user wants an empty chroot directory to work with.
  1193. fi
  1194.  
  1195.  
  1196. # 4. convert chosen SFS to robranches
  1197. robranches=""
  1198. for a in $(cat $TMPFILE) ; do
  1199.    #a="$(echo "$a" | sed 's/,$//')" # | sed 's/^'//' | sed 's/'$//' )"
  1200.    echo "a=$a"
  1201.      log stop
  1202.      read -p "Press enter to continue"
  1203.      log start
  1204.    a="$(echo "$a" | sed 's/"//g')" # | sed 's/^'//' | sed 's/'$//' )"
  1205.   robranches=$robranches:$a=ro
  1206.   #TODO, remove line if layer is off in config file.
  1207.   sed -i "\#^$a # {s/ off / on /}" /tmp/get_items_out #If we have a config file then we may need to strip out some stuff like if the layer is off or on.
  1208.  
  1209. done
  1210. if [ ! -z "$OUTPUT_FILE" ]; then
  1211.   cp "/tmp/get_items_out" "$OUTPUT_FILE"
  1212.   if [ ! "$NO_EXIT" = true ]; then
  1213.     exit 0
  1214.   fi
  1215. fi
  1216. rm $TMPFILE
  1217.  
  1218. #!!!! New Section Get rw image if not specified (unless pfx=ram?), and mount SANDBOX_IMG if not already mounted and nt a directory.
  1219. # 5. get location of rw image
  1220. [ -z ${savebranch+x} ] && choose_save
  1221. mkdir -p $SANDBOX_IMG
  1222. [ ${#SANDBOX_IMG} -gt 1 ] || echo "Pathlenth too short SANDBOX_IMG='$SANDBOX_IMG'"
  1223. if [ ! -z "$savebranch"  ]; then
  1224.   if [ -f "$savebranch" ]; then
  1225.         loop=$(losetup-FULL -a | grep  "$savebranch"  | sed "s/:.*$//" )
  1226.         if [ ! -z "$loop" ]; then
  1227.           SANDBOX_IMG=$(cat /proc/mounts | grep $loop | cut -d " " -f2)
  1228.         else
  1229.           mount -o loop "$savebranch" $SANDBOX_IMG
  1230.         fi
  1231.   fi
  1232. fi
  1233.  
  1234.  
  1235. #!!!! New code. Flag TMPFS for creation, if in suitable pumode.
  1236. #!!!! TMPFS may already be flagged for creation if suitable option is provided.
  1237.   if [ ! -z "$PUPMODE" ]; then
  1238.     if [ $PUPMODE  -ne 5 ] && [ $PUPMODE  -ne 5 ] && [ $PUPMODE  -ne 13 ] && [ $PUPMODE  -ne 77 ]; then
  1239.       if  [ -z ${SANDBOX_TMPFS+x} ]; then
  1240.         SANDBOX_TMPFS="" #Later we use [ -z ${SANDBOX_TMPFS+x} ] to check that this is set
  1241.       fi
  1242.     fi
  1243.   fi
  1244.  
  1245. #!!!! New find PDRV code
  1246. if [ ! -z "$SANDBOX_ROOT" ]; then
  1247.   DEV_SAVE=$SANDBOX_ROOT/dev_save
  1248.   mkdir -p "$DEV_SAVE"
  1249.   if [ -z "$PDRV" ]; then
  1250.     if [[ "$SANDBOX_IMG" = *"/mnt/"* ]]; then
  1251.       PSUBDIR=${SANDBOX_IMG#/mnt/*/}
  1252.       PDRV=${SANDBOX_IMG%"/$PSUBDIR"}
  1253.       PDRV_real=$(cat /proc/mounts | grep $(realpath $PDRV) | cut -d " " -f1)
  1254.           PSUBDIR_i=${PSUBDIR}
  1255.           PDRV_i=${PDRV}
  1256.           PDRV_real_i=${PDRV_real}      
  1257.       while (true); do
  1258.  
  1259.           if [[ PDRV_real_i = /dev/loop* ]]; then
  1260.             PDRV_real_i=$(losetup-FULL -a | grep "$(basename PDRV_real)")
  1261.             PDRV_real_i=${PDRV_real#*(}
  1262.             PDRV_real_i=${PDRV_real%)}
  1263.             PSUBDIR_i=${PDRV_real_i#/mnt/*/}
  1264.             PDRV_real=$PSUBDIR_i/$PDRV_real
  1265.             PDRV_real_i=${SANDBOX_IMG%"/$PSUBDIR_i"}
  1266.             PDRV_real_i=$(cat /proc/mounts | grep $(realpath $PDRV_real_i) | cut -d " " -f1)
  1267.           elif [[ PDRV_real_i = /dev/* ]]; then
  1268.             PDRV_real=$(blkid | grep $PDRV_real)
  1269.             break
  1270.           else
  1271.             echo "could not identify PDRV_real"
  1272.             break
  1273.           fi
  1274.          
  1275.       done
  1276.     fi
  1277.   fi
  1278. fi
  1279.  
  1280. #(!!!!Removed Section -- old set set_sandbox_tmpfs code -- Se psandbox_removed.sh)
  1281.  
  1282.  
  1283. [ -z $PDRV ] && PDRV=/mnt/home
  1284. if [ -z  "$SANDBOX_IMG" ] || [ ! -z ${SANDBOX_TMPFS+x} ]; then
  1285.   if [ -z "$SANDBOX_TMPFS" ] ; then
  1286.     #SANDBOX_TMPFS=$SANDBOX_ROOT/sandbox
  1287.     set_sandbox_tmpfs
  1288.    
  1289.     #if grep -q $SANDBOX_TMPFS /proc/mounts; then
  1290.     #  #FAKEROOT=$(mktemp -d -p $SANDBOX_ROOT ${FAKEROOT##*/}.XXXXXXX)
  1291.     #  #SANDBOX_ID=".${FAKEROOT##*.}"
  1292.     #  SANDBOX_TMPFS=$SANDBOX_ROOT/${SANDBOX_ID/}${SANDBOX_ID}
  1293.     #  mkdir -p -f SANDBOX_TMPFS
  1294.     #  mount -t tmpfs none $SANDBOX_TMPFS; #We could exit if this fails but we don't need to becuase we can still write to SANDBOX_TMPFS even if it isn't tmpfs.
  1295.     #  rmdir $FAKEROOT
  1296.     #fi
  1297.   fi
  1298.  
  1299.   if [ ! -z "${SANDBOX_TMPFS}" ] && [ ! -z "$(grep -q ${SANDBOX_TMPFS} /proc/mounts)" ]; then
  1300.     mount -t tmpfs none $SANDBOX_TMPFS;
  1301.   fi
  1302. elif [ ! -z "${SANDBOX_TMPFS}" ]; then
  1303.   if [ ! -z "${SANDBOX_TMPFS}" ] && [ ! -z "$(grep -q ${SANDBOX_TMPFS} /proc/mounts)" ]; then
  1304.     mount -t tmpfs none $SANDBOX_TMPFS;
  1305.   fi
  1306. fi
  1307. if [ -z "$SANDBOX_TMPFS" ]; then
  1308.   SANDBOX_TMPFS=$SANDBOX_IMG
  1309. else
  1310.   if [ $robranches ~= ** ]; then
  1311.     robranches=$SANDBOX_IMG=rr:$robranches
  1312.   fi
  1313. fi
  1314. mkdir -p $FAKEROOT
  1315.  
  1316. #mk_initrd_dir
  1317.  
  1318.  
  1319. ## (!!!Removed Section. See psandbox_removed.sh!!) 6. do the magic - mount the tmpfs first, and then the rest with aufs
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325. # 5. do the magic - mount the rw image first, and then the rest with aufs
  1326. #if mount -o loop "$rwbranch" $SANDBOX_IMG; then
  1327. if [ ${#FAKEROOT} -gt 1 ] && ! grep -q $FAKEROOT /proc/mounts; then
  1328.  
  1329.  
  1330.   echo "mount -t aufs -o \"br:$SANDBOX_TMPFS=rw$robranches\" aufs ${FAKEROOT}"
  1331.   echo "About to mount FAKEROOT at $FAKEROOT"
  1332.   read -p "Press enter to continue"
  1333.  
  1334.     mount -t aufs -o "br:$SANDBOX_TMPFS=rw$robranches" aufs ${FAKEROOT}
  1335.  
  1336.         # 5. record our new aufs-root-id so tools don't hack real filesystem
  1337.         SANDBOX_AUFS_ID=$(grep $FAKEROOT /proc/mounts | sed 's/.*si=/si_/; s/ .*//') #'
  1338.         sed -i -e '/AUFS_ROOT_ID/ d' $FAKEROOT/etc/BOOTSTATE 2> /dev/null
  1339.         echo AUFS_ROOT_ID=$SANDBOX_AUFS_ID >> $FAKEROOT/etc/BOOTSTATE  
  1340.    
  1341.    
  1342.     # 7. sandbox is ready, now just need to mount other supports - pts, proc, sysfs, usb and tmp    
  1343.    
  1344.     mkdir -p $FAKEROOT/dev $FAKEROOT/sys $FAKEROOT/proc $FAKEROOT/tmp
  1345.     mkdir -p  "$DEV_SAVE/${PSUBDIR}"
  1346.     mount -o bind  "$PDRV/${PSUBDIR}" "$DEV_SAVE/${PSUBDIR}"
  1347.    
  1348.     #mount -o bind  "$DEV_SAVE/${PSUBDIR}" "$FAKEROOT/initrd/mnt/dev_save"
  1349.     mount -o bind  "$DEV_SAVE" "$FAKEROOT/initrd/mnt/dev_save"
  1350.  
  1351.     #Maybe optionally do this based on some input paramater:
  1352.     #Also pull these layers from an array
  1353.     for layer_name in "pup_ro2" "pup_ro3" "pup_ro4" "pup_ro5" "pup_z"; do
  1354.         layer="$(eval 'echo $'$layer_name)"
  1355.       if [ ! -z "$layer" ] ; then
  1356.         mount -o bind  "$layer" "$FAKEROOT/initrd/$layer_name"
  1357.       fi
  1358.     done
  1359.  
  1360.     case "$(uname -a)" in
  1361.     *fatdog*)
  1362.       mkdir -p "$FAKEROOT/aufs"
  1363.       #mount -o bind  "$DEV_SAVE/${PSUBDIR}" "$FAKEROOT/aufs/dev_save"
  1364.       mkdir -p "$FAKEROOT/aufs/dev_save"
  1365.       mount -o bind  /mnt/home "$FAKEROOT/aufs/dev_save"
  1366.       cd $FAKEROOT
  1367.       #mkdir -p mnt/home
  1368.       cd mnt
  1369.       ln -s home ../aufs/dev_save
  1370.       pup_save="$SANDBOX_IMG"
  1371.       mount -o bind  "$pup_save" "$FAKEROOT/aufs/pup_save"
  1372.       base_sfs=/aufs/pup_ro
  1373.       mount -o bind  "$base_sfs" "$FAKEROOT/aufs/pup_ro"
  1374.       if [ "$SANDBOX_TMPFS" != "$SANDBOX_IMG" ]; then
  1375.          pup_rw="$SANDBOX_TMPFS"
  1376.          mount -o bind  "$pup_rw" "$FAKEROOT/aufs/pup_rw"
  1377.       fi
  1378.       ;;    
  1379.     *) #assume this is puppy
  1380.       mk_initrd_dir
  1381.       #mkdir -p "$FAKEROOT/initrd/mnt/dev_save"
  1382.       #mount -o bind  /mnt/home "$FAKEROOT/initrd/mnt/dev_save"
  1383.       #mkdir $FAKEROOT/mnt
  1384.       #cd $FAKEROOT/mnt
  1385.       #ln -s ../initrd/mnt/dev_save
  1386.       ;;
  1387.     esac
  1388.     mkdir -p $FAKEROOT/mnt/home
  1389.     mount -o rbind /dev $FAKEROOT/dev
  1390.     mount -t sysfs none $FAKEROOT/sys
  1391.     mount -t proc none $FAKEROOT/proc
  1392.     if [ PUPMODE = 2 ] || [[ "$(uname -a)" = *fatdog* ]]; then #Full Install #Maybe don't base this on PUPMODE
  1393.       tmp_des=$FAKEROOT/tmp
  1394.       tmp_source=/tmp
  1395.     else
  1396.       #case "$(uname -a)" in
  1397.       #*fadog*)
  1398.       #
  1399.       #*) #assume this is puppy
  1400.         mkdir -p $FAKEROOT/initrd/mnt/tmpfs
  1401.         tmp_des=$FAKEROOT/initrd/mnt/tmpfs
  1402.         tmp_source=/initrd/mnt/tmpfs
  1403.         cd $FAKEROOT
  1404.       rm tmp
  1405.       ln -s initrd/mnt/tmpfs tmp
  1406.     fi
  1407.     mount -o bind $tmp_source $tmp_des
  1408.  
  1409.     cd $FAKEROOT
  1410.     case "$(uname -a)" in
  1411.     *fatdog*)
  1412.       mkdir -p $FAKEROOT/aufs
  1413.       mount -o bind $SANDBOX_TMPFS $FAKEROOT/$SANDBOX_TMPFS
  1414.       ;;
  1415.     *) #assume this is puppy
  1416.       mk_initrd_dir
  1417.       #ln -s initrd/mnt/tmpfs tmp  
  1418.       #mkdir -p $FAKEROOT/$SANDBOX_TMPFS
  1419.       #mount -o bind $SANDBOX_TMPFS $FAKEROOT/$SANDBOX_TMPFS # so we can access it within sandbox
  1420.       ;;
  1421.     esac
  1422.  
  1423. #    #mkdir -p $FAKEROOT/$SANDBOX_TMPFS
  1424. #    mkdir -p $FAKEROOT/$SANDBOX_IMG
  1425. #    mount -o bind $SANDBOX_IMG $FAKEROOT/$SANDBOX_IMG  # so we can access it within sandbox    
  1426.      cp /usr/share/sandbox/* $FAKEROOT/usr/bin 2> /dev/null
  1427.    
  1428.  
  1429.  
  1430.         # 8. optional copy, to enable running sandbox-ed xwin
  1431.         cp /usr/share/sandbox/* $FAKEROOT/usr/bin 2> /dev/null
  1432.        
  1433.         # 9. make sure we identify ourself as in sandbox - and we're good to go!
  1434.         echo -e '\nexport PS1="sandbox'${SANDBOX_ID}'# "' >> $FAKEROOT/etc/shinit #fatdog 600
  1435.         sed -i -e '/^PS1/ s/^.*$/PS1="sandbox'${SANDBOX_ID}'# "/' $FAKEROOT/etc/profile # earlier fatdog
  1436.        
  1437.     if [ -d "$FULL_SAVE_PATH" ]; then #TODO verify that this works with a save file
  1438.       if [ $PUPMODE -eq 13 ] && [ $PUPMODE -eq 77 ]; then
  1439.         #TODO: when PUPMODE=77 (multisession cd) we need to copy folders. See: https://github.com/puppylinux-woof-CE/woof-CE/blob/c483d010a8402c5a1711517c2dce782b3551a0b8/initrd-progs/0initrd/init#L1084
  1440.         #and copy_folders()  https://github.com/puppylinux-woof-CE/woof-CE/blob/c483d010a8402c5a1711517c2dce782b3551a0b8/initrd-progs/0initrd/init#L482
  1441.           #https://github.com/puppylinux-woof-CE/woof-CE/blob/c483d010a8402c5a1711517c2dce782b3551a0b8/initrd-progs/0initrd/init#L1091
  1442.           mount -o remount,prepend:"$FULL_SAVE_PATH"=rw,mod:"$SANDBOX_TMPFS"=ro,del:"$SANDBOX_TMPFS" "$FAKEROOT"
  1443.           #mount -o remount,add:1:"$FULL_SAVE_PATH"=ro+wh "$FAKEROOT"
  1444.       fi
  1445.     fi
  1446.        
  1447.        
  1448.         echo "Starting sandbox now."
  1449.         log stop
  1450.         if [ $USE_NS ]; then
  1451.             unshare -f -p --mount-proc=$FAKEROOT/proc chroot $FAKEROOT
  1452.         else
  1453.             chroot $FAKEROOT
  1454.         fi
  1455.         log start
  1456.         # 8. done - clean up everything
  1457.         umountall
  1458.         echo "Leaving sandbox."  
  1459.    
  1460. elif [ "${FAKEROOT:-/}" = "/" ]; then
  1461.   #[ -z "$FAKEROOT" ] &&  $FAKEROOT="/"
  1462.   echo "mount -t aufs -o \"remount,br:$SANDBOX_TMPFS=rw$robranches\" aufs  ${FAKEROOT:-/}"
  1463.   echo "Warning!  about to remount rootfs at $FAKEROOT"
  1464.   read -p "Press enter to continue"
  1465.   trap - 1 #Clear traps
  1466.   trap
  1467.   mount -t aufs -o "br:$SANDBOX_TMPFS=rw$robranches" aufs ${FAKEROOT:-/};
  1468.   mkdir -p /dev /sys /proc /tmp #These probably already exist
  1469.   [[ "`mountpoint /dev`"  != *"is a mountpoint"* ]] && mount -t devtmpfs devtmpfs /dev
  1470.   mkdir -p /initrd/mnt/tmpfs
  1471.   [[ "`mountpoint /initrd/mnt/tmpfs`"  != *"is a mountpoint"* ]] && mount -t tmpfs none /initrd/mnt/tmpfs
  1472.   mkdir -p /initrd/mnt/tmpfs/tmp
  1473.   if [[ "`mountpoint /tmp`"  != *"is a mountpoint"* ]]; then
  1474.     if [[ "`mountpoint /initrd/mnt/tmpfs`"  != *"is a mountpoint"* ]]; then
  1475.       mount -o bind /initrd/mnt/tmpfs/tmp /tmp
  1476.     else
  1477.       mount -t tmpfs none /tmp
  1478.     fi
  1479.   fi
  1480. else
  1481.   echo "not implemented for FAKEROOT=${FAKEROOT:-/}}"
  1482.   exit
  1483. fi
  1484.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement