blob: 37d0ccfb148c99fe0ed5105e9be96a9863d03088 [file] [log] [blame]
Nicolas De Loofdfe81a32016-05-28 17:26:01 +02001#! /bin/bash
Nicolas De Loof0ef5a622016-05-27 19:14:29 +02002
Sýlvan Heuserb20f3882016-06-01 15:47:38 +02003# Resolve dependencies and download plugins given on the command line
4#
5# FROM jenkins
6# RUN install-plugins.sh docker-slaves github-branch-source
7
8set -e
9
10REF=/usr/share/jenkins/ref/plugins
11mkdir -p "$REF"
12
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020013function download() {
Nicolas De Loof4675f042016-06-01 14:07:33 +020014 local plugin=$1; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020015
16 if [[ ! -f ${plugin}.hpi ]]; then
17
Nicolas De Loof4675f042016-06-01 14:07:33 +020018 url=${JENKINS_UC}/latest/${plugin}.hpi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020019 echo "download plugin : $plugin from $url"
20
21 curl -s -f -L $url -o ${plugin}.hpi
22 if [[ $? -ne 0 ]]
23 then
Nicolas De Loof4675f042016-06-01 14:07:33 +020024 # some plugin don't follow the rules about artifact ID
25 # typically: docker-plugin
26 curl -s -f -L $url -o ${plugin}-plugin.hpi
27 if [[ $? -ne 0 ]]
28 then
29 >&2 echo "failed to download plugin ${plugin}"
30 exit -1
31 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020032 fi
33 else
Baptiste Mathus0e7eac32016-05-29 16:14:40 +020034 echo "$plugin is already downloaded."
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020035 fi
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020036
37 if [[ ! -f ${plugin}.resolved ]]; then
Sýlvan Heuser2f2bdc92016-06-01 15:46:16 +020038 resolveDependencies $plugin
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020039 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020040}
41
42function resolveDependencies() {
Nicolas De Loof4675f042016-06-01 14:07:33 +020043 local plugin=$1; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020044
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020045 dependencies=`jrunscript -e '\
46 java.lang.System.out.println(\
47 new java.util.jar.JarFile("'${plugin}.hpi'")\
48 .getManifest()\
49 .getMainAttributes()\
50 .getValue("Plugin-Dependencies")\
51 );'`
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020052
53 if [[ "$dependencies" == "null" ]]; then
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020054 echo " > plugin has no dependencies"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020055 return
56 fi
57
58 echo " > depends on ${dependencies}"
59
60 IFS=',' read -a array <<< "${dependencies}"
61
62 for d in "${array[@]}"
63 do
64 plugin=$(echo $d | cut -d':' -f1 -)
65 if [[ $d == *"resolution:=optional"* ]]
66 then
67 echo "skipping optional dependency $plugin"
68 else
69 download $plugin
70 fi
71 done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020072 touch ${plugin}.resolved
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020073}
74
Sýlvan Heuserb20f3882016-06-01 15:47:38 +020075cd "$REF"
76
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020077for plugin in "$@"
78do
79 download $plugin
80done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020081
82# cleanup 'resolved' flag files
83rm *.resolved