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