| 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 while [ ${#cleanup_actions[*]} -gt 0 ]; do |
| 40 perform_latest_cleanup_action |
| 41 done |
| 42 |
| 43 set -e |
| 44 } |
| 45 |
| 46 # ANSI color codes used when displaying messages. |
| 47 # Taken from src/scripts/common.sh. |
| 48 V_RED="\e[31m" |
| 49 V_YELLOW="\e[33m" |
| 50 V_BOLD_GREEN="\e[1;32m" |
| 51 V_BOLD_RED="\e[1;31m" |
| 52 V_BOLD_YELLOW="\e[1;33m" |
| 53 V_VIDOFF="\e[0m" |
| 54 |
| 55 # Prints an informational message. |
| 56 # Taken from src/scripts/common.sh. |
| 57 # Arg: MESSAGE |
| 58 info() { |
| 59 echo -e >&2 "${V_BOLD_GREEN}INFO : $1${V_VIDOFF}" |
| 60 } |
| 61 |
| 62 # Prints a warning message. |
| 63 # Taken from src/scripts/common.sh. |
| 64 # Arg: MESSAGE |
| 65 warn() { |
| 66 echo -e >&2 "${V_BOLD_YELLOW}WARNING: $1${V_VIDOFF}" |
| 67 } |
| 68 |
| 69 # Prints the specified error and exit the script with an error code. |
| 70 # Taken from src/scripts/common.sh. |
| 71 # Args: MESSAGE |
| 72 error() { |
| 73 echo -e >&2 "${V_BOLD_RED}ERROR : $1${V_VIDOFF}" |
| 74 } |
| 75 |
| 76 # Prints an error message and exit with an error code. |
| 77 # Taken from src/scripts/common.sh. |
| 78 # Args: MESSAGE |
| 79 die() { |
| 80 error "$1" |
| 81 exit 1 |
| 82 } |
| 83 |
| 15 # Finds and loads the 'shflags' library, or return as failed. | 84 # Finds and loads the 'shflags' library, or return as failed. |
| 16 load_shflags() { | 85 load_shflags() { |
| 17 # Load shflags | 86 # Load shflags |
| 18 if [ -f /usr/lib/shflags ]; then | 87 if [ -f /usr/lib/shflags ]; then |
| 19 . /usr/lib/shflags | 88 . /usr/lib/shflags |
| 20 elif [ -f "${SCRIPT_DIR}/shflags" ]; then | 89 elif [ -f "${SCRIPT_DIR}/shflags" ]; then |
| 21 . "${SCRIPT_DIR}/shflags" | 90 . "${SCRIPT_DIR}/shflags" |
| 22 elif [ -f "${SCRIPT_DIR}/lib/shflags/shflags" ]; then | 91 elif [ -f "${SCRIPT_DIR}/lib/shflags/shflags" ]; then |
| 23 . "${SCRIPT_DIR}/lib/shflags/shflags" | 92 . "${SCRIPT_DIR}/lib/shflags/shflags" |
| 24 else | 93 else |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return 1 | 307 return 1 |
| 239 } | 308 } |
| 240 | 309 |
| 241 # Check if the 'chronos' user already has a password | 310 # Check if the 'chronos' user already has a password |
| 242 # ARGS: rootfs | 311 # ARGS: rootfs |
| 243 no_chronos_password() { | 312 no_chronos_password() { |
| 244 local rootfs=$1 | 313 local rootfs=$1 |
| 245 sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow" | 314 sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow" |
| 246 } | 315 } |
| 247 | 316 |
| 248 trap "cleanup_temps_and_mounts" EXIT | 317 trap "cleanup" INT TERM EXIT |
| 249 | 318 |
| 319 add_cleanup_action "cleanup_temps_and_mounts" |
| 320 |
| OLD | NEW |