blob: 2fa42cdfa665906f6de9b1d18456206a20dd7963 [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
Dave Head-Rapson595a4682016-02-29 13:41:53 +00005# Copy files from /usr/share/jenkins/ref into $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"
Dave Head-Rapson595a4682016-02-29 13:41:53 +000016 if [[ ! -e $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"
Dave Head-Rapson595a4682016-02-29 13:41:53 +000019 mkdir -p "$JENKINS_HOME/${dir:23}"
20 cp -r "${f}" "$JENKINS_HOME/${rel}";
Carlos Sanchez69d55cd2015-05-15 10:45:13 +020021 # pin plugins on initial copy
Dave Head-Rapson595a4682016-02-29 13:41:53 +000022 [[ ${rel} == plugins/*.jpi ]] && touch "$JENKINS_HOME/${rel}.pinned"
Bastiaan Bakker45b0f672016-01-11 17:37:53 +010023 fi;
Nicolas De Loofacb86492014-10-24 13:43:13 +020024}
Dave Head-Rapson595a4682016-02-29 13:41:53 +000025: ${JENKINS_HOME:="/var/jenkins_home"}
Nicolas De Loofacb86492014-10-24 13:43:13 +020026export -f copy_reference_file
Carlos Sanchezbd2f6c92016-01-14 09:15:47 +010027touch "${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 +030028echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
Vincent Latombeaa2b3542015-08-04 14:10:24 +020029find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
Nicolas De Loofacb86492014-10-24 13:43:13 +020030
Nicolas De Loof07c307d2014-10-07 14:02:42 +020031# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
32if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
Carlos Sancheze7d56fa2016-02-29 13:55:33 +010033 eval "exec java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS \"\$@\""
Nicolas De Loof07c307d2014-10-07 14:02:42 +020034fi
35
36# 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 +020037exec "$@"