1 #!/bin/sh 2 3 # Configuration: 4 if [ -e userinstall-defaults ]; then 5 . "$PWD/userinstall-defaults" 6 elif [ -e /etc/default/userinstall ]; then 7 . /etc/default/userinstall 8 else 9 echo "No defaults found for userinstall." 1>&2 10 exit 1 11 fi 12 13 # Root installations benefit from having the proc and sys filesystems mounted. 14 15 mount -o bind /proc "$PACKAGEROOT/proc" 16 mount -o bind /sys "$PACKAGEROOT/sys" 17 18 if [ "$1" = '--dev' ]; then 19 DEV=$1 20 shift 1 21 22 # Backup any existing device directory. 23 24 if [ ! -e "$PACKAGEROOT/dev.orig" ] && [ -e "$PACKAGEROOT/dev" ]; then 25 mv "$PACKAGEROOT/dev" "$PACKAGEROOT/dev.orig" 26 fi 27 28 # Make an empty device directory if appropriate. 29 30 if [ ! -e "$PACKAGEROOT/dev" ] || rmdir "$PACKAGEROOT/dev" ; then 31 mkdir "$PACKAGEROOT/dev" 32 mount -o bind /dev "$PACKAGEROOT/dev" 33 else 34 echo "Devices may already be defined for the installation." 1>&2 35 fi 36 37 # Record this process's usage of the devices. 38 39 touch "$PACKAGEROOT/dev.userinstall.$$" 40 41 elif [ ! -e "$PACKAGEROOT/dev" ]; then 42 cat 1>&2 <<EOF 43 Devices are not defined for the installation. 44 To mount the host system's devices, use the --dev option. 45 EOF 46 exit 1 47 fi 48 49 # Enter the installation. 50 51 chroot "$PACKAGEROOT" $* 52 53 # Unmount the filesystems. 54 55 umount "$PACKAGEROOT/proc" 56 umount "$PACKAGEROOT/sys" 57 58 if [ "$DEV" ] ; then 59 rm "$PACKAGEROOT/dev.userinstall.$$" 60 61 for FILENAME in "$PACKAGEROOT/dev.userinstall."* ; do 62 63 # If the pattern does not expand to produce filenames, no such 64 # files are present. 65 66 if [ "$FILENAME" = "$PACKAGEROOT/dev.userinstall.*" ]; then 67 umount "$PACKAGEROOT/dev" && rmdir "$PACKAGEROOT/dev" 68 if [ -e "$PACKAGEROOT/dev.orig" ] && [ ! -e "$PACKAGEROOT/dev" ]; then 69 mv "$PACKAGEROOT/dev.orig" "$PACKAGEROOT/dev" 70 fi 71 fi 72 break 73 done 74 fi