Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 1 | #! /bin/bash |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 2 | |
Sýlvan Heuser | b20f388 | 2016-06-01 15:47:38 +0200 | [diff] [blame] | 3 | # 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 Loof | cf78b91 | 2016-06-02 09:12:54 +0200 | [diff] [blame] | 8 | set -e |
Sýlvan Heuser | b20f388 | 2016-06-01 15:47:38 +0200 | [diff] [blame] | 9 | |
Nicolas De Loof | a9d458b | 2016-06-02 08:55:15 +0200 | [diff] [blame] | 10 | REF=${REF:-/usr/share/jenkins/ref/plugins} |
Sýlvan Heuser | b20f388 | 2016-06-01 15:47:38 +0200 | [diff] [blame] | 11 | mkdir -p "$REF" |
12 | |||||
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 13 | function download() { |
Sýlvan Heuser | 62421ca | 2016-06-01 15:52:33 +0200 | [diff] [blame] | 14 | local plugin="$1"; shift |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 15 | |
Sýlvan Heuser | 62421ca | 2016-06-01 15:52:33 +0200 | [diff] [blame] | 16 | if [[ ! -f "${plugin}.hpi" ]]; then |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 17 | |
Nicolas De Loof | a9d458b | 2016-06-02 08:55:15 +0200 | [diff] [blame] | 18 | local url="${JENKINS_UC}/latest/${plugin}.hpi" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 19 | echo "download plugin : $plugin from $url" |
20 | |||||
Nicolas De Loof | cf78b91 | 2016-06-02 09:12:54 +0200 | [diff] [blame] | 21 | if ! curl -s -f -L "$url" -o "${plugin}.hpi" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 22 | then |
Nicolas De Loof | 4675f04 | 2016-06-01 14:07:33 +0200 | [diff] [blame] | 23 | # some plugin don't follow the rules about artifact ID |
24 | # typically: docker-plugin | ||||
Nicolas De Loof | cf78b91 | 2016-06-02 09:12:54 +0200 | [diff] [blame] | 25 | plugin=${plugin}-plugin |
26 | |||||
27 | local url="${JENKINS_UC}/latest/${plugin}.hpi" | ||||
Nicolas De Loof | a9d458b | 2016-06-02 08:55:15 +0200 | [diff] [blame] | 28 | echo "download plugin : $plugin from $url" |
Nicolas De Loof | cf78b91 | 2016-06-02 09:12:54 +0200 | [diff] [blame] | 29 | if ! curl -s -f -L "${url}" -o "${plugin}.hpi" |
Nicolas De Loof | 4675f04 | 2016-06-01 14:07:33 +0200 | [diff] [blame] | 30 | then |
31 | >&2 echo "failed to download plugin ${plugin}" | ||||
32 | exit -1 | ||||
33 | fi | ||||
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 34 | fi |
35 | else | ||||
Baptiste Mathus | 0e7eac3 | 2016-05-29 16:14:40 +0200 | [diff] [blame] | 36 | echo "$plugin is already downloaded." |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 37 | fi |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame] | 38 | |
39 | if [[ ! -f ${plugin}.resolved ]]; then | ||||
Sýlvan Heuser | 62421ca | 2016-06-01 15:52:33 +0200 | [diff] [blame] | 40 | resolveDependencies "$plugin" |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame] | 41 | fi |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 42 | } |
43 | |||||
44 | function resolveDependencies() { | ||||
Sýlvan Heuser | 62421ca | 2016-06-01 15:52:33 +0200 | [diff] [blame] | 45 | local plugin="$1"; shift |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 46 | |
Nicolas De Loof | a9d458b | 2016-06-02 08:55:15 +0200 | [diff] [blame] | 47 | local dependencies=`jrunscript -e '\ |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 48 | java.lang.System.out.println(\ |
49 | new java.util.jar.JarFile("'${plugin}.hpi'")\ | ||||
50 | .getManifest()\ | ||||
51 | .getMainAttributes()\ | ||||
52 | .getValue("Plugin-Dependencies")\ | ||||
53 | );'` | ||||
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 54 | |
55 | if [[ "$dependencies" == "null" ]]; then | ||||
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 56 | echo " > plugin has no dependencies" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 57 | return |
58 | fi | ||||
59 | |||||
60 | echo " > depends on ${dependencies}" | ||||
61 | |||||
62 | IFS=',' read -a array <<< "${dependencies}" | ||||
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 63 | for d in "${array[@]}" |
64 | do | ||||
Nicolas De Loof | a9d458b | 2016-06-02 08:55:15 +0200 | [diff] [blame] | 65 | local p=$(echo $d | cut -d':' -f1 -) |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 66 | if [[ $d == *"resolution:=optional"* ]] |
67 | then | ||||
Nicolas De Loof | a9d458b | 2016-06-02 08:55:15 +0200 | [diff] [blame] | 68 | echo "skipping optional dependency $p" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 69 | else |
Nicolas De Loof | a9d458b | 2016-06-02 08:55:15 +0200 | [diff] [blame] | 70 | download "$p" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 71 | fi |
72 | done | ||||
Sýlvan Heuser | 62421ca | 2016-06-01 15:52:33 +0200 | [diff] [blame] | 73 | touch "${plugin}.resolved" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 74 | } |
75 | |||||
Sýlvan Heuser | b20f388 | 2016-06-01 15:47:38 +0200 | [diff] [blame] | 76 | cd "$REF" |
77 | |||||
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 78 | for plugin in "$@" |
79 | do | ||||
Sýlvan Heuser | 62421ca | 2016-06-01 15:52:33 +0200 | [diff] [blame] | 80 | download "$plugin" |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 81 | done |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame] | 82 | |
83 | # cleanup 'resolved' flag files | ||||
jgmchan | e550fba | 2016-06-11 18:58:42 +1000 | [diff] [blame] | 84 | rm -f *.resolved |