~pwlars/ubuntu-mobile/mobile-scripts-aufs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
#
# script to grow vfat imagefiles
# needs syslinux and mtools installed so no loop mounting
# and no root access is required
#
# Requires: mtools, syslinux
#
# Copyright 2008 Canoical LTD.
# Author: Oliver Grawert <ogra@ubuntu.com>
#
# Lincensed under terms and conditions of the GPL v2
#
# TODO: * add more input error checking (check if image is a real image,
#         make sure stripped growth value is numeric)
#       * check filesystem space before proceeding

if [ -z $2 ];then
    echo "usage: $0 <path to existing imagefile> <amount of megabytes to grow image by>"
    exit 0
fi

TDIR="$(mktemp -d)"
OLDIMAGE=$1
NEWIMAGE="$TDIR/$1.new"
GROWTH=$(echo $2|tr -d [A-Z] |tr -d [a-z])

export MTOOLSRC="$(tempfile)";trap "rm -f $MTOOLSRC" EXIT HUP INT QUIT TERM;

cat > $MTOOLSRC <<EOF
drive a:
    file="${OLDIMAGE}" use_xdf=1
drive b:
    file="${NEWIMAGE}" use_xdf=1
EOF

NEWSIZE=$(($(ls -lh $1 |cut -d' ' -f5|tr -d [A-Z])+$GROWTH))

dd if=/dev/zero of=$NEWIMAGE bs=1M count=$NEWSIZE >/dev/null 2>&1
mkdosfs $NEWIMAGE >/dev/null 2>&1

mcopy -s a: b: >/dev/null 2>&1
mv $NEWIMAGE $OLDIMAGE

syslinux $OLDIMAGE

rm -rf $TDIR