blob: bbba8b0705561875f9fb9280835a959fd28189b8 [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
13# This directory
14CUR_DIR=$(cd $(dirname "$0") && pwd)
15
16# Install software
Anthony Youngc18af142011-11-09 12:20:37 -080017DEPS="jenkins cloud-utils"
Anthony Young43acae42011-11-08 14:23:56 -080018apt-get install -y --force-yes $DEPS
19
20# Install jenkins
21if [ ! -e /var/lib/jenkins ]; then
22 echo "Jenkins installation failed"
23 exit 1
24fi
25
26# Setup sudo
27JENKINS_SUDO=/etc/sudoers.d/jenkins
28cat > $JENKINS_SUDO <<EOF
29jenkins ALL = NOPASSWD: ALL
30EOF
31chmod 440 $JENKINS_SUDO
32
33# Setup .gitconfig
34JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml
35cat > $JENKINS_GITCONF <<EOF
36<?xml version='1.0' encoding='UTF-8'?>
37<hudson.plugins.git.GitSCM_-DescriptorImpl>
38 <generation>4</generation>
39 <globalConfigName>Jenkins</globalConfigName>
40 <globalConfigEmail>jenkins@rcb.me</globalConfigEmail>
41</hudson.plugins.git.GitSCM_-DescriptorImpl>
42EOF
43
Anthony Youngec67f1e2011-11-09 17:46:28 -080044# Add build numbers
45for job in ${`ls jobs`// / }; do
46 if [ ! -e jobs/$job/nextBuildNumber ]; then
47 echo 1 > jobs/$job/nextBuildNumber
48 fi
49done
50
Anthony Young43acae42011-11-08 14:23:56 -080051# Set ownership to jenkins
52chown -R jenkins $CUR_DIR
53
Anthony Young316117a2011-11-09 11:10:26 -080054# Make sure this directory is accessible to jenkins
55if ! su -c "ls $CUR_DIR" jenkins; then
56 echo "Your devstack directory is not accessible by jenkins."
57 echo "There is a decent chance you are trying to run this from a directory in /root."
58 echo "If so, try moving devstack elsewhere (eg. /opt/devstack)."
59 exit 1
60fi
61
Anthony Young48336d02011-11-09 11:12:14 -080062# Move aside old jobs, if present
Anthony Young43acae42011-11-08 14:23:56 -080063if [ ! -h /var/lib/jenkins/jobs ]; then
64 echo "Installing jobs symlink"
65 if [ -d /var/lib/jenkins/jobs ]; then
66 mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old
67 fi
Anthony Young43acae42011-11-08 14:23:56 -080068fi
69
Anthony Young48336d02011-11-09 11:12:14 -080070# Set up jobs symlink
71rm -f /var/lib/jenkins/jobs
72ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs
73
Anthony Young43acae42011-11-08 14:23:56 -080074# List of plugins
75PLUGINS=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
76
77# Configure plugins
78for plugin in ${PLUGINS//,/ }; do
79 name=`basename $plugin`
80 dest=/var/lib/jenkins/plugins/$name
81 if [ ! -e $dest ]; then
82 curl -L $plugin -o $dest
83 fi
84done
85
86# Restart jenkins
87restart jenkins