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 | |
| 8 | set -e |
| 9 | |
| 10 | REF=/usr/share/jenkins/ref/plugins |
| 11 | mkdir -p "$REF" |
| 12 | |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 13 | function download() { |
Nicolas De Loof | 4675f04 | 2016-06-01 14:07:33 +0200 | [diff] [blame] | 14 | local plugin=$1; shift |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 15 | |
| 16 | if [[ ! -f ${plugin}.hpi ]]; then |
| 17 | |
Nicolas De Loof | 4675f04 | 2016-06-01 14:07:33 +0200 | [diff] [blame] | 18 | 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 | |
| 21 | curl -s -f -L $url -o ${plugin}.hpi |
| 22 | if [[ $? -ne 0 ]] |
| 23 | then |
Nicolas De Loof | 4675f04 | 2016-06-01 14:07:33 +0200 | [diff] [blame] | 24 | # some plugin don't follow the rules about artifact ID |
| 25 | # typically: docker-plugin |
| 26 | curl -s -f -L $url -o ${plugin}-plugin.hpi |
| 27 | if [[ $? -ne 0 ]] |
| 28 | then |
| 29 | >&2 echo "failed to download plugin ${plugin}" |
| 30 | exit -1 |
| 31 | fi |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 32 | fi |
| 33 | else |
Baptiste Mathus | 0e7eac3 | 2016-05-29 16:14:40 +0200 | [diff] [blame] | 34 | echo "$plugin is already downloaded." |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 35 | fi |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame] | 36 | |
| 37 | if [[ ! -f ${plugin}.resolved ]]; then |
Sýlvan Heuser | 2f2bdc9 | 2016-06-01 15:46:16 +0200 | [diff] [blame] | 38 | resolveDependencies $plugin |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame] | 39 | fi |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | function resolveDependencies() { |
Nicolas De Loof | 4675f04 | 2016-06-01 14:07:33 +0200 | [diff] [blame] | 43 | local plugin=$1; shift |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 44 | |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 45 | 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 Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 52 | |
| 53 | if [[ "$dependencies" == "null" ]]; then |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 54 | echo " > plugin has no dependencies" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 55 | 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 |
| 69 | download $plugin |
| 70 | fi |
| 71 | done |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +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 |
| 79 | download $plugin |
| 80 | done |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame] | 81 | |
| 82 | # cleanup 'resolved' flag files |
| 83 | rm *.resolved |