-
Notifications
You must be signed in to change notification settings - Fork 38
/
install_jenkins_plugin.sh
executable file
·77 lines (61 loc) · 1.77 KB
/
install_jenkins_plugin.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
#!/bin/bash
# get from https://gist.github.com/chuxau/6bc42f0f271704cd4e91
set -e
UPDATES_URL="http://updates.jenkins-ci.org/download/plugins/"
#UPDATES_RUL="http://mirrors.jenkins-ci.org/plugins/"
if [ $# -lt 2 ]; then
echo "USAGE: $0 plugin-list-file destination-directory"
exit 1
fi
plugin_list=$1
plugin_dir=$2
#file_owner=jenkins.jenkins
mkdir -p $plugin_dir
installPlugin() {
if [ -f ${plugin_dir}/${1}.hpi -o -f ${plugin_dir}/${1}.jpi ]; then
if [ "$2" == "1" ]; then
return 1
fi
echo "Skipped: $1 (already installed)"
return 0
else
echo "Installing: $1"
curl -L --silent --output ${plugin_dir}/${1}.hpi ${UPDATES_URL}/${1}/${2}/${1}.hpi
return 0
fi
}
while IFS="|" read plugin version
do
#escape comments
if [[ $plugin =~ ^# ]]; then
continue
fi
#install the plugin
installPlugin $plugin $version
done < $plugin_list
changed=1
maxloops=100
while [ "$changed" == "1" ]; do
echo "Check for missing dependecies ..."
if [ $maxloops -lt 1 ] ; then
echo "Max loop count reached - probably a bug in this script: $0"
exit 1
fi
((maxloops--))
changed=0
for f in ${plugin_dir}/*.hpi ; do
# get a list of only non-optional dependencies
deps=$( unzip -p ${f} META-INF/MANIFEST.MF|tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e 'Plugin-Dependencies' | awk '{print $2}' | tr "," "\n" | grep -v 'resolution:=optional')
#if deps were found, install them .. then set changed, so we re-loop all over all xpi's
if [[ ! -z $deps ]]; then
echo $deps | tr ' ' '\n' |
while IFS=: read plugin version; do
installPlugin $plugin $version
done
changed=1
fi
done
done
#echo "fixing permissions"
#chown ${file_owner} ${plugin_dir} -R
echo "all done"