From 805c2cef0e3c91ffdd4892d7a3408a9cc7959ea9 Mon Sep 17 00:00:00 2001 From: Sergey Kraynev Date: Wed, 3 Aug 2016 12:24:13 +0300 Subject: [PATCH] Fix errors reported by shellcheck for Gerrit and Jenkins Change-Id: Ia383b6e788429fc3170d0362afded8f3bc43e61f --- .../package/Resources/scripts/create_account.sh | 8 ++++---- .../package/Resources/scripts/gen_rsa_key.sh | 14 +++++++------- .../package/Resources/scripts/gen_ssl_cert.sh | 8 ++++---- .../package/Resources/scripts/gen_rsa_key.sh | 4 ++-- .../package/Resources/scripts/install_plugins.sh | 8 ++++---- .../scripts/switch_to_local_project_config.sh | 2 +- .../package/Resources/scripts/update_jobs.sh | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/murano-apps/Gerrit/package/Resources/scripts/create_account.sh b/murano-apps/Gerrit/package/Resources/scripts/create_account.sh index 7e638b0..5561c58 100644 --- a/murano-apps/Gerrit/package/Resources/scripts/create_account.sh +++ b/murano-apps/Gerrit/package/Resources/scripts/create_account.sh @@ -1,6 +1,6 @@ #!/bin/bash -GERRIT_USER="$1" +# GERRIT_USER="$1" GROUP="$2" FULL_NAME="$3" EMAIL="$4" @@ -12,7 +12,7 @@ NAME="$6" # ssh -p 29418 $GERRIT_USER@localhost -i /home/gerrit2/review_site/etc/ssh_host_rsa_key gerrit create-account \ # --group "'$GROUP'" --full-name "'$FULL_NAME'" --email $EMAIL --ssh-key "'$SSHKEY'" $NAME -HOSTNAME="`hostname -f`" +HOSTNAME="$(hostname -f)" create_args= set_args= @@ -42,12 +42,12 @@ fi set +e su gerrit2 -c "ssh -p 29418 -i /home/gerrit2/review_site/etc/ssh_project_rsa_key project-creator@$HOSTNAME \ -gerrit create-account ${create_args[@]} $NAME" +gerrit create-account ${create_args[*]} $NAME" code=$? if [ $code -ne 0 ]; then # Do not create account but set related properties. su gerrit2 -c "ssh -p 29418 -i /home/gerrit2/review_site/etc/ssh_project_rsa_key project-creator@$HOSTNAME \ - gerrit set-account ${set_args[@]} $NAME" + gerrit set-account ${set_args[*]} $NAME" fi diff --git a/murano-apps/Gerrit/package/Resources/scripts/gen_rsa_key.sh b/murano-apps/Gerrit/package/Resources/scripts/gen_rsa_key.sh index c848e17..2d60770 100644 --- a/murano-apps/Gerrit/package/Resources/scripts/gen_rsa_key.sh +++ b/murano-apps/Gerrit/package/Resources/scripts/gen_rsa_key.sh @@ -8,10 +8,10 @@ datafile='/etc/puppet/hieradata/murano.yaml' # ssh-keygen -t rsa -N "" -f gerrit-rsa.key -q -content=`cat gerrit-rsa.key` +content=$(cat gerrit-rsa.key) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssh_rsa_key_contents', value=>'$content', }" -content=`cat gerrit-rsa.key.pub` +content=$(cat gerrit-rsa.key.pub) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssh_rsa_pubkey_contents', value=>'$content', }" # @@ -19,10 +19,10 @@ puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'ger # ssh-keygen -t rsa -N "" -f gerrit-dsa.key -q -content=`cat gerrit-dsa.key` +content=$(cat gerrit-dsa.key) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssh_dsa_key_contents', value=>'$content', }" -content=`cat gerrit-dsa.key.pub` +content=$(cat gerrit-dsa.key.pub) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssh_dsa_pubkey_contents', value=>'$content', }" # @@ -30,10 +30,10 @@ puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'ger # ssh-keygen -t rsa -N "" -f project-rsa.key -q -content=`cat project-rsa.key` +content=$(cat project-rsa.key) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssh_project_rsa_key_contents', value=>'$content', }" -content=`cat project-rsa.key.pub` +content=$(cat project-rsa.key.pub) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssh_project_rsa_pubkey_contents', value=>'$content', }" -exit \ No newline at end of file +exit diff --git a/murano-apps/Gerrit/package/Resources/scripts/gen_ssl_cert.sh b/murano-apps/Gerrit/package/Resources/scripts/gen_ssl_cert.sh index 91288e7..519d32d 100644 --- a/murano-apps/Gerrit/package/Resources/scripts/gen_ssl_cert.sh +++ b/murano-apps/Gerrit/package/Resources/scripts/gen_ssl_cert.sh @@ -3,7 +3,7 @@ logger Generate SSL certificate for Gerrit datafile='/etc/puppet/hieradata/murano.yaml' -fqdn=`hostname` +fqdn=$(hostname) openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=$fqdn" \ -keyout server.key -out server.cert @@ -11,10 +11,10 @@ openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/ cp server.key server.key.org openssl rsa -in server.key.org -out server.key -content=`cat server.key` +content=$(cat server.key) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssl_key_file_contents', value=>'$content', }" -content=`cat server.cert` +content=$(cat server.cert) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'gerrit_ssl_cert_file_contents', value=>'$content', }" content='' @@ -23,4 +23,4 @@ puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'ger # create getent group ssl-cert || addgroup --system 'ssl-cert' -exit \ No newline at end of file +exit diff --git a/murano-apps/Jenkins/package/Resources/scripts/gen_rsa_key.sh b/murano-apps/Jenkins/package/Resources/scripts/gen_rsa_key.sh index 3f15de1..0c46daa 100755 --- a/murano-apps/Jenkins/package/Resources/scripts/gen_rsa_key.sh +++ b/murano-apps/Jenkins/package/Resources/scripts/gen_rsa_key.sh @@ -7,8 +7,8 @@ ssh-keygen -t rsa -N "" -f jenkins.key -q datafile='/etc/puppet/hieradata/murano.yaml' -content=`cat jenkins.key` +content=$(cat jenkins.key) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'jenkins_ssh_private_key_contents', value=>'$content', }" -content=`cat jenkins.key.pub` +content=$(cat jenkins.key.pub) puppet apply --execute "yaml_setting { 'example': target=>'$datafile', key=>'jenkins_ssh_pubkey_contents', value=>'$content', }" diff --git a/murano-apps/Jenkins/package/Resources/scripts/install_plugins.sh b/murano-apps/Jenkins/package/Resources/scripts/install_plugins.sh index 9fd6ddc..502e6da 100755 --- a/murano-apps/Jenkins/package/Resources/scripts/install_plugins.sh +++ b/murano-apps/Jenkins/package/Resources/scripts/install_plugins.sh @@ -14,18 +14,18 @@ mkdir -p ${plugin_dir} installPlugin() { plugin_name=$1 - if [ -f ${plugin_dir}/${plugin_name}.hpi -o -f ${plugin_dir}/${plugin_name}.jpi ]; then + if [ -f "${plugin_dir}/${plugin_name}.hpi" -o -f "${plugin_dir}/${plugin_name}.jpi" ]; then if [ "$2" == "1" ]; then return 1 fi fi echo "Installing: $plugin_name" - curl -L --silent --output ${plugin_dir}/${plugin_name}.hpi https://updates.jenkins-ci.org/latest/${plugin_name}.hpi + curl -L --silent --output "${plugin_dir}/${plugin_name}.hpi" "https://updates.jenkins-ci.org/latest/${plugin_name}.hpi" return 0 } # Install plugin. -for plugin in $* +for plugin in "$@" do installPlugin "$plugin" done @@ -46,7 +46,7 @@ while [ "$changed" == "1" ]; do # Without optionals. # deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | awk -F ':' '{ print $1 }' | tr '\n' ' ' ) # With optionals. - deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | awk -F ':' '{ print $1 }' | tr '\n' ' ' ) + deps=$( unzip -p "${f}" META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | awk -F ':' '{ print $1 }' | tr '\n' ' ' ) for plugin in $deps; do # if installPlugin returns 1 then 'changed' stays as is. (it means that the whole jenkins plugins state is not changed and in fact, nothing installed) # if installPlugin returns 0 then changed=1 diff --git a/murano-apps/Jenkins/package/Resources/scripts/switch_to_local_project_config.sh b/murano-apps/Jenkins/package/Resources/scripts/switch_to_local_project_config.sh index 7cd0249..aaa915a 100644 --- a/murano-apps/Jenkins/package/Resources/scripts/switch_to_local_project_config.sh +++ b/murano-apps/Jenkins/package/Resources/scripts/switch_to_local_project_config.sh @@ -2,7 +2,7 @@ # Cloning 'project-config' from deployed Gerrit -GERRIT_URL=`hiera -c /etc/puppet/hiera.yaml gerrit_host` +GERRIT_URL=$(hiera -c /etc/puppet/hiera.yaml gerrit_host) su jenkins -c "git clone ssh://jenkins@$GERRIT_URL:29418/open-paas/project-config /tmp/project-config/" # Removing old project-config diff --git a/murano-apps/Jenkins/package/Resources/scripts/update_jobs.sh b/murano-apps/Jenkins/package/Resources/scripts/update_jobs.sh index 3db214d..8c7e61c 100644 --- a/murano-apps/Jenkins/package/Resources/scripts/update_jobs.sh +++ b/murano-apps/Jenkins/package/Resources/scripts/update_jobs.sh @@ -5,9 +5,9 @@ cd /etc/project-config # Check whether we have local Gerrit installed or not. # If yes, then 'git pull' should be executed under 'jenkins' user -GERRIT_URL=`hiera -c /etc/puppet/hiera.yaml gerrit_host` +GERRIT_URL=$(hiera -c /etc/puppet/hiera.yaml gerrit_host) -if [ $GERRIT_URL != "nil" ]; then +if [ "$GERRIT_URL" != "nil" ]; then echo "Pulling changes from installed Gerrit" su jenkins -c "git pull" else