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