Fix shellcheck warnings
diff --git a/install-plugins.sh b/install-plugins.sh
index a04dfb2..fa6f5fd 100755
--- a/install-plugins.sh
+++ b/install-plugins.sh
@@ -103,8 +103,8 @@
local pluginInstalled
if pluginInstalled="$(echo "${bundledPlugins}" | grep "^${plugin}:")"; then
pluginInstalled="${pluginInstalled//[$'\r']}"
- local versionInstalled=$(versionFromPlugin "${pluginInstalled}")
- local versionToInstall=$(versionFromPlugin "${d}")
+ local versionInstalled; versionInstalled=$(versionFromPlugin "${pluginInstalled}")
+ local versionToInstall; versionToInstall=$(versionFromPlugin "${d}")
if versionLT "${versionInstalled}" "${versionToInstall}"; then
echo "Upgrading bundled dependency $d ($versionToInstall > $versionInstalled)"
download "$plugin" "$versionToInstall" &
@@ -124,18 +124,18 @@
if [ -f $JENKINS_WAR ]
then
TEMP_PLUGIN_DIR=/tmp/plugintemp.$$
- for i in `jar tf $JENKINS_WAR | egrep '[^detached-]plugins.*\..pi' | sort`
+ for i in $(jar tf $JENKINS_WAR | egrep '[^detached-]plugins.*\..pi' | sort)
do
rm -fr $TEMP_PLUGIN_DIR
mkdir -p $TEMP_PLUGIN_DIR
- PLUGIN=`basename $i|cut -f1 -d'.'`
- (cd $TEMP_PLUGIN_DIR;jar xf $JENKINS_WAR "$i";jar xvf $TEMP_PLUGIN_DIR/$i META-INF/MANIFEST.MF >/dev/null 2>&1)
- VER=`egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d\: -f2|sed 's/ //'`
+ PLUGIN=$(basename "$i"|cut -f1 -d'.')
+ (cd $TEMP_PLUGIN_DIR;jar xf "$JENKINS_WAR" "$i";jar xvf "$TEMP_PLUGIN_DIR/$i" META-INF/MANIFEST.MF >/dev/null 2>&1)
+ VER=$(egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //')
echo "$PLUGIN:$VER"
done
rm -fr $TEMP_PLUGIN_DIR
else
- rm -f $TEMP_ALREADY_INSTALLED
+ rm -f "$TEMP_ALREADY_INSTALLED"
echo "ERROR file not found: $JENKINS_WAR"
exit 1
fi
diff --git a/jenkins-support b/jenkins-support
index 6174b86..0e3ea92 100755
--- a/jenkins-support
+++ b/jenkins-support
@@ -1,11 +1,11 @@
-#!/bin/bash -e
+#!/bin/bash -eu
# compare if version1 < version2
versionLT() {
- local v1; v1=$(echo $1 | cut -d '-' -f 1 )
- local q1; q1=$(echo $1 | cut -s -d '-' -f 2- )
- local v2; v2=$(echo $2 | cut -d '-' -f 1 )
- local q2; q2=$(echo $2 | cut -s -d '-' -f 2- )
+ local v1; v1=$(echo "$1" | cut -d '-' -f 1 )
+ local q1; q1=$(echo "$1" | cut -s -d '-' -f 2- )
+ local v2; v2=$(echo "$2" | cut -d '-' -f 1 )
+ local q2; q2=$(echo "$2" | cut -s -d '-' -f 2- )
if [ "$v1" = "$v2" ]; then
if [ "$q1" = "$q2" ]; then
return 1
@@ -16,21 +16,21 @@
if [ -z "$q2" ]; then
return 0
else
- [ "$q1" = "`echo -e "$q1\n$q2" | sort -V | head -n1`" ]
+ [ "$q1" = "$(echo -e "$q1\n$q2" | sort -V | head -n1)" ]
fi
fi
fi
else
- [ "$v1" = "`echo -e "$v1\n$v2" | sort -V | head -n1`" ]
+ [ "$v1" = "$(echo -e "$v1\n$v2" | sort -V | head -n1)" ]
fi
}
# returns a plugin version from a plugin archive
get_plugin_version() {
local archive; archive=$1
- local version; version=$(unzip -p $archive META-INF/MANIFEST.MF | grep "^Plugin-Version: " | sed -e 's#^Plugin-Version: ##')
+ local version; version=$(unzip -p "$archive" META-INF/MANIFEST.MF | grep "^Plugin-Version: " | sed -e 's#^Plugin-Version: ##')
version=${version%%[[:space:]]}
- echo $version
+ echo "$version"
}
# Copy files from /usr/share/jenkins/ref into $JENKINS_HOME
@@ -50,11 +50,11 @@
local marker_version;
local log; log=false
if [[ ${rel} == plugins/*.jpi ]]; then
- container_version=$(get_plugin_version $JENKINS_HOME/${rel})
- image_version=$(get_plugin_version ${f})
+ container_version=$(get_plugin_version "$JENKINS_HOME/${rel}")
+ image_version=$(get_plugin_version "${f}")
if [[ -e $JENKINS_HOME/${version_marker} ]]; then
- marker_version=$(cat $JENKINS_HOME/${version_marker})
- if versionLT $marker_version $container_version; then
+ marker_version=$(cat "$JENKINS_HOME/${version_marker}")
+ if versionLT "$marker_version" "$container_version"; then
action="SKIPPED"
reason="Installed version ($container_version) has been manually upgraded from initial version ($marker_version)"
log=true
@@ -63,7 +63,7 @@
action="SKIPPED"
reason="Version from image is the same as the installed version $image_version"
else
- if versionLT $image_version $container_version; then
+ if versionLT "$image_version" "$container_version"; then
action="SKIPPED"
log=true
reason="Image version ($image_version) is older than installed version ($container_version)"
@@ -80,9 +80,9 @@
action="SKIPPED"
reason="Version from image is the same as the installed version $image_version (no marker found)"
# Add marker for next time
- echo $image_version > $JENKINS_HOME/${version_marker}
+ echo "$image_version" > "$JENKINS_HOME/${version_marker}"
else
- if versionLT $image_version $container_version; then
+ if versionLT "$image_version" "$container_version"; then
action="SKIPPED"
log=true
reason="Image version ($image_version) is older than installed version ($container_version) (no marker found)"
@@ -101,7 +101,7 @@
cp -r "${f}" "$JENKINS_HOME/${rel}";
# pin plugins on initial copy
touch "$JENKINS_HOME/${rel}.pinned"
- echo $image_version > $JENKINS_HOME/${version_marker}
+ echo "$image_version" > "$JENKINS_HOME/${version_marker}"
reason=${reason:-$image_version}
else
action=${action:-"SKIPPED"}