Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/image-digestor.sh
diff options
context:
space:
mode:
authorMartin Dengler <martin@martindengler.com>2009-07-05 11:43:10 (GMT)
committer Martin Dengler <martin@martindengler.com>2009-07-05 11:43:10 (GMT)
commitf18e05773e947c6254caf36a86a189ed5b208db4 (patch)
treed7fb060a99e17e539d1ddad786c36c947fb49f09 /image-digestor.sh
parentb04ad4e58b89899aad86399db690edd9bc03cb05 (diff)
use Makefile instead of 'build'
Diffstat (limited to 'image-digestor.sh')
-rwxr-xr-ximage-digestor.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/image-digestor.sh b/image-digestor.sh
new file mode 100755
index 0000000..793342a
--- /dev/null
+++ b/image-digestor.sh
@@ -0,0 +1,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