forked from jenkinsci/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-plugins.sh
executable file
·83 lines (67 loc) · 1.69 KB
/
install-plugins.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/bash
# Resolve dependencies and download plugins given on the command line
#
# FROM jenkins
# RUN install-plugins.sh docker-slaves github-branch-source
REF=${REF:-/usr/share/jenkins/ref/plugins}
mkdir -p "$REF"
function download() {
local plugin="$1"; shift
if [[ ! -f "${plugin}.hpi" ]]; then
local url="${JENKINS_UC}/latest/${plugin}.hpi"
echo "download plugin : $plugin from $url"
curl -s -f -L "$url" -o "${plugin}.hpi"
if [[ $? -ne 0 ]]
then
# some plugin don't follow the rules about artifact ID
# typically: docker-plugin
local url="${JENKINS_UC}/latest/${plugin}-plugin.hpi"
echo "download plugin : $plugin from $url"
curl -s -f -L "${url}" -o "${plugin}.hpi"
if [[ $? -ne 0 ]]
then
>&2 echo "failed to download plugin ${plugin}"
exit -1
fi
fi
else
echo "$plugin is already downloaded."
fi
if [[ ! -f ${plugin}.resolved ]]; then
resolveDependencies "$plugin"
fi
}
function resolveDependencies() {
local plugin="$1"; shift
local dependencies=`jrunscript -e '\
java.lang.System.out.println(\
new java.util.jar.JarFile("'${plugin}.hpi'")\
.getManifest()\
.getMainAttributes()\
.getValue("Plugin-Dependencies")\
);'`
if [[ "$dependencies" == "null" ]]; then
echo " > plugin has no dependencies"
return
fi
echo " > depends on ${dependencies}"
IFS=',' read -a array <<< "${dependencies}"
for d in "${array[@]}"
do
local p=$(echo $d | cut -d':' -f1 -)
if [[ $d == *"resolution:=optional"* ]]
then
echo "skipping optional dependency $p"
else
download "$p"
fi
done
touch "${plugin}.resolved"
}
cd "$REF"
for plugin in "$@"
do
download "$plugin"
done
# cleanup 'resolved' flag files
rm *.resolved