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 else 49 echo "Devices may already be defined for the installation." 1>&2 50 fi 51 52 # Record this process's usage of the devices. 53 54 touch "$PACKAGEROOT/dev.userinstall.$$" 55 56 elif [ ! -e "$PACKAGEROOT/dev" ]; then 57 cat 1>&2 <<EOF 58 Devices are not defined for the installation. 59 To mount the host system's devices, use the --dev option. 60 EOF 61 exit 1 62 fi 63 64 # Enter the installation. 65 66 /usr/sbin/chroot "$PACKAGEROOT" $* 67 68 # Unmount the filesystems. 69 70 umount "$PACKAGEROOT/proc" 71 umount "$PACKAGEROOT/sys" 72 73 if [ "$DEV" ] ; then 74 rm "$PACKAGEROOT/dev.userinstall.$$" 75 76 for FILENAME in "$PACKAGEROOT/dev.userinstall."* ; do 77 78 # If the pattern does not expand to produce filenames, no such 79 # files are present. 80 81 if [ "$FILENAME" = "$PACKAGEROOT/dev.userinstall.*" ]; then 82 umount "$PACKAGEROOT/dev" && rmdir "$PACKAGEROOT/dev" 83 if [ -e "$PACKAGEROOT/dev.orig" ] && [ ! -e "$PACKAGEROOT/dev" ]; then 84 mv "$PACKAGEROOT/dev.orig" "$PACKAGEROOT/dev" 85 fi 86 fi 87 break 88 done 89 fi