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 | |
| 13 | # This directory |
| 14 | CUR_DIR=$(cd $(dirname "$0") && pwd) |
| 15 | |
| 16 | # Install software |
| 17 | DEPS="jenkins" |
| 18 | apt-get install -y --force-yes $DEPS |
| 19 | |
| 20 | # Install jenkins |
| 21 | if [ ! -e /var/lib/jenkins ]; then |
| 22 | echo "Jenkins installation failed" |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
| 26 | # Setup sudo |
| 27 | JENKINS_SUDO=/etc/sudoers.d/jenkins |
| 28 | cat > $JENKINS_SUDO <<EOF |
| 29 | jenkins ALL = NOPASSWD: ALL |
| 30 | EOF |
| 31 | chmod 440 $JENKINS_SUDO |
| 32 | |
| 33 | # Setup .gitconfig |
| 34 | JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml |
| 35 | cat > $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> |
| 42 | EOF |
| 43 | |
| 44 | # Set ownership to jenkins |
| 45 | chown -R jenkins $CUR_DIR |
| 46 | |
Anthony Young | 316117a | 2011-11-09 11:10:26 -0800 | [diff] [blame^] | 47 | # Make sure this directory is accessible to jenkins |
| 48 | if ! su -c "ls $CUR_DIR" jenkins; then |
| 49 | echo "Your devstack directory is not accessible by jenkins." |
| 50 | echo "There is a decent chance you are trying to run this from a directory in /root." |
| 51 | echo "If so, try moving devstack elsewhere (eg. /opt/devstack)." |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
Anthony Young | 43acae4 | 2011-11-08 14:23:56 -0800 | [diff] [blame] | 55 | # Set up jobs symlink |
| 56 | if [ ! -h /var/lib/jenkins/jobs ]; then |
| 57 | echo "Installing jobs symlink" |
| 58 | if [ -d /var/lib/jenkins/jobs ]; then |
| 59 | mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old |
| 60 | fi |
| 61 | ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs |
| 62 | fi |
| 63 | |
| 64 | # List of plugins |
| 65 | 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 |
| 66 | |
| 67 | # Configure plugins |
| 68 | for plugin in ${PLUGINS//,/ }; do |
| 69 | name=`basename $plugin` |
| 70 | dest=/var/lib/jenkins/plugins/$name |
| 71 | if [ ! -e $dest ]; then |
| 72 | curl -L $plugin -o $dest |
| 73 | fi |
| 74 | done |
| 75 | |
| 76 | # Restart jenkins |
| 77 | restart jenkins |