forked from screeninvader/ScreenInvader_old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makestick.sh
executable file
·126 lines (95 loc) · 3.04 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
#!/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`"
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
EOUSAGE
exit 1
}
function makeSyslinuxConf() {
uuid="`blkid $DEVICE*1 | cut -d '"' -f2`"
templates/syslinux_cfg "$uuid" > "$1/boot/syslinux/syslinux.cfg"
}
function doCheckPreCond() {
check "'extlinux' installed" \
"which extlinux"
check "'parted' installed" \
"which parted"
}
export BOOTSTRAP_LOG="makestick.log"
source "$MAKEPARTITION_DIR/.functions.sh"
WRITE_ZEROES=
SIZES=500
while getopts 'zs:' c
do
case $c in
z) WRITE_ZEROES="YES";;
s) SIZE="$OPTARG";;
\?) 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 "Make disk label" \
"parted -s $DEVICE mklabel msdos"
check "Make partition" \
"parted -s $DEVICE mkpart primary ext4 0 ${SIZE}M"
check "Make filesystem" \
"mkfs.ext4 $DEVICE*1"
check "Enable writeback mode" \
"tune2fs -o journal_data_writeback $DEVICE*1"
check "Disable journaling" \
"tune2fs -O ^has_journal $DEVICE*1"
tmpdir=`mktemp -d`
check "Make temporary mount dir" \
"[ $? -eq 0 ]"
check "Mount file system" \
"mount $DEVICE*1 $tmpdir"
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 ]"
check "Umount file system" \
"umount $DEVICE*1"
check "Remove temporary mount dir" \
"rmdir $tmpdir"
check "Install syslinux mbr" \
"printf '\1' | cat syslinux_altmbr.bin - | dd bs=440 count=1 conv=notrunc of=$DEVICE"
check "Check file system" \
"fsck.ext4 -fa $DEVICE*1"
exit 0