Index: src/scripts/emit_gpt_scripts.sh |
diff --git a/src/scripts/emit_gpt_scripts.sh b/src/scripts/emit_gpt_scripts.sh |
new file mode 100755 |
index 0000000000000000000000000000000000000000..386414f4f079a7205ed57c99d72eb1d2a77df74c |
--- /dev/null |
+++ b/src/scripts/emit_gpt_scripts.sh |
@@ -0,0 +1,68 @@ |
+#!/bin/bash -x |
adlr
2010/04/01 02:14:12
take out -x
|
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+# |
+# Emit scripts to pack and unpack the partitions from a GPT disk image. |
+ |
+# Load common constants. This should be the first executable line. |
+# The path to common.sh should be relative to your script's location. |
+. "$(dirname "$0")/common.sh" |
+ |
+set -e |
+ |
+# Usage |
+IMAGE=${1:-} |
+DIR=${2:-} |
+if [[ -z "$IMAGE" || -z "$DIR" ]]; then |
+ echo "Usage: $0 GPT_DEVICE DIRECTORY" 1>&2 |
+ exit 1 |
+fi |
+ |
+# We need to locate the gpt tool. It should already be installed in the build |
adlr
2010/04/01 02:14:12
can you just include chromeos-common.sh to get thi
|
+# chroot, but some of these functions may be invoked outside the chroot (by |
+# image_to_usb or similar), so we need to find it. |
+GPT=$(which gpt 2>/dev/null) || /bin/true |
+if [ -z "$GPT" ]; then |
+ if [ -x "${DEFAULT_CHROOT_DIR:-}/usr/bin/gpt" ]; then |
+ GPT="${DEFAULT_CHROOT_DIR:-}/usr/bin/gpt" |
+ else |
+ echo "can't find gpt tool" 1>&2 |
+ exit 1 |
+ fi |
+fi |
+ |
+PACK="${DIR}/pack_partitions.sh" |
+UNPACK="${DIR}/unpack_partitions.sh" |
+ |
+TMP=$(mktemp) |
+sudo $GPT -r show -l "$IMAGE" > $TMP |
+ |
+HEADER='#!/bin/sh -eu |
+# generated file. do not edit. |
adlr
2010/04/01 02:14:12
perhaps say, "File generated by emit_gpt_scripts.s
|
+TARGET=${1:-} |
+if [[ -z "$TARGET" ]]; then |
+ echo "Usage: $0 DEVICE" 1>&2 |
+ exit 1 |
+fi |
+set -x' |
+ |
+echo "$HEADER" > "$PACK" |
+echo "$HEADER" > "$UNPACK" |
+cat $TMP | sed -e 's/^/# /' >> "$PACK" |
+cat $TMP | sed -e 's/^/# /' >> "$UNPACK" |
+ |
+sort -n -k 3 $TMP | \ |
+ grep 'GPT part -' | \ |
+ while read start size part x x x label x; do \ |
+ file="part_$part" |
+ loc="\"\$TARGET\"" |
+ echo "sudo dd if=$loc of=$file bs=512 skip=$start count=$size" \ |
+ >> "$UNPACK" |
+ echo "sudo dd if=$file of=$loc bs=512 seek=$start count=$size conv=notrunc" \ |
adlr
2010/04/01 02:14:12
80 cols
|
+ >> "$PACK" |
+ done |
+ |
+chmod +x "$PACK" "$UNPACK" |
+ |
+rm $TMP |