blob: 414ac078080d4de9bdbd24d34bed1a5c72b22c9c [file] [log] [blame]
Nicolas De Loofd6064382014-10-04 08:17:28 +02001#! /bin/bash
2
Mike Dillon1f9d73c2015-04-06 17:17:40 -07003set -e
4
Nicolas De Loofacb86492014-10-24 13:43:13 +02005# Copy files from /usr/share/jenkins/ref into /var/jenkins_home
Bastiaan Bakker45b0f672016-01-11 17:37:53 +01006# So the initial JENKINS-HOME is set with expected content.
7# Don't override, as this is just a reference setup, and use from UI
Nicolas De Loofacb86492014-10-24 13:43:13 +02008# can then change this, upgrade plugins, etc.
9copy_reference_file() {
Kanstantsin Shautsou44096322015-12-11 02:21:20 +030010 f="${1%/}"
Bastiaan Bakker45b0f672016-01-11 17:37:53 +010011 b="${f%.override}"
Kanstantsin Shautsou44096322015-12-11 02:21:20 +030012 echo "$f" >> "$COPY_REFERENCE_FILE_LOG"
Bastiaan Bakker45b0f672016-01-11 17:37:53 +010013 rel="${b:23}"
14 dir=$(dirname "${b}")
15 echo " $f -> $rel" >> "$COPY_REFERENCE_FILE_LOG"
16 if [[ ! -e /var/jenkins_home/${rel} || $f = *.override ]]
Nicolas De Loofacb86492014-10-24 13:43:13 +020017 then
Kanstantsin Shautsou44096322015-12-11 02:21:20 +030018 echo "copy $rel to JENKINS_HOME" >> "$COPY_REFERENCE_FILE_LOG"
19 mkdir -p "/var/jenkins_home/${dir:23}"
Bastiaan Bakker45b0f672016-01-11 17:37:53 +010020 cp -r "${f}" "/var/jenkins_home/${rel}";
Carlos Sanchez69d55cd2015-05-15 10:45:13 +020021 # pin plugins on initial copy
Kanstantsin Shautsou44096322015-12-11 02:21:20 +030022 [[ ${rel} == plugins/*.jpi ]] && touch "/var/jenkins_home/${rel}.pinned"
Bastiaan Bakker45b0f672016-01-11 17:37:53 +010023 fi;
Nicolas De Loofacb86492014-10-24 13:43:13 +020024}
25export -f copy_reference_file
Carlos Sanchezbd2f6c92016-01-14 09:15:47 +010026touch "${COPY_REFERENCE_FILE_LOG}" || (echo "Can not write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?" && exit 1)
Kanstantsin Shautsou44096322015-12-11 02:21:20 +030027echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
Vincent Latombeaa2b3542015-08-04 14:10:24 +020028find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
Nicolas De Loofacb86492014-10-24 13:43:13 +020029
Nicolas De Loof07c307d2014-10-07 14:02:42 +020030# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
31if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
Nicolas De Looff744bdb2014-10-23 14:23:58 +020032 exec java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS "$@"
Nicolas De Loof07c307d2014-10-07 14:02:42 +020033fi
34
35# As argument is not jenkins, assume user want to run his own process, for sample a `bash` shell to explore this image
Nicolas De loofb2b442e2014-10-08 08:05:02 +020036exec "$@"