From 183148768c993ec99220e1143e4a56d604f2faac Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Fri, 3 Mar 2017 11:30:24 -0500 Subject: [PATCH] Fix shellcheck for scripts directory 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 --- scripts/check-unicode.sh | 7 ++++--- scripts/delete-jobs.sh | 16 ++++++++-------- scripts/rename-jobs.sh | 20 ++++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/scripts/check-unicode.sh b/scripts/check-unicode.sh index db45f6ac6..cb0af7215 100755 --- a/scripts/check-unicode.sh +++ b/scripts/check-unicode.sh @@ -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" diff --git a/scripts/delete-jobs.sh b/scripts/delete-jobs.sh index 547e51a7f..ef8c84fa4 100755 --- a/scripts/delete-jobs.sh +++ b/scripts/delete-jobs.sh @@ -11,21 +11,21 @@ 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 diff --git a/scripts/rename-jobs.sh b/scripts/rename-jobs.sh index 505e9cda9..95b387676 100755 --- a/scripts/rename-jobs.sh +++ b/scripts/rename-jobs.sh @@ -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 -- 2.36.6