Guest User

Untitled

a guest
Sep 10th, 2011
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ROOTFS=/tmp/jail
  4.  
  5. # ensure that the TC initrd file is available
  6. mount | grep -qF '/dev/hdc' || mount /dev/hdc
  7. [ -f /mnt/hdc/boot/tinycore.gz ] || ! echo "can not find initrd file" || exit 1
  8.  
  9. # remove all traces of a previous run
  10. MOUNTS=$(mount | grep -F " on ${ROOTFS}/" | sed -e 's#.* on ##' -e 's# .*##')
  11. [ -z "$MOUNTS" ] || echo "$MOUNTS" | xargs -n 1 umount \
  12. || ! echo "umount failed" || exit 3
  13. sudo rm -rf $ROOTFS 2> /dev/null || ! echo "rm $ROOTFS failed" || exit 4
  14.  
  15. # prepare the "jail" (step 1): extract initrd
  16. mkdir -p $ROOTFS
  17. cd $ROOTFS
  18. zcat /mnt/hdc/boot/tinycore.gz | sudo cpio -idum > /dev/null
  19.  
  20. # prepare the "jail" (step 2): execute a subset of /etc/init.d/tc-config + more
  21. for D in usr/local/tce.icons usr/local/tce.installed usr/local/tce.menu \
  22. tmp/tce tmp/tcloop ; do
  23. [ -d "$D" ] || sudo mkdir "$D"
  24. sudo chgrp staff "$D"
  25. sudo chmod g+w "$D"
  26. done
  27. echo '/tmp/tce' > opt/.tce_dir
  28. # ensure the presence of ~/.Xauthority
  29. [ -f $HOME/.Xauthority ] && cp -p $HOME/.Xauthority ${HOME#/}
  30.  
  31. # prepare the "jail" (step 3): mount the required file systems
  32. sudo mount -o bind /proc $ROOTFS/proc
  33. sudo mount -o bind /dev/pts $ROOTFS/dev/pts
  34. sudo mount -o bind /tmp $ROOTFS/tmp
  35.  
  36. echo "you should now be able to execute: sudo chroot $ROOTFS su $USER"
Advertisement
Add Comment
Please, Sign In to add comment