Skip to content

Instantly share code, notes, and snippets.

@mjnohai
Forked from micw/install_jenkins_plugin.sh
Created February 14, 2017 22:04
Show Gist options
  • Save mjnohai/98ef132024c0e4b64fe6fe70ae7486c8 to your computer and use it in GitHub Desktop.
Save mjnohai/98ef132024c0e4b64fe6fe70ae7486c8 to your computer and use it in GitHub Desktop.

Revisions

  1. @micw micw revised this gist Sep 12, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions install_jenkins_plugin.sh
    Original file line number Diff line number Diff line change
    @@ -44,9 +44,9 @@ while [ "$changed" == "1" ]; do
    changed=0
    for f in ${plugin_dir}/*.hpi ; do
    # without optionals
    #deps=$( unzip -p /var/lib/jenkins/plugins/${plugin}.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    #deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    # with optionals
    deps=$( unzip -p /var/lib/jenkins/plugins/${plugin}.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    for plugin in $deps; do
    installPlugin "$plugin" 1 && changed=1
    done
  2. @micw micw revised this gist Sep 12, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions install_jenkins_plugin.sh
    Original file line number Diff line number Diff line change
    @@ -44,9 +44,9 @@ while [ "$changed" == "1" ]; do
    changed=0
    for f in ${plugin_dir}/*.hpi ; do
    # without optionals
    #deps=$( unzip -p /var/lib/jenkins/plugins/git.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    #deps=$( unzip -p /var/lib/jenkins/plugins/${plugin}.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    # with optionals
    deps=$( unzip -p /var/lib/jenkins/plugins/git.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    deps=$( unzip -p /var/lib/jenkins/plugins/${plugin}.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    for plugin in $deps; do
    installPlugin "$plugin" 1 && changed=1
    done
  3. @micw micw created this gist Sep 11, 2014.
    60 changes: 60 additions & 0 deletions install_jenkins_plugin.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/bin/bash

    set -e

    if [ $# -eq 0 ]; then
    echo "USAGE: $0 plugin1 plugin2 ..."
    exit 1
    fi

    plugin_dir=/var/lib/jenkins/plugins
    file_owner=jenkins.jenkins

    mkdir -p /var/lib/jenkins/plugins

    installPlugin() {
    if [ -f ${plugin_dir}/${1}.hpi -o -f ${plugin_dir}/${1}.jpi ]; then
    if [ "$2" == "1" ]; then
    return 1
    fi
    echo "Skipped: $1 (already installed)"
    return 0
    else
    echo "Installing: $1"
    curl -L --silent --output ${plugin_dir}/${1}.hpi https://updates.jenkins-ci.org/latest/${1}.hpi
    return 0
    fi
    }

    for plugin in $*
    do
    installPlugin "$plugin"
    done

    changed=1
    maxloops=100

    while [ "$changed" == "1" ]; do
    echo "Check for missing dependecies ..."
    if [ $maxloops -lt 1 ] ; then
    echo "Max loop count reached - probably a bug in this script: $0"
    exit 1
    fi
    ((maxloops--))
    changed=0
    for f in ${plugin_dir}/*.hpi ; do
    # without optionals
    #deps=$( unzip -p /var/lib/jenkins/plugins/git.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    # with optionals
    deps=$( unzip -p /var/lib/jenkins/plugins/git.hpi META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | awk -F ':' '{ print $1 }' | tr '\n' ' ' )
    for plugin in $deps; do
    installPlugin "$plugin" 1 && changed=1
    done
    done
    done

    echo "fixing permissions"

    chown ${file_owner} ${plugin_dir} -R

    echo "all done"