blob: d6ac4cc856c0eba0fc621488a71d676919378eeb [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() {
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
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020018 url="${JENKINS_UC}/latest/${plugin}.hpi"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020019 echo "download plugin : $plugin from $url"
20
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020021 curl -s -f -L "$url" -o "${plugin}.hpi"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020022 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
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020026 curl -s -f -L "$url" -o "${plugin}-plugin.hpi"
Nicolas De Loof4675f042016-06-01 14:07:33 +020027 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 Heuser62421ca2016-06-01 15:52:33 +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() {
Sýlvan Heuser62421ca2016-06-01 15:52: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
Sýlvan Heuser62421ca2016-06-01 15:52:33 +020069 download "$plugin"
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