Chromium Code Reviews| Index: scripts/image_signing/common.sh |
| diff --git a/scripts/image_signing/common.sh b/scripts/image_signing/common.sh |
| index 5a3e600b316c86c622d418a1364ec0ad07f15386..369d1a8f579ca609cd1dffe071a3211981447c98 100755 |
| --- a/scripts/image_signing/common.sh |
| +++ b/scripts/image_signing/common.sh |
| @@ -12,6 +12,77 @@ 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 |
| + |
| + local num_actions=${#cleanup_actions[*]} |
| + while [ $num_actions -gt 0 ]; do |
|
petkov
2011/01/04 20:56:55
maybe propagate num_actions to avoid some code...
thieule
2011/01/04 23:24:33
Done.
|
| + perform_latest_cleanup_action |
| + num_actions=${#cleanup_actions[*]} |
| + 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='[m' |
|
adlr
2011/01/04 19:04:48
should this be:
\e[0m
?
thieule
2011/01/04 23:24:33
Done.
|
| + |
| +# 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 +316,7 @@ no_chronos_password() { |
| sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow" |
| } |
| -trap "cleanup_temps_and_mounts" EXIT |
| +trap "cleanup" EXIT |
| + |
| +add_cleanup_action "cleanup_temps_and_mounts" |