Nicolas De Loof | 0ef5a62 | 2016-05-27 19:14:29 +0200 | [diff] [blame^] | 1 | #! /bin/sh |
| 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 | |
| 26 | dependencies=`jrunscript -e 'java.lang.System.out.println(new java.util.jar.JarFile("'${plugin}.hpi'").getManifest().getMainAttributes().getValue("Plugin-Dependencies"));'` |
| 27 | |
| 28 | if [[ "$dependencies" == "null" ]]; then |
| 29 | return |
| 30 | fi |
| 31 | |
| 32 | echo " > depends on ${dependencies}" |
| 33 | |
| 34 | IFS=',' read -a array <<< "${dependencies}" |
| 35 | |
| 36 | for d in "${array[@]}" |
| 37 | do |
| 38 | plugin=$(echo $d | cut -d':' -f1 -) |
| 39 | if [[ $d == *"resolution:=optional"* ]] |
| 40 | then |
| 41 | echo "skipping optional dependency $plugin" |
| 42 | else |
| 43 | download $plugin |
| 44 | fi |
| 45 | done |
| 46 | } |
| 47 | |
| 48 | |
| 49 | download $1 |