Skip to content

Instantly share code, notes, and snippets.

@scoheb
Last active March 31, 2017 14:07
Show Gist options
  • Save scoheb/4ee26ca9911a8b08fec039a2fd374586 to your computer and use it in GitHub Desktop.
Save scoheb/4ee26ca9911a8b08fec039a2fd374586 to your computer and use it in GitHub Desktop.
This script compare plugin name and versions between a local installation of Jenkins and the CCI Update Center versions
#!/usr/bin/env bash
###############################################
#
# This script compare plugin name and versions
# between a local installation of Jenkins
# and the CCI Update Center versions
#
##############################################
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
if [ -z "$1" ] ; then
echo "Usage: compare-plugins.sh <JENKINS_HOME>"
exit 1
fi
JENKINS_HOME=$1
PLUGIN_DIR=${JENKINS_HOME}/plugins/
if [ ! -d "${PLUGIN_DIR}" ] ; then
echo "PLUGIN_DIR ${PLUGIN_DIR} does not exist!"
exit 1
fi
rm -rf current*.txt > /dev/null 2>&1
rm -rf csb*.txt > /dev/null 2>&1
echo "** Scanning $PLUGIN_DIR"
PLUGINS=$(find ${PLUGIN_DIR} -name *.MF 2>/dev/null)
if [ -z "$PLUGINS" ] ; then
echo "Error: no plugins found in $PLUGIN_DIR"
exit 1
fi
for i in $PLUGINS ;do
name=$(grep 'Short-Name:' $i | tr '\n' ' '| tr '\r' ' '| awk '{print $2}')
if [ -z "$name" ] ; then
echo "WARNING: Short-Name: not found for $i"
else
version=$(grep 'Plugin-Version:' $i | tr '\n' ' '| tr '\r' ' '| awk '{print $2}')
echo $name==$version >> current-raw.txt
fi
done
if [ ! -e current-raw.txt ] ; then
echo "Error: no plugins found in $PLUGIN_DIR"
exit 1
fi
cat current-raw.txt | sort > current.txt
echo " Found $(cat current.txt | wc -l ) plugins"
echo ""
echo "** Downloading CCI Update Center metadata..."
## get update center files
echo " - default"
wget -q "https://code.engineering.redhat.com/gerrit/gitweb?p=ci-ops-central.git;a=blob_plain;f=project/jenkins-plugin-lists/default.txt;hb=stage" -O default.txt
echo " - optional"
wget -q "https://code.engineering.redhat.com/gerrit/gitweb?p=ci-ops-central.git;a=blob_plain;f=project/jenkins-plugin-lists/optional.txt;hb=stage" -O optional.txt
echo " - redhat"
wget -q "https://code.engineering.redhat.com/gerrit/gitweb?p=ci-ops-central.git;a=blob_plain;f=project/jenkins-plugin-lists/redhat.txt;hb=stage" -O redhat.txt
cat default.txt > csb-raw.txt
cat optional.txt >> csb-raw.txt
cat redhat.txt >> csb-raw.txt
cat csb-raw.txt | sort > csb.txt
echo ""
echo "*** Looking for differences..."
echo ""
for r in $(cat current.txt); do
name=$(echo $r | cut -f1 -d=)
version=$(echo $r | cut -f3 -d=)
FOUND=$(grep "$name==" csb.txt)
MESSAGE=
if [ -z "${FOUND}" ] ; then
MESSAGE="___ [WARN] MISSING from CSB"
else
VERSIONFOUND=$(grep "$name==$version" csb.txt)
if [ -z "$VERSIONFOUND" ] ; then
csbversion=$(grep "$name==" csb.txt| cut -f3 -d=)
vercomp $version $csbversion
if [ $? -eq 1 ] ; then
MESSAGE="___ [WARN] Current instance has newer version ($version > $csbversion)"
fi
fi
fi
if [ ! -z "$MESSAGE" ] ; then
echo $name $MESSAGE
fi
done
echo ""
echo "*** Looking for Optional plugins ..."
echo " (These plugins reside in Optional Update Center and will need to be installed manually)"
echo ""
for r in $(cat current.txt); do
name=$(echo $r | cut -f1 -d=)
version=$(echo $r | cut -f3 -d=)
FOUND=$(grep "$name==" csb.txt)
MESSAGE=
OPTIONALFOUND=
if [ -z "${FOUND}" ] ; then
MESSAGE=""
else
OPTIONALFOUND=$(grep "$name==" optional.txt)
fi
if [ ! -z "$OPTIONALFOUND" ] ; then
echo " - $name"
fi
done
echo ""
echo "** Done"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment