1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/qi-emdebian-install Wed Sep 05 00:25:27 2012 +0200
1.3 @@ -0,0 +1,73 @@
1.4 +#!/bin/sh
1.5 +
1.6 +# Copyright (C) 2012 Paul Boddie <paul@boddie.org.uk>
1.7 +#
1.8 +# This program is free software; you can redistribute it and/or modify it under
1.9 +# the terms of the GNU General Public License as published by the Free Software
1.10 +# Foundation; either version 3 of the License, or (at your option) any later
1.11 +# version.
1.12 +#
1.13 +# This program is distributed in the hope that it will be useful, but WITHOUT
1.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.15 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.16 +# details.
1.17 +#
1.18 +# You should have received a copy of the GNU General Public License along with
1.19 +# this program. If not, see <http://www.gnu.org/licenses/>.
1.20 +
1.21 +PROGNAME=`basename $0`
1.22 +
1.23 +if [ ! "$1" ] || [ "$1" = '--help' ]; then
1.24 + cat 1>&2 <<EOF
1.25 +Usage: $PROGNAME <root filesystem path> <device path> --mkfs | --update
1.26 +
1.27 +Example: $PROGNAME rootfs /dev/sdb1 --mkfs
1.28 +
1.29 +This program copies the contents of the specified root filesystem directory
1.30 +onto the indicated device.
1.31 +
1.32 +If --mkfs is specified, a new filesystem is created on the device, erasing any
1.33 +existing filesystem. Then, the copying of the root filesystem is performed.
1.34 +
1.35 +If --update is specified, any existing filesystem is preserved on the device.
1.36 +
1.37 +Be very careful using this program. Please verify first that the specified
1.38 +device really does refer to a medium that can be overwritten. If in doubt, use
1.39 +the dmesg tool to check the kernel log, and use the fdisk tool to list any
1.40 +partitions on the medium and the devices these correspond to.
1.41 +EOF
1.42 + exit 1
1.43 +fi
1.44 +
1.45 +ROOTDIR=$1
1.46 +DEVICE=$2
1.47 +OPTION=$3
1.48 +
1.49 +if [ ! "$DEVICE" ]; then
1.50 + echo "$PROGNAME: Need a device to store the system image." 1>&2
1.51 + exit 1
1.52 +fi
1.53 +
1.54 +if [ "$OPTION" = '--mkfs' ]; then
1.55 + /sbin/mkfs.ext2 "$DEVICE"
1.56 +elif [ "$OPTION" = '--update' ]; then
1.57 + echo "$PROGNAME: Not erasing the media using mkfs." 1>&2
1.58 +else
1.59 + echo "$PROGNAME: Please specify --mkfs or --update." 1>&2
1.60 + exit 1
1.61 +fi
1.62 +
1.63 +MEDIADIR="/media/`basename $DEVICE`"
1.64 +
1.65 +if [ ! -e "$MEDIADIR" ]; then
1.66 + mkdir "$MEDIADIR"
1.67 +fi
1.68 +
1.69 +echo "$PROGNAME: Mounting $DEVICE at $MEDIADIR..." 1>&2
1.70 +mount "$DEVICE" "$MEDIADIR"
1.71 +
1.72 +echo "$PROGNAME: Copying system from $ROOTDIR..." 1>&2
1.73 +cp -a $ROOTDIR/* "$MEDIADIR/"
1.74 +
1.75 +echo "$PROGNAME: Unmounting $MEDIADIR..." 1>&2
1.76 +umount "$MEDIADIR"