Advertisement
s243a

sandbox_s243a_debug5.sh

Jan 23rd, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.22 KB | None | 0 0
  1. #!/bin/bash
  2. # James Budiono 2011, 2013, 2015
  3. # puppy test/compilation sandbox
  4. # this version uses tmpfs instead of an rw image,
  5. # and you can also choose which SFS to use
  6. # run this from terminal.
  7. # version 4 - replace sed with awk - more powerful and more correct, will handle all oddball cases
  8. #             where loop-N and pup_ro-N numbers don't match
  9. # version 5 - add compatibility when running with pup_rw=tmpfs (step 2.a)
  10. # version 6 - (2012) adapted to be more flexible - for Fatdog64 600
  11. # version 7 - (2012) cleanup mounts if if we are killed
  12. # version 8 - (2013) re-launch in terminal if we aren't in terminal
  13. # version 9 - (2013) enable running multiple sandboxes
  14. # version 10 - (2015) use pid/mount namespaces if available
  15.  
  16. # 0. directory locations
  17. #. $BOOTSTATE_PATH # AUFS_ROOT_ID
  18. #XTERM="defaultterm"
  19. # -o, --output-file
  20. #    Just write layer paths to an output file but don't mount the sandbox.
  21. # --no-exit
  22. #   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.
  23. # f, --input-file
  24. #   read layer paths from a file rather than reading existing layers
  25. # m,--pmedia
  26. #   determines pupmodes. Refer to puppy boot parmaters
  27. # d, --pdrv
  28. #   this is the particiaion where the puppy files are located. The default is /mnt/home
  29. # s, psubdir
  30. #   this is the sub directory where the puppy files are located
  31. # c, --clear-env
  32. #   deletes enviornental variabls
  33. # --env-prefix
  34. #   enviornental variable prefix
  35. # b --boot-config
  36. #   path to boot config (e.g. /etc/rc.d/BOOTCONFIG
  37. # --disto-specs
  38. #   path to distro specs (e.g. /etc/DISTRO_SPECS; e.g. /initrd/distro-specs)
  39. # L, --layer
  40. #   a subgke kater
  41. #  e, --extra-sfs
  42. #   a list of extra sfs files (space seperated)
  43. #  u, --union-record
  44. # --xterm
  45. # --sandbox
  46. # -initrd
  47. declare -A KEYs_by_MNT_PT
  48. declare -A KEYs_by_FILE_PATH
  49. declare -A KEYs_by_trimmed_MNT_PT
  50. declare -A KEYs_by_trimmed_FILE_PATH
  51. declare -A MNT_PTs
  52. declare -A FILE_PATHs
  53. declare -A ON_status
  54. MAX_STR_LEN=50
  55.  
  56.  
  57. XTERM=${XTERM:-urxvt}
  58. SANDBOX_ROOT=${SANDBOX_ROOT:-/mnt/sb}
  59. declare -a options="$(getopt -o f:,o:,m:,d:,s:,b:,e: --long input-file:output-file:,pmedia:,pdrv:,psubdir:,boot-config:,distro-specs:,extra-sfs:,maybe-aufs,maybe-psubdir:,no-exit:: -- "$@")"
  60. declare -a options2
  61. declare -a LAYER_SOURCES
  62. LAYER_SOURCE=none
  63. eval set --"$options"
  64. while [ $# -gt 0 ]; do
  65.   case "$1" in
  66.   -f|--input-file) INPUT_FILE=$2;
  67.     LAYER_SOURCE=INPUT_FILE
  68.     LAYER_SOURCES+=( input-file )
  69.     shift 2; ;;      
  70.   -o|--output-file) OUTPUT_FILE=$2; shift 2; ;;
  71.   --no-exit)
  72.     if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  73.       NO_EXIT="$2"
  74.       shift 2
  75.     else
  76.       NO_EXIT=true
  77.       shift 1
  78.     fi; ;;
  79.   -p|--env-prefix) ENV_PREFIX=$2; shift 2; ;;
  80.   -m|--pmedia) PMEDIA=$2; shift 2; ;;
  81.   -d| --pdrv) PDRV=$2; shift 2; ;;
  82.   -s|--psubdir) PSUBDIR=$2;
  83.     LAYER_SOURCE=psubdir  
  84.     LAYER_SOURCES+=( psubdir )
  85.     shift 2; ;;
  86.     --maybe-psubdir) PSUBDIR=$2;
  87.     LAYER_SOURCE=maybe-psubdir  
  88.     LAYER_SOURCES+=( maybe-psubdir )
  89.     shift 2; ;;    
  90.   --distro-specs)
  91.      DISTRO_SPECS=$2;
  92.      . "$DISTRO_SPECS"
  93.      shift 2
  94.      ;;
  95.    --boot-config)
  96.        DISTRO_SPECS=$2;
  97.      . "$BOOTCONFIG"
  98.      shift 2
  99.      ;;
  100.    --union-record)  
  101.      LASTUNIONRECORD="$2";
  102.      LAYER_SOURCES+=( union-record )
  103.      shift 2; ;;
  104.    -e|--extra-sfs)
  105.      EXTRASFSLIST="$2";
  106.      LAYER_SOURCES+=( extrasfs )
  107.      shift 2; ;;
  108.   --maybe-aufs)
  109.     LAYER_SOURCE=maybe-aufs  
  110.     LAYER_SOURCES+=( maybe-aufs )
  111.     shift 1; ;;
  112.   --)
  113.     shift 1
  114.     options2+=( "$@" )
  115.     break; ;;
  116.   *)
  117.      options2+=( "$1" )
  118.      shift 1; ;;
  119.   esac
  120. done
  121.  
  122. #set -- "${options2[@]}"
  123. if [ "$LAYER_SOURCE" = none ] && [ ! -z "$PDRV" ]; then
  124.   PDRV=${PDRV:-/mnt/home}
  125.   for rec in $LASTUNIONRECORD; do
  126.     if [ -f "$PDRV/$rec" ]; then
  127.       items+="\"$PDRV/$rec\" \"$rec\""$'\n'
  128.     fi
  129.   done
  130.   if [ -z "$items" ]; then
  131.     [ -z "$DISTRO_PUPPYSFS" ] && DISTRO_PUPPYSFS=$(ls -1 /mnt/home | grep -m1 puppy_.*\.sfs$)
  132.     [ -z "$DISTRO_ZDRVSFS" ] && DISTRO_ZDRVSFS=$(ls -1 /mnt/home | grep -m1 zdrv.*\.sfs$)
  133.     [ -z "$DISTRO_FDRVSFS" ] && DISTRO_FDRVSFS=$(ls -1 /mnt/home | grep -m1 fdrv.*\.sfs$)
  134.     [ -z "$DISTRO_ADRVSFS" ] && DISTRO_ADRVSFS=$(ls -1 /mnt/home | grep -m1 fdrv.*\.sfs$)    
  135.     [ -z "$DISTRO_YDRVSFS" ] && DISTRO_YDRVSFS=$(ls -1 /mnt/home | grep -m1 fdrv.*\.sfs$)    
  136.     for rec in "$DISTRO_PUPPYSFS" "$DISTRO_ZDRVSFS" "$DISTRO_FDRVSFS" "$DISTRO_ADRVSFS" "$DISTRO_YDRVSFS"; do
  137.       items+="$PDRV/$rec" "$rec"$'\n'  
  138.     done
  139.   fi
  140.   if [ ! -z "$items" ]; then  
  141.     for rec in $EXTRASFSLIST; do
  142.       if [ -f "$PDRV/$rec" ]; then
  143.         items+="\"$PDRV/$rec\" \"$rec\" "on"\""$'\n'
  144.       fi
  145.     done
  146.   fi
  147. fi
  148. if [ -z "$items" ] && [ "$LAYER_SOURCE" = none ] ; then
  149.     LAYER_SOURCE=aufs  
  150.     LAYER_SOURCES+=( aufs )
  151. fi
  152. [ -z "$PDRV" ] && PDRV="$(realpath /mnt/home)"
  153. if [ "$(cat /proc/mounts | grep -c "$PDRV")" = 0 ]; then
  154.   PDRV_DEV="$(blkid | grep -m1 "$PDRV" | cut -d ':' -f1)"
  155.   PDRV="$(echo "$PDRV_DEV" | sed 's#^/dev/#/mnt/#')"
  156.   mount "$PDRV_DEV" "$PDRVV"
  157. fi  
  158.  
  159.  
  160. FAKEROOT=$SANDBOX_ROOT/fakeroot   # mounted chroot location of sandbox - ie, the fake root
  161. SANDBOX_TMPFS=$SANDBOX_ROOT/sandbox # mounted rw location of tmpfs used for sandbox
  162. SANDBOX_ID=
  163. TMPFILE=$(mktemp -p /tmp)
  164. # use namespaces if available
  165. #[ -e /proc/1/ns/pid ] && [ -e /proc/1/ns/mnt ] && type unshare >/dev/null && USE_NS=1
  166.  
  167.  
  168.  
  169.  
  170. # umount all if we are accidentally killed
  171. trap 'umountall' 1
  172. umountall() {
  173.     {
  174.     umount -l $FAKEROOT/$SANDBOX_TMPFS
  175.     umount -l $FAKEROOT/tmp
  176.     umount -l $FAKEROOT/proc
  177.     umount -l $FAKEROOT/sys
  178.     umount -l $FAKEROOT/dev
  179.    
  180.     umount -l $FAKEROOT
  181.     umount -l $SANDBOX_TMPFS
  182.     rmdir $FAKEROOT
  183.     rmdir $SANDBOX_TMPFS
  184.     } 2> /dev/null
  185. }
  186.  
  187. # 0.1 must be root
  188. if [ $(id -u) -ne 0 ]; then
  189.     echo "You must be root to use sandbox."
  190.     exit
  191. fi
  192.  
  193. # 0.2 cannot launch sandbox within sandbox
  194. if [ "$AUFS_ROOT_ID" != "" ] ; then
  195.     grep -q $SANDBOX_ROOT /sys/fs/aufs/$AUFS_ROOT_ID/br0 &&
  196.         echo "Cannot launch sandbox within sandbox." && exit
  197. fi
  198.  
  199. # 0.3 help
  200. case "$1" in
  201.     --help|-h)
  202.     echo "Usage: ${0##*/}"
  203.     echo "Starts an in-memory (throwaway) sandbox. Type 'exit' to leave."
  204.     exit
  205. esac
  206.  
  207. # 0.4 if not running from terminal but in Xorg, then launch via terminal
  208. ! [ -t 0 ] && [ -n "$DISPLAY" ] && exec $XTERM -e "$0" "$@"
  209. ! [ -t 0 ] && exit
  210. # 1. get aufs system-id for the root filesystem
  211. if [ -z "$AUFS_ROOT_ID" ] ; then
  212.     AUFS_ROOT_ID=$(
  213.         awk '{ if ($2 == "/" && $3 == "aufs") { match($4,/si=[0-9a-f]*/); print "si_" substr($4,RSTART+3,RLENGTH-3) } }' /proc/mounts
  214.     )
  215. fi
  216. function get_items(){
  217.     local out
  218.     OUTFILE=/tmp/get_items_out
  219.     rm "$OUTFILE"
  220.    
  221.     out+="$(
  222.  { echo ==mount==; cat /proc/mounts;
  223.    echo ==losetup==; losetup-FULL -a;
  224.    echo ==branches==;
  225.      if [ $# -eq 0 ]; then
  226.        ls -v /sys/fs/aufs/$AUFS_ROOT_ID/br[0-9]* | xargs sed 's/=.*//';
  227.      else
  228.        if [ "$1" = "-f" ]; then
  229.          cat "$2";
  230.        elif [ "$1" = "-s" ]; then
  231.          cat <<<"$2";
  232.        fi;
  233.      fi; } | \
  234.    awk -v PDRV="$PDRV" -v MAX_STR_LEN="$MAX_STR_LEN" -v OUTFILE="$OUTFILE" \
  235. -f /usr/bin/sandbox.awk
  236. )"
  237.   echo "$out"
  238. }
  239.  
  240. function mount_fn(){
  241.     local MNT_PT=''
  242.     FULL_PATH=$(realpath "$1")
  243.     key=$(md5sum < <( echo "$FULL_PATH" ) | cut -f1 -d' ')
  244.     key=${key:0:5}
  245.     FNAME="$(echo "${FULL_PATH}__${key}" | sed 's#/#+#g' | sed 's#\.#+#g')"
  246.    
  247.     if [ ! -z "$2" ]; then
  248.       MNT_PT="$(cat /proc/mounts | grep "$2" | grep -m1 $FNAME | cut -d ' ' -f2 )"              
  249.       [ -z "$MNT_PT" ] && MNT_PT="$(cat /proc/mounts | grep -m1 "$2" | cut -d ' ' -f2 )"
  250.       [ -z "$MNT_PT" ] && MNT_PT="$(cat /proc/mounts | grep -m1 $FNAME | cut -d ' ' -f2 )"            
  251.    else
  252.        MNT_PT="$(cat /proc/mounts | grep -m1 $FNAME | cut -d ' ' -f2)"    
  253.    fi
  254.     if [ -z "${MNT_PT}" ]; then  
  255.       #case "FNAME" in
  256.       #*.iso)
  257.       #   DIR_PATH=/media; ;;
  258.       #*)
  259.         DIR_PATH=/mnt #; ;;
  260.       #esac
  261.       #if [ -z "$2" ]; then
  262.        # MNT_PT="$2"
  263.       #fi
  264.       #[ -z "$MNT_PT" ] && MNT_PT="${DIR_PATH}/$FNAME"
  265.       LN=${#FNAME}
  266.       start="$((LN-MAX_STR_LEN-4))"
  267.       if [ "$start" -lt 0 ]; then
  268.         start=0
  269.       fi
  270.       FNAME=${FNAME:$start}
  271.       MNT_PT="${DIR_PATH}/$FNAME"
  272.      
  273.       mkdir -p "${MNT_PT}"
  274.       mount $FULL_PATH "${MNT_PT}"    
  275.       MNT_PT="$(cat /proc/mounts | grep -m1 $FNAME | cut -d ' ' -f2 )"          
  276.    fi
  277.   echo  "${MNT_PT}"
  278. }
  279. if [ -z "$items" ]; then
  280.  
  281.   for item_source in "${LAYER_SOURCES[@]}"; do
  282.   # 2. get branches, then map branches to mount types or loop devices
  283.     case "$item_source" in
  284.     input-file)
  285.   items+="$(get_items -f "$INPUT_FILE")"; ;;
  286.     union-record)
  287.        new_items=''
  288.        for rec in $LASTUNIONRECORD; do
  289.         if [ -f "$rec" ]; then
  290.           MNT_PT="$(mount_fm "$rec" )"
  291.           new_items+="\"$MNT_PT\" \"$rec\" \"on\""$'\n'
  292.         elif [ -f "$PDRV/$rec" ]; then
  293.           MNT_PT="$(mount_fm "$PDRV/$rec" )"
  294.           new_items+="\"$MNT_PT\", \"$PDRV/$rec\", \"on\""$'\n'
  295.         fi
  296.       done
  297.       items+="$(get_items -f <<<"$new_items")"
  298.       ;;
  299.     extra-sfs)
  300.        new_items=''
  301.        for rec in $EXTRASFSLIST; do
  302.        if [ -f "$rec" ]; then
  303.           MNT_PT="$(mount_fm "$rec" )"
  304.           new_items+="\"$MNT_PT\" \"$rec\" \"on\""$'\n'
  305.         elif [ -f "$PDRV/$rec" ]; then
  306.           MNT_PT="$(mount_fm "$PDRV/$rec" )"
  307.           new_items+="\"$MNT_PT\" \"$PDRV/$rec\" \"on\""$'\n'
  308.         fi
  309.       done
  310.       ;;
  311.     layer=*)
  312.       item_path="$(echo ${litem_source#*=})"
  313.       if [ -f "$item_path" ]; then
  314.         MNT_PT="$(mount_fm "$item_path" )"
  315.       elif [ -d "$item_path" ]; then  
  316.         MNT_PT="$item_path" #This isn't really a mount poing
  317.       elif [ ! -d  "$item_path" ]; then
  318.         echo "Warning  cannot mount $item_path"
  319.         continue
  320.       fi
  321.       items+="\"$MNT_PT\" \"$item_path\" \"on\""$'\n'
  322.       ;;
  323.     psubdir|maybe-psubdir)
  324.       if [ "$item_source" = "maybe-psubdir" ]; then
  325.          [ ! -z "$items" ] && continue
  326.       fi
  327.       [ -z "$DISTRO_PUPPYSFS" ] && DISTRO_PUPPYSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 puppy_.*\.sfs$)
  328.       [ -z "$DISTRO_ZDRVSFS" ] && DISTRO_ZDRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 zdrv.*\.sfs$)
  329.       [ -z "$DISTRO_FDRVSFS" ] && DISTRO_FDRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 fdrv.*\.sfs$)
  330.       [ -z "$DISTRO_ADRVSFS" ] && DISTRO_ADRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 fdrv.*\.sfs$)    
  331.       [ -z "$DISTRO_YDRVSFS" ] && DISTRO_YDRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 fdrv.*\.sfs$)    
  332.       new_items=""
  333.       for rec in "$DISTRO_PUPPYSFS" "$DISTRO_ZDRVSFS" "$DISTRO_FDRVSFS" "$DISTRO_ADRVSFS" "$DISTRO_YDRVSFS"; do
  334.         #MNT_PATH="${rec}"
  335.         #[ ! -z "${PSUBDIR}" ] && MNT_PATH=${PSUBDIR}/${MNT_PATH}
  336.         MNT_PATH="${PDRV}/${PSUBDIR}/$rec"
  337.         MNT_PT="$(mount_fn "$MNT_PATH")"
  338.         new_items+="\"${MNT_PT}\" \"$rec\" "'"on"'$'\n'  
  339.       done
  340.       export new_items="$new_items"
  341.       echo "$new_items"
  342.       items+="$(get_items -s "$new_items")"
  343.       ;;      
  344.     aufs)
  345.       items+="$(get_items)" ; ;;  
  346.     maybe-aufs)
  347.        [  -z "$items" ] && items+="$(get_items)"; ;;  
  348.   esac
  349.   items="$(echo "$items" | sed -n '/^\s*\(on\)\?\s*$/! p' | sed -n '/^Error: Expected on/! p' | sed -n '/^Use --help on/! p')"
  350.   done
  351. fi
  352. # 3. Ask user to choose the SFS
  353.  
  354. dialog --separate-output --backtitle "tmpfs sandbox" --title "sandbox config" \
  355.     --checklist "Choose which SFS you want to use" 0 0 0 $items 2> $TMPFILE
  356. chosen="$(cat $TMPFILE)"
  357.  
  358. clear
  359. if [ -z "$chosen" ]; then
  360.     echo "Cancelled or no SFS is chosen - exiting."
  361.     exit 1
  362. fi
  363.  
  364. if [ ! -z "$OUTPUT_FILE" ]; then
  365.   cp "$TMPFILE" "$OUTPUT_FILE"
  366.   if [ ! "$NO_EXIT" = true ]; then
  367.     exit 0
  368.   fi
  369. fi
  370. # 0.5 is this the first sandbox? If not, then create another name for mountpoints
  371. if grep -q $FAKEROOT /proc/mounts; then
  372.     FAKEROOT=$(mktemp -d -p $SANDBOX_ROOT ${FAKEROOT##*/}.XXXXXXX)
  373.     SANDBOX_ID=".${FAKEROOT##*.}"
  374.     SANDBOX_TMPFS=$SANDBOX_ROOT/${SANDBOX_TMPFS##*/}${SANDBOX_ID}
  375.     rmdir $FAKEROOT
  376. fi
  377.  
  378.  
  379.  
  380. # 4. convert chosen SFS to robranches
  381. robranches=""
  382. for a in $(cat $TMPFILE) ; do
  383.     #a="$(echo "$a" | sed 's/,$//')" # | sed 's/^'//' | sed 's/'$//' )"
  384.     a="$(echo "$a" | sed 's/"//g')" # | sed 's/^'//' | sed 's/'$//' )"
  385.     robranches=$robranches:$a=ro
  386. done
  387. rm $TMPFILE
  388.  
  389. # 5. make the mountpoints if not exist  yet
  390. mkdir -p $FAKEROOT $SANDBOX_TMPFS
  391.  
  392. function mk_initrd_dir(){
  393.     mkdir -p "$FAKEROOT"/initrd
  394.     if [ -z "$PUPMODE" ] ; then
  395.         if [ -z "$PMEDIA" ]; then
  396.         #if [ "$PUPMODE" = 5 ] ; then
  397.         #  #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  398.         #  #First boot (or pfix=ram):  tmpfs                         pup_xxx.sfs      5
  399.           PUPMODE=5
  400.         elif [ PMEDIA = 'atahd' ] || [ "$PMEDIA" = usbhd ]; then
  401.           #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  402.           #Normal running puppy:      pup_save.3fs                  pup_xxx.sfs      12
  403.           PUPMODE=12
  404.         elif [ "$PUPMODE" = 13 ] || [ PMEDIA = 'usbflash' ] || [ pmedia = 'ideflash' ]; then
  405.            #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  406.            #ditto, but flash drive:    tmpfs         pup_save.3fs    pup_xxx.sfs      13
  407.            PUPMODE=13
  408.         elif [ "$PUPMODE" = 77 ]; then
  409.           #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  410.           #Multisession cd/dvd:       tmpfs         folders         pup_xxx.sfs      77
  411.         else #[PUPMODE=2 -> full install
  412.        
  413.         fi    
  414.     fi
  415.     if [ "$PUPMODE" = 5 ] ; then
  416.        #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  417.       #First boot (or pfix=ram):  tmpfs                         pup_xxx.sfs      5
  418.     elif [ "$PUPMODE" = 12 ] || [ PMEDIA = 'atahd' ] || [ "$PMEDIA" = usbhd ]; then
  419.       #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  420.       #Normal running puppy:      pup_save.3fs                  pup_xxx.sfs      12
  421.     elif [ "$PUPMODE" = 13 ] || [ PMEDIA = 'usbflash' ] || [ pmedia = 'ideflash' ]; then
  422.        #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  423.        #ditto, but flash drive:    tmpfs         pup_save.3fs    pup_xxx.sfs      13
  424.     elif [ "$PUPMODE" = 77 ]; then
  425.       #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  426.       #Multisession cd/dvd:       tmpfs         folders         pup_xxx.sfs      77
  427.     else #[PUPMODE=2 -> full install
  428.    
  429.     fi
  430. }
  431.  
  432. # 6. do the magic - mount the tmpfs first, and then the rest with aufs
  433. if mount -t tmpfs none $SANDBOX_TMPFS; then
  434.     if mount -t aufs -o "br:$SANDBOX_TMPFS=rw$robranches" aufs $FAKEROOT; then
  435.         # 5. record our new aufs-root-id so tools don't hack real filesystem   
  436.         SANDBOX_AUFS_ID=$(grep $FAKEROOT /proc/mounts | sed 's/.*si=/si_/; s/ .*//') #'
  437.         sed -i -e '/AUFS_ROOT_ID/ d' $FAKEROOT/etc/BOOTSTATE 2> /dev/null
  438.         echo AUFS_ROOT_ID=$SANDBOX_AUFS_ID >> $FAKEROOT/etc/BOOTSTATE
  439.        
  440.         # 7. sandbox is ready, now just need to mount other supports - pts, proc, sysfs, usb and tmp
  441.         mkdir -p $FAKEROOT/dev $FAKEROOT/sys $FAKEROOT/proc $FAKEROOT/tmp
  442.         mount -o rbind /dev $FAKEROOT/dev
  443.         mount -t sysfs none $FAKEROOT/sys
  444.         mount -t proc none $FAKEROOT/proc
  445.         mount -o bind /tmp $FAKEROOT/tmp
  446.         mkdir -p $FAKEROOT/$SANDBOX_TMPFS
  447.         mount -o bind $SANDBOX_TMPFS $FAKEROOT/$SANDBOX_TMPFS   # so we can access it within sandbox
  448.        
  449.         # 8. optional copy, to enable running sandbox-ed xwin
  450.         cp /usr/share/sandbox/* $FAKEROOT/usr/bin 2> /dev/null
  451.        
  452.         # 9. make sure we identify ourself as in sandbox - and we're good to go!
  453.         echo -e '\nexport PS1="sandbox'${SANDBOX_ID}'# "' >> $FAKEROOT/etc/shinit #fatdog 600
  454.         sed -i -e '/^PS1/ s/^.*$/PS1="sandbox'${SANDBOX_ID}'# "/' $FAKEROOT/etc/profile # earlier fatdog
  455.         echo "Starting sandbox now."
  456.         if [ $USE_NS ]; then
  457.             unshare -f -p --mount-proc=$FAKEROOT/proc chroot $FAKEROOT
  458.         else
  459.             chroot $FAKEROOT
  460.         fi
  461.  
  462.         # 10. done - clean up everything
  463.         umountall
  464.         echo "Leaving sandbox."
  465.     else
  466.         echo "Unable to mount aufs br:$SANDBOX_TMPFS=rw$robranches"
  467.         umount -l $SANDBOX_TMPFS       
  468.     fi
  469. else
  470.     echo "unable to mount tmpfs."
  471. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement