blob: e1150fc87eb757e54c892256f2cf94db67aa9bf7 [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
Nicolas De Loofcf78b912016-06-02 09:12:54 +02008set -e
Sýlvan Heuserb20f3882016-06-01 15:47:38 +02009
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020010REF=${REF:-/usr/share/jenkins/ref/plugins}
Sýlvan Heuserb20f3882016-06-01 15:47:38 +020011mkdir -p "$REF"
12
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020013function download() {
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020014 local plugin="$1"; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020015
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020016 if [[ ! -f "${plugin}.hpi" ]]; then
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020017
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020018 local url="${JENKINS_UC}/latest/${plugin}.hpi"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020019 echo "download plugin : $plugin from $url"
20
Nicolas De Loofcf78b912016-06-02 09:12:54 +020021 if ! curl -s -f -L "$url" -o "${plugin}.hpi"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020022 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 Loofcf78b912016-06-02 09:12:54 +020025 plugin=${plugin}-plugin
26
27 local url="${JENKINS_UC}/latest/${plugin}.hpi"
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020028 echo "download plugin : $plugin from $url"
Nicolas De Loofcf78b912016-06-02 09:12:54 +020029 if ! curl -s -f -L "${url}" -o "${plugin}.hpi"
Nicolas De Loof4675f042016-06-01 14:07:33 +020030 then
31 >&2 echo "failed to download plugin ${plugin}"
32 exit -1
33 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020034 fi
35 else
Baptiste Mathus0e7eac32016-05-29 16:14:40 +020036 echo "$plugin is already downloaded."
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020037 fi
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020038
39 if [[ ! -f ${plugin}.resolved ]]; then
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020040 resolveDependencies "$plugin"
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020041 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020042}
43
44function resolveDependencies() {
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020045 local plugin="$1"; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020046
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020047 local dependencies=`jrunscript -e '\
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020048 java.lang.System.out.println(\
49 new java.util.jar.JarFile("'${plugin}.hpi'")\
50 .getManifest()\
51 .getMainAttributes()\
52 .getValue("Plugin-Dependencies")\
53 );'`
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020054
55 if [[ "$dependencies" == "null" ]]; then
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020056 echo " > plugin has no dependencies"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020057 return
58 fi
59
60 echo " > depends on ${dependencies}"
61
62 IFS=',' read -a array <<< "${dependencies}"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020063 for d in "${array[@]}"
64 do
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020065 local p=$(echo $d | cut -d':' -f1 -)
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020066 if [[ $d == *"resolution:=optional"* ]]
67 then
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020068 echo "skipping optional dependency $p"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020069 else
Nicolas De Loofa9d458b2016-06-02 08:55:15 +020070 download "$p"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020071 fi
72 done
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020073 touch "${plugin}.resolved"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020074}
75
Sýlvan Heuserb20f3882016-06-01 15:47:38 +020076cd "$REF"
77
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020078for plugin in "$@"
79do
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020080 download "$plugin"
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020081done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020082
83# cleanup 'resolved' flag files
jgmchane550fba2016-06-11 18:58:42 +100084rm -f *.resolved