blob: 1a3407f2000c1f74bfb199cc72cf9d53a4498554 [file] [log] [blame]
Anthony Young43acae42011-11-08 14:23:56 -08001#!/bin/bash
2
3# Echo commands, exit on error
4set -o xtrace
5set -o errexit
6
7# Make sure only root can run our script
8if [[ $EUID -ne 0 ]]; then
9 echo "This script must be run as root"
10 exit 1
11fi
12
Anthony Youngb2256822011-11-10 12:57:59 -080013# Make sure user has configured an ssh pubkey
14if [ ! -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
18fi
19
Anthony Young43acae42011-11-08 14:23:56 -080020# This directory
21CUR_DIR=$(cd $(dirname "$0") && pwd)
22
23# Install software
Anthony Youngc18af142011-11-09 12:20:37 -080024DEPS="jenkins cloud-utils"
Anthony Young43acae42011-11-08 14:23:56 -080025apt-get install -y --force-yes $DEPS
26
27# Install jenkins
28if [ ! -e /var/lib/jenkins ]; then
29 echo "Jenkins installation failed"
30 exit 1
31fi
32
33# Setup sudo
34JENKINS_SUDO=/etc/sudoers.d/jenkins
35cat > $JENKINS_SUDO <<EOF
36jenkins ALL = NOPASSWD: ALL
37EOF
38chmod 440 $JENKINS_SUDO
39
40# Setup .gitconfig
41JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml
42cat > $JENKINS_GITCONF <<EOF
43<?xml version='1.0' encoding='UTF-8'?>
44<hudson.plugins.git.GitSCM_-DescriptorImpl>
45 <generation>4</generation>
46 <globalConfigName>Jenkins</globalConfigName>
47 <globalConfigEmail>jenkins@rcb.me</globalConfigEmail>
48</hudson.plugins.git.GitSCM_-DescriptorImpl>
49EOF
50
Anthony Youngec67f1e2011-11-09 17:46:28 -080051# Add build numbers
Anthony Young5df68182011-11-10 09:56:12 -080052JOBS=`ls jobs`
53for job in ${JOBS// / }; do
Anthony Youngec67f1e2011-11-09 17:46:28 -080054 if [ ! -e jobs/$job/nextBuildNumber ]; then
55 echo 1 > jobs/$job/nextBuildNumber
56 fi
57done
58
Anthony Young43acae42011-11-08 14:23:56 -080059# Set ownership to jenkins
60chown -R jenkins $CUR_DIR
61
Anthony Young316117a2011-11-09 11:10:26 -080062# Make sure this directory is accessible to jenkins
63if ! su -c "ls $CUR_DIR" jenkins; then
64 echo "Your devstack directory is not accessible by jenkins."
65 echo "There is a decent chance you are trying to run this from a directory in /root."
66 echo "If so, try moving devstack elsewhere (eg. /opt/devstack)."
67 exit 1
68fi
69
Anthony Young48336d02011-11-09 11:12:14 -080070# Move aside old jobs, if present
Anthony Young43acae42011-11-08 14:23:56 -080071if [ ! -h /var/lib/jenkins/jobs ]; then
72 echo "Installing jobs symlink"
73 if [ -d /var/lib/jenkins/jobs ]; then
74 mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old
75 fi
Anthony Young43acae42011-11-08 14:23:56 -080076fi
77
Anthony Young48336d02011-11-09 11:12:14 -080078# Set up jobs symlink
79rm -f /var/lib/jenkins/jobs
80ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs
81
Anthony Young43acae42011-11-08 14:23:56 -080082# List of plugins
83PLUGINS=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
84
85# Configure plugins
86for plugin in ${PLUGINS//,/ }; do
87 name=`basename $plugin`
88 dest=/var/lib/jenkins/plugins/$name
89 if [ ! -e $dest ]; then
90 curl -L $plugin -o $dest
91 fi
92done
93
94# Restart jenkins
Anthony Youngec38c402011-11-10 09:42:28 -080095stop jenkins || true
96start jenkins