mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-04 11:51:14 +02:00
common.sh: move output helper funcs up top the top
The shflags sourcing logic tries to use `die` before we've defined it, so if there's an issue, we end up with: bash: die: command not found and the shflags code doesn't actually get loaded. So relocate these small helpers to the top so we don't have to worry about when it's safe to use these things. BUG=None TEST=`rm lib/shflags/shflags && (. ./common.sh)` now exits properly Change-Id: Ibdc268e6c081aa07679dc9fce76e5603b7217b20 Reviewed-on: https://gerrit.chromium.org/gerrit/15442 Reviewed-by: Brian Harring <ferringb@chromium.org> Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
0ddf0241d4
commit
669b28b666
69
common.sh
69
common.sh
@ -35,6 +35,41 @@ else
|
||||
INSIDE_CHROOT=0
|
||||
fi
|
||||
|
||||
# Determine and set up variables needed for fancy color output (if supported).
|
||||
V_BOLD_RED=
|
||||
V_BOLD_GREEN=
|
||||
V_BOLD_YELLOW=
|
||||
V_REVERSE=
|
||||
V_VIDOFF=
|
||||
|
||||
if tput colors >/dev/null 2>&1; then
|
||||
# order matters: we want VIDOFF last so that when we trace with `set -x`,
|
||||
# our terminal doesn't bleed colors as bash dumps the values of vars.
|
||||
V_BOLD_RED="$(tput bold; tput setaf 1)"
|
||||
V_BOLD_GREEN="$(tput bold; tput setaf 2)"
|
||||
V_BOLD_YELLOW="$(tput bold; tput setaf 3)"
|
||||
V_REVERSE="$(tput rev)"
|
||||
V_VIDOFF="$(tput sgr0)"
|
||||
fi
|
||||
|
||||
# Declare these asap so that code below can safely assume they exist.
|
||||
function info {
|
||||
echo -e >&2 "${V_BOLD_GREEN}INFO ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
|
||||
}
|
||||
|
||||
function warn {
|
||||
echo -e >&2 "${V_BOLD_YELLOW}WARNING ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
|
||||
}
|
||||
|
||||
function error {
|
||||
echo -e >&2 "${V_BOLD_RED}ERROR ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
|
||||
}
|
||||
|
||||
function die {
|
||||
error "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 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.
|
||||
@ -244,23 +279,6 @@ FACTORY_SHIM_INSTALL_MASK="
|
||||
/usr/share/zoneinfo
|
||||
"
|
||||
|
||||
# Determine and set up variables needed for fancy color output (if supported).
|
||||
V_BOLD_RED=
|
||||
V_BOLD_GREEN=
|
||||
V_BOLD_YELLOW=
|
||||
V_REVERSE=
|
||||
V_VIDOFF=
|
||||
|
||||
if tput colors >/dev/null 2>&1; then
|
||||
# order matters: we want VIDOFF last so that when we trace with `set -x`,
|
||||
# our terminal doesn't bleed colors as bash dumps the values of vars.
|
||||
V_BOLD_RED="$(tput bold; tput setaf 1)"
|
||||
V_BOLD_GREEN="$(tput bold; tput setaf 2)"
|
||||
V_BOLD_YELLOW="$(tput bold; tput setaf 3)"
|
||||
V_REVERSE="$(tput rev)"
|
||||
V_VIDOFF="$(tput sgr0)"
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Functions
|
||||
|
||||
@ -350,23 +368,6 @@ function check_flags_only_and_allow_null_arg {
|
||||
return $do_shift
|
||||
}
|
||||
|
||||
function info {
|
||||
echo -e >&2 "${V_BOLD_GREEN}INFO ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
|
||||
}
|
||||
|
||||
function warn {
|
||||
echo -e >&2 "${V_BOLD_YELLOW}WARNING ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
|
||||
}
|
||||
|
||||
function error {
|
||||
echo -e >&2 "${V_BOLD_RED}ERROR ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
|
||||
}
|
||||
|
||||
function die {
|
||||
error "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Retry an emerge command according to $FLAGS_retries
|
||||
# The $EMERGE_JOBS flags will only be added the first time the command is run
|
||||
function eretry () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user