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 | |
| 3 | function download() { |
| 4 | plugin=$1 |
| 5 | |
| 6 | if [[ ! -f ${plugin}.hpi ]]; then |
| 7 | |
| 8 | url=http://updates.jenkins-ci.org/latest/${plugin}.hpi |
| 9 | echo "download plugin : $plugin from $url" |
| 10 | |
| 11 | curl -s -f -L $url -o ${plugin}.hpi |
| 12 | if [[ $? -ne 0 ]] |
| 13 | then |
| 14 | >&2 echo "failed to download plugin ${plugin}" |
| 15 | exit -1 |
| 16 | fi |
| 17 | else |
Baptiste Mathus | 0e7eac3 | 2016-05-29 16:14:40 +0200 | [diff] [blame] | 18 | echo "$plugin is already downloaded." |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 19 | fi |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame^] | 20 | |
| 21 | if [[ ! -f ${plugin}.resolved ]]; then |
| 22 | resolveDependencies $1 |
| 23 | fi |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | function resolveDependencies() { |
| 27 | plugin=$1 |
| 28 | |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 29 | dependencies=`jrunscript -e '\ |
| 30 | java.lang.System.out.println(\ |
| 31 | new java.util.jar.JarFile("'${plugin}.hpi'")\ |
| 32 | .getManifest()\ |
| 33 | .getMainAttributes()\ |
| 34 | .getValue("Plugin-Dependencies")\ |
| 35 | );'` |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 36 | |
| 37 | if [[ "$dependencies" == "null" ]]; then |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 38 | echo " > plugin has no dependencies" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 39 | return |
| 40 | fi |
| 41 | |
| 42 | echo " > depends on ${dependencies}" |
| 43 | |
| 44 | IFS=',' read -a array <<< "${dependencies}" |
| 45 | |
| 46 | for d in "${array[@]}" |
| 47 | do |
| 48 | plugin=$(echo $d | cut -d':' -f1 -) |
| 49 | if [[ $d == *"resolution:=optional"* ]] |
| 50 | then |
| 51 | echo "skipping optional dependency $plugin" |
| 52 | else |
| 53 | download $plugin |
| 54 | fi |
| 55 | done |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame^] | 56 | touch ${plugin}.resolved |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 60 | shift |
| 61 | for plugin in "$@" |
| 62 | do |
| 63 | download $plugin |
| 64 | done |
Nicolas De Loof | a7a34c3 | 2016-05-30 09:10:58 +0200 | [diff] [blame^] | 65 | |
| 66 | # cleanup 'resolved' flag files |
| 67 | rm *.resolved |