Advertisement
s243a

sandbox_s243a_debug2.sh

Jan 19th, 2020
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.45 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.  
  48. XTERM=${XTERM:-urxvt}
  49. SANDBOX_ROOT=${SANDBOX_ROOT:-/mnt/sb}
  50. 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:: -- "$@")"
  51. declare -a options2
  52. declare -a LAYER_SOURCES
  53. LAYER_SOURCE=none
  54. eval set --"$options"
  55. while [ $# -gt 0 ]; do
  56.   case "$1" in
  57.   -f|--input-file) INPUT_FILE=$2;
  58.     LAYER_SOURCE=INPUT_FILE
  59.     LAYER_SOURCES+=( input-file )
  60.     shift 2; ;;      
  61.   -o|--output-file) OUTPUT_FILE=$2; shift 2; ;;
  62.   --no-exit)
  63.     if [ $# -gt 1 ] && [[ ! "$2" = --* ]] && [ ! -z "$2" ]; then
  64.       NO_EXIT="$2"
  65.       shift 2
  66.     else
  67.       NO_EXIT=true
  68.       shift 1
  69.     fi; ;;
  70.   -p|--env-prefix) ENV_PREFIX=$2; shift 2; ;;
  71.   -m|--pmedia) PMEDIA=$2; shift 2; ;;
  72.   -d| --pdrv) PDRV=$2; shift 2; ;;
  73.   -s|--psubdir) PSUBDIR=$2;
  74.     LAYER_SOURCE=psubdir  
  75.     LAYER_SOURCES+=( psubdir )
  76.     shift 2; ;;
  77.     --maybe-psubdir) PSUBDIR=$2;
  78.     LAYER_SOURCE=maybe-psubdir  
  79.     LAYER_SOURCES+=( maybe-psubdir )
  80.     shift 2; ;;    
  81.   --distro-specs)
  82.      DISTRO_SPECS=$2;
  83.      . "$DISTRO_SPECS"
  84.      shift 2
  85.      ;;
  86.    --boot-config)
  87.        DISTRO_SPECS=$2;
  88.      . "$BOOTCONFIG"
  89.      shift 2
  90.      ;;
  91.    --union-record)  
  92.      LASTUNIONRECORD="$2";
  93.      LAYER_SOURCES+=( union-record )
  94.      shift 2; ;;
  95.    -e|--extra-sfs)
  96.      EXTRASFSLIST="$2";
  97.      LAYER_SOURCES+=( extrasfs )
  98.      shift 2; ;;
  99.   --maybe-aufs)
  100.     LAYER_SOURCE=maybe-aufs  
  101.     LAYER_SOURCES+=( maybe-aufs )
  102.     shift 1; ;;
  103.   --)
  104.     shift 1
  105.     options2+=( "$@" )
  106.     break; ;;
  107.   *)
  108.      options2+=( "$1" )
  109.      shift 1; ;;
  110.   esac
  111. done
  112.  
  113. #set -- "${options2[@]}"
  114. if [ "$LAYER_SOURCE" = none ] && [ ! -z "$PDRV" ]; then
  115.   PDRV=${PDRV:-/mnt/home}
  116.   for rec in $LASTUNIONRECORD; do
  117.     if [ -f "$PDRV/$rec" ]; then
  118.       items+="\"$PDRV/$rec\" \"$rec\""$'\n'
  119.     fi
  120.   done
  121.   if [ -z "$items" ]; then
  122.     [ -z "$DISTRO_PUPPYSFS" ] && DISTRO_PUPPYSFS=$(ls -1 /mnt/home | grep -m1 puppy_.*\.sfs$)
  123.     [ -z "$DISTRO_ZDRVSFS" ] && DISTRO_ZDRVSFS=$(ls -1 /mnt/home | grep -m1 zdrv.*\.sfs$)
  124.     [ -z "$DISTRO_FDRVSFS" ] && DISTRO_FDRVSFS=$(ls -1 /mnt/home | grep -m1 fdrv.*\.sfs$)
  125.     [ -z "$DISTRO_ADRVSFS" ] && DISTRO_ADRVSFS=$(ls -1 /mnt/home | grep -m1 fdrv.*\.sfs$)    
  126.     [ -z "$DISTRO_YDRVSFS" ] && DISTRO_YDRVSFS=$(ls -1 /mnt/home | grep -m1 fdrv.*\.sfs$)    
  127.     for rec in "$DISTRO_PUPPYSFS" "$DISTRO_ZDRVSFS" "$DISTRO_FDRVSFS" "$DISTRO_ADRVSFS" "$DISTRO_YDRVSFS"; do
  128.       items+="$PDRV/$rec" "$rec"$'\n'  
  129.     done
  130.   fi
  131.   if [ ! -z "$items" ]; then  
  132.     for rec in $EXTRASFSLIST; do
  133.       if [ -f "$PDRV/$rec" ]; then
  134.         items+="\"$PDRV/$rec\" \"$rec\" "on"\""$'\n'
  135.       fi
  136.     done
  137.   fi
  138. fi
  139. if [ -z "$items" ] && [ "$LAYER_SOURCE" = none ] ; then
  140.     LAYER_SOURCE=aufs  
  141.     LAYER_SOURCES+=( aufs )
  142. fi
  143. [ -z "$PDRV" ] && PDRV="$(realpath /mnt/home)"
  144. if [ "$(cat /proc/mounts | grep -c "$PDRV")" = 0 ]; then
  145.   PDRV_DEV="$(blkid | grep -m1 "$PDRV" | cut -d ':' -f1)"
  146.   PDRV="$(echo "$PDRV_DEV" | sed 's#^/dev/#/mnt/#')"
  147.   mount "$PDRV_DEV" "$PDRVV"
  148. fi  
  149.  
  150.  
  151. FAKEROOT=$SANDBOX_ROOT/fakeroot   # mounted chroot location of sandbox - ie, the fake root
  152. SANDBOX_TMPFS=$SANDBOX_ROOT/sandbox # mounted rw location of tmpfs used for sandbox
  153. SANDBOX_ID=
  154. TMPFILE=$(mktemp -p /tmp)
  155. # use namespaces if available
  156. #[ -e /proc/1/ns/pid ] && [ -e /proc/1/ns/mnt ] && type unshare >/dev/null && USE_NS=1
  157.  
  158.  
  159.  
  160.  
  161. # umount all if we are accidentally killed
  162. trap 'umountall' 1
  163. umountall() {
  164.     {
  165.     umount -l $FAKEROOT/$SANDBOX_TMPFS
  166.     umount -l $FAKEROOT/tmp
  167.     umount -l $FAKEROOT/proc
  168.     umount -l $FAKEROOT/sys
  169.     umount -l $FAKEROOT/dev
  170.    
  171.     umount -l $FAKEROOT
  172.     umount -l $SANDBOX_TMPFS
  173.     rmdir $FAKEROOT
  174.     rmdir $SANDBOX_TMPFS
  175.     } 2> /dev/null
  176. }
  177.  
  178. # 0.1 must be root
  179. if [ $(id -u) -ne 0 ]; then
  180.     echo "You must be root to use sandbox."
  181.     exit
  182. fi
  183.  
  184. # 0.2 cannot launch sandbox within sandbox
  185. if [ "$AUFS_ROOT_ID" != "" ] ; then
  186.     grep -q $SANDBOX_ROOT /sys/fs/aufs/$AUFS_ROOT_ID/br0 &&
  187.         echo "Cannot launch sandbox within sandbox." && exit
  188. fi
  189.  
  190. # 0.3 help
  191. case "$1" in
  192.     --help|-h)
  193.     echo "Usage: ${0##*/}"
  194.     echo "Starts an in-memory (throwaway) sandbox. Type 'exit' to leave."
  195.     exit
  196. esac
  197.  
  198. # 0.4 if not running from terminal but in Xorg, then launch via terminal
  199. ! [ -t 0 ] && [ -n "$DISPLAY" ] && exec $XTERM -e "$0" "$@"
  200. ! [ -t 0 ] && exit
  201. # 1. get aufs system-id for the root filesystem
  202. if [ -z "$AUFS_ROOT_ID" ] ; then
  203.     AUFS_ROOT_ID=$(
  204.         awk '{ if ($2 == "/" && $3 == "aufs") { match($4,/si=[0-9a-f]*/); print "si_" substr($4,RSTART+3,RLENGTH-3) } }' /proc/mounts
  205.     )
  206. fi
  207. function get_items(){
  208.  
  209.  
  210.  
  211.     items+=$(
  212.   { echo ==mount==; cat /proc/mounts;
  213.     echo ==losetup==; losetup-FULL -a;
  214.     echo ==branches==;
  215.       if [ $# -eq 0 ]; then
  216.         ls -v /sys/fs/aufs/$AUFS_ROOT_ID/br[0-9]* | xargs sed 's/=.*//';
  217.       else
  218.         if [ "$1" = "-f" ]; then
  219.           cat "$2";
  220.         elif [ "$1" = "-s" ]; then
  221.           cat <<<"$2";
  222.         fi;
  223.       fi; } | \
  224.     awk -v PDRV="$PDRV" '
  225.    function mount(MNT_PT,MNT_PATH){
  226.      system("mkdir -p " MNT_PT)
  227.      system("mount " MNT_PATH " " MNT_PT " 2>/dev/null")
  228.    }
  229.    function mount_if_valid(MNT_PT,MNT_PATH,PROOT,PDRV                  ,F_MNT_PATH,D_MNT_PATH){
  230.          if (system("[ -f " MNT_PATH " ] && exit 0 || exit 1") == 0){
  231.            F_MNT_PATH=MNT_PATH
  232.          } else if (system("[ -f " PROOT "/" MNT_PATH " ] && exit 0 || exit 1") == 0){
  233.           F_MNT_PATH=PROOT "/" MNT_PATH
  234.         } else if (system("[ -f " PDRV "/" PROOT "/" MNT_PATH " ]  && exit 0 || exit 1") == 0){
  235.           F_MNT_PATH=PROOT "/" MNT_PATH
  236.          } else if (system("[ -d " MNT_PATH " ] && exit 0 || exit 1") == 0){
  237.            D_MNT_PATH=MNT_PATH
  238.         } else if (system("[ -d " PROOT "/" MNT_PATH " ]  && exit 0 || exit 1") == 0){
  239.           D_MNT_PATH=PROOT "/" MNT_PATH
  240.         } else if (system("[ -d " PDRV "/" PROOT "/" MNT_PATH " ]  && exit 0 || exit 1") == 0 ){
  241.           D_MNT_PATH=PROOT "/" MNT_PATH
  242.         } else {
  243.           F_MNT_PATH=""
  244.           D_MNT_PATH=""
  245.        }
  246.        if (length(F_MNT_PATH)>0){
  247.            mount(MNT_PT,F_MNT_PATH)
  248.            if (system("cat /proc/mounts | grep -c -m1 " MNT_PT) > 0){
  249.              result=sucess }
  250.            else {
  251.              result=fail }
  252.        }
  253.        else if (length(D_MNT_PATH)>0) {
  254.           result=directory
  255.        } else {
  256.          result=fail
  257.        }
  258.        return result    
  259.    }
  260.    BEGIN {
  261.      FPAT = "'"([^ ]+)|(\\\\'[^\\\\']+\\\\')"'"
  262.    }
  263.    /==mount==/ { mode=1 }
  264.    /==losetup==/ { mode=2 }
  265.    /==branches==/ { mode=3 }
  266.    {
  267.    if (mode == 1) {
  268.      # get list of mount points, types, and devices - index is $3 (mount points)
  269.      mountdev[$2]=$1
  270.      mounttypes[$2]=$3
  271.    } else if (mode == 2) {
  272.      # get list of loop devices and files - index is $1 (loop devs)
  273.      sub(/:/,"",$1)
  274.      sub(/.*\//,"",$3); sub(/)/,"",$3)
  275.      loopdev[$1]=$3
  276.    } else if (mode == 3) {
  277.      # map mount types to loop files if mount devices is a loop
  278.      for (m in mountdev) {
  279.        if ( loopdev[mountdev[m]] != "" ) mounttypes[m]=loopdev[mountdev[m]]
  280.      }
  281.      # for (m in mountdev) print m " on " mountdev[m] " type " mounttypes[m]
  282.      mode=4
  283.    } else if (mode==4) {
  284.      # print the branches and its mappings
  285.       system("echo '"'"'AWK (mode==4):" $0 "'"'"' >/dev/stderr")      
  286.      if ($1 in mounttypes){
  287.        print $1, mounttypes[$1], "on"
  288.      }
  289.      else {
  290.  
  291.        MNT_PT=$1
  292.        MNT_PATH=$2
  293.        if (length(MNT_PATH)==0){
  294.          MNT_PATH=$1
  295.        }
  296.        if (length(MNT_PATH) ==0){
  297.           next
  298.        }
  299.        mnt_status=mount_if_valid(MNT_PT,MNT_PATH,PDRV)
  300.        if(mnt_status == "fail"){
  301.            next
  302.        }
  303.        BNAME=MNT_PATH
  304.        sub(/.*\//,"",BNAME)    
  305.        if (NF>2){
  306.          STATE=$3
  307.        } else {
  308.          STATE="on"
  309.       }
  310.       if ("$STATE" !~ /(on|off)/){
  311.         STATE="on"
  312.       }
  313.       print MNT_PT, BNAME, STATE
  314.    }
  315.    }
  316.  }
  317.  '
  318.   )
  319.   echo "$items"
  320. }
  321. function mount_fn(){
  322.     local MNT_PT=''
  323.     FULL_PATH=$(realpath "$1")
  324.     FNAME="$(echo "$FULL_PATH" | sed 's#/#+#g' | sed 's#\.#+#g')"
  325.  
  326.     if [ ! -z "$2" ]; then
  327.       MNT_PT="$(cat /proc/mounts | grep "$2" | grep -m1 $FNAME | cut -d ' ' -f2 )"              
  328.       [ -z "$MNT_PT" ] && MNT_PT="$(cat /proc/mounts | grep -m1 "$2" | cut -d ' ' -f2 )"
  329.       [ -z "$MNT_PT" ] && MNT_PT="$(cat /proc/mounts | grep -m1 $FNAME | cut -d ' ' -f2 )"            
  330.    else
  331.        MNT_PT="$(cat /proc/mounts | grep -m1 $FNAME | cut -d ' ' -f2)"    
  332.    fi
  333.     if [ -z "${MNT_PT}" ]; then  
  334.       case "FNAME" in
  335.       *.iso)
  336.          DIR_PATH=/media; ;;
  337.       *)
  338.         DIR_PATH=/mnt; ;;
  339.       esac
  340.       if [ -z "$2" ]; then
  341.         MNT_PT="$2"
  342.       fi
  343.       [ -z "$MNT_PT" ] && MNT_PT="${DIR_PATH}/$FNAME"
  344.       mkdir -p "${MNT_PT}"
  345.       mount $FULL_PATH "${MNT_PT}"    
  346.       MNT_PT="$(cat /proc/mounts | grep -m1 $FNAME | cut -d ' ' -f2 )"          
  347.    fi
  348.   echo  "${MNT_PT}"
  349. }
  350. if [ -z "$items" ]; then
  351.  
  352.   for item_source in "${LAYER_SOURCES[@]}"; do
  353.   # 2. get branches, then map branches to mount types or loop devices
  354.     case "$item_source" in
  355.     input-file)
  356.   items+="$(get_items -f "$INPUT_FILE")"; ;;
  357.     union-record)
  358.        new_items=''
  359.        for rec in $LASTUNIONRECORD; do
  360.         if [ -f "$rec" ]; then
  361.           MNT_PT="$(mount_fm "$rec" )"
  362.           new_items+="\"$MNT_PT\" \"$rec\" \"on\""$'\n'
  363.         elif [ -f "$PDRV/$rec" ]; then
  364.           MNT_PT="$(mount_fm "$PDRV/$rec" )"
  365.           new_items+="\"$MNT_PT\", \"$PDRV/$rec\", \"on\""$'\n'
  366.         fi
  367.       done
  368.       items+="$(get_items -f <<<"$new_items")"
  369.       ;;
  370.     extra-sfs)
  371.        new_items=''
  372.        for rec in $EXTRASFSLIST; do
  373.        if [ -f "$rec" ]; then
  374.           MNT_PT="$(mount_fm "$rec" )"
  375.           new_items+="\"$MNT_PT\" \"$rec\" \"on\""$'\n'
  376.         elif [ -f "$PDRV/$rec" ]; then
  377.           MNT_PT="$(mount_fm "$PDRV/$rec" )"
  378.           new_items+="\"$MNT_PT\" \"$PDRV/$rec\" \"on\""$'\n'
  379.         fi
  380.       done
  381.       ;;
  382.     layer=*)
  383.       item_path="$(echo ${litem_source#*=})"
  384.       if [ -f "$item_path" ]; then
  385.         MNT_PT="$(mount_fm "$item_path" )"
  386.       elif [ -d "$item_path" ]; then  
  387.         MNT_PT="$item_path" #This isn't really a mount poing
  388.       elif [ ! -d  "$item_path" ]; then
  389.         echo "Warning  cannot mount $item_path"
  390.         continue
  391.       fi
  392.       items+="\"$MNT_PT\" \"$item_path\" \"on\""$'\n'
  393.       ;;
  394.     psubdir|maybe-psubdir)
  395.       if [ "$item_source" = "maybe-psubdir" ]; then
  396.          [ ! -z "$items" ] && continue
  397.       fi
  398.       [ -z "$DISTRO_PUPPYSFS" ] && DISTRO_PUPPYSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 puppy_.*\.sfs$)
  399.       [ -z "$DISTRO_ZDRVSFS" ] && DISTRO_ZDRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 zdrv.*\.sfs$)
  400.       [ -z "$DISTRO_FDRVSFS" ] && DISTRO_FDRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 fdrv.*\.sfs$)
  401.       [ -z "$DISTRO_ADRVSFS" ] && DISTRO_ADRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 fdrv.*\.sfs$)    
  402.       [ -z "$DISTRO_YDRVSFS" ] && DISTRO_YDRVSFS=$(ls -1 "${PDRV}/${PSUBDIR}" | grep -m1 fdrv.*\.sfs$)    
  403.       new_items=""
  404.       for rec in "$DISTRO_PUPPYSFS" "$DISTRO_ZDRVSFS" "$DISTRO_FDRVSFS" "$DISTRO_ADRVSFS" "$DISTRO_YDRVSFS"; do
  405.         #MNT_PATH="${rec}"
  406.         #[ ! -z "${PSUBDIR}" ] && MNT_PATH=${PSUBDIR}/${MNT_PATH}
  407.         MNT_PATH="${PDRV}/${PSUBDIR}/$rec"
  408.         MNT_PT="$(mount_fn "$MNT_PATH")"
  409.         new_items+="\"${MNT_PT}\" \"$rec\" "'"on"'$'\n'  
  410.       done
  411.       export new_items="$new_items"
  412.       echo "$new_items"
  413.       items+="$(get_items -s "$new_items")"
  414.       ;;      
  415.     aufs)
  416.       items+="$(get_items)" ; ;;  
  417.     maybe-aufs)
  418.        [  -z "$items" ] && items+="$(get_items)"; ;;  
  419.   esac
  420.   items="$(echo "$items" | sed -n '/^\s*\(on\)\?\s*$/! p' | sed -n '/^Error: Expected on/! p' | sed -n '/^Use --help on/! p')"
  421.   done
  422. fi
  423. # 3. Ask user to choose the SFS
  424.  
  425. dialog --single-quoted --output-separator ", " --backtitle "tmpfs sandbox" --title "sandbox config" \
  426.     --checklist "Choose which SFS you want to use" 0 0 0 $items 2> $TMPFILE
  427. chosen="$(cat $TMPFILE)"
  428.  
  429. clear
  430. if [ -z "$chosen" ]; then
  431.     echo "Cancelled or no SFS is chosen - exiting."
  432.     exit 1
  433. fi
  434.  
  435. if [ ! -z "$OUTPUT_FILE" ]; then
  436.   cp "$TMPFILE" "$OUTPUT_FILE"
  437.   if [ ! "$NO_EXIT" = true ]; then
  438.     exit 0
  439.   fi
  440. fi
  441. # 0.5 is this the first sandbox? If not, then create another name for mountpoints
  442. if grep -q $FAKEROOT /proc/mounts; then
  443.     FAKEROOT=$(mktemp -d -p $SANDBOX_ROOT ${FAKEROOT##*/}.XXXXXXX)
  444.     SANDBOX_ID=".${FAKEROOT##*.}"
  445.     SANDBOX_TMPFS=$SANDBOX_ROOT/${SANDBOX_TMPFS##*/}${SANDBOX_ID}
  446.     rmdir $FAKEROOT
  447. fi
  448.  
  449.  
  450.  
  451. # 4. convert chosen SFS to robranches
  452. robranches=""
  453. for a in $(cat $TMPFILE) ; do
  454.     a="$(echo "$a" | sed 's/,$//')" # | sed 's/^'//' | sed 's/'$//' )"
  455.     robranches="$robranches:$a=ro"
  456. done
  457. rm $TMPFILE
  458.  
  459. # 5. make the mountpoints if not exist  yet
  460. mkdir -p $FAKEROOT $SANDBOX_TMPFS
  461.  
  462. # 6. do the magic - mount the tmpfs first, and then the rest with aufs
  463. if mount -t tmpfs none $SANDBOX_TMPFS; then
  464.     if mount -t aufs -o "br:$SANDBOX_TMPFS=rw$robranches" aufs $FAKEROOT; then
  465.         # 5. record our new aufs-root-id so tools don't hack real filesystem   
  466.         SANDBOX_AUFS_ID=$(grep $FAKEROOT /proc/mounts | sed 's/.*si=/si_/; s/ .*//') #'
  467.         sed -i -e '/AUFS_ROOT_ID/ d' $FAKEROOT/etc/BOOTSTATE 2> /dev/null
  468.         echo AUFS_ROOT_ID=$SANDBOX_AUFS_ID >> $FAKEROOT/etc/BOOTSTATE
  469.        
  470.         # 7. sandbox is ready, now just need to mount other supports - pts, proc, sysfs, usb and tmp
  471.         mkdir -p $FAKEROOT/dev $FAKEROOT/sys $FAKEROOT/proc $FAKEROOT/tmp
  472.         mount -o rbind /dev $FAKEROOT/dev
  473.         mount -t sysfs none $FAKEROOT/sys
  474.         mount -t proc none $FAKEROOT/proc
  475.         mount -o bind /tmp $FAKEROOT/tmp
  476.         mkdir -p $FAKEROOT/$SANDBOX_TMPFS
  477.         mount -o bind $SANDBOX_TMPFS $FAKEROOT/$SANDBOX_TMPFS   # so we can access it within sandbox
  478.        
  479.         # 8. optional copy, to enable running sandbox-ed xwin
  480.         cp /usr/share/sandbox/* $FAKEROOT/usr/bin 2> /dev/null
  481.        
  482.         # 9. make sure we identify ourself as in sandbox - and we're good to go!
  483.         echo -e '\nexport PS1="sandbox'${SANDBOX_ID}'# "' >> $FAKEROOT/etc/shinit #fatdog 600
  484.         sed -i -e '/^PS1/ s/^.*$/PS1="sandbox'${SANDBOX_ID}'# "/' $FAKEROOT/etc/profile # earlier fatdog
  485.         echo "Starting sandbox now."
  486.         if [ $USE_NS ]; then
  487.             unshare -f -p --mount-proc=$FAKEROOT/proc chroot $FAKEROOT
  488.         else
  489.             chroot $FAKEROOT
  490.         fi
  491.  
  492.         # 10. done - clean up everything
  493.         umountall
  494.         echo "Leaving sandbox."
  495.     else
  496.         echo "Unable to mount aufs br:$SANDBOX_TMPFS=rw$robranches"
  497.         umount -l $SANDBOX_TMPFS       
  498.     fi
  499. else
  500.     echo "unable to mount tmpfs."
  501. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement