-
Notifications
You must be signed in to change notification settings - Fork 10
/
makeimage.sh
executable file
·108 lines (84 loc) · 2.91 KB
/
makeimage.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
#
# ScreenInvader - A shared media experience. Instant and seamless.
# Copyright (C) 2012 Amir Hassan <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
dir="`dirname $0`"
MAKEIMAGE_DIR="`cd $dir; pwd`"
export BOOTSTRAP_LOG="makeimage.log"
source "$MAKEIMAGE_DIR/.functions.sh"
function absDir() {
dir="`dirname $1`"
absdir="`cd $dir; pwd`"
echo $absdir
}
function absPath() {
dir="`dirname $1`"
base="`basename $1`"
absdir="`cd $dir; pwd`"
echo $absdir/$base
}
function printUsage() {
cat 1>&2 <<EOUSAGE
makeimage.sh - Prepare a disk image for installation of the ScreenInvader system.
Usage: $0 [-z][-c <chrootdir>][-s <sizeInM>] <target>
<target> the target location for the disk image
Options:
-z write zeroes to the device before creating the partition
-s <sizeInM> overwrite the default (= 500MB) disk image size.
-c <chrootdir> after creating the disk image mount it in the specified directory
EOUSAGE
exit 1
}
WRITE_ZEROES=
IMAGE_SIZE=500
IMAGE_FILE=
CHROOT_DIR=
while getopts 'zs:c:' c
do
case $c in
z) WRITE_ZEROES="YES";;
s) IMAGE_SIZE="$OPTARG";;
c) CHROOT_DIR="$OPTARG";;
\?) printUsage;;
esac
done
shift $(($OPTIND - 1))
[ $# -ne 1 ] && printUsage
IMAGE_FILE="`absPath $1`"
LOOPBACK_DEVICE=`losetup -f`
MAKESTICK_OPTS="-s $IMAGE_SIZE"
[ -n "$WRITE_ZEROES" ] && MAKESTICK_OPTS="$MAKESTICK_OPTS -z"
[ -n "$CHROOT_DIR" ] && check "Mountpoint $CHROOT_DIR is unused" \
"! mountpoint -q $CHROOT_DIR"
check "Creating disk image file $IMAGE_FILE of size $IMAGE_SIZE MB" \
"dd if=/dev/zero of=$IMAGE_FILE bs=1M count=1 seek=$[ $IMAGE_SIZE - 1 ] > /dev/null"
check "Setting up disk image file on loopback device $LOOPBACK_DEVICE" \
"losetup $LOOPBACK_DEVICE $IMAGE_FILE"
./makestick.sh $MAKESTICK_OPTS "$LOOPBACK_DEVICE"
check "Run makestick.sh $MAKESTICK_OPTS $LOOPBACK_DEVICE" \
"[ $? -eq 0 ]"
OFFSET=`parted -s -m $LOOPBACK_DEVICE unit B print | grep "^1:" | cut -f 2 -d ":" | tr B ' '`
check "Read partition offset" \
"[ $? -eq 0 ]"
check "Sync" \
"sync"
check "Detaching disk image file" \
"losetup -d $LOOPBACK_DEVICE"
[ -n "$CHROOT_DIR" ] && check "Mounting screen invader partition on $CHROOT_DIR" \
"mount $IMAGE_FILE $CHROOT_DIR -o loop,offset=$OFFSET"
exit 0