From b4de489ae901b4a88cbad0eb2a17b524923beef4 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Tue, 9 Jan 2018 18:21:41 -0500 Subject: [PATCH] Fix ShellCheck v0.4.7 lint issues v0.4.7 introduces some new rules which now need to be handled. Change-Id: I9c769bd819b787d817ef7708c312e9c637ee7dfc Signed-off-by: Thanh Ha --- shell/deploy | 36 ++++++++++++++++++------------------ shell/fix_yamllint | 25 ++++++++++++++----------- shell/sign | 24 ++++++++++++------------ 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/shell/deploy b/shell/deploy index c20893bd..a983baa6 100755 --- a/shell/deploy +++ b/shell/deploy @@ -32,7 +32,7 @@ copy_archives() { local dest_dir dest_dir="$(pwd)" - pushd "$workspace" + pushd "$workspace" || exit # First copy all archives provided by user if any if [ "$(ls -A "$workspace/archives/")" ]; then @@ -58,7 +58,7 @@ copy_archives() { done shopt -u globstar # Disable globstar once archives are copied fi - popd + popd || exit } deploy() { @@ -143,7 +143,7 @@ deploy_archives() { local archive_pattern="${4:-}" tmpdir=$(mktemp -d) - pushd "$tmpdir" + pushd "$tmpdir" || exit ################### # BEGIN ARCHIVING # @@ -174,7 +174,7 @@ deploy_archives() { echo "Nothing to archive." fi - popd + popd || exit rm -rf "$tmpdir" } @@ -207,7 +207,7 @@ deploy_logs() { local build_url="$3" tmpdir=$(mktemp -d) - pushd "$tmpdir" + pushd "$tmpdir" || exit touch "_build-details.log" { @@ -254,7 +254,7 @@ deploy_logs() { curl --netrc --upload-file console-logs.zip \ "${nexus_url}/service/local/repositories/logs/content-compressed/${nexus_path}" - popd + popd || exit rm -rf "$tmpdir" } @@ -530,7 +530,7 @@ deploy_nexus() { # https://issues.apache.org/jira/browse/MDEPLOY-193 local snapshot="false" - while getopts s o; do + while getopts hs o; do case "$o" in h) deploy_nexus_usage @@ -558,18 +558,18 @@ deploy_nexus() { exit 1 fi - pushd "$deploy_dir" + pushd "$deploy_dir" || exit if [ "$snapshot" == "true" ]; then - file_list=($(find . -type f \ - ! -name _remote.repositories \ - ! -name resolver-status.properties \ - | cut -c 3-)) + mapfile -t file_list < <(find . -type f \ + ! -name _remote.repositories \ + ! -name resolver-status.properties \ + | cut -c 3-) else - file_list=($(find . -type f \ - ! -name "maven-metadata*" \ - ! -name _remote.repositories \ - ! -name resolver-status.properties \ - | cut -c 3-)) + mapfile -t file_list < <(find . -type f \ + ! -name "maven-metadata*" \ + ! -name _remote.repositories \ + ! -name resolver-status.properties \ + | cut -c 3-) fi if hash parallel 2>/dev/null; then export -f upload_to_nexus @@ -580,7 +580,7 @@ deploy_nexus() { upload_to_nexus "$nexus_repo_url" "$file" done fi - popd + popd || exit } deploy_nexus_stage() { diff --git a/shell/fix_yamllint b/shell/fix_yamllint index 32cdf9bb..e3da73ed 100755 --- a/shell/fix_yamllint +++ b/shell/fix_yamllint @@ -13,18 +13,21 @@ # function loop_log_file takes care of the most common problems so far function start_script { - while getopts 'af:h' opt "$@"; do + while getopts af:h opt "$@"; do case $opt in - 'a') - option=1 - ;; - 'f') - option=2 - FILES="$OPTARG" - ;; - 'h') - option=3 - ;; + a) + option=1 + ;; + f) + option=2 + FILES="$OPTARG" + ;; + h) + option=3 + ;; + *) + echo "ERROR: Unknown flag passed." + ;; esac done diff --git a/shell/sign b/shell/sign index 54855a74..84a6fc81 100755 --- a/shell/sign +++ b/shell/sign @@ -57,14 +57,14 @@ sign_dir() { test_gpg_key set -e # Fail immediately if any if signing fails - files_to_sign=($(find "$dir" -type f ! -name "*.asc" \ - ! -name "*.md5" \ - ! -name "*.sha1" \ - ! -name "_maven.repositories" \ - ! -name "_remote.repositories" \ - ! -name "*.lastUpdated" \ - ! -name "maven-metadata-local.xml" \ - ! -name "maven-metadata.xml")) + mapfile -t files_to_sign < <(find "$dir" -type f ! -name "*.asc" \ + ! -name "*.md5" \ + ! -name "*.sha1" \ + ! -name "_maven.repositories" \ + ! -name "_remote.repositories" \ + ! -name "*.lastUpdated" \ + ! -name "maven-metadata-local.xml" \ + ! -name "maven-metadata.xml") if [ "${#files_to_sign[@]}" -eq 0 ]; then echo "ERROR: No files to sign. Quitting..." @@ -106,7 +106,7 @@ sign_nexus() { # The resultant output of this command is stored in # /tmp/gpg-signatures.XXXXXXXXXX unless the -d parameter is passed to # override. - while getopts d: o; do + while getopts d:h o; do case "$o" in h) sign_nexus_usage @@ -155,7 +155,7 @@ sign_nexus() { fi echo "Removing files that do not need to be cloned..." - remove_files=($(find . -type f -name "index.html" \ + mapfile -t remove_files < <(find . -type f -name "index.html" \ -o -name "*.asc" \ -o -name "*.md5" \ -o -name "*.sha1" \ @@ -163,7 +163,7 @@ sign_nexus() { -o -name "_remote.repositories*" \ -o -name "maven-metadata-local.xml*" \ -o -name "maven-metadata.xml*" \ - -o -name "archetype-catalog.xml")) + -o -name "archetype-catalog.xml") for f in "${remove_files[@]}"; do rm "$f" done @@ -172,7 +172,7 @@ sign_nexus() { sign_dir "$sign_dir" echo "Removing non-signature files..." - remove_files=($(find . -type f -not -name '*.asc')) + mapfile -t remove_files < <(find . -type f -not -name '*.asc') for f in "${remove_files[@]}"; do rm "$f" done -- 2.16.6