Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 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 | |
Anthony Young | b225682 | 2011-11-10 12:57:59 -0800 | [diff] [blame] | 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 | |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 20 | # This directory |
| 21 | CUR_DIR=$(cd $(dirname "$0") && pwd) |
| 22 | |
Anthony Young | 723e2d2 | 2011-11-11 13:42:09 -0800 | [diff] [blame] | 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 | |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 28 | # Install software |
Anthony Young | c18af14 | 2011-11-09 12:20:37 -0800 | [diff] [blame] | 29 | DEPS="jenkins cloud-utils" |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 30 | apt-get install -y --force-yes $DEPS |
| 31 | |
| 32 | # Install jenkins |
| 33 | if [ ! -e /var/lib/jenkins ]; then |
| 34 | echo "Jenkins installation failed" |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | # Setup sudo |
| 39 | JENKINS_SUDO=/etc/sudoers.d/jenkins |
| 40 | cat > $JENKINS_SUDO <<EOF |
| 41 | jenkins ALL = NOPASSWD: ALL |
| 42 | EOF |
| 43 | chmod 440 $JENKINS_SUDO |
| 44 | |
| 45 | # Setup .gitconfig |
| 46 | JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml |
| 47 | cat > $JENKINS_GITCONF <<EOF |
| 48 | <?xml version='1.0' encoding='UTF-8'?> |
| 49 | <hudson.plugins.git.GitSCM_-DescriptorImpl> |
| 50 | <generation>4</generation> |
| 51 | <globalConfigName>Jenkins</globalConfigName> |
| 52 | <globalConfigEmail>jenkins@rcb.me</globalConfigEmail> |
| 53 | </hudson.plugins.git.GitSCM_-DescriptorImpl> |
| 54 | EOF |
| 55 | |
Anthony Young | ec67f1e | 2011-11-09 17:46:28 -0800 | [diff] [blame] | 56 | # Add build numbers |
Anthony Young | 5df6818 | 2011-11-10 09:56:12 -0800 | [diff] [blame] | 57 | JOBS=`ls jobs` |
| 58 | for job in ${JOBS// / }; do |
Anthony Young | ec67f1e | 2011-11-09 17:46:28 -0800 | [diff] [blame] | 59 | if [ ! -e jobs/$job/nextBuildNumber ]; then |
| 60 | echo 1 > jobs/$job/nextBuildNumber |
| 61 | fi |
| 62 | done |
| 63 | |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 64 | # Set ownership to jenkins |
| 65 | chown -R jenkins $CUR_DIR |
| 66 | |
Anthony Young | 316117a | 2011-11-09 11:10:26 -0800 | [diff] [blame] | 67 | # Make sure this directory is accessible to jenkins |
| 68 | if ! su -c "ls $CUR_DIR" jenkins; then |
| 69 | echo "Your devstack directory is not accessible by jenkins." |
| 70 | echo "There is a decent chance you are trying to run this from a directory in /root." |
| 71 | echo "If so, try moving devstack elsewhere (eg. /opt/devstack)." |
| 72 | exit 1 |
| 73 | fi |
| 74 | |
Anthony Young | 48336d0 | 2011-11-09 11:12:14 -0800 | [diff] [blame] | 75 | # Move aside old jobs, if present |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 76 | if [ ! -h /var/lib/jenkins/jobs ]; then |
| 77 | echo "Installing jobs symlink" |
| 78 | if [ -d /var/lib/jenkins/jobs ]; then |
| 79 | mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old |
| 80 | fi |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 81 | fi |
| 82 | |
Anthony Young | 48336d0 | 2011-11-09 11:12:14 -0800 | [diff] [blame] | 83 | # Set up jobs symlink |
| 84 | rm -f /var/lib/jenkins/jobs |
| 85 | ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs |
| 86 | |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 87 | # List of plugins |
| 88 | 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 |
| 89 | |
| 90 | # Configure plugins |
| 91 | for plugin in ${PLUGINS//,/ }; do |
| 92 | name=`basename $plugin` |
| 93 | dest=/var/lib/jenkins/plugins/$name |
| 94 | if [ ! -e $dest ]; then |
| 95 | curl -L $plugin -o $dest |
| 96 | fi |
| 97 | done |
| 98 | |
| 99 | # Restart jenkins |
Anthony Young | c0d4e67 | 2011-11-11 13:46:44 -0800 | [diff] [blame^] | 100 | /etc/init.d/jenkins stop || true |
| 101 | /etc/init.d/jenkins start |