From 61dc9c129cc8bf0618b03d543c406e5dc1f12e61 Mon Sep 17 00:00:00 2001 From: Guillaume Lambert Date: Tue, 4 May 2021 11:27:12 +0200 Subject: [PATCH] Refactor: use POSIX shell function declaration POSIX function style is already used in most of shell scripts. By the way, this style fixes bashate E020 warnings. Non POSIX function declarations in a format different from ^function name {$ are warned by bashate. There are several equivalent ways to define functions in Bash. This is for consistency. Signed-off-by: Guillaume Lambert Change-Id: I5f02e7052101617314157ec408532dd024e80a72 --- jenkins-init-scripts/lf-env.sh | 28 +++++++++++++--------------- shell/logs-deploy.sh | 3 +-- shell/openstack-stack-copy-ssh-keys.sh | 2 +- shell/scrape-job-cost.sh | 3 +-- shell/sudo-logs.sh | 3 +-- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/jenkins-init-scripts/lf-env.sh b/jenkins-init-scripts/lf-env.sh index da51d4b9..01ecda32 100644 --- a/jenkins-init-scripts/lf-env.sh +++ b/jenkins-init-scripts/lf-env.sh @@ -23,7 +23,8 @@ # ################################################################################ # -# Name: lf-echo-stderr +# NAME +# lf-echo-stderr # # SYNOPSIS # source ~/lf-env.sh @@ -38,12 +39,14 @@ # ################################################################################ -function lf-echo-stderr() { echo "$@" 1>&2; } +lf-echo-stderr () { + echo "$@" 1>&2 +} ################################################################################ # # NAME -# lf-boolean() +# lf-boolean # # SYNOPSIS # # shellcheck disable=SC1090 @@ -65,8 +68,7 @@ function lf-echo-stderr() { echo "$@" 1>&2; } # ################################################################################ -function lf-boolean() -{ +lf-boolean () { if (( $# != 1 )); then echo "ERROR: ${FUNCNAME[0]}() line: ${BASH_LINENO[0]} : Missing Required Argument" return 1 @@ -141,8 +143,7 @@ function lf-boolean() # ################################################################################ -function lf-activate-venv() -{ +lf-activate-venv () { lf_venv=$(mktemp -d /tmp/venv-XXXX) local python=python3 local options @@ -215,7 +216,7 @@ function lf-activate-venv() echo "${FUNCNAME[0]}(): INFO: Path not set, lf_venv set to: $lf_venv" fi -} # End lf-activate-venv() +} # End lf-activate-venv ################################################################################ # @@ -237,8 +238,7 @@ function lf-activate-venv() # ################################################################################ -function lf-git-validate-jira-urls() -{ +lf-git-validate-jira-urls () { echo "Checking for JIRA URLs in commit message..." # if JIRA_URL is not defined, nothing to do if [[ -v JIRA_URL ]]; then @@ -258,7 +258,7 @@ function lf-git-validate-jira-urls() ################################################################################ # # NAME -# lf-jjb-check-ascii() +# lf-jjb-check-ascii # # SYNOPSIS # # shellcheck disable=SC1090 @@ -276,8 +276,7 @@ function lf-git-validate-jira-urls() # ################################################################################ -function lf-jjb-check-ascii() -{ +lf-jjb-check-ascii () { if [[ ! -d "jjb" ]]; then lf-echo-stderr "${FUNCNAME[0]}(): ERROR: missing jjb directory" lf-echo-stderr "This function can only be run from top of global-jjb directory" @@ -299,8 +298,7 @@ function lf-jjb-check-ascii() # Shellcheck knows they are shell variables and will check for # 'used-before-set'. -function lf-set-maven-options() -{ +lf-set-maven-options () { # Disable 'unused-variable' check # shellcheck disable=SC2034 maven_options="--show-version --batch-mode -Djenkins \ diff --git a/shell/logs-deploy.sh b/shell/logs-deploy.sh index 53cef700..bd416080 100644 --- a/shell/logs-deploy.sh +++ b/shell/logs-deploy.sh @@ -24,8 +24,7 @@ set -euf -o pipefail # self-contained, we ensure it exists here. mkdir -p "$WORKSPACE/archives" -function get_pattern_opts() -{ +get_pattern_opts () { opts=() for arg in ${ARCHIVE_ARTIFACTS:-}; do opts+=("-p" "$arg") diff --git a/shell/openstack-stack-copy-ssh-keys.sh b/shell/openstack-stack-copy-ssh-keys.sh index 463a386e..a1a01cb1 100644 --- a/shell/openstack-stack-copy-ssh-keys.sh +++ b/shell/openstack-stack-copy-ssh-keys.sh @@ -13,7 +13,7 @@ echo "---> Copy SSH public keys to CSIT lab" os_cloud="${OS_CLOUD:-vex}" stack_name="${OS_STACK_NAME}" -function copy_ssh_keys() { +copy_ssh_keys () { if [ -z "$1" ]; then >&2 echo "ERROR: Missing required arguments." >&2 echo "Usage: copy_ssh_keys IP_ADDRESS" diff --git a/shell/scrape-job-cost.sh b/shell/scrape-job-cost.sh index 7a753a51..e51474b3 100755 --- a/shell/scrape-job-cost.sh +++ b/shell/scrape-job-cost.sh @@ -44,8 +44,7 @@ $debug && echo "DEBUG Enabled" set -eufo pipefail -function get-year-list() -{ +get-year-list () { # Grab the years for each cost record use sort | uniq to get the # list of unique years found local list diff --git a/shell/sudo-logs.sh b/shell/sudo-logs.sh index 257ee23a..ccc7fb35 100755 --- a/shell/sudo-logs.sh +++ b/shell/sudo-logs.sh @@ -13,8 +13,7 @@ echo "---> sudo-logs.sh" set -eu -o pipefail -o noglob # Copy/Generate 'sudo' log and copy to archive directory -function copy_log() -{ +copy_log () { case $os in fedora|centos|redhat|ubuntu|debian) if ! sudo cp "$sudo_log" /tmp; then -- 2.16.6