paul@32 | 1 | #!/bin/sh |
paul@32 | 2 | |
paul@63 | 3 | # Copyright (C) 2011, 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@32 | 18 | # Configuration: |
paul@32 | 19 | if [ -e userinstall-defaults-uml ]; then |
paul@32 | 20 | . "$PWD/userinstall-defaults-uml" |
paul@32 | 21 | elif [ -e /etc/default/userinstall-uml ]; then |
paul@32 | 22 | . /etc/default/userinstall-uml |
paul@32 | 23 | else |
paul@32 | 24 | echo "No defaults found for userinstall (UML)." 1>&2 |
paul@32 | 25 | exit 1 |
paul@32 | 26 | fi |
paul@32 | 27 | |
paul@32 | 28 | if [ ! "$1" ]; then |
paul@32 | 29 | echo "A program needs to be given as an argument to this script." 1>&2 |
paul@32 | 30 | exit 1 |
paul@32 | 31 | fi |
paul@32 | 32 | |
paul@32 | 33 | COMMAND="$1" |
paul@32 | 34 | shift 1 |
paul@32 | 35 | |
paul@32 | 36 | echo "Accessing the image..." 1>&2 |
paul@32 | 37 | if [ ! -e "$IMAGEDIR" ]; then |
paul@32 | 38 | mkdir "$IMAGEDIR" |
paul@32 | 39 | fi |
paul@71 | 40 | |
paul@71 | 41 | if ! sudo mount -o loop "$IMAGE" "$IMAGEDIR" ; then |
paul@71 | 42 | echo "Could not mount the image." 1>&2 |
paul@71 | 43 | exit 1 |
paul@71 | 44 | fi |
paul@32 | 45 | |
paul@32 | 46 | echo "Performing the requested activity..." 1>&2 |
paul@32 | 47 | "$COMMAND" $* |
paul@32 | 48 | |
paul@32 | 49 | echo "Unmounting the image..." 1>&2 |
paul@32 | 50 | sudo umount "$IMAGEDIR" |
paul@32 | 51 | rmdir "$IMAGEDIR" |