Skip to content

Commit

Permalink
shellcheck: bin/
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Jun 12, 2019
1 parent e41d771 commit 3548b97
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 78 deletions.
49 changes: 22 additions & 27 deletions bin/rose
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,14 @@
if ${ROSE_DEBUG:-false}; then
set -x
fi
. $(dirname $0)/../lib/bash/rose_init
. "$(dirname "$0")/../lib/bash/rose_init"
rose_init

# Print actual command of a command alias
get_alias() {
local NAME=$1
local ALIAS=$(sed '/^#/d' $ROSE_HOME_BIN/$ROSE_NS-$NAME || true)
if [[ $(wc -l <<<"$ALIAS") == 1 ]] \
&& grep -q "^exec \$(dirname \$0)/$ROSE_NS-.* \"\$@\"\$" <<<"$ALIAS"
then
ALIAS=${ALIAS#"exec \$(dirname \$0)/$ROSE_NS-"}
ALIAS=${ALIAS%' "$@"'}
echo $ALIAS
fi
local NAME="$1"
sed -n 's/exec.*'"$ROSE_NS"'-\([^"]*\).*/\1/p' \
"$ROSE_HOME_BIN/$ROSE_NS-$NAME"
}

# Print help for a given utility
Expand All @@ -61,18 +55,19 @@ help_util() {
echo "$1: utility not found." >&2
return 1
fi
local ALIAS=$(get_alias $NAME)
local ALIAS
ALIAS="$(get_alias "$NAME")"
if [[ -n $ALIAS ]]; then
COMMAND=$ROSE_HOME_BIN/$ROSE_NS-$ALIAS
COMMAND=${COMMAND%% *}
fi
case $(head -1 -- $COMMAND) in
case $(head -1 -- "$COMMAND") in
*bash*)
awk '{
if (/^# NAME/) {
do {print substr($0, 3)} while (getline && !/^#----------/);
}
}' $COMMAND | ${PAGER:-less}
}' "$COMMAND" | "${PAGER:-less}"
;;
*python*)
$COMMAND --help | ${PAGER:-less} # FIXME: not too pretty at the moment
Expand Down Expand Up @@ -123,16 +118,16 @@ help|h|?|--help|-h)
rose_usage
echo
echo "$ROSE_NS provides the following utilities:"
for U in $(cd $ROSE_HOME_BIN && ls $ROSE_NS-*); do
NAME=$(sed "s/^$ROSE_NS-\\(.*\\)\$/\1/" <<<$U)
ALIAS=$(get_alias $NAME)
for U in $(cd "$ROSE_HOME_BIN" && ls "$ROSE_NS-"*); do
NAME="$(sed "s/^$ROSE_NS-\\(.*\\)\$/\1/" <<<"$U")"
ALIAS="$(get_alias "$NAME")"
if [[ -n $ALIAS ]]; then
echo " $NAME"
echo " (=$ALIAS)"
else
echo " $NAME"
sed '1,/^# DESCRIPTION$/d;{s/^# / /;q;}' \
$ROSE_HOME_BIN/$U
"$ROSE_HOME_BIN/$U"
fi
done
} | ${PAGER:-less}
Expand All @@ -143,7 +138,7 @@ help|h|?|--help|-h)
if [[ $U == 'help' || $U == 'version' ]]; then
continue
fi
help_util $U || RC=$?
help_util "$U" || RC=$?
done
exit $RC
:;;
Expand All @@ -156,10 +151,10 @@ doc)
PYTHONPATH=$(path_lead "${PYTHONPATH:-}" "$ROSE_HOME/lib/python")
ROSE_UTIL=$UTIL
export PATH PYTHONPATH ROSE_UTIL
let ns_len=${#ROSE_NS}+2
for U in $(cd $ROSE_HOME_BIN && ls $ROSE_NS-*); do
NAME=$(sed "s/^$ROSE_NS-\\(.*\\)\$/\1/" <<<$U)
ALIAS=$(get_alias $NAME)
ns_len=$(( ${#ROSE_NS}+2 ))
for U in $(cd "$ROSE_HOME_BIN" && ls "$ROSE_NS-"*); do
NAME="$(sed "s/^$ROSE_NS-\\(.*\\)\$/\1/" <<<"$U")"
ALIAS="$(get_alias "$NAME")"
if [[ -n $ALIAS ]]; then
echo '=================================================='
echo "${ROSE_NS} ${NAME} -> ${ROSE_NS} ${ALIAS}"
Expand All @@ -171,27 +166,27 @@ doc)
echo "$ROSE_NS $NAME"
echo '=================================================='
echo
PAGER=cat
help_util $(cut -c "${ns_len}-" <<<"${U}")
PAGER='cat'
help_util "$(cut -c "${ns_len}-" <<<"${U}")"
echo
fi
done
exit 0
:;;
esac

COMMAND=$(dirname $0)/$ROSE_NS-$UTIL
COMMAND="$(dirname "$0")/$ROSE_NS-$UTIL"
if [[ ! -f $COMMAND || ! -x $COMMAND ]]; then
echo "$ROSE_NS: $UTIL: unknown utility. Abort." >&2
echo "Type \"$ROSE_NS help\" for a list of utilities." >&2
exit 1
fi
if (($# > 0)) && [[ $1 == '--help' || $1 == '-h' ]]; then
help_util $UTIL
help_util "$UTIL"
exit
fi
PATH=$(path_lead "${PATH:-}" "$ROSE_HOME_BIN")
PYTHONPATH=$(path_lead "${PYTHONPATH:-}" "$ROSE_HOME/lib/python")
ROSE_UTIL=$UTIL
export PATH PYTHONPATH ROSE_UTIL
exec $COMMAND "$@"
exec "$COMMAND" "$@"
2 changes: 1 addition & 1 deletion bin/rose-edit
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#-------------------------------------------------------------------------------
# Alias of "rose config-edit".
#-------------------------------------------------------------------------------
exec $(dirname $0)/rose-config-edit "$@"
exec "$(dirname "$0")/rose-config-edit" "$@"
41 changes: 20 additions & 21 deletions bin/rose-make-docs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,11 @@ SPHINX_PATH=sphinx
. "${ROSE_HOME}/rose-version"
# documentation root output directory
DOCS_DIR="${ROSE_HOME}/doc"
# documentation output directory for this version
BUILD_DIR="${DOCS_DIR}/${ROSE_VERSION}"
# glob for documentation formats within a rose version
DOC_FORMATS=!(*.html|doctrees)
DOC_FORMATS=(!(*.html|doctrees))

# is the virtualenv command available
if which virtualenv >/dev/null 2>&1; then
if command -v virtualenv >/dev/null 2>&1; then
VENV_COMPLIANT=true
else
VENV_COMPLIANT=false
Expand All @@ -124,8 +122,8 @@ VENV_MODE=false
FORCE=false
DEV_MODE=false
DEBUG=''
BUILDS=''
SPHINX_OPTS=''
BUILDS=()
SPHINX_OPTS=()
DEFAULT_ALIAS='doc'
DEFAULT_VERSION=
while [[ $# -gt 0 ]]; do
Expand All @@ -143,7 +141,7 @@ while [[ $# -gt 0 ]]; do
shift
;;
--strict)
SPHINX_OPTS='SPHINXOPTS=-aEW'
SPHINX_OPTS+=('SPHINXOPTS=-aEW')
shift
;;
--debug)
Expand All @@ -156,16 +154,16 @@ while [[ $# -gt 0 ]]; do
shift
;;
*)
BUILDS="${BUILDS} $1"
BUILDS+=("$1")
shift
;;
esac
done
if [[ -z "${BUILDS}" ]]; then
BUILDS='html'
if [[ "${#BUILDS}" == 0 ]]; then
BUILDS=('html')
fi
# glob for documented rose versions
DOC_VERSIONS=!(*.html|doc|versions.json|"${DEFAULT_ALIAS}"|CHANGES.md|404.md|_config.yml)
DOC_VERSIONS=(!(*.html|doc|versions.json|"${DEFAULT_ALIAS}"|CHANGES.md|404.md|_config.yml))


venv-activate () {
Expand Down Expand Up @@ -194,7 +192,7 @@ venv-destroy () {

json_list () {
# write out a bash array as a JSON list
echo -n "[\"$(local IFS=','; echo "$*" | sed 's/,/", "/g';)\"]"
local IFS=','; list="$*"; echo -n "[\"${list//,/\", \"}\"]";
}

version_file () {
Expand All @@ -203,11 +201,12 @@ version_file () {

echo '{'
# scrape filesystem for list of rose versions which have built docs
VERSIONS=( $(cd "${DOCS_DIR}"; echo $DOC_VERSIONS) )
mapfile -t VERSIONS < <(cd "${DOCS_DIR}"; echo "${DOC_VERSIONS[@]}")
for version in "${VERSIONS[@]}"; do
# scrape filesystem to get list of formats this version is available in
formats=( $(cd "${DOCS_DIR}/${version}"; echo $DOC_FORMATS) )
list=" \"${version}\": $(json_list ${formats[@]})"
mapfile -t formats \
< <(cd "${DOCS_DIR}/${version}"; echo "${DOC_FORMATS[@]}")
list=" \"${version}\": $(json_list "${formats[@]}")"
if [[ $version == "${VERSIONS[$(( ${#VERSIONS[@]} - 1 ))]}" ]]; then
# JSON doesn't permit a comma after the last item in a collection
echo "${list}"
Expand All @@ -223,16 +222,16 @@ html_redirect () {
SRC="$1"
DEST="$2"

cat >"$2" << __HTML__
cat >"$DEST" << __HTML__
<!DOCTYPE html>
<html>
<head>
<title>Rose Documentation</title>
<meta http-equiv="REFRESH" content="0;url=$1">
<meta http-equiv="REFRESH" content="0;url=$SRC">
</head>
<body>
<p>If not automatically redirected, please click
<a href="$1">Rose Documentation</a>.</p>
<a href="$SRC">Rose Documentation</a>.</p>
</body>
</html>
__HTML__
Expand All @@ -256,7 +255,7 @@ if ! rose-check-software --doc >/dev/null; then
venv-install
elif ! "${FORCE}"; then
echo 'Software required by the rose documentation builder is not
present (run `rose check-software --doc` for details).
present (run "rose check-software --doc" for details).
For information on building a Python environment for the Rose documentation
builder see the "Software Dependencies" section of the help page for this
Expand All @@ -266,10 +265,10 @@ command.' >&2
fi

# makefile argument to set the output directory for this build
SPHINX_OPTS="${SPHINX_OPTS} BUILDDIR=${DOCS_DIR}/${ROSE_VERSION}"
SPHINX_OPTS+=("BUILDDIR=${DOCS_DIR}/${ROSE_VERSION}")

# run sphinx-build
if make ${DEBUG} -C "${SPHINX_PATH}" ${BUILDS} ${SPHINX_OPTS}; then
if make ${DEBUG} -C "${SPHINX_PATH}" "${BUILDS[@]}" "${SPHINX_OPTS[@]}"; then
RET=0
# output file containing details of all versions and formats the
# documentation has been built in (locally) for the version / format
Expand Down
32 changes: 18 additions & 14 deletions bin/rose-mpi-launch
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
# DIAGNOSTICS
# Return 0 on success, 1 or exit code of the launcher program on failure.
#-------------------------------------------------------------------------------
. $(dirname $0)/../lib/bash/rose_init
. "$(dirname "$0")/../lib/bash/rose_init"
rose_init rose_log

# ------------------------------------------------------------------------------
Expand All @@ -135,14 +135,14 @@ while (($# > 0)); do
shift 1
if [[ -n ${ROSE_LAUNCHER_ULIMIT_OPTS:-} ]]; then
while getopts 'HST:ab:c:d:e:f:i:l:m:n:p:q:r:s:t:u:v:x:' \
OPT $ROSE_LAUNCHER_ULIMIT_OPTS
OPT "$ROSE_LAUNCHER_ULIMIT_OPTS"
do
case "$OPT" in
'?')
err "ROSE_LAUNCHER_ULIMIT_OPTS=$ROSE_LAUNCHER_ULIMIT_OPTS"
:;;
*)
ulimit -$OPT ${OPTARG:-} || err \
ulimit "-$OPT" "${OPTARG:-}" || err \
"ROSE_LAUNCHER_ULIMIT_OPTS=$ROSE_LAUNCHER_ULIMIT_OPTS"
:;;
esac
Expand Down Expand Up @@ -189,14 +189,14 @@ else
if (($# < 1)); then
rose_usage 1
fi
if ! ROSE_COMMAND=$(type -P $1); then
if ! ROSE_COMMAND="$(type -P "$1")"; then
err "$1: COMMAND not found"
fi
shift 1
fi

ROSE_LAUNCHER_LIST=${ROSE_LAUNCHER_LIST:-$( \
rose config --default= $ROSE_NS launcher-list)}
rose config --default= "$ROSE_NS" launcher-list)}
export NPROC=${NPROC:-1}

#-------------------------------------------------------------------------------
Expand All @@ -211,7 +211,7 @@ ROSE_LAUNCHER_LIST="${ROSE_LAUNCHER_MPICH:-} $ROSE_LAUNCHER_LIST"
if ! printenv ROSE_LAUNCHER >/dev/null; then
ROSE_LAUNCHER=
for LAUNCHER in $ROSE_LAUNCHER_LIST; do
if type -P $LAUNCHER >/dev/null; then
if type -P "$LAUNCHER" >/dev/null; then
ROSE_LAUNCHER=$LAUNCHER
break
fi
Expand All @@ -224,11 +224,11 @@ fi
ROSE_LAUNCHER_BASE=
if [[ -n $ROSE_LAUNCHER ]]; then
# Path
if ! ROSE_LAUNCHER_PATH=$(type -P $ROSE_LAUNCHER); then
if ! ROSE_LAUNCHER_PATH="$(type -P "$ROSE_LAUNCHER")"; then
err "ROSE_LAUNCHER: $ROSE_LAUNCHER: command not found"
fi
ROSE_LAUNCHER=$ROSE_LAUNCHER_PATH
ROSE_LAUNCHER_BASE=$(basename $ROSE_LAUNCHER)
ROSE_LAUNCHER_BASE="$(basename "$ROSE_LAUNCHER")"
fi

#-------------------------------------------------------------------------------
Expand All @@ -239,9 +239,10 @@ if [[ -n $ROSE_COMMAND_FILE ]]; then
err "ROSE_LAUNCHER not defined, command file not supported."
fi
ROSE_LAUNCHER_FILEOPTS=${ROSE_LAUNCHER_FILEOPTS:-$( \
rose config --default= $ROSE_NS launcher-fileopts.$ROSE_LAUNCHER_BASE)}
eval "info 2 exec $ROSE_LAUNCHER $ROSE_LAUNCHER_FILEOPTS $@"
eval "exec $ROSE_LAUNCHER $ROSE_LAUNCHER_FILEOPTS $@"
rose config --default= "$ROSE_NS" \
"launcher-fileopts.$ROSE_LAUNCHER_BASE")}
eval "info 2 exec $ROSE_LAUNCHER $ROSE_LAUNCHER_FILEOPTS $*"
eval "exec $ROSE_LAUNCHER $ROSE_LAUNCHER_FILEOPTS $*"
else
if [[ -n $ROSE_LAUNCHER_BASE ]]; then
ROSE_LAUNCH_INNER=
Expand All @@ -250,9 +251,9 @@ else
fi
# Options
ROSE_LAUNCHER_PREOPTS=${ROSE_LAUNCHER_PREOPTS:-$(rose config -E \
--default= $ROSE_NS launcher-preopts.$ROSE_LAUNCHER_BASE)}
--default= "$ROSE_NS" "launcher-preopts.$ROSE_LAUNCHER_BASE")}
ROSE_LAUNCHER_POSTOPTS=${ROSE_LAUNCHER_POSTOPTS:-$(rose config -E \
--default= $ROSE_NS launcher-postopts.$ROSE_LAUNCHER_BASE)}
--default= "$ROSE_NS" "launcher-postopts.$ROSE_LAUNCHER_BASE")}
else
ROSE_LAUNCH_INNER=
ROSE_LAUNCHER_PREOPTS=
Expand All @@ -261,15 +262,18 @@ else
if ((ROSE_VERBOSITY >= 3)); then
info 3 printenv
printenv | sort
run ldd $ROSE_COMMAND || true 2>/dev/null
run ldd "$ROSE_COMMAND" || true 2>/dev/null
fi

# shellcheck disable=SC2086
info 2 exec \
$ROSE_LAUNCHER \
$ROSE_LAUNCHER_PREOPTS \
$ROSE_LAUNCH_INNER \
"$ROSE_COMMAND" \
$ROSE_LAUNCHER_POSTOPTS \
"$@"
# shellcheck disable=SC2086
exec \
$ROSE_LAUNCHER \
$ROSE_LAUNCHER_PREOPTS \
Expand Down
2 changes: 1 addition & 1 deletion bin/rose-slv
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#-------------------------------------------------------------------------------
# Alias of "rose suite-log".
#-------------------------------------------------------------------------------
exec $(dirname $0)/rose-suite-log "$@"
exec "$(dirname "$0")/rose-suite-log" "$@"
2 changes: 1 addition & 1 deletion bin/rose-suite-init
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# Deprecated.
# Alias of "rose suite-run".
#-------------------------------------------------------------------------------
exec $(dirname $0)/rose-suite-run "$@"
exec "$(dirname "$0")/rose-suite-run" "$@"
2 changes: 1 addition & 1 deletion bin/rose-suite-log-view
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#-------------------------------------------------------------------------------
# Alias of "rose suite-log".
#-------------------------------------------------------------------------------
exec $(dirname $0)/rose-suite-log "$@"
exec "$(dirname "$0")/rose-suite-log" "$@"
2 changes: 1 addition & 1 deletion bin/rose-suite-stop
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#-------------------------------------------------------------------------------
# Alias of "rose suite-shutdown".
#-------------------------------------------------------------------------------
exec $(dirname $0)/rose-suite-shutdown "$@"
exec "$(dirname "$0")/rose-suite-shutdown" "$@"
2 changes: 1 addition & 1 deletion bin/rose-task-hook
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#-------------------------------------------------------------------------------
# Alias of "rose suite-hook".
#-------------------------------------------------------------------------------
exec $(dirname $0)/rose-suite-hook "$@"
exec "$(dirname "$0")/rose-suite-hook" "$@"
Loading

0 comments on commit 3548b97

Please sign in to comment.