-
Notifications
You must be signed in to change notification settings - Fork 2
/
makestick.sh
executable file
·178 lines (138 loc) · 4.24 KB
/
makestick.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/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
#
trap 'kpartx -dv $DEVICE' EXIT
dir="`dirname $0`"
MAKEPARTITION_DIR="`cd $dir; pwd`"
function printUsage() {
cat 1>&2 <<EOUSAGE
makestick.sh - Prepare a file system for installation of the ScreenInvader system.
Usage: $0 [-z][-s <sizeInM>] <device-file>
<device-file> a block special device.
Options:
-s <sizeInM> overwrite the default (= 500MB) file system size.
-z write zeroes to the device before creating the partition
-x install extlinux
-u install uboot-sunxi
EOUSAGE
exit 1
}
function makeSyslinuxConf() {
uuid="`blkid $DEVICE*2 | cut -d '"' -f2`"
templates/syslinux_cfg "$uuid" > "$1/boot/syslinux/syslinux.cfg"
}
function doCheckPreCond() {
check "'sfdisk' installed" \
"which sfdisk"
check "'mkfs.vfat' installed" \
"which mkfs.vfat"
check "'mkfs.ext4' installed" \
"which mkfs.ext4"
check "'kpartx' installed" \
"which kpartx"
check "'blkid' installed" \
"which blkid"
check "'extlinux' installed" \
"which extlinux"
}
export BOOTSTRAP_LOG="makestick.log"
source "$MAKEPARTITION_DIR/.functions.sh"
WRITE_ZEROES=
SIZE=2000
while getopts 'zxus:' c
do
case $c in
z) WRITE_ZEROES="YES";;
s) SIZE="$OPTARG";;
x) MAKE_SYSLINUX="YES";;
u) MAKE_UBOOT="YES";;
\?) printUsage;;
esac
done
shift $(($OPTIND - 1))
DEVICE="$1"
[ $# -ne 1 ] && printUsage;
[ ! -b "$DEVICE" ] && error "Not a block device: $DEVICE";
[ printf "%d" $SIZE &> /dev/null -o $SIZE -lt 100 ] && error "Invalid size: $SIZE"
doCheckPreCond
if [ -n "$WRITE_ZEROES" ]; then
check "Write zeros to device" \
"dd if=/dev/zero of=$DEVICE bs=1M count=$SIZE"
fi
check "Re-read partition table" \
"sfdisk -R $DEVICE"
cat <<EOT | sfdisk --in-order -L -uM $DEVICE &>> $BOOTSTRAP_LOG
1,32,c
,,L
EOT
err=$?
check "Make partition layout" \
"[ $err -eq 0 ] || false"
if [ ! -f "$DEVICE*1" ]; then
DEVICE="`kpartx -asv "$DEVICE" | head -n1 | cut -d" " -f8 2>> $BOOTSTRAP_LOG`"
err=$?
check "Map partion devices" \
"[ $err -eq 0 ] || false"
fi
check "Make boot filesystem" \
"mkfs.vfat $DEVICE*1"
check "Make root filesystem" \
"mkfs.ext4 $DEVICE*2"
check "Enable writeback mode" \
"tune2fs -o journal_data_writeback $DEVICE*2"
check "Disable journaling" \
"tune2fs -O ^has_journal $DEVICE*2"
tmpdir=`mktemp -d`
check "Make temporary mount dir" \
"[ $? -eq 0 ]"
check "Mount file system" \
"mount $DEVICE*2 $tmpdir"
if [ -n "$MAKE_SYSLINUX" ]; then
check "Prune syslinux dir" \
"mkdir -p $tmpdir/boot/syslinux/"
check "Install extlinux" \
"extlinux --install $tmpdir/boot/syslinux"
makeSyslinuxConf "$tmpdir"
check "Make syslinux.cfg" \
"[ $? -eq 0 ]"
fi
if [ -n "$MAKE_UBOOT" ]; then
if [ -d "./u-boot-sunxi" ]; then
check "Update u-boot-sunxi" \
"cd u-boot-sunxi; git pull"
else
check "Clone u-boot-sunxi" \
"git clone https://github.com/screeninvader/u-boot-sunxi.git"
fi
check "Make uboot config" \
"cd u-boot-sunxi; make CROSS_COMPILE=arm-none-eabi- Bananapi_config"
check "Build uboot" \
"cd u-boot-sunxi; make CROSS_COMPILE=arm-none-eabi-"
check "Install uboot" \
"cd u-boot-sunxi; dd if=u-boot-sunxi-with-spl.bin of=$DEVICE bs=1024 seek=8"
fi
check "Umount file system" \
"umount $DEVICE*2"
check "Remove temporary mount dir" \
"rmdir $tmpdir"
check "Check boot system" \
"fsck.vfat -fa $DEVICE*1"
check "Check root system" \
"fsck.ext4 -fa $DEVICE*2"
exit 0