paul@31 | 1 | #!/bin/sh |
paul@31 | 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@31 | 18 | # Configuration: |
paul@31 | 19 | if [ -e userinstall-defaults-uml ]; then |
paul@31 | 20 | . "$PWD/userinstall-defaults-uml" |
paul@31 | 21 | elif [ -e /etc/default/userinstall-uml ]; then |
paul@31 | 22 | . /etc/default/userinstall-uml |
paul@31 | 23 | else |
paul@31 | 24 | echo "No defaults found for userinstall (UML)." 1>&2 |
paul@31 | 25 | exit 1 |
paul@31 | 26 | fi |
paul@31 | 27 | |
paul@34 | 28 | if [ "$1" = '--help' ]; then |
paul@65 | 29 | echo "Usage: `basename $0` [ --root ] [ --no-fs ] [ --do-not-populate ] <root image size in GB> <swap image size in MB>" 1>&2 |
paul@34 | 30 | exit 1 |
paul@34 | 31 | fi |
paul@34 | 32 | |
paul@34 | 33 | if [ "$1" = '--root' ]; then |
paul@34 | 34 | shift 1 |
paul@34 | 35 | AS_USER="sudo" |
paul@34 | 36 | else |
paul@34 | 37 | AS_USER= |
paul@34 | 38 | fi |
paul@34 | 39 | |
paul@65 | 40 | if [ "$1" = '--no-fs' ]; then |
paul@65 | 41 | shift 1 |
paul@65 | 42 | NO_FS=$1 |
paul@65 | 43 | else |
paul@65 | 44 | NO_FS= |
paul@65 | 45 | fi |
paul@65 | 46 | |
paul@40 | 47 | if [ "$1" = '--do-not-populate' ]; then |
paul@40 | 48 | shift 1 |
paul@40 | 49 | DO_NOT_POPULATE=$1 |
paul@40 | 50 | else |
paul@40 | 51 | DO_NOT_POPULATE= |
paul@40 | 52 | fi |
paul@40 | 53 | |
paul@31 | 54 | if [ ! "$1" ]; then |
paul@34 | 55 | echo "Need a root image size in GB." 1>&2 |
paul@34 | 56 | exit 1 |
paul@31 | 57 | fi |
paul@31 | 58 | |
paul@31 | 59 | if [ ! "$2" ]; then |
paul@34 | 60 | echo "Need a swap image size in MB." 1>&2 |
paul@34 | 61 | exit 1 |
paul@31 | 62 | fi |
paul@31 | 63 | |
paul@31 | 64 | IMAGESIZE=$1 |
paul@31 | 65 | SWAPSIZE=$2 |
paul@31 | 66 | THISDIR=`dirname "$0"` |
paul@31 | 67 | |
paul@65 | 68 | if [ ! -e "$PACKAGEROOT" ] && [ ! "$NO_FS" ] && [ ! "$DO_NOT_POPULATE" ]; then |
paul@34 | 69 | echo "A package root must first be made using user-setup." 1>&2 |
paul@34 | 70 | exit 1 |
paul@31 | 71 | fi |
paul@31 | 72 | |
paul@31 | 73 | if [ ! "$IMAGEDIR" ]; then |
paul@34 | 74 | echo "An image directory must be defined." 1>&2 |
paul@34 | 75 | exit 1 |
paul@31 | 76 | fi |
paul@31 | 77 | |
paul@65 | 78 | # Make image files. |
paul@65 | 79 | |
paul@31 | 80 | echo "Making the filesystem with size ${IMAGESIZE}GB..." |
paul@62 | 81 | if dd if=/dev/zero of=$IMAGE bs=1024 count=1 seek=$(($IMAGESIZE*1024*1024-1024)) ; then |
paul@65 | 82 | |
paul@65 | 83 | # Make a filesystem unless otherwise requested. |
paul@65 | 84 | |
paul@65 | 85 | if [ ! "$NO_FS" ]; then |
paul@70 | 86 | /sbin/mkfs.ext3 $IMAGE |
paul@65 | 87 | fi |
paul@62 | 88 | else |
paul@62 | 89 | cat 1>&2 <<EOF |
paul@62 | 90 | Unable to create an image file for the root partition. |
paul@62 | 91 | See the error messages above for more information. |
paul@62 | 92 | EOF |
paul@62 | 93 | exit 1 |
paul@62 | 94 | fi |
paul@31 | 95 | |
paul@31 | 96 | echo "Making the swap file with size ${SWAPSIZE}MB..." |
paul@62 | 97 | if ! dd if=/dev/zero of=$SWAPIMAGE bs=1M count=$SWAPSIZE ; then |
paul@62 | 98 | cat 1>&2 <<EOF |
paul@62 | 99 | Unable to create an image file for the swap partition. |
paul@62 | 100 | See the error messages above for more information. |
paul@62 | 101 | EOF |
paul@62 | 102 | exit 1 |
paul@62 | 103 | fi |
paul@31 | 104 | |
paul@32 | 105 | # Image population activities. |
paul@31 | 106 | |
paul@65 | 107 | if [ ! "$DO_NOT_POPULATE" ] && [ ! "$NO_FS" ]; then |
paul@59 | 108 | $AS_USER "$THISDIR/uml-access-image" "$THISDIR/uml-populate-image" |
paul@59 | 109 | $AS_USER "$THISDIR/uml-access-image" "$THISDIR/uml-make-network" |
paul@40 | 110 | fi |