-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreLoadPlugins.sh
executable file
·71 lines (56 loc) · 1.82 KB
/
preLoadPlugins.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
#!/bin/bash
set -e
if [ ! -f ./jenkins.env ]; then
echo "run prepareSetup.sh first to set your Jenkins-Version"
exit -1
fi
. ./jenkins.env
MAJOR_MINOR=${MAJOR}.${MINOR}
plugin_dir=jenkins/plugins-${MAJOR_MINOR}
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: ${plugin_dir}/$1 (already installed)"
return 0
else
echo "Downloading: https://updates.jenkins-ci.org/${MAJOR_MINOR}/latest/${1}.hpi to ${plugin_dir}"
curl -L --silent --output ${plugin_dir}/${1}.hpi https://updates.jenkins-ci.org/${MAJOR_MINOR}/latest/${1}.hpi
return 0
fi
}
for plugin in $(cat jenkins/plugins.txt)
do
installPlugin "$plugin"
done
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
# without optionals
#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" | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
# with optionals
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' | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
for plugin in $deps; do
installPlugin "$plugin" 1 && changed=1
done
done
done
COUNT=$(find ${plugin_dir} -name *.hpi | wc -l)
if [ $COUNT -gt 0 ] ; then
echo "Renaming all .hpi to .jpi"
for file in $(ls ${plugin_dir}/*.hpi)
do
mv $file ${file%.*}.jpi
done
fi
echo "all done"