Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
set -e
UPDATES_URL="http://updates.jenkins-ci.org/download/plugins/"
if [ $# -lt 2 ]; then
echo "USAGE: $0 plugin-list-file destination-directory"
exit 1
fi
plugin_list=$1
plugin_dir=$2
#file_owner=jenkins.jenkins
mkdir -p $plugin_dir
installPlugin() {
if [ -f ${plugin_dir}/${1}.hpi -o -f ${plugin_dir}/${1}.jpi ]; then
if [ "$2" == "1" ]; then
return 1
fi
echo "Skipped: $1 (already installed)"
return 0
else
echo "Installing: $1"
curl -L --silent --output ${plugin_dir}/${1}.hpi ${UPDATES_URL}/${1}/${2}/${1}.hpi
return 0
fi
}
while IFS="|" read plugin version
do
#escape comments
if [[ $plugin =~ ^# ]]; then
continue
fi
#install the plugin
installPlugin $plugin $version
done < $plugin_list
changed=1
maxloops=100
while [ "$changed" == "1" ]; do
echo "Check for missing dependecies ..."
if [ $maxloops -lt 1 ] ; then
echo "Max loop count reached - probably a bug in this script: $0"
exit 1
fi
((maxloops--))
changed=0
for f in ${plugin_dir}/*.hpi ; do
# get a list of only non-optional dependencies
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')
#if deps were found, install them .. then set changed, so we re-loop all over all xpi's
if [[ ! -z $deps ]]; then
echo $deps | tr ' ' '\n' |
while IFS=: read plugin version; do
installPlugin $plugin $version
done
changed=1
fi
done
done
#echo "fixing permissions"
#chown ${file_owner} ${plugin_dir} -R
echo "all done"
@chuxau

This comment has been minimized.

Owner

chuxau commented Apr 10, 2015

Originally cloned from https://gist.github.com/micw/e80d739c6099078ce0f3 and modified for my needs ..

To Use

  1. Create a file listing the plugins and the required versions .. in the format below. Supply that file's name as your first parameter when you run the script
  2. The destination for the plugins to be downloaded should be the second parameter

Format of plugin list file:

plugin|version

envinject|1.90
parameterized-trigger|2.25
etc

To Do

  • Check parameters
  • Test for plugin-list file and destination directory
  • Allow field separator as a parameter
  • Trap errors
@Joeasaurus

This comment has been minimized.

Joeasaurus commented Nov 5, 2016

Thank you for including the UPDATES_URL instead of leaving it to be populated by the environment!

@vitaminmoo

This comment has been minimized.

vitaminmoo commented May 4, 2017

Note that the set -e breaks dep resolution in the event that a plugin without deps ends up first in the plugins directory because the unzip pipe fails. You can either turn off set -e, or add ||true to the end of the unzip pipeline.

@dgeissl

This comment has been minimized.

dgeissl commented Jun 9, 2017

just as a hint, if you want to use that on windows (or write the listing there) make sure the file containing the plugins has unix style line endings otherwise you will get wired errors from curl that the url contains incorrect characters (the carriage return screws the url string).

@dmacsuibhne

This comment has been minimized.

dmacsuibhne commented Aug 16, 2017

For me it seems that the last line in the plugin list file is ignored, the workaround is simply to end your plugin list file with a blank line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment