Advertisement
Guest User

Untitled

a guest
Sep 15th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.96 KB | None | 0 0
  1. # Copy files from /usr/share/jenkins/ref into $JENKINS_HOME
  2. # So the initial JENKINS-HOME is set with expected content.
  3. # Don't override, as this is just a reference setup, and use from UI
  4. # can then change this, upgrade plugins, etc.
  5. copy_reference_file() {
  6.     f="${1%/}"
  7.     b="${f%.override}"
  8.     rel="${b:23}"
  9.     version_marker="${rel}.version_from_image"
  10.     dir=$(dirname "${b}")
  11.     local action;
  12.     local reason;
  13.     local container_version;
  14.     local image_version;
  15.     local marker_version;
  16.     local log; log=false
  17.     if [[ ${rel} == plugins/*.jpi ]]; then
  18.         container_version=$(get_plugin_version "$JENKINS_HOME/${rel}")
  19.         image_version=$(get_plugin_version "${f}")
  20.         if [[ -e $JENKINS_HOME/${version_marker} ]]; then
  21.             marker_version=$(cat "$JENKINS_HOME/${version_marker}")
  22.             if versionLT "$marker_version" "$container_version"; then
  23.                 action="SKIPPED"
  24.                 reason="Installed version ($container_version) has been manually upgraded from initial version ($marker_version)"
  25.                 log=true
  26.             else
  27.                 if [[ "$image_version" == "$container_version" ]]; then
  28.                     action="SKIPPED"
  29.                     reason="Version from image is the same as the installed version $image_version"
  30.                 else
  31.                     if versionLT "$image_version" "$container_version"; then
  32.                         action="SKIPPED"
  33.                         log=true
  34.                         reason="Image version ($image_version) is older than installed version ($container_version)"
  35.                     else
  36.                         action="UPGRADED"
  37.                         log=true
  38.                         reason="Image version ($image_version) is newer than installed version ($container_version)"
  39.                     fi
  40.                 fi
  41.             fi
  42.         else
  43.             if [[ -n "$TRY_UPGRADE_IF_NO_MARKER" ]]; then
  44.                 if [[ "$image_version" == "$container_version" ]]; then
  45.                     action="SKIPPED"
  46.                     reason="Version from image is the same as the installed version $image_version (no marker found)"
  47.                     # Add marker for next time
  48.                     echo "$image_version" > "$JENKINS_HOME/${version_marker}"
  49.                 else
  50.                     if versionLT "$image_version" "$container_version"; then
  51.                         action="SKIPPED"
  52.                         log=true
  53.                         reason="Image version ($image_version) is older than installed version ($container_version) (no marker found)"
  54.                     else
  55.                         action="UPGRADED"
  56.                         log=true
  57.                         reason="Image version ($image_version) is newer than installed version ($container_version) (no marker found)"
  58.                     fi
  59.                 fi
  60.             fi
  61.         fi
  62.         if [[ ! -e $JENKINS_HOME/${rel} || "$action" == "UPGRADED" || $f = *.override ]]; then
  63.             action=${action:-"INSTALLED"}
  64.             log=true
  65.             mkdir -p "$JENKINS_HOME/${dir:23}"
  66.             cp -r "${f}" "$JENKINS_HOME/${rel}";
  67.             # pin plugins on initial copy
  68.             touch "$JENKINS_HOME/${rel}.pinned"
  69.             echo "$image_version" > "$JENKINS_HOME/${version_marker}"
  70.             reason=${reason:-$image_version}
  71.         else
  72.             action=${action:-"SKIPPED"}
  73.         fi
  74.     else
  75.         if [[ ! -e $JENKINS_HOME/${rel} || $f = *.override ]]
  76.         then
  77.             action="INSTALLED"
  78.             log=true
  79.             mkdir -p "$JENKINS_HOME/${dir:23}"
  80.             cp -r "${f}" "$JENKINS_HOME/${rel}";
  81.         else
  82.             action="SKIPPED"
  83.         fi
  84.     fi
  85.     if [[ -n "$VERBOSE" || "$log" == "true" ]]; then
  86.         if [ -z "$reason" ]; then
  87.             echo "$action $rel" >> "$COPY_REFERENCE_FILE_LOG"
  88.         else
  89.             echo "$action $rel : $reason" >> "$COPY_REFERENCE_FILE_LOG"
  90.         fi
  91.     fi
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement