Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/image-digestor.sh
blob: 793342a9330e4841065798f47eedc746b8e43674 (plain)
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
#!/bin/bash -e
#
# Copyright © 2008  Andres Salomon <dilinger@queued.net>
#
# This file 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.

check_for_cmds()
{
	for cmd in $@; do
		which $cmd >/dev/null || {
			echo "Missing required command '$cmd'!" 1>&2
			return 1
		}
	done

	return 0
}

check_for_cmds dd sha256sum

usage()
{
	echo "" 1>&2
	echo "Usage: $0 <img>" 1>&2
    echo "Produces <img_basename>.plc"
    echo "For use in secure reflash, the resulting placement control file"
    echo "(*.plc) must be included as data.img in an OLPC-signed fs.zip."
	echo "" 1>&2
	exit 1
}

if [ "$#" != "1" ]; then
	usage
fi

IMAGE_FILE_NAME=$1
IMAGE_FILE_BASENAME=`basename $IMAGE_FILE_NAME`
PLACEMENT_CONTROL_FILE=${IMAGE_FILE_BASENAME/.img/.plc}


do_sha256()
{
	f=$1
	eblocks=$((`stat --printf "%s\n" $f` / (128*1024)))
	for b in $(seq 0 $(($eblocks - 1))); do
		sha=$(dd status=noxfer bs=128KiB skip=$b count=1 if=$f 2>/dev/null | sha256sum | cut -d\  -f1)
		echo "eblock: `printf '%x' $b` sha256 $sha" >> ${PLACEMENT_CONTROL_FILE}
	done
}

cat >${PLACEMENT_CONTROL_FILE}<<EOF
data:  ${IMAGE_FILE_BASENAME}
erase-all
mark-pending: 0
EOF
do_sha256 "${IMAGE_FILE_NAME}"
cat >>${PLACEMENT_CONTROL_FILE}<<EOF
cleanmarkers
mark-complete: 0
EOF