Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1483)

Unified Diff: src/scripts/emit_gpt_scripts.sh

Issue 1567013: Clean up temporary files and directories left by build_image, etc. (Closed)
Patch Set: Emit scripts to pack/unpack the image. Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scripts/build_image ('k') | src/scripts/image_to_usb.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/scripts/build_image ('k') | src/scripts/image_to_usb.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698