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

Unified Diff: scripts/image_signing/common.sh

Issue 6079004: Preserves file system metadata between new build and latest shipping image. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Removed sudo from clean up trap. 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 | « scripts/image_signing/align_rootfs.sh ('k') | no next file » | 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 5a3e600b316c86c622d418a1364ec0ad07f15386..5465feb81e95629a84ef37ebc17c99c47cd29d96 100755
--- a/scripts/image_signing/common.sh
+++ b/scripts/image_signing/common.sh
@@ -12,6 +12,75 @@ GPT=cgpt
# The tag when the rootfs is changed.
TAG_NEEDS_TO_BE_SIGNED="/root/.need_to_be_signed"
+# Array of actions that are executed during the clean up process.
+declare -a cleanup_actions
+
+# Adds an action to be executed during the clean up process.
+# Actions are executed in the reverse order of when they were added.
+# ARGS: ACTION
+add_cleanup_action() {
+ cleanup_actions[${#cleanup_actions[*]}]=$1
+}
+
+# Performs the latest clean up action and removes it from the list.
+perform_latest_cleanup_action() {
+ local num_actions=${#cleanup_actions[*]}
+ if [ ${num_actions} -gt 0 ]; then
+ eval "${cleanup_actions[$num_actions-1]}" > /dev/null 2>&1
+ unset cleanup_actions[$num_actions-1]
+ fi
+}
+
+# Performs clean up by executing actions in the cleanup_actions array in
+# reversed order.
+cleanup() {
+ set +e
+
+ while [ ${#cleanup_actions[*]} -gt 0 ]; do
+ perform_latest_cleanup_action
+ done
+
+ set -e
+}
+
+# ANSI color codes used when displaying messages.
+# Taken from src/scripts/common.sh.
+V_RED="\e[31m"
+V_YELLOW="\e[33m"
+V_BOLD_GREEN="\e[1;32m"
+V_BOLD_RED="\e[1;31m"
+V_BOLD_YELLOW="\e[1;33m"
+V_VIDOFF="\e[0m"
+
+# Prints an informational message.
+# Taken from src/scripts/common.sh.
+# Arg: MESSAGE
+info() {
+ echo -e >&2 "${V_BOLD_GREEN}INFO : $1${V_VIDOFF}"
+}
+
+# Prints a warning message.
+# Taken from src/scripts/common.sh.
+# Arg: MESSAGE
+warn() {
+ echo -e >&2 "${V_BOLD_YELLOW}WARNING: $1${V_VIDOFF}"
+}
+
+# Prints the specified error and exit the script with an error code.
+# Taken from src/scripts/common.sh.
+# Args: MESSAGE
+error() {
+ echo -e >&2 "${V_BOLD_RED}ERROR : $1${V_VIDOFF}"
+}
+
+# Prints an error message and exit with an error code.
+# Taken from src/scripts/common.sh.
+# Args: MESSAGE
+die() {
+ error "$1"
+ exit 1
+}
+
# Finds and loads the 'shflags' library, or return as failed.
load_shflags() {
# Load shflags
@@ -245,5 +314,7 @@ no_chronos_password() {
sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow"
}
-trap "cleanup_temps_and_mounts" EXIT
+trap "cleanup" INT TERM EXIT
+
+add_cleanup_action "cleanup_temps_and_mounts"
« no previous file with comments | « scripts/image_signing/align_rootfs.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698