File jenkins-agent-download.sh of Package jenkins-agent
#!/bin/sh
# Jenkins Agent Downloader
# Georg Pfuetzenreuter <georg.pfuetzenreuter@suse.com>
set -Ceu
if ! ( command -v curl && command -v file ) >/dev/null
then
echo 'This tool requires `curl` and `file` to be installed.'
exit 1
fi
if [ $(id -u) != 0 ]
then
echo 'This tool needs to be run as root.'
exit 1
fi
if [ -f '/etc/sysconfig/jenkins-agent' ]
then
. /etc/sysconfig/jenkins-agent
fi
if [ -z "$JENKINS_BASE" ]
then
echo 'JENKINS_BASE is not defined in /etc/sysconfig/jenkins.'
JENKINS_BASE="${1?Specify the Jenkins controller FQDN as the first argument or define JENKINS_BASE.}"
exit 1
fi
EXTRA_ARGS="${2-:none}"
BINDIR='/opt/jenkins/bin'
if [ ! -d "$BINDIR" ]
then
echo "$BINDIR needs to exist."
exit 1
fi
URL="$JENKINS_BASE/jnlpJars/agent.jar"
BIN="$BINDIR/agent.jar"
if [ -f "$BIN" ]
then
if [ "$EXTRA_ARGS" = 'none' ]
then
echo 'Agent exists, skipping download.'
exit
elif [ "$EXTRA_ARGS" = '--force' ]
then
echo 'Agent exists, re-download requested.'
fi
fi
if curl -sSLo "$BIN" "$URL"
then
echo 'Agent downloaded.'
if [ "$(file -bi $BIN)" == 'application/zip; charset=binary' ]
then
echo 'Agent JAR file is valid.'
else
echo 'Agent JAR file is invalid.'
exit 1
fi
else
echo 'Agent download failed.'
exit 1
fi