1 #!/bin/sh 2 3 # Copyright (C) 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk> 4 # 5 # This program is free software; you can redistribute it and/or modify it under 6 # the terms of the GNU General Public License as published by the Free Software 7 # Foundation; either version 3 of the License, or (at your option) any later 8 # version. 9 # 10 # This program is distributed in the hope that it will be useful, but WITHOUT 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 # details. 14 # 15 # You should have received a copy of the GNU General Public License along with 16 # this program. If not, see <http://www.gnu.org/licenses/>. 17 18 # Configuration: 19 if [ -e userinstall-defaults ]; then 20 . "$PWD/userinstall-defaults" 21 elif [ -e /etc/default/userinstall ]; then 22 . /etc/default/userinstall 23 else 24 echo "No defaults found for userinstall." 1>&2 25 exit 1 26 fi 27 28 # Root installations benefit from having the proc and sys filesystems mounted. 29 30 mount -o bind /proc "$PACKAGEROOT/proc" 31 mount -o bind /sys "$PACKAGEROOT/sys" 32 33 if [ "$1" = '--dev' ]; then 34 DEV=$1 35 shift 1 36 37 # Backup any existing device directory. 38 39 if [ ! -e "$PACKAGEROOT/dev.orig" ] && [ -e "$PACKAGEROOT/dev" ]; then 40 mv "$PACKAGEROOT/dev" "$PACKAGEROOT/dev.orig" 41 fi 42 43 # Make an empty device directory if appropriate. 44 45 if [ ! -e "$PACKAGEROOT/dev" ] || rmdir "$PACKAGEROOT/dev" ; then 46 mkdir "$PACKAGEROOT/dev" 47 mount -o bind /dev "$PACKAGEROOT/dev" 48 mount -o bind /dev/pts "$PACKAGEROOT/dev/pts" 49 else 50 echo "Devices may already be defined for the installation." 1>&2 51 fi 52 53 # Record this process's usage of the devices. 54 55 touch "$PACKAGEROOT/dev.userinstall.$$" 56 57 elif [ ! -e "$PACKAGEROOT/dev" ]; then 58 cat 1>&2 <<EOF 59 Devices are not defined for the installation. 60 To mount the host system's devices, use the --dev option. 61 EOF 62 exit 1 63 fi 64 65 # Enter the installation. 66 67 /usr/sbin/chroot "$PACKAGEROOT" $* 68 69 # Unmount the filesystems. 70 71 umount "$PACKAGEROOT/proc" 72 umount "$PACKAGEROOT/sys" 73 74 if [ "$DEV" ] ; then 75 rm "$PACKAGEROOT/dev.userinstall.$$" 76 77 for FILENAME in "$PACKAGEROOT/dev.userinstall."* ; do 78 79 # If the pattern does not expand to produce filenames, no such 80 # files are present. 81 82 if [ "$FILENAME" = "$PACKAGEROOT/dev.userinstall.*" ]; then 83 umount "$PACKAGEROOT/dev/pts" 84 umount "$PACKAGEROOT/dev" && rmdir "$PACKAGEROOT/dev" 85 if [ -e "$PACKAGEROOT/dev.orig" ] && [ ! -e "$PACKAGEROOT/dev" ]; then 86 mv "$PACKAGEROOT/dev.orig" "$PACKAGEROOT/dev" 87 fi 88 fi 89 break 90 done 91 fi