Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # Determine script directory | 7 # Determine script directory |
| 8 SCRIPT_DIR=$(dirname $0) | 8 SCRIPT_DIR=$(dirname $0) |
| 9 PROG=$(basename $0) | 9 PROG=$(basename $0) |
| 10 GPT=cgpt | 10 GPT=cgpt |
| 11 | 11 |
| 12 # The tag when the rootfs is changed. | 12 # The tag when the rootfs is changed. |
| 13 TAG_NEEDS_TO_BE_SIGNED="/root/.need_to_be_signed" | 13 TAG_NEEDS_TO_BE_SIGNED="/root/.need_to_be_signed" |
| 14 | 14 |
| 15 # Array of actions that are executed during the clean up process. | |
| 16 declare -a cleanup_actions | |
| 17 | |
| 18 # Adds an action to be executed during the clean up process. | |
| 19 # Actions are executed in the reverse order of when they were added. | |
| 20 # ARGS: ACTION | |
| 21 add_cleanup_action() { | |
| 22 cleanup_actions[${#cleanup_actions[*]}]=$1 | |
| 23 } | |
| 24 | |
| 25 # Performs the latest clean up action and removes it from the list. | |
| 26 perform_latest_cleanup_action() { | |
| 27 local num_actions=${#cleanup_actions[*]} | |
| 28 if [ ${num_actions} -gt 0 ]; then | |
| 29 eval "${cleanup_actions[$num_actions-1]}" > /dev/null 2>&1 | |
| 30 unset cleanup_actions[$num_actions-1] | |
| 31 fi | |
| 32 } | |
| 33 | |
| 34 # Performs clean up by executing actions in the cleanup_actions array in | |
| 35 # reversed order. | |
| 36 cleanup() { | |
| 37 set +e | |
| 38 | |
| 39 local num_actions=${#cleanup_actions[*]} | |
| 40 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.
| |
| 41 perform_latest_cleanup_action | |
| 42 num_actions=${#cleanup_actions[*]} | |
| 43 done | |
| 44 | |
| 45 set -e | |
| 46 } | |
| 47 | |
| 48 # ANSI color codes used when displaying messages. | |
| 49 # Taken from src/scripts/common.sh. | |
| 50 V_RED="\e[31m" | |
| 51 V_YELLOW="\e[33m" | |
| 52 V_BOLD_GREEN="\e[1;32m" | |
| 53 V_BOLD_RED="\e[1;31m" | |
| 54 V_BOLD_YELLOW="\e[1;33m" | |
| 55 V_VIDOFF='[m' | |
|
adlr
2011/01/04 19:04:48
should this be:
\e[0m
?
thieule
2011/01/04 23:24:33
Done.
| |
| 56 | |
| 57 # Prints an informational message. | |
| 58 # Taken from src/scripts/common.sh. | |
| 59 # Arg: MESSAGE | |
| 60 info() { | |
| 61 echo -e >&2 "${V_BOLD_GREEN}INFO : $1${V_VIDOFF}" | |
| 62 } | |
| 63 | |
| 64 # Prints a warning message. | |
| 65 # Taken from src/scripts/common.sh. | |
| 66 # Arg: MESSAGE | |
| 67 warn() { | |
| 68 echo -e >&2 "${V_BOLD_YELLOW}WARNING: $1${V_VIDOFF}" | |
| 69 } | |
| 70 | |
| 71 # Prints the specified error and exit the script with an error code. | |
| 72 # Taken from src/scripts/common.sh. | |
| 73 # Args: MESSAGE | |
| 74 error() { | |
| 75 echo -e >&2 "${V_BOLD_RED}ERROR : $1${V_VIDOFF}" | |
| 76 } | |
| 77 | |
| 78 # Prints an error message and exit with an error code. | |
| 79 # Taken from src/scripts/common.sh. | |
| 80 # Args: MESSAGE | |
| 81 die() { | |
| 82 error "$1" | |
| 83 exit 1 | |
| 84 } | |
| 85 | |
| 15 # Finds and loads the 'shflags' library, or return as failed. | 86 # Finds and loads the 'shflags' library, or return as failed. |
| 16 load_shflags() { | 87 load_shflags() { |
| 17 # Load shflags | 88 # Load shflags |
| 18 if [ -f /usr/lib/shflags ]; then | 89 if [ -f /usr/lib/shflags ]; then |
| 19 . /usr/lib/shflags | 90 . /usr/lib/shflags |
| 20 elif [ -f "${SCRIPT_DIR}/shflags" ]; then | 91 elif [ -f "${SCRIPT_DIR}/shflags" ]; then |
| 21 . "${SCRIPT_DIR}/shflags" | 92 . "${SCRIPT_DIR}/shflags" |
| 22 elif [ -f "${SCRIPT_DIR}/lib/shflags/shflags" ]; then | 93 elif [ -f "${SCRIPT_DIR}/lib/shflags/shflags" ]; then |
| 23 . "${SCRIPT_DIR}/lib/shflags/shflags" | 94 . "${SCRIPT_DIR}/lib/shflags/shflags" |
| 24 else | 95 else |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 return 1 | 309 return 1 |
| 239 } | 310 } |
| 240 | 311 |
| 241 # Check if the 'chronos' user already has a password | 312 # Check if the 'chronos' user already has a password |
| 242 # ARGS: rootfs | 313 # ARGS: rootfs |
| 243 no_chronos_password() { | 314 no_chronos_password() { |
| 244 local rootfs=$1 | 315 local rootfs=$1 |
| 245 sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow" | 316 sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow" |
| 246 } | 317 } |
| 247 | 318 |
| 248 trap "cleanup_temps_and_mounts" EXIT | 319 trap "cleanup" EXIT |
| 249 | 320 |
| 321 add_cleanup_action "cleanup_temps_and_mounts" | |
| 322 | |
| OLD | NEW |