mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-21 21:51:57 +02:00
fix up function style
The "function" keyword is superfluous, not in POSIX, is inconsistent between bash files, and generally makes me angry. So convert every instance to the form: foo() { BUG=None TEST=`cbuildbot x86-generic-paladin` works Change-Id: I97f5ca30a3edfef7222b1e08ac23917dc613b556 Reviewed-on: https://gerrit.chromium.org/gerrit/22467 Reviewed-by: David James <davidjames@chromium.org> Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
078164ea85
commit
6b1abb2a6f
@ -23,11 +23,11 @@ DEFINE_string output_tag "chromeos-hwqual" "Name used in tar"
|
||||
|
||||
TMP=$(mktemp -d "/tmp/image.XXXX")
|
||||
|
||||
function cleanup() {
|
||||
cleanup() {
|
||||
rm -rf "${TMP}"
|
||||
}
|
||||
|
||||
function main() {
|
||||
main() {
|
||||
assert_outside_chroot
|
||||
assert_not_root_user
|
||||
|
||||
|
@ -42,7 +42,7 @@ FLAGS "$@" || exit 1
|
||||
|
||||
TMP=$(mktemp -d /tmp/cros_package_to_live.XXXX)
|
||||
|
||||
function cleanup {
|
||||
cleanup() {
|
||||
if [ "${root_mount_type}" = ro ]; then
|
||||
remote_sh "mount -o remount,ro /" || /bin/true
|
||||
fi
|
||||
|
@ -14,7 +14,7 @@ CHOST="$(portageq envvar CHOST)"
|
||||
# This is the lowest we want to go in this particular case.
|
||||
MINIMUM_GCC="4.4.6"
|
||||
|
||||
function env_setup() {
|
||||
env_setup() {
|
||||
GCC_VERSIONS="$(gcc-config -l | grep "${CHOST}" | \
|
||||
cut -f3 -d' ')"
|
||||
GCC_LATEST="$(gcc-config -l | grep "${CHOST}" | tail -n1 | \
|
||||
|
64
common.sh
64
common.sh
@ -55,8 +55,8 @@ if tput colors >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
# Stubs for sh compatibility.
|
||||
function _dump_trace() { :; }
|
||||
function _escaped_echo() {
|
||||
_dump_trace() { :; }
|
||||
_escaped_echo() {
|
||||
printf '%b\n' "$*"
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ if [ -n "${BASH_VERSION-}" ]; then
|
||||
fi
|
||||
|
||||
# Declare these asap so that code below can safely assume they exist.
|
||||
function _message {
|
||||
_message() {
|
||||
local prefix="${1}"
|
||||
shift
|
||||
if [ $# -eq 0 ]; then
|
||||
@ -105,15 +105,15 @@ function _message {
|
||||
)
|
||||
}
|
||||
|
||||
function info {
|
||||
info() {
|
||||
_message "${V_BOLD_GREEN}INFO " "$*"
|
||||
}
|
||||
|
||||
function warn {
|
||||
warn() {
|
||||
_message "${V_BOLD_YELLOW}WARNING " "$*"
|
||||
}
|
||||
|
||||
function error {
|
||||
error() {
|
||||
_message "${V_BOLD_RED}ERROR " "$*"
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ function error {
|
||||
# no reason to have them cause their own crash if we're inthe middle
|
||||
# of reporting an error condition then exiting.
|
||||
|
||||
function die_err_trap {
|
||||
die_err_trap() {
|
||||
local command="$1" result="$2"
|
||||
set +e +u
|
||||
|
||||
@ -145,7 +145,7 @@ function die_err_trap {
|
||||
}
|
||||
|
||||
# Exit this script due to a failure, outputting a backtrace in the process.
|
||||
function die {
|
||||
die() {
|
||||
set +e +u
|
||||
_dump_trace
|
||||
error
|
||||
@ -155,7 +155,7 @@ function die {
|
||||
}
|
||||
|
||||
# Exit this script w/out a backtrace.
|
||||
function die_notrace {
|
||||
die_notrace() {
|
||||
set +e +u
|
||||
if [ $# -eq 0 ]; then
|
||||
set -- '(no error message given)'
|
||||
@ -169,7 +169,7 @@ function die_notrace {
|
||||
# Construct a list of possible locations for the source tree. This list is
|
||||
# based on various environment variables and globals that may have been set
|
||||
# by the calling script.
|
||||
function get_gclient_root_list() {
|
||||
get_gclient_root_list() {
|
||||
if [ $INSIDE_CHROOT -eq 1 ]; then
|
||||
echo "/home/${USER}/trunk"
|
||||
|
||||
@ -183,7 +183,7 @@ function get_gclient_root_list() {
|
||||
# Based on the list of possible source locations we set GCLIENT_ROOT if it is
|
||||
# not already defined by looking for a src directory in each seach path
|
||||
# location. If we do not find a valid looking root we error out.
|
||||
function get_gclient_root() {
|
||||
get_gclient_root() {
|
||||
if [ -n "${GCLIENT_ROOT}" ]; then
|
||||
return
|
||||
fi
|
||||
@ -379,7 +379,7 @@ FACTORY_SHIM_INSTALL_MASK="
|
||||
# -----------------------------------------------------------------------------
|
||||
# Functions
|
||||
|
||||
function setup_board_warning {
|
||||
setup_board_warning() {
|
||||
echo
|
||||
echo "$V_REVERSE================= WARNING ======================$V_VIDOFF"
|
||||
echo
|
||||
@ -392,7 +392,7 @@ function setup_board_warning {
|
||||
|
||||
|
||||
# Sets the default board variable for calling script
|
||||
function get_default_board {
|
||||
get_default_board() {
|
||||
DEFAULT_BOARD=
|
||||
|
||||
if [ -f "$GCLIENT_ROOT/src/scripts/.default_board" ] ; then
|
||||
@ -407,7 +407,7 @@ function get_default_board {
|
||||
|
||||
|
||||
# Enter a chroot and restart the current script if needed
|
||||
function restart_in_chroot_if_needed {
|
||||
restart_in_chroot_if_needed() {
|
||||
# NB: Pass in ARGV: restart_in_chroot_if_needed "$@"
|
||||
if [ $INSIDE_CHROOT -ne 1 ]; then
|
||||
# Get inside_chroot path for script.
|
||||
@ -418,7 +418,7 @@ function restart_in_chroot_if_needed {
|
||||
|
||||
# Fail unless we're inside the chroot. This guards against messing up your
|
||||
# workstation.
|
||||
function assert_inside_chroot {
|
||||
assert_inside_chroot() {
|
||||
if [ $INSIDE_CHROOT -ne 1 ]; then
|
||||
echo "This script must be run inside the chroot. Run this first:"
|
||||
echo " cros_sdk"
|
||||
@ -428,14 +428,14 @@ function assert_inside_chroot {
|
||||
|
||||
# Fail if we're inside the chroot. This guards against creating or entering
|
||||
# nested chroots, among other potential problems.
|
||||
function assert_outside_chroot {
|
||||
assert_outside_chroot() {
|
||||
if [ $INSIDE_CHROOT -ne 0 ]; then
|
||||
echo "This script must be run outside the chroot."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function assert_not_root_user {
|
||||
assert_not_root_user() {
|
||||
if [ $(id -u) = 0 ]; then
|
||||
echo "This script must be run as a non-root user."
|
||||
exit 1
|
||||
@ -450,7 +450,7 @@ function assert_not_root_user {
|
||||
# then change this function.
|
||||
#
|
||||
# Usage: check_flags_only_and_allow_null_arg "$@" && set --
|
||||
function check_flags_only_and_allow_null_arg {
|
||||
check_flags_only_and_allow_null_arg() {
|
||||
do_shift=1
|
||||
if [[ $# == 1 && -z "$@" ]]; then
|
||||
echo "$0: warning: ignoring null argument" >&2
|
||||
@ -470,21 +470,21 @@ function check_flags_only_and_allow_null_arg {
|
||||
# $1 - string which optionally has surrounding quotes
|
||||
# Returns:
|
||||
# None, but prints the string without quotes.
|
||||
function remove_quotes() {
|
||||
remove_quotes() {
|
||||
echo "$1" | sed -e "s/^'//; s/'$//"
|
||||
}
|
||||
|
||||
# Writes stdin to the given file name as root using sudo in overwrite mode.
|
||||
#
|
||||
# $1 - The output file name.
|
||||
function sudo_clobber() {
|
||||
sudo_clobber() {
|
||||
sudo tee "$1" > /dev/null
|
||||
}
|
||||
|
||||
# Writes stdin to the given file name as root using sudo in append mode.
|
||||
#
|
||||
# $1 - The output file name.
|
||||
function sudo_append() {
|
||||
sudo_append() {
|
||||
sudo tee -a "$1" > /dev/null
|
||||
}
|
||||
|
||||
@ -494,7 +494,7 @@ function sudo_append() {
|
||||
# but hopefully no one will ever try that many at once.
|
||||
#
|
||||
# $@ - The commands to execute, one per arg.
|
||||
function sudo_multi() {
|
||||
sudo_multi() {
|
||||
local i cmds
|
||||
|
||||
# Construct the shell code to execute. It'll be of the form:
|
||||
@ -521,7 +521,7 @@ function sudo_multi() {
|
||||
# Locate all mounts below a specified directory.
|
||||
#
|
||||
# $1 - The root tree.
|
||||
function sub_mounts() {
|
||||
sub_mounts() {
|
||||
# Assume that `mount` outputs a list of mount points in the order
|
||||
# that things were mounted (since it always has and hopefully always
|
||||
# will). As such, we have to unmount in reverse order to cleanly
|
||||
@ -534,7 +534,7 @@ function sub_mounts() {
|
||||
# Unmounts a directory, if the unmount fails, warn, and then lazily unmount.
|
||||
#
|
||||
# $1 - The path to unmount.
|
||||
function safe_umount_tree {
|
||||
safe_umount_tree() {
|
||||
local mounts=$(sub_mounts "$1")
|
||||
|
||||
# Hmm, this shouldn't normally happen, but anything is possible.
|
||||
@ -788,7 +788,7 @@ check_for_tool() {
|
||||
# Reinterprets path from outside the chroot for use inside.
|
||||
# Returns "" if "" given.
|
||||
# $1 - The path to reinterpret.
|
||||
function reinterpret_path_for_chroot() {
|
||||
reinterpret_path_for_chroot() {
|
||||
if [ $INSIDE_CHROOT -ne 1 ]; then
|
||||
if [ -z "${1}" ]; then
|
||||
echo ""
|
||||
@ -813,7 +813,7 @@ function reinterpret_path_for_chroot() {
|
||||
fi
|
||||
}
|
||||
|
||||
function emerge_custom_kernel() {
|
||||
emerge_custom_kernel() {
|
||||
local install_root="$1"
|
||||
local root=/build/${FLAGS_board}
|
||||
local tmp_pkgdir=${root}/custom-packages
|
||||
@ -851,7 +851,7 @@ function emerge_custom_kernel() {
|
||||
--root=${install_root} ${kernel} || die "Cannot emerge kernel to root"
|
||||
}
|
||||
|
||||
function enable_strict_sudo {
|
||||
enable_strict_sudo() {
|
||||
if [ -z "$CROS_SUDO_KEEP_ALIVE" ]; then
|
||||
echo "$0 was somehow invoked in a way that the sudo keep alive could"
|
||||
echo "not be found. Failing due to this. See crosbug.com/18393."
|
||||
@ -866,11 +866,11 @@ function enable_strict_sudo {
|
||||
# If so, we assume that there is a live user we can interact with.
|
||||
# This check can be overridden by setting the CROS_NO_PROMPT environment
|
||||
# variable to a non-empty value.
|
||||
function is_interactive() {
|
||||
is_interactive() {
|
||||
[ -z "${CROS_NO_PROMPT}" -a -t 0 -a -t 2 ]
|
||||
}
|
||||
|
||||
function assert_interactive() {
|
||||
assert_interactive() {
|
||||
if ! is_interactive; then
|
||||
die "Script ${0##*/} tried to get user input on a non-interactive terminal."
|
||||
fi
|
||||
@ -902,7 +902,7 @@ function assert_interactive() {
|
||||
# 1, 2 or 3, the return value will be "foo", "bar" or "foobar", respectively.
|
||||
# If it is empty (i.e. the user clicked Enter) it will be "foo". Anything else
|
||||
# will return "ERROR".
|
||||
function choose() {
|
||||
choose() {
|
||||
typeset -i choose_i=1
|
||||
|
||||
# Retrieve output variable name and default return value.
|
||||
@ -951,7 +951,7 @@ function choose() {
|
||||
# 3) Declare the options that you don't want to appear in help.
|
||||
#
|
||||
# See build_packages for example usage.
|
||||
function show_help_if_requested() {
|
||||
show_help_if_requested() {
|
||||
for opt in "$@"; do
|
||||
if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
|
||||
flags_help
|
||||
@ -960,7 +960,7 @@ function show_help_if_requested() {
|
||||
done
|
||||
}
|
||||
|
||||
function switch_to_strict_mode() {
|
||||
switch_to_strict_mode() {
|
||||
# Set up strict execution mode; note that the trap
|
||||
# must follow switch_to_strict_mode, else it will have no effect.
|
||||
set -e
|
||||
|
@ -8,7 +8,7 @@
|
||||
# Output a backtrace all the way back to the raw invocation, suppressing
|
||||
# only the _dump_trace frame itself.
|
||||
|
||||
function _dump_trace {
|
||||
_dump_trace() {
|
||||
local j n p func src line args
|
||||
p=${#BASH_ARGV[@]}
|
||||
for (( n = ${#FUNCNAME[@]}; n > 1; n-- )); do
|
||||
|
@ -28,7 +28,7 @@ DUMP_SYMS32="dump_syms.32"
|
||||
|
||||
ERROR_COUNT=0
|
||||
|
||||
function debug() {
|
||||
debug() {
|
||||
if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then
|
||||
info "$@"
|
||||
fi
|
||||
@ -46,7 +46,7 @@ NOTIFIED=
|
||||
CONTROL_PIPE=
|
||||
CONTROL_PIPE_FD=
|
||||
|
||||
function _worker_finished() {
|
||||
_worker_finished() {
|
||||
if [ -z "${NOTIFIED}" ]; then
|
||||
debug "Sending notification of $BASHPID ${1-1}"
|
||||
echo "$BASHPID ${1-1}" > /dev/fd/${CONTROL_PIPE_FD}
|
||||
@ -54,12 +54,12 @@ function _worker_finished() {
|
||||
fi
|
||||
}
|
||||
|
||||
function _cleanup_worker() {
|
||||
_cleanup_worker() {
|
||||
rm -f "${SYM_FILE}" "${ERR_FILE}"
|
||||
_worker_finished 1
|
||||
}
|
||||
|
||||
function _cleanup_master() {
|
||||
_cleanup_master() {
|
||||
set +eu
|
||||
rm -f "${CONTROL_PIPE}"
|
||||
if [ ${#JOBS_ARRAY[@]} != 0 ]; then
|
||||
@ -72,7 +72,7 @@ function _cleanup_master() {
|
||||
|
||||
declare -A JOBS_ARRAY
|
||||
|
||||
function finish_job() {
|
||||
finish_job() {
|
||||
local finished result
|
||||
read -r -u ${CONTROL_PIPE_FD} finished result
|
||||
# Bash doesn't allow for zombies, but tell it to clean up its intenral
|
||||
@ -88,7 +88,7 @@ function finish_job() {
|
||||
unset JOBS_ARRAY[${finished}]
|
||||
}
|
||||
|
||||
function run_job() {
|
||||
run_job() {
|
||||
local debug_file=${1} text_file=${2} newpid
|
||||
|
||||
if [ ${#JOBS_ARRAY[@]} -ge ${NUM_JOBS} ]; then
|
||||
@ -103,7 +103,7 @@ function run_job() {
|
||||
}
|
||||
|
||||
# Given path to a debug file, return its text file
|
||||
function get_text_for_debug() {
|
||||
get_text_for_debug() {
|
||||
local debug_file=$1
|
||||
local text_dir=$(dirname "${debug_file#$DEBUG_ROOT}")
|
||||
local text_path=${SYSROOT}${text_dir}/$(basename "${debug_file}" .debug)
|
||||
@ -111,7 +111,7 @@ function get_text_for_debug() {
|
||||
}
|
||||
|
||||
# Given path to a text file, return its debug file
|
||||
function get_debug_for_text() {
|
||||
get_debug_for_text() {
|
||||
local text_file=$1
|
||||
local text_path=${text_file#${SYSROOT}}
|
||||
local debug_path=${DEBUG_ROOT}${text_path}.debug
|
||||
@ -119,7 +119,7 @@ function get_debug_for_text() {
|
||||
}
|
||||
|
||||
# Returns true if the file given is a 32-bit ELF file.
|
||||
function is_32b_elf() {
|
||||
is_32b_elf() {
|
||||
local elf="$1"
|
||||
file "${elf}" | grep -q "ELF 32-bit"
|
||||
}
|
||||
@ -127,7 +127,7 @@ function is_32b_elf() {
|
||||
# Dump given debug and text file. Returns 1 if any errors, even
|
||||
# if they can be ignored, but only sets ERROR_COUNT if the error should not
|
||||
# be ignored (and we should not proceed to upload).
|
||||
function dump_file() {
|
||||
dump_file() {
|
||||
trap '_cleanup_worker; exit 1' INT TERM
|
||||
trap _cleanup_worker EXIT
|
||||
local debug_file="$1"
|
||||
@ -186,7 +186,7 @@ function dump_file() {
|
||||
}
|
||||
|
||||
# Convert the given debug file. No return value.
|
||||
function process_file() {
|
||||
process_file() {
|
||||
local debug_file="$1"
|
||||
local text_file="$(get_text_for_debug ${debug_file})"
|
||||
if [ -h "${debug_file}" ]; then
|
||||
@ -214,7 +214,7 @@ function process_file() {
|
||||
run_job "${debug_file}" "${text_file}"
|
||||
}
|
||||
|
||||
function main() {
|
||||
main() {
|
||||
|
||||
# Parse command line
|
||||
FLAGS_HELP="usage: $0 [flags] [<files...>]"
|
||||
|
@ -10,7 +10,7 @@
|
||||
. "$(dirname $0)/common.sh" || { echo "Unable to load common.sh"; exit 1; }
|
||||
assert_inside_chroot "$@"
|
||||
|
||||
function usage() {
|
||||
usage() {
|
||||
echo "Usage: $0 url_or_path_to_debug_tgz url_to_bvt_test_results"
|
||||
}
|
||||
|
||||
@ -31,25 +31,25 @@ BREAKPAD_DIR="debug/breakpad"
|
||||
STACKS_GENERATED=""
|
||||
OUTPUT_DIR="$(mktemp -d)"
|
||||
|
||||
function extract_tarball() {
|
||||
extract_tarball() {
|
||||
info "Extracting breakpad symbols from $1..."
|
||||
tar zxf "$1" -C "${OUTPUT_DIR}" "${BREAKPAD_DIR}"
|
||||
}
|
||||
|
||||
function generate_stacktrace() {
|
||||
generate_stacktrace() {
|
||||
echo "$1.txt"
|
||||
minidump_stackwalk "$1" "${OUTPUT_DIR}/${BREAKPAD_DIR}" \
|
||||
>"$1.txt" 2>/dev/null
|
||||
}
|
||||
|
||||
function find_and_generate_stacktraces() {
|
||||
find_and_generate_stacktraces() {
|
||||
find "${OUTPUT_DIR}" -name "*.dmp" |
|
||||
while read filename ; do
|
||||
generate_stacktrace "${filename}"
|
||||
done
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
cleanup() {
|
||||
if [ -n "${OUTPUT_DIR}" -a -z "${STACKS_GENERATED}" ] ; then
|
||||
rm -rf "${OUTPUT_DIR}"
|
||||
fi
|
||||
|
@ -26,7 +26,7 @@ DEFINE_string breakpad_root "" \
|
||||
DEFINE_boolean clean ${FLAGS_FALSE} \
|
||||
"Remove crash reports from remote system after showing stacks"
|
||||
|
||||
function usage() {
|
||||
usage() {
|
||||
echo "usage: $(basename $0) [--remote=<IP>] [dump...]"
|
||||
echo "Specify either a remote IP of a ChromeOS device to gather "
|
||||
echo "all crash reports from, or list crash reports"
|
||||
@ -34,13 +34,13 @@ function usage() {
|
||||
}
|
||||
|
||||
# Clean up remote access and temp files.
|
||||
function cleanup() {
|
||||
cleanup() {
|
||||
[ ${USING_REMOTE} -eq 1 ] && cleanup_remote_access
|
||||
rm -rf "${TMP}"
|
||||
}
|
||||
|
||||
# Echoes kind of crash (minidump or kcrash).
|
||||
function get_kind() {
|
||||
get_kind() {
|
||||
local kind="${1##*.}"
|
||||
if [ "${kind}" = "dmp" ]; then
|
||||
kind="minidump"
|
||||
@ -52,7 +52,7 @@ function get_kind() {
|
||||
# Args:
|
||||
# $1 - file with a "module" per line. A module is the full target's
|
||||
# path to a DSO or executable that was loaded during a crash.
|
||||
function generate_symbols() {
|
||||
generate_symbols() {
|
||||
local modules_file="$1"
|
||||
local modules=""
|
||||
local any_missing=0
|
||||
@ -78,7 +78,7 @@ function generate_symbols() {
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
main() {
|
||||
FLAGS "$@" || usage
|
||||
local basename=$(basename "$0")
|
||||
TMP=$(mktemp -d /tmp/${basename}.XXXX)
|
||||
|
@ -64,7 +64,7 @@ fi
|
||||
|
||||
# Generates a descriptive string of a removable device. Includes the
|
||||
# manufacturer (if non-empty), product and a human-readable size.
|
||||
function get_disk_string() {
|
||||
get_disk_string() {
|
||||
local disk="${1##*/}"
|
||||
local manufacturer_string=$(get_disk_info $disk manufacturer)
|
||||
local product_string=$(get_disk_info $disk product)
|
||||
@ -79,7 +79,7 @@ function get_disk_string() {
|
||||
|
||||
# Prompt for user confirmation. Default is no, which will gracefully terminate
|
||||
# the script.
|
||||
function are_you_sure() {
|
||||
are_you_sure() {
|
||||
local sure
|
||||
read -p "Are you sure (y/N)? " sure
|
||||
if [ "${sure}" != "y" ]; then
|
||||
|
@ -15,7 +15,7 @@ DEFINE_string vnc "" "VNC Server to display to instead of SDL."
|
||||
KVM_PID_FILE=/tmp/kvm.$$.pid
|
||||
LIVE_VM_IMAGE=
|
||||
|
||||
function get_pid() {
|
||||
get_pid() {
|
||||
sudo cat "${KVM_PID_FILE}"
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ function get_pid() {
|
||||
# $2 signal to send (-#).
|
||||
# $3 max timeout in seconds.
|
||||
# Returns 0 on success.
|
||||
function blocking_kill() {
|
||||
blocking_kill() {
|
||||
local timeout=1
|
||||
sudo kill -$2 $1
|
||||
while ps -p $1 > /dev/null && [ ${timeout} -le $3 ]; do
|
||||
@ -37,7 +37,7 @@ function blocking_kill() {
|
||||
! ps -p ${1} > /dev/null
|
||||
}
|
||||
|
||||
function kvm_version_greater_equal() {
|
||||
kvm_version_greater_equal() {
|
||||
local test_version="${1}"
|
||||
local kvm_version=$(kvm --version | sed -E 's/^.*version ([0-9\.]*) .*$/\1/')
|
||||
|
||||
@ -46,7 +46,7 @@ function kvm_version_greater_equal() {
|
||||
}
|
||||
|
||||
# $1: Path to the virtual image to start.
|
||||
function start_kvm() {
|
||||
start_kvm() {
|
||||
# Override default pid file.
|
||||
local start_vm=0
|
||||
[ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid}
|
||||
@ -106,7 +106,7 @@ function start_kvm() {
|
||||
}
|
||||
|
||||
# Checks to see if we can access the target virtual machine with ssh.
|
||||
function ssh_ping() {
|
||||
ssh_ping() {
|
||||
# TODO(sosa): Remove outside chroot use once all callers work inside chroot.
|
||||
local cmd
|
||||
if [ $INSIDE_CHROOT -ne 1 ]; then
|
||||
@ -121,7 +121,7 @@ function ssh_ping() {
|
||||
|
||||
# Tries to ssh into live image $1 times. After first failure, a try involves
|
||||
# shutting down and restarting kvm.
|
||||
function retry_until_ssh() {
|
||||
retry_until_ssh() {
|
||||
local can_ssh_into=1
|
||||
local max_retries=3
|
||||
local retries=0
|
||||
@ -137,7 +137,7 @@ function retry_until_ssh() {
|
||||
return ${can_ssh_into}
|
||||
}
|
||||
|
||||
function stop_kvm() {
|
||||
stop_kvm() {
|
||||
if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then
|
||||
echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \
|
||||
"--kvm_pid ${KVM_PID_FILE} to re-connect to it." >&2
|
||||
|
@ -77,7 +77,7 @@ if [ -f "${FLAGS_from}" ]; then
|
||||
fi
|
||||
|
||||
# Common unmounts for either a device or directory
|
||||
function unmount_image() {
|
||||
unmount_image() {
|
||||
info "Unmounting image from ${FLAGS_stateful_mountpt}" \
|
||||
"and ${FLAGS_rootfs_mountpt}"
|
||||
# Don't die on error to force cleanup
|
||||
@ -98,7 +98,7 @@ function unmount_image() {
|
||||
switch_to_strict_mode
|
||||
}
|
||||
|
||||
function get_usb_partitions() {
|
||||
get_usb_partitions() {
|
||||
local ro_flag=""
|
||||
local safe_flag=""
|
||||
[ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ] && ro_flag="-o ro"
|
||||
@ -112,7 +112,7 @@ function get_usb_partitions() {
|
||||
fi
|
||||
}
|
||||
|
||||
function get_gpt_partitions() {
|
||||
get_gpt_partitions() {
|
||||
local filename="${FLAGS_image}"
|
||||
|
||||
# Mount the rootfs partition using a loopback device.
|
||||
@ -163,7 +163,7 @@ function get_gpt_partitions() {
|
||||
}
|
||||
|
||||
# Mount a gpt based image.
|
||||
function mount_image() {
|
||||
mount_image() {
|
||||
mkdir -p "${FLAGS_rootfs_mountpt}"
|
||||
mkdir -p "${FLAGS_stateful_mountpt}"
|
||||
if [[ -n "${FLAGS_esp_mountpt}" ]]; then
|
||||
|
@ -18,7 +18,7 @@ SSH_CONNECT_SETTINGS="-o Protocol=2 -o ConnectTimeout=30 \
|
||||
-o ServerAliveCountMax=3 -o StrictHostKeyChecking=no"
|
||||
|
||||
# Copies $1 to $2 on remote host
|
||||
function remote_cp_to() {
|
||||
remote_cp_to() {
|
||||
REMOTE_OUT=$(scp -P ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY $1 \
|
||||
root@$FLAGS_remote:$2)
|
||||
@ -27,13 +27,13 @@ function remote_cp_to() {
|
||||
|
||||
# Copies a list of remote files specified in file $1 to local location
|
||||
# $2. Directory paths in $1 are collapsed into $2.
|
||||
function remote_rsync_from() {
|
||||
remote_rsync_from() {
|
||||
rsync -e "ssh -p ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY" \
|
||||
--no-R --files-from=$1 root@${FLAGS_remote}:/ $2
|
||||
}
|
||||
|
||||
function _remote_sh() {
|
||||
_remote_sh() {
|
||||
REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY \
|
||||
root@$FLAGS_remote "$@")
|
||||
@ -42,7 +42,7 @@ function _remote_sh() {
|
||||
|
||||
# Wrapper for ssh that runs the commmand given by the args on the remote host
|
||||
# If an ssh error occurs, re-runs the ssh command.
|
||||
function remote_sh() {
|
||||
remote_sh() {
|
||||
local ssh_status=0
|
||||
_remote_sh "$@" || ssh_status=$?
|
||||
# 255 indicates an ssh error.
|
||||
@ -53,19 +53,19 @@ function remote_sh() {
|
||||
fi
|
||||
}
|
||||
|
||||
function remote_sh_raw() {
|
||||
remote_sh_raw() {
|
||||
ssh -p ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY \
|
||||
$EXTRA_REMOTE_SH_ARGS root@$FLAGS_remote "$@"
|
||||
return $?
|
||||
}
|
||||
|
||||
function remote_sh_allow_changed_host_key() {
|
||||
remote_sh_allow_changed_host_key() {
|
||||
rm -f $TMP_KNOWN_HOSTS
|
||||
remote_sh "$@"
|
||||
}
|
||||
|
||||
function set_up_remote_access() {
|
||||
set_up_remote_access() {
|
||||
cp $FLAGS_private_key $TMP_PRIVATE_KEY
|
||||
chmod 0400 $TMP_PRIVATE_KEY
|
||||
|
||||
@ -83,7 +83,7 @@ function set_up_remote_access() {
|
||||
}
|
||||
|
||||
# Ask the target what board it is
|
||||
function learn_board() {
|
||||
learn_board() {
|
||||
[ -n "${FLAGS_board}" ] && return
|
||||
remote_sh grep CHROMEOS_RELEASE_BOARD /etc/lsb-release
|
||||
FLAGS_board=$(echo "${REMOTE_OUT}" | cut -d '=' -f 2)
|
||||
@ -94,7 +94,7 @@ function learn_board() {
|
||||
info "Target reports board is ${FLAGS_board}"
|
||||
}
|
||||
|
||||
function learn_arch() {
|
||||
learn_arch() {
|
||||
[ -n "${FLAGS_arch}" ] && return
|
||||
remote_sh uname -m
|
||||
FLAGS_arch=$(echo "${REMOTE_OUT}" | sed -e s/armv7l/arm/ -e s/i686/x86/ )
|
||||
@ -115,7 +115,7 @@ function learn_arch() {
|
||||
# 0: The device has rebooted successfully
|
||||
# 1: The device has not yet rebooted
|
||||
# 255: Unable to communicate with the device
|
||||
function _check_if_rebooted() {
|
||||
_check_if_rebooted() {
|
||||
(
|
||||
# In my tests SSH seems to be waiting rather longer than would be expected
|
||||
# from these parameters. These values produce a ~10 second wait.
|
||||
@ -133,7 +133,7 @@ function _check_if_rebooted() {
|
||||
# This function will not return until the SSH server on the remote device
|
||||
# is available after the reboot.
|
||||
#
|
||||
function remote_reboot() {
|
||||
remote_reboot() {
|
||||
info "Rebooting ${FLAGS_remote}..."
|
||||
remote_sh "touch /tmp/awaiting_reboot; reboot"
|
||||
local start_time=${SECONDS}
|
||||
@ -172,11 +172,11 @@ function remote_reboot() {
|
||||
|
||||
# Called by clients before exiting.
|
||||
# Part of the remote_access.sh interface but now empty.
|
||||
function cleanup_remote_access() {
|
||||
cleanup_remote_access() {
|
||||
true
|
||||
}
|
||||
|
||||
function remote_access_init() {
|
||||
remote_access_init() {
|
||||
TMP_PRIVATE_KEY=$TMP/private_key
|
||||
TMP_KNOWN_HOSTS=$TMP/known_hosts
|
||||
if [ -z "$FLAGS_remote" ]; then
|
||||
|
@ -27,7 +27,7 @@ FLAGS "$@" || exit 1
|
||||
VERSION_FILE=/etc/cros_chroot_version
|
||||
UPGRADE_D="$(dirname ${0})/chroot_version_hooks.d"
|
||||
|
||||
function update_version() {
|
||||
update_version() {
|
||||
sudo touch ${VERSION_FILE}
|
||||
sudo chown ${USER} ${VERSION_FILE}
|
||||
echo "${1}" > "${VERSION_FILE}"
|
||||
|
@ -57,7 +57,7 @@ Otherwise, provides an interactive shell.
|
||||
"
|
||||
|
||||
# Version of info from common.sh that only echos if --verbose is set.
|
||||
function debug {
|
||||
debug() {
|
||||
if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then
|
||||
info "$*"
|
||||
fi
|
||||
@ -96,11 +96,11 @@ SYNCERPIDFILE="${FLAGS_chroot}/var/tmp/enter_chroot_sync.pid"
|
||||
|
||||
|
||||
MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
|
||||
function mount_queue_init {
|
||||
mount_queue_init() {
|
||||
MOUNT_QUEUE=()
|
||||
}
|
||||
|
||||
function queue_mount {
|
||||
queue_mount() {
|
||||
# If necessary, mount $source in the host FS at $target inside the
|
||||
# chroot directory with $mount_args.
|
||||
local source="$1"
|
||||
@ -123,7 +123,7 @@ function queue_mount {
|
||||
esac
|
||||
}
|
||||
|
||||
function process_mounts {
|
||||
process_mounts() {
|
||||
if [[ ${#MOUNT_QUEUE[@]} -eq 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
@ -131,7 +131,7 @@ function process_mounts {
|
||||
mount_queue_init
|
||||
}
|
||||
|
||||
function env_sync_proc {
|
||||
env_sync_proc() {
|
||||
# This function runs and performs periodic updates to the chroot env, if
|
||||
# necessary.
|
||||
|
||||
@ -161,7 +161,7 @@ function env_sync_proc {
|
||||
done
|
||||
}
|
||||
|
||||
function copy_ssh_config {
|
||||
copy_ssh_config() {
|
||||
# Copy user .ssh/config into the chroot filtering out strings not supported
|
||||
# by the chroot ssh. The chroot .ssh directory is passed in as the first
|
||||
# parameter.
|
||||
@ -195,13 +195,13 @@ function copy_ssh_config {
|
||||
sed "/^.*\(${filter}\).*$/d" "${sshc}" > "${chroot_ssh_dir}/config"
|
||||
}
|
||||
|
||||
function copy_into_chroot_if_exists {
|
||||
copy_into_chroot_if_exists() {
|
||||
# $1 is file path outside of chroot to copy to path $2 inside chroot.
|
||||
[ -e "$1" ] || return
|
||||
cp "$1" "${FLAGS_chroot}/$2"
|
||||
}
|
||||
|
||||
function setup_env {
|
||||
setup_env() {
|
||||
# Validate sudo timestamp before entering the critical section so that we
|
||||
# don't stall for a password while we have the lockfile.
|
||||
# Don't use sudo -v since that has issues on machines w/ no password.
|
||||
@ -455,7 +455,7 @@ function setup_env {
|
||||
) 200>>"$LOCKFILE" || die "setup_env failed"
|
||||
}
|
||||
|
||||
function teardown_env {
|
||||
teardown_env() {
|
||||
# Validate sudo timestamp before entering the critical section so that we
|
||||
# don't stall for a password while we have the lockfile.
|
||||
# Don't use sudo -v since that has issues on machines w/ no password.
|
||||
|
@ -87,14 +87,14 @@ ENTER_CHROOT_ARGS=(
|
||||
)
|
||||
|
||||
# Invoke enter_chroot. This can only be used after sudo has been installed.
|
||||
function enter_chroot {
|
||||
enter_chroot() {
|
||||
"$ENTER_CHROOT" --chroot "$FLAGS_chroot" -- "${ENTER_CHROOT_ARGS[@]}" "$@"
|
||||
}
|
||||
|
||||
# Invoke enter_chroot running the command as root, and w/out sudo.
|
||||
# This should be used prior to sudo being merged.
|
||||
early_env=()
|
||||
function early_enter_chroot() {
|
||||
early_enter_chroot() {
|
||||
"$ENTER_CHROOT" --chroot "$FLAGS_chroot" --early_make_chroot \
|
||||
-- "${ENTER_CHROOT_ARGS[@]}" "${early_env[@]}" "$@"
|
||||
}
|
||||
@ -106,12 +106,12 @@ sudo_chroot() {
|
||||
sudo chroot "${FLAGS_chroot}" "$@"
|
||||
}
|
||||
|
||||
function cleanup {
|
||||
cleanup() {
|
||||
# Clean up mounts
|
||||
safe_umount_tree "${FLAGS_chroot}"
|
||||
}
|
||||
|
||||
function delete_existing {
|
||||
delete_existing() {
|
||||
# Delete old chroot dir.
|
||||
if [[ ! -e "$FLAGS_chroot" ]]; then
|
||||
return
|
||||
@ -123,7 +123,7 @@ function delete_existing {
|
||||
info "Done."
|
||||
}
|
||||
|
||||
function init_users () {
|
||||
init_users () {
|
||||
info "Set timezone..."
|
||||
# date +%Z has trouble with daylight time, so use host's info.
|
||||
sudo rm -f "${FLAGS_chroot}/etc/localtime"
|
||||
@ -147,7 +147,7 @@ function init_users () {
|
||||
sudo sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd"
|
||||
}
|
||||
|
||||
function init_setup () {
|
||||
init_setup () {
|
||||
info "Running init_setup()..."
|
||||
sudo mkdir -p -m 755 "${FLAGS_chroot}/usr" \
|
||||
"${FLAGS_chroot}/usr/local/portage" \
|
||||
|
@ -12,12 +12,12 @@ SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
||||
. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
|
||||
. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh"
|
||||
|
||||
function cleanup {
|
||||
cleanup() {
|
||||
cleanup_remote_access
|
||||
rm -rf "${TMP}"
|
||||
}
|
||||
|
||||
function main() {
|
||||
main() {
|
||||
cd "${SCRIPTS_DIR}"
|
||||
|
||||
FLAGS "$@" || exit 1
|
||||
|
@ -27,12 +27,12 @@ eval set -- "${FLAGS_ARGV}"
|
||||
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
|
||||
switch_to_strict_mode
|
||||
|
||||
function cleanup {
|
||||
cleanup() {
|
||||
cleanup_remote_access
|
||||
rm -rf "${TMP}"
|
||||
}
|
||||
|
||||
function learn_device() {
|
||||
learn_device() {
|
||||
[ -n "${FLAGS_device}" ] && return
|
||||
remote_sh df /mnt/stateful_partition
|
||||
FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//)
|
||||
@ -40,7 +40,7 @@ function learn_device() {
|
||||
}
|
||||
|
||||
# Ask the target what the kernel partition is
|
||||
function learn_partition_and_ro() {
|
||||
learn_partition_and_ro() {
|
||||
[ -n "${FLAGS_partition}" ] && return
|
||||
! remote_sh rootdev
|
||||
if [ "${REMOTE_OUT}" == "/dev/dm-0" ]; then
|
||||
@ -64,7 +64,7 @@ function learn_partition_and_ro() {
|
||||
info "Target reports kernel partition is ${FLAGS_partition}"
|
||||
}
|
||||
|
||||
function make_kernelimage() {
|
||||
make_kernelimage() {
|
||||
local bootloader_path
|
||||
local kernel_image
|
||||
if [[ "${FLAGS_arch}" == "arm" ]]; then
|
||||
@ -85,7 +85,7 @@ function make_kernelimage() {
|
||||
--arch "${FLAGS_arch}"
|
||||
}
|
||||
|
||||
function copy_kernelimage() {
|
||||
copy_kernelimage() {
|
||||
if [ "${FLAGS_arch}" == "arm" -a ${REMOTE_VERITY} -eq ${FLAGS_FALSE} ]; then
|
||||
remote_cp_to /build/${FLAGS_board}/boot/vmlinux.uimg /boot
|
||||
fi
|
||||
@ -95,7 +95,7 @@ function copy_kernelimage() {
|
||||
remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}"
|
||||
}
|
||||
|
||||
function main() {
|
||||
main() {
|
||||
trap cleanup EXIT
|
||||
|
||||
TMP=$(mktemp -d /tmp/update_kernel.XXXXXX)
|
||||
|
@ -57,11 +57,11 @@ TOTAL_ERROR_COUNT=0
|
||||
|
||||
OUT_DIR=$(mktemp -d "/tmp/err.XXXX")
|
||||
|
||||
function cleanup() {
|
||||
cleanup() {
|
||||
rm -rf "${OUT_DIR}"
|
||||
}
|
||||
|
||||
function really_upload() {
|
||||
really_upload() {
|
||||
if [ ${FLAGS_yes} -eq ${FLAGS_TRUE} ]; then
|
||||
return 0
|
||||
fi
|
||||
@ -80,7 +80,7 @@ function really_upload() {
|
||||
}
|
||||
|
||||
# Upload the given symbol file to given URL.
|
||||
function upload_file() {
|
||||
upload_file() {
|
||||
local symbol_file="$1"
|
||||
local upload_url="$2"
|
||||
local upload_file="${symbol_file}"
|
||||
@ -169,7 +169,7 @@ due to too many total errors"
|
||||
return 0
|
||||
}
|
||||
|
||||
function main() {
|
||||
main() {
|
||||
trap cleanup EXIT
|
||||
|
||||
# Parse command line
|
||||
|
@ -43,7 +43,7 @@ fi
|
||||
|
||||
switch_to_strict_mode
|
||||
|
||||
function get_partitions() {
|
||||
get_partitions() {
|
||||
if [ -b ${FLAGS_image} ] ; then
|
||||
KERNEL_IMG=$(make_partition_dev "${FLAGS_image}" 2)
|
||||
ROOTFS_IMG=$(make_partition_dev "${FLAGS_image}" 3)
|
||||
@ -64,7 +64,7 @@ function get_partitions() {
|
||||
count=${rootfs_count} &>/dev/null
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
cleanup() {
|
||||
for i in ${KERNEL_IMG} ${ROOTFS_IMG}; do
|
||||
if [ ! -b ${i} ]; then
|
||||
rm -f ${i}
|
||||
|
Loading…
x
Reference in New Issue
Block a user