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 |
| 18 | echo "$plugin is allready downloaded." |
| 19 | fi |
| 20 | resolveDependencies $1 |
| 21 | } |
| 22 | |
| 23 | function resolveDependencies() { |
| 24 | plugin=$1 |
| 25 | |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 26 | dependencies=`jrunscript -e '\ |
| 27 | java.lang.System.out.println(\ |
| 28 | new java.util.jar.JarFile("'${plugin}.hpi'")\ |
| 29 | .getManifest()\ |
| 30 | .getMainAttributes()\ |
| 31 | .getValue("Plugin-Dependencies")\ |
| 32 | );'` |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 33 | |
| 34 | if [[ "$dependencies" == "null" ]]; then |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 35 | echo " > plugin has no dependencies" |
Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame] | 36 | return |
| 37 | fi |
| 38 | |
| 39 | echo " > depends on ${dependencies}" |
| 40 | |
| 41 | IFS=',' read -a array <<< "${dependencies}" |
| 42 | |
| 43 | for d in "${array[@]}" |
| 44 | do |
| 45 | plugin=$(echo $d | cut -d':' -f1 -) |
| 46 | if [[ $d == *"resolution:=optional"* ]] |
| 47 | then |
| 48 | echo "skipping optional dependency $plugin" |
| 49 | else |
| 50 | download $plugin |
| 51 | fi |
| 52 | done |
| 53 | } |
| 54 | |
| 55 | |
Nicolas De Loof | dfe81a3 | 2016-05-28 17:26:01 +0200 | [diff] [blame] | 56 | shift |
| 57 | for plugin in "$@" |
| 58 | do |
| 59 | download $plugin |
| 60 | done |