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

Unified Diff: scripts/image_signing/common.sh

Issue 5878005: Check in tofactory script. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Re-upload after repo sync Created 9 years, 12 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 | « no previous file | scripts/image_signing/make_dev_firmware.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/image_signing/common.sh
diff --git a/scripts/image_signing/common.sh b/scripts/image_signing/common.sh
index 5465feb81e95629a84ef37ebc17c99c47cd29d96..1566b9d317aca6abfa4990f63b8bdf3690becc0b 100755
--- a/scripts/image_signing/common.sh
+++ b/scripts/image_signing/common.sh
@@ -4,6 +4,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# Globals
+# ----------------------------------------------------------------------------
+
# Determine script directory
SCRIPT_DIR=$(dirname $0)
PROG=$(basename $0)
@@ -94,11 +97,81 @@ load_shflags() {
echo "ERROR: Cannot find the required shflags library."
return 1
fi
+
+ # Add debug option for debug output below
+ DEFINE_boolean debug $FLAGS_FALSE "Provide debug messages" "d"
+}
+
+# Functions for debug output
+# ----------------------------------------------------------------------------
+
+# Reports error message and exit(1)
+# Args: error message
+err_die() {
+ echo "ERROR: $*" 1>&2
+ exit 1
+}
+
+# Returns true if we're running in debug mode.
+#
+# Note that if you don't set up shflags by calling load_shflags(), you
+# must set $FLAGS_debug and $FLAGS_TRUE yourself. The default
+# behavior is that debug will be off if you define neither $FLAGS_TRUE
+# nor $FLAGS_debug.
+is_debug_mode() {
+ [ "${FLAGS_debug:-not$FLAGS_TRUE}" = "$FLAGS_TRUE" ]
+}
+
+# Prints messages (in parameters) in debug mode
+# Args: debug message
+debug_msg() {
+ if is_debug_mode; then
+ echo "DEBUG: $*" 1>&2
+ fi
+}
+
+# Functions for temporary files and directories
+# ----------------------------------------------------------------------------
+
+# Create a new temporary file and return its name.
+# File is automatically cleaned when cleanup_temps_and_mounts() is called.
+make_temp_file() {
+ local tempfile=$(mktemp)
+ echo "$tempfile" >> $TEMP_FILE_LIST
+ echo $tempfile
+}
+
+# Create a new temporary directory and return its name.
+# Directory is automatically deleted and any filesystem mounted on it unmounted
+# when cleanup_temps_and_mounts() is called.
+make_temp_dir() {
+ local tempdir=$(mktemp -d)
+ echo "$tempdir" >> $TEMP_DIR_LIST
+ echo $tempdir
}
-# List of Temporary files and mount points.
-TEMP_FILE_LIST=$(mktemp)
-TEMP_DIR_LIST=$(mktemp)
+cleanup_temps_and_mounts() {
+ for i in $(cat $TEMP_FILE_LIST); do
+ rm -f $i
+ done
+ set +e # umount may fail for unmounted directories
+ for i in $(cat $TEMP_DIR_LIST); do
+ if [ -n "$i" ]; then
+ if has_needs_to_be_resigned_tag "$i"; then
+ echo "Warning: image may be modified. Please resign image."
+ fi
+ sudo umount -d $i 2>/dev/null
+ rm -rf $i
+ fi
+ done
+ set -e
+ rm -rf $TEMP_DIR_LIST $TEMP_FILE_LIST
+}
+
+trap "cleanup_temps_and_mounts" EXIT
+
+# Functions for partition management
+# ----------------------------------------------------------------------------
# Read GPT table to find the starting location of a specific partition.
# Args: DEVICE PARTNUM
@@ -185,54 +258,6 @@ replace_image_partition() {
dd if=$input_file of=$image bs=512 seek=$offset count=$size conv=notrunc
}
-# Create a new temporary file and return its name.
-# File is automatically cleaned when cleanup_temps_and_mounts() is called.
-make_temp_file() {
- local tempfile=$(mktemp)
- echo "$tempfile" >> $TEMP_FILE_LIST
- echo $tempfile
-}
-
-# Create a new temporary directory and return its name.
-# Directory is automatically deleted and any filesystem mounted on it unmounted
-# when cleanup_temps_and_mounts() is called.
-make_temp_dir() {
- local tempdir=$(mktemp -d)
- echo "$tempdir" >> $TEMP_DIR_LIST
- echo $tempdir
-}
-
-cleanup_temps_and_mounts() {
- for i in "$(cat $TEMP_FILE_LIST)"; do
- rm -f $i
- done
- set +e # umount may fail for unmounted directories
- for i in "$(cat $TEMP_DIR_LIST)"; do
- if [ -n "$i" ]; then
- if has_needs_to_be_resigned_tag "$i"; then
- echo "Warning: image may be modified. Please resign image."
- fi
- sudo umount -d $i 2>/dev/null
- rm -rf $i
- fi
- done
- set -e
- rm -rf $TEMP_DIR_LIST $TEMP_FILE_LIST
-}
-
-# Returns true if all files in parameters exist.
-ensure_files_exist() {
- local filename return_value=0
- for filename in "$@"; do
- if [ ! -f "$filename" -a ! -b "$filename" ]; then
- echo "ERROR: Cannot find required file: $filename"
- return_value=1
- fi
- done
-
- return $return_value
-}
-
# For details, see crosutils.git/common.sh
enable_rw_mount() {
local rootfs="$1"
@@ -307,8 +332,25 @@ rw_mount_disabled() {
return 1
}
+# Misc functions
+# ----------------------------------------------------------------------------
+
+# Returns true if all files in parameters exist.
+# Args: List of files
+ensure_files_exist() {
+ local filename return_value=0
+ for filename in "$@"; do
+ if [ ! -f "$filename" -a ! -b "$filename" ]; then
+ echo "ERROR: Cannot find required file: $filename"
+ return_value=1
+ fi
+ done
+
+ return $return_value
+}
+
# Check if the 'chronos' user already has a password
-# ARGS: rootfs
+# Args: rootfs
no_chronos_password() {
local rootfs=$1
sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow"
@@ -317,4 +359,3 @@ no_chronos_password() {
trap "cleanup" INT TERM EXIT
add_cleanup_action "cleanup_temps_and_mounts"
-
« no previous file with comments | « no previous file | scripts/image_signing/make_dev_firmware.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698