Tabs to spaces
diff --git a/install-plugins.sh b/install-plugins.sh
index fa6f5fd..2c8cc20 100755
--- a/install-plugins.sh
+++ b/install-plugins.sh
@@ -13,178 +13,178 @@
. /usr/local/bin/jenkins-support
function getLockFile() {
- echo -n "$REF_DIR/${1}.lock"
+ echo -n "$REF_DIR/${1}.lock"
}
function getArchiveFilename() {
- echo -n "$REF_DIR/${1}.jpi"
+ echo -n "$REF_DIR/${1}.jpi"
}
function download() {
- local plugin originalPlugin version lock ignoreLockFile
- plugin="$1"
- version="${2:-latest}"
- ignoreLockFile="${3:-}"
- lock="$(getLockFile "$plugin")"
+ local plugin originalPlugin version lock ignoreLockFile
+ plugin="$1"
+ version="${2:-latest}"
+ ignoreLockFile="${3:-}"
+ lock="$(getLockFile "$plugin")"
- if [[ $ignoreLockFile ]] || mkdir "$lock" &>/dev/null; then
- if ! doDownload "$plugin" "$version"; then
- # some plugin don't follow the rules about artifact ID
- # typically: docker-plugin
- originalPlugin="$plugin"
- plugin="${plugin}-plugin"
- if ! doDownload "$plugin" "$version"; then
- echo "Failed to download plugin: $originalPlugin or $plugin" >&2
- echo "Not downloaded: ${originalPlugin}" >> "$FAILED"
- return 1
- fi
- fi
+ if [[ $ignoreLockFile ]] || mkdir "$lock" &>/dev/null; then
+ if ! doDownload "$plugin" "$version"; then
+ # some plugin don't follow the rules about artifact ID
+ # typically: docker-plugin
+ originalPlugin="$plugin"
+ plugin="${plugin}-plugin"
+ if ! doDownload "$plugin" "$version"; then
+ echo "Failed to download plugin: $originalPlugin or $plugin" >&2
+ echo "Not downloaded: ${originalPlugin}" >> "$FAILED"
+ return 1
+ fi
+ fi
- if ! checkIntegrity "$plugin"; then
- echo "Downloaded file is not a valid ZIP: $(getArchiveFilename "$plugin")" >&2
- echo "Download integrity: ${plugin}" >> "$FAILED"
- return 1
- fi
+ if ! checkIntegrity "$plugin"; then
+ echo "Downloaded file is not a valid ZIP: $(getArchiveFilename "$plugin")" >&2
+ echo "Download integrity: ${plugin}" >> "$FAILED"
+ return 1
+ fi
- resolveDependencies "$plugin"
- fi
+ resolveDependencies "$plugin"
+ fi
}
function doDownload() {
- local plugin version url jpi
- plugin="$1"
- version="$2"
- jpi="$(getArchiveFilename "$plugin")"
+ local plugin version url jpi
+ plugin="$1"
+ version="$2"
+ jpi="$(getArchiveFilename "$plugin")"
- # If plugin already exists and is the same version do not download
- if test -f "$jpi" && unzip -p "$jpi" META-INF/MANIFEST.MF | tr -d '\r' | grep "^Plugin-Version: ${version}$" > /dev/null; then
- echo "Using provided plugin: $plugin"
- return 0
- fi
+ # If plugin already exists and is the same version do not download
+ if test -f "$jpi" && unzip -p "$jpi" META-INF/MANIFEST.MF | tr -d '\r' | grep "^Plugin-Version: ${version}$" > /dev/null; then
+ echo "Using provided plugin: $plugin"
+ return 0
+ fi
- url="$JENKINS_UC/download/plugins/$plugin/$version/${plugin}.hpi"
+ url="$JENKINS_UC/download/plugins/$plugin/$version/${plugin}.hpi"
- echo "Downloading plugin: $plugin from $url"
- curl --connect-timeout 5 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L "$url" -o "$jpi"
- return $?
+ echo "Downloading plugin: $plugin from $url"
+ curl --connect-timeout 5 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L "$url" -o "$jpi"
+ return $?
}
function checkIntegrity() {
- local plugin jpi
- plugin="$1"
- jpi="$(getArchiveFilename "$plugin")"
+ local plugin jpi
+ plugin="$1"
+ jpi="$(getArchiveFilename "$plugin")"
- zip -T "$jpi" >/dev/null
- return $?
+ zip -T "$jpi" >/dev/null
+ return $?
}
function resolveDependencies() {
- local plugin jpi dependencies
- plugin="$1"
- jpi="$(getArchiveFilename "$plugin")"
+ local plugin jpi dependencies
+ plugin="$1"
+ jpi="$(getArchiveFilename "$plugin")"
- dependencies="$(unzip -p "$jpi" META-INF/MANIFEST.MF | tr -d '\r' | tr '\n' '|' | sed -e 's#| ##g' | tr '|' '\n' | grep "^Plugin-Dependencies: " | sed -e 's#^Plugin-Dependencies: ##')"
+ dependencies="$(unzip -p "$jpi" META-INF/MANIFEST.MF | tr -d '\r' | tr '\n' '|' | sed -e 's#| ##g' | tr '|' '\n' | grep "^Plugin-Dependencies: " | sed -e 's#^Plugin-Dependencies: ##')"
- if [[ ! $dependencies ]]; then
- echo " > $plugin has no dependencies"
- return
- fi
+ if [[ ! $dependencies ]]; then
+ echo " > $plugin has no dependencies"
+ return
+ fi
- echo " > $plugin depends on $dependencies"
+ echo " > $plugin depends on $dependencies"
- IFS=',' read -a array <<< "$dependencies"
+ IFS=',' read -a array <<< "$dependencies"
- for d in "${array[@]}"
- do
- plugin="$(cut -d':' -f1 - <<< "$d")"
- if [[ $d == *"resolution:=optional"* ]]; then
- echo "Skipping optional dependency $plugin"
- else
- local pluginInstalled
- if pluginInstalled="$(echo "${bundledPlugins}" | grep "^${plugin}:")"; then
- pluginInstalled="${pluginInstalled//[$'\r']}"
- local versionInstalled; versionInstalled=$(versionFromPlugin "${pluginInstalled}")
- local versionToInstall; versionToInstall=$(versionFromPlugin "${d}")
- if versionLT "${versionInstalled}" "${versionToInstall}"; then
- echo "Upgrading bundled dependency $d ($versionToInstall > $versionInstalled)"
- download "$plugin" "$versionToInstall" &
- else
- echo "Skipping already bundled dependency $d ($versionToInstall <= $versionInstalled)"
- fi
- else
- download "$plugin" "$(versionFromPlugin "${d}")" &
- fi
- fi
- done
- wait
+ for d in "${array[@]}"
+ do
+ plugin="$(cut -d':' -f1 - <<< "$d")"
+ if [[ $d == *"resolution:=optional"* ]]; then
+ echo "Skipping optional dependency $plugin"
+ else
+ local pluginInstalled
+ if pluginInstalled="$(echo "${bundledPlugins}" | grep "^${plugin}:")"; then
+ pluginInstalled="${pluginInstalled//[$'\r']}"
+ local versionInstalled; versionInstalled=$(versionFromPlugin "${pluginInstalled}")
+ local versionToInstall; versionToInstall=$(versionFromPlugin "${d}")
+ if versionLT "${versionInstalled}" "${versionToInstall}"; then
+ echo "Upgrading bundled dependency $d ($versionToInstall > $versionInstalled)"
+ download "$plugin" "$versionToInstall" &
+ else
+ echo "Skipping already bundled dependency $d ($versionToInstall <= $versionInstalled)"
+ fi
+ else
+ download "$plugin" "$(versionFromPlugin "${d}")" &
+ fi
+ fi
+ done
+ wait
}
function bundledPlugins() {
- local JENKINS_WAR=/usr/share/jenkins/jenkins.war
- if [ -f $JENKINS_WAR ]
- then
- TEMP_PLUGIN_DIR=/tmp/plugintemp.$$
- for i in $(jar tf $JENKINS_WAR | egrep '[^detached-]plugins.*\..pi' | sort)
- do
- rm -fr $TEMP_PLUGIN_DIR
- mkdir -p $TEMP_PLUGIN_DIR
- PLUGIN=$(basename "$i"|cut -f1 -d'.')
- (cd $TEMP_PLUGIN_DIR;jar xf "$JENKINS_WAR" "$i";jar xvf "$TEMP_PLUGIN_DIR/$i" META-INF/MANIFEST.MF >/dev/null 2>&1)
- VER=$(egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //')
- echo "$PLUGIN:$VER"
- done
- rm -fr $TEMP_PLUGIN_DIR
- else
- rm -f "$TEMP_ALREADY_INSTALLED"
- echo "ERROR file not found: $JENKINS_WAR"
- exit 1
- fi
+ local JENKINS_WAR=/usr/share/jenkins/jenkins.war
+ if [ -f $JENKINS_WAR ]
+ then
+ TEMP_PLUGIN_DIR=/tmp/plugintemp.$$
+ for i in $(jar tf $JENKINS_WAR | egrep '[^detached-]plugins.*\..pi' | sort)
+ do
+ rm -fr $TEMP_PLUGIN_DIR
+ mkdir -p $TEMP_PLUGIN_DIR
+ PLUGIN=$(basename "$i"|cut -f1 -d'.')
+ (cd $TEMP_PLUGIN_DIR;jar xf "$JENKINS_WAR" "$i";jar xvf "$TEMP_PLUGIN_DIR/$i" META-INF/MANIFEST.MF >/dev/null 2>&1)
+ VER=$(egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //')
+ echo "$PLUGIN:$VER"
+ done
+ rm -fr $TEMP_PLUGIN_DIR
+ else
+ rm -f "$TEMP_ALREADY_INSTALLED"
+ echo "ERROR file not found: $JENKINS_WAR"
+ exit 1
+ fi
}
function versionFromPlugin() {
- local plugin=$1
- if [[ $plugin =~ .*:.* ]]; then
- echo "${plugin##*:}"
- else
- echo "latest"
- fi
+ local plugin=$1
+ if [[ $plugin =~ .*:.* ]]; then
+ echo "${plugin##*:}"
+ else
+ echo "latest"
+ fi
}
main() {
- local plugin version
+ local plugin version
- mkdir -p "$REF_DIR" || exit 1
+ mkdir -p "$REF_DIR" || exit 1
- # Create lockfile manually before first run to make sure any explicit version set is used.
- echo "Creating initial locks..."
- for plugin in "$@"; do
- mkdir "$(getLockFile "${plugin%%:*}")"
- done
+ # Create lockfile manually before first run to make sure any explicit version set is used.
+ echo "Creating initial locks..."
+ for plugin in "$@"; do
+ mkdir "$(getLockFile "${plugin%%:*}")"
+ done
- echo -e "\nAnalyzing war..."
- bundledPlugins="$(bundledPlugins)"
+ echo -e "\nAnalyzing war..."
+ bundledPlugins="$(bundledPlugins)"
- echo -e "\nDownloading plugins..."
- for plugin in "$@"; do
- version=""
+ echo -e "\nDownloading plugins..."
+ for plugin in "$@"; do
+ version=""
- if [[ $plugin =~ .*:.* ]]; then
- version=$(versionFromPlugin "${plugin}")
- plugin="${plugin%%:*}"
- fi
+ if [[ $plugin =~ .*:.* ]]; then
+ version=$(versionFromPlugin "${plugin}")
+ plugin="${plugin%%:*}"
+ fi
- download "$plugin" "$version" "true" &
- done
- wait
+ download "$plugin" "$version" "true" &
+ done
+ wait
- if [[ -f $FAILED ]]; then
- echo -e "\nSome plugins failed to download!\n$(<"$FAILED")" >&2
- exit 1
- fi
+ if [[ -f $FAILED ]]; then
+ echo -e "\nSome plugins failed to download!\n$(<"$FAILED")" >&2
+ exit 1
+ fi
- echo -e "\nCleaning up locks"
- rm -r "$REF_DIR"/*.lock
+ echo -e "\nCleaning up locks"
+ rm -r "$REF_DIR"/*.lock
}
main "$@"
diff --git a/jenkins-support b/jenkins-support
index 0e3ea92..1ee4a8c 100755
--- a/jenkins-support
+++ b/jenkins-support
@@ -2,35 +2,35 @@
# compare if version1 < version2
versionLT() {
- local v1; v1=$(echo "$1" | cut -d '-' -f 1 )
- local q1; q1=$(echo "$1" | cut -s -d '-' -f 2- )
- local v2; v2=$(echo "$2" | cut -d '-' -f 1 )
- local q2; q2=$(echo "$2" | cut -s -d '-' -f 2- )
- if [ "$v1" = "$v2" ]; then
- if [ "$q1" = "$q2" ]; then
- return 1
- else
- if [ -z "$q1" ]; then
- return 1
- else
- if [ -z "$q2" ]; then
- return 0
- else
- [ "$q1" = "$(echo -e "$q1\n$q2" | sort -V | head -n1)" ]
- fi
- fi
- fi
- else
- [ "$v1" = "$(echo -e "$v1\n$v2" | sort -V | head -n1)" ]
- fi
+ local v1; v1=$(echo "$1" | cut -d '-' -f 1 )
+ local q1; q1=$(echo "$1" | cut -s -d '-' -f 2- )
+ local v2; v2=$(echo "$2" | cut -d '-' -f 1 )
+ local q2; q2=$(echo "$2" | cut -s -d '-' -f 2- )
+ if [ "$v1" = "$v2" ]; then
+ if [ "$q1" = "$q2" ]; then
+ return 1
+ else
+ if [ -z "$q1" ]; then
+ return 1
+ else
+ if [ -z "$q2" ]; then
+ return 0
+ else
+ [ "$q1" = "$(echo -e "$q1\n$q2" | sort -V | head -n1)" ]
+ fi
+ fi
+ fi
+ else
+ [ "$v1" = "$(echo -e "$v1\n$v2" | sort -V | head -n1)" ]
+ fi
}
# returns a plugin version from a plugin archive
get_plugin_version() {
- local archive; archive=$1
- local version; version=$(unzip -p "$archive" META-INF/MANIFEST.MF | grep "^Plugin-Version: " | sed -e 's#^Plugin-Version: ##')
- version=${version%%[[:space:]]}
- echo "$version"
+ local archive; archive=$1
+ local version; version=$(unzip -p "$archive" META-INF/MANIFEST.MF | grep "^Plugin-Version: " | sed -e 's#^Plugin-Version: ##')
+ version=${version%%[[:space:]]}
+ echo "$version"
}
# Copy files from /usr/share/jenkins/ref into $JENKINS_HOME
@@ -38,21 +38,21 @@
# Don't override, as this is just a reference setup, and use from UI
# can then change this, upgrade plugins, etc.
copy_reference_file() {
- f="${1%/}"
- b="${f%.override}"
- rel="${b:23}"
- version_marker="${rel}.version_from_image"
- dir=$(dirname "${b}")
- local action;
- local reason;
- local container_version;
- local image_version;
- local marker_version;
- local log; log=false
- if [[ ${rel} == plugins/*.jpi ]]; then
- container_version=$(get_plugin_version "$JENKINS_HOME/${rel}")
+ f="${1%/}"
+ b="${f%.override}"
+ rel="${b:23}"
+ version_marker="${rel}.version_from_image"
+ dir=$(dirname "${b}")
+ local action;
+ local reason;
+ local container_version;
+ local image_version;
+ local marker_version;
+ local log; log=false
+ if [[ ${rel} == plugins/*.jpi ]]; then
+ container_version=$(get_plugin_version "$JENKINS_HOME/${rel}")
image_version=$(get_plugin_version "${f}")
- if [[ -e $JENKINS_HOME/${version_marker} ]]; then
+ if [[ -e $JENKINS_HOME/${version_marker} ]]; then
marker_version=$(cat "$JENKINS_HOME/${version_marker}")
if versionLT "$marker_version" "$container_version"; then
action="SKIPPED"
@@ -93,19 +93,19 @@
fi
fi
fi
- fi
+ fi
if [[ ! -e $JENKINS_HOME/${rel} || "$action" == "UPGRADED" || $f = *.override ]]; then
action=${action:-"INSTALLED"}
log=true
mkdir -p "$JENKINS_HOME/${dir:23}"
cp -r "${f}" "$JENKINS_HOME/${rel}";
- # pin plugins on initial copy
- touch "$JENKINS_HOME/${rel}.pinned"
+ # pin plugins on initial copy
+ touch "$JENKINS_HOME/${rel}.pinned"
echo "$image_version" > "$JENKINS_HOME/${version_marker}"
reason=${reason:-$image_version}
else
action=${action:-"SKIPPED"}
- fi
+ fi
else
if [[ ! -e $JENKINS_HOME/${rel} || $f = *.override ]]
then
@@ -116,12 +116,12 @@
else
action="SKIPPED"
fi
- fi
- if [[ -n "$VERBOSE" || "$log" == "true" ]]; then
+ fi
+ if [[ -n "$VERBOSE" || "$log" == "true" ]]; then
if [ -z "$reason" ]; then
echo "$action $rel" >> "$COPY_REFERENCE_FILE_LOG"
else
echo "$action $rel : $reason" >> "$COPY_REFERENCE_FILE_LOG"
fi
- fi
+ fi
}
\ No newline at end of file