Fix shellcheck for scripts directory 72/52772/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Fri, 3 Mar 2017 16:30:24 +0000 (11:30 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Fri, 3 Mar 2017 16:30:26 +0000 (11:30 -0500)
ShellCheck is useful for finding common bad patterns in shell script
code. We're trying to enable ShellCheck for the entire releng/builder
repo. Refer to Trello for further details.

Trello: https://trello.com/c/MlgqXKq6
Change-Id: Ife828f7b9a4c12042bef0a2fe626928faf6de6e2
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
scripts/check-unicode.sh
scripts/delete-jobs.sh
scripts/rename-jobs.sh

index db45f6ac698c6dab2dd95e061f99342aebb8fdae..cb0af7215361776612e8cc117f34cb0491c3322f 100755 (executable)
@@ -19,11 +19,12 @@ if [ ! -z "$1" ]; then
 fi
 
 echo "Scanning $directory"
-for x in $(find $directory -type f); do
+while IFS= read -r -d '' x
+do
     if LC_ALL=C grep -q '[^[:print:][:space:]]' "$x"; then
-        echo "file "$x" contains non-ascii characters"
+        echo "file $x contains non-ascii characters"
         exit 1
     fi
-done
+done < <(find "$directory" -type f -print0)
 
 echo "All files are ASCII only"
index 547e51a7f411b9299eae7beeffe5805a07b415c5..ef8c84fa4db7cf5c656a4f60ee33182bd4713b85 100755 (executable)
 search_string=$1
 
 echo -n "Enter system (sandbox|releng): "
-read system
+read -r system
 echo -n "Enter username: "
-read username
+read -r username
 echo -n "Enter api_token: "
-read password
+read -r password
 
-echo $username:$password
+echo "$username:$password"
 
-wget -O jenkins-jobs.xml https://jenkins.opendaylight.org/$system/api/xml
+wget -O jenkins-jobs.xml "https://jenkins.opendaylight.org/$system/api/xml"
 
-jobs=`xmlstarlet sel -t -m '//hudson/job' \
+jobs=$(xmlstarlet sel -t -m '//hudson/job' \
                      -n -v 'name' jenkins-jobs.xml | \
-      grep ${search_string}`
+      grep "$search_string")
 
-for job in `echo $jobs | tr "\n" " "`; do
+for job in $(echo "$jobs" | tr "\n" " "); do
     echo "Deleting $job"
     curl -X POST "https://$username:$password@jenkins.opendaylight.org/$system/job/${job}/doDelete"
 done
index 505e9cda91d74535c9a78308bace7d24a40b956f..95b387676a2190de417661e8d3e06ffb60321a0a 100755 (executable)
@@ -13,22 +13,22 @@ search_string=$1
 replace_string=$2
 
 echo -n "Enter system (sandbox|releng): "
-read system
+read -r system
 echo -n "Enter username: "
-read username
+read -r username
 echo -n "Enter api_token: "
-read password
+read -r password
 
-echo $username:$password
+echo "$username:$password"
 
-wget -O jenkins-jobs.xml https://jenkins.opendaylight.org/$system/api/xml
+wget -O jenkins-jobs.xml "https://jenkins.opendaylight.org/$system/api/xml"
 
-jobs=`xmlstarlet sel -t -m '//hudson/job' \
+jobs=$(xmlstarlet sel -t -m '//hudson/job' \
                      -n -v 'name' jenkins-jobs.xml | \
-      grep ${search_string}`
+      grep "$search_string")
 
-for job in `echo $jobs | tr "\n" " "`; do
-    new_job=`echo $job | sed -e "s/${search_string}/${replace_string}/"`
+for job in $(echo "$jobs" | tr "\n" " "); do
+    new_job="${job//$search_string/$replace_string}"
     echo "Renaming $job to $new_job"
-    curl --data "newName=${new_job}" "https://$username:$password@jenkins.opendaylight.org/$system/job/${job}/doRename"
+    #curl --data "newName=${new_job}" "https://$username:$password@jenkins.opendaylight.org/$system/job/${job}/doRename"
 done