-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswarm-client-download.sh
More file actions
executable file
·85 lines (68 loc) · 2.56 KB
/
Copy pathswarm-client-download.sh
File metadata and controls
executable file
·85 lines (68 loc) · 2.56 KB
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
84
85
#!/bin/sh
# Jenkins Swarm Client integration for NUT CI farm
# Copyright (C)
# 2021-2026 by Jim Klimov <jimklimov+nut@gmail.com>
# License: MIT
# Settings below can be overridden by optional "swarm-client-download.conf":
# Fetches newest swarm client build, e.g.:
#LASTVER=1273.v578674cc1b_ca_.jar
### OLDER:
#LASTVER=3.25
#LASTVER=PR493-1
BASEURL="https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/"
# Optional private CA collection
# * For Java:
[ -n "${CACERTS_JKS_BASENAME}" ] || CACERTS_JKS_BASENAME="jenkins-swarm.cacerts.jks"
# * For Curl:
[ -n "${CACERTS_PEM_BASENAME}" ] || CACERTS_PEM_BASENAME="jenkins-swarm.cacerts.pem"
[ -n "${AGENT_NAME-}" ] || AGENT_NAME="`hostname | sed 's,\..*$,,'`"
CURL_OPTS="-sL"
WGET_OPTS=""
getLastVer_Incrementals() {
( curl $CURL_OPTS "${BASEURL}" || wget $WGET_OPTS -O - "${BASEURL}" ) \
| grep -E '<a href="[0-9]+\.v[0-9a-f_]+/">' \
| sed 's,^.*a href="\([0-9][0-9]*\.v[0-9a-f_]*\)/*".*$,\1,' \
| grep -vE '^\d\.' \
| sort -t. -k1,1n -k2,2n \
| tail -1
}
getLastVer_Old() {
( curl $CURL_OPTS "${BASEURL}" || wget $WGET_OPTS -O - "${BASEURL}" ) \
| grep -E '<a href="[0-9]+\.[0-9]+/">' \
| sed 's,^.*a href="\([0-9][0-9]*\.[0-9][0-9]*\)/*".*$,\1,' \
| sort -t. -k1,1n -k2,2n \
| tail -1
}
getLastVer() {
getLastVer_Incrementals
}
SCRIPTDIR="`dirname \"$0\"`"
SCRIPTDIR="`cd \"${SCRIPTDIR}\" && pwd`"
cd "${SCRIPTDIR}"
[ -n "${AGENT_DIR-}" ] || AGENT_DIR="${SCRIPTDIR}/../jenkins-${AGENT_NAME}/"
if [ -s "./swarm-client-download.conf" ]; then
ls -la "`pwd`/swarm-client-download.conf"
. "./swarm-client-download.conf" || exit
fi
if [ -n "${CACERTS_PEM_BASENAME}" ] ; then
CACERTS_PEM="${SCRIPTDIR}/${CACERTS_PEM_BASENAME}"
if [ -n "${AGENT_DIR}" ] && [ -s "${AGENT_DIR}/${CACERTS_PEM_BASENAME}" ] ; then
CACERTS_PEM="${AGENT_DIR}/${CACERTS_PEM_BASENAME}"
fi
if [ -s "${CACERTS_PEM_BASENAME}" ] ; then
CURL_OPTS="${CURL_OPTS} --cacert ${CACERTS_PEM}"
WGET_OPTS="${WGET_OPTS} --ca-certificate=${CACERTS_PEM}"
fi
fi
{ [ -n "${LASTVER-}" ] || LASTVER="`getLastVer`" ; } && [ -n "$LASTVER" ] || exit
if [ -s "swarm-client-${LASTVER}.jar" ] ; then
echo "swarm-client-${LASTVER}.jar is the newest published version" >&2
exit 0
fi
JARURL="${BASEURL}/${LASTVER}/swarm-client-${LASTVER}.jar"
echo "Fetching $JARURL" >&2
# Let several runners coexist in same homedir... somehow
JARTMP="swarm-client-${LASTVER}.jar.$$.tmp"
( ( curl $CURL_OPTS "${JARURL}" > "${JARTMP}" && [ -s "${JARTMP}" ] ) \
|| ( wget $WGET_OPTS -O "${JARTMP}" "${JARURL}" && [ -s "${JARTMP}" ] ) ) \
&& mv -f "${JARTMP}" "swarm-client-${LASTVER}.jar"