Fix ShellCheck v0.4.7 lint issues 20/8320/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 9 Jan 2018 23:21:41 +0000 (18:21 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 9 Jan 2018 23:22:00 +0000 (18:22 -0500)
v0.4.7 introduces some new rules which now need to be handled.

Change-Id: I9c769bd819b787d817ef7708c312e9c637ee7dfc
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
shell/deploy
shell/fix_yamllint
shell/sign

index c20893b..a983baa 100755 (executable)
@@ -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() {
index 32cdf9b..e3da73e 100755 (executable)
 # 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
 
index 54855a7..84a6fc8 100755 (executable)
@@ -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