|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Echo commands, exit on error |
| 4 | +set -o xtrace |
| 5 | +set -o errexit |
| 6 | + |
| 7 | +# Make sure only root can run our script |
| 8 | +if [[ $EUID -ne 0 ]]; then |
| 9 | + echo "This script must be run as root" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +# Make sure user has configured an ssh pubkey |
| 14 | +if [ ! -e /root/.ssh/id_rsa.pub ]; then |
| 15 | + echo "Public key is missing. This is used to ssh into your instances." |
| 16 | + echo "Please run ssh-keygen before proceeding" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +# This directory |
| 21 | +CUR_DIR=$(cd $(dirname "$0") && pwd) |
| 22 | + |
| 23 | +# Configure trunk jenkins! |
| 24 | +echo "deb http://pkg.jenkins-ci.org/debian binary/" > /etc/apt/sources.list.d/jenkins.list |
| 25 | +wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - |
| 26 | +apt-get update |
| 27 | + |
| 28 | + |
| 29 | +# Clean out old jenkins - useful if you are having issues upgrading |
| 30 | +CLEAN_JENKINS=${CLEAN_JENKINS:-no} |
| 31 | +if [ "$CLEAN_JENKINS" = "yes" ] then; |
| 32 | + apt-get remove jenkins jenkins-common |
| 33 | +fi |
| 34 | + |
| 35 | +# Install software |
| 36 | +DEPS="jenkins cloud-utils" |
| 37 | +apt-get install -y --force-yes $DEPS |
| 38 | + |
| 39 | +# Install jenkins |
| 40 | +if [ ! -e /var/lib/jenkins ]; then |
| 41 | + echo "Jenkins installation failed" |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | + |
| 45 | +# Setup sudo |
| 46 | +JENKINS_SUDO=/etc/sudoers.d/jenkins |
| 47 | +cat > $JENKINS_SUDO <<EOF |
| 48 | +jenkins ALL = NOPASSWD: ALL |
| 49 | +EOF |
| 50 | +chmod 440 $JENKINS_SUDO |
| 51 | + |
| 52 | +# Setup .gitconfig |
| 53 | +JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml |
| 54 | +cat > $JENKINS_GITCONF <<EOF |
| 55 | +<?xml version='1.0' encoding='UTF-8'?> |
| 56 | +<hudson.plugins.git.GitSCM_-DescriptorImpl> |
| 57 | + <generation>4</generation> |
| 58 | + <globalConfigName>Jenkins</globalConfigName> |
| 59 | + <globalConfigEmail>jenkins@rcb.me</globalConfigEmail> |
| 60 | +</hudson.plugins.git.GitSCM_-DescriptorImpl> |
| 61 | +EOF |
| 62 | + |
| 63 | +# Add build numbers |
| 64 | +JOBS=`ls jobs` |
| 65 | +for job in ${JOBS// / }; do |
| 66 | + if [ ! -e jobs/$job/nextBuildNumber ]; then |
| 67 | + echo 1 > jobs/$job/nextBuildNumber |
| 68 | + fi |
| 69 | +done |
| 70 | + |
| 71 | +# Set ownership to jenkins |
| 72 | +chown -R jenkins $CUR_DIR |
| 73 | + |
| 74 | +# Make sure this directory is accessible to jenkins |
| 75 | +if ! su -c "ls $CUR_DIR" jenkins; then |
| 76 | + echo "Your devstack directory is not accessible by jenkins." |
| 77 | + echo "There is a decent chance you are trying to run this from a directory in /root." |
| 78 | + echo "If so, try moving devstack elsewhere (eg. /opt/devstack)." |
| 79 | + exit 1 |
| 80 | +fi |
| 81 | + |
| 82 | +# Move aside old jobs, if present |
| 83 | +if [ ! -h /var/lib/jenkins/jobs ]; then |
| 84 | + echo "Installing jobs symlink" |
| 85 | + if [ -d /var/lib/jenkins/jobs ]; then |
| 86 | + mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old |
| 87 | + fi |
| 88 | +fi |
| 89 | + |
| 90 | +# Set up jobs symlink |
| 91 | +rm -f /var/lib/jenkins/jobs |
| 92 | +ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs |
| 93 | + |
| 94 | +# List of plugins |
| 95 | +PLUGINS=http://hudson-ci.org/downloads/plugins/build-timeout/1.6/build-timeout.hpi,http://mirrors.jenkins-ci.org/plugins/git/1.1.12/git.hpi,http://hudson-ci.org/downloads/plugins/global-build-stats/1.2/global-build-stats.hpi,http://hudson-ci.org/downloads/plugins/greenballs/1.10/greenballs.hpi,http://download.hudson-labs.org/plugins/console-column-plugin/1.0/console-column-plugin.hpi |
| 96 | + |
| 97 | +# Configure plugins |
| 98 | +for plugin in ${PLUGINS//,/ }; do |
| 99 | + name=`basename $plugin` |
| 100 | + dest=/var/lib/jenkins/plugins/$name |
| 101 | + if [ ! -e $dest ]; then |
| 102 | + curl -L $plugin -o $dest |
| 103 | + fi |
| 104 | +done |
| 105 | + |
| 106 | +# Restart jenkins |
| 107 | +/etc/init.d/jenkins stop || true |
| 108 | +/etc/init.d/jenkins start |
0 commit comments