blob: 1bce1bf38fa64cdd89a04e7adc610a6f193d0ecf [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
Sýlvan Heuserb20f3882016-06-01 15:47:38 +02008
Nicolas De Loofa9d458b2016-06-02 08:55:15 +02009REF=${REF:-/usr/share/jenkins/ref/plugins}
Sýlvan Heuserb20f3882016-06-01 15:47:38 +020010mkdir -p "$REF"
11
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020012function download() {
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020013 local plugin="$1"; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020014
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020015 if [[ ! -f "${plugin}.hpi" ]]; then
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020016
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020017 local url="${JENKINS_UC}/latest/${plugin}.hpi"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020018 echo "download plugin : $plugin from $url"
19
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020020 curl -s -f -L "$url" -o "${plugin}.hpi"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020021 if [[ $? -ne 0 ]]
22 then
Nicolas De Loof4675f042016-06-01 14:07:33 +020023 # some plugin don't follow the rules about artifact ID
24 # typically: docker-plugin
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020025 local url="${JENKINS_UC}/latest/${plugin}-plugin.hpi"
26 echo "download plugin : $plugin from $url"
27 curl -s -f -L "${url}" -o "${plugin}.hpi"
Nicolas De Loof4675f042016-06-01 14:07:33 +020028 if [[ $? -ne 0 ]]
29 then
30 >&2 echo "failed to download plugin ${plugin}"
31 exit -1
32 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020033 fi
34 else
Baptiste Mathus0e7eac32016-05-29 16:14:40 +020035 echo "$plugin is already downloaded."
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020036 fi
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020037
38 if [[ ! -f ${plugin}.resolved ]]; then
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020039 resolveDependencies "$plugin"
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020040 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020041}
42
43function resolveDependencies() {
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020044 local plugin="$1"; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020045
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020046 local dependencies=`jrunscript -e '\
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020047 java.lang.System.out.println(\
48 new java.util.jar.JarFile("'${plugin}.hpi'")\
49 .getManifest()\
50 .getMainAttributes()\
51 .getValue("Plugin-Dependencies")\
52 );'`
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020053
54 if [[ "$dependencies" == "null" ]]; then
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020055 echo " > plugin has no dependencies"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020056 return
57 fi
58
59 echo " > depends on ${dependencies}"
60
61 IFS=',' read -a array <<< "${dependencies}"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020062 for d in "${array[@]}"
63 do
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020064 local p=$(echo $d | cut -d':' -f1 -)
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020065 if [[ $d == *"resolution:=optional"* ]]
66 then
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020067 echo "skipping optional dependency $p"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020068 else
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020069 download "$p"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020070 fi
71 done
Sýlvan Heuser62421ca2016-06-01 15:52:33 +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
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020079 download "$plugin"
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020080done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020081
82# cleanup 'resolved' flag files
83rm *.resolved