userinstall

Annotated uml-make-image

59:82028abe0236
2012-11-04 Paul Boddie Fixed expansion of AS_USER.
paul@31 1
#!/bin/sh
paul@31 2
paul@31 3
# Configuration:
paul@31 4
if [ -e userinstall-defaults-uml ]; then
paul@31 5
        . "$PWD/userinstall-defaults-uml"
paul@31 6
elif [ -e /etc/default/userinstall-uml ]; then
paul@31 7
        . /etc/default/userinstall-uml
paul@31 8
else
paul@31 9
        echo "No defaults found for userinstall (UML)." 1>&2
paul@31 10
        exit 1
paul@31 11
fi
paul@31 12
paul@34 13
if [ "$1" = '--help' ]; then
paul@40 14
        echo "Usage: `basename $0` [ --root ] [ --do-not-populate ] <root image size in GB> <swap image size in MB>" 1>&2
paul@34 15
        exit 1
paul@34 16
fi
paul@34 17
paul@34 18
if [ "$1" = '--root' ]; then
paul@34 19
        shift 1
paul@34 20
        AS_USER="sudo"
paul@34 21
else
paul@34 22
        AS_USER=
paul@34 23
fi
paul@34 24
paul@40 25
if [ "$1" = '--do-not-populate' ]; then
paul@40 26
        shift 1
paul@40 27
        DO_NOT_POPULATE=$1
paul@40 28
else
paul@40 29
        DO_NOT_POPULATE=
paul@40 30
fi
paul@40 31
paul@31 32
if [ ! "$1" ]; then
paul@34 33
        echo "Need a root image size in GB." 1>&2
paul@34 34
        exit 1
paul@31 35
fi
paul@31 36
paul@31 37
if [ ! "$2" ]; then
paul@34 38
        echo "Need a swap image size in MB." 1>&2
paul@34 39
        exit 1
paul@31 40
fi
paul@31 41
paul@31 42
IMAGESIZE=$1
paul@31 43
SWAPSIZE=$2
paul@31 44
THISDIR=`dirname "$0"`
paul@31 45
paul@40 46
if [ ! -e "$PACKAGEROOT" ] && [ ! "$DO_NOT_POPULATE" ]; then
paul@34 47
        echo "A package root must first be made using user-setup." 1>&2
paul@34 48
        exit 1
paul@31 49
fi
paul@31 50
paul@31 51
if [ ! "$IMAGEDIR" ]; then
paul@34 52
        echo "An image directory must be defined." 1>&2
paul@34 53
        exit 1
paul@31 54
fi
paul@31 55
paul@31 56
echo "Making the filesystem with size ${IMAGESIZE}GB..."
paul@31 57
dd if=/dev/zero of=$IMAGE bs=1024 count=1 seek=$(($IMAGESIZE*1024*1024-1024))
paul@31 58
mkfs.ext3 $IMAGE
paul@31 59
paul@31 60
echo "Making the swap file with size ${SWAPSIZE}MB..."
paul@31 61
dd if=/dev/zero of=$SWAPIMAGE bs=1M count=$SWAPSIZE
paul@31 62
paul@32 63
# Image population activities.
paul@31 64
paul@40 65
if [ ! "$DO_NOT_POPULATE" ]; then
paul@59 66
        $AS_USER "$THISDIR/uml-access-image" "$THISDIR/uml-populate-image"
paul@59 67
        $AS_USER "$THISDIR/uml-access-image" "$THISDIR/uml-make-network"
paul@40 68
fi