~bac/charms/oneiric/buildbot-master/initial

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Hook for handling config changes.
set -eux # -x for verbose logging to juju debug-log

# config_file is changed via juju like:
# juju set buildbot-master config-file=`uuencode master.cfg`

BUILDBOT_DIR=`config-get installdir`
juju-log "--> config-changed"

juju-log "Updating buildbot configuration."
CONFIG_FILE=`config-get config-file`
CONFIG_TRANSPORT=`config-get config-transport`
CONFIG_URL=`config-get config-url`

#
if [[ -n $CONFIG_FILE ]]; then
    echo "$CONFIG_FILE" | uudecode -o "$BUILDBOT_DIR"/master.cfg
    juju-log "Config decoded and written."
elif [ "$CONFIG_TRANSPORT" == "bzr" ] && [[ -n $CONFIG_URL ]]; then
    # If the branch is private then more setup needs to be done.  The
    # gpg-agent needs to send the key over and the bzr launchpad-login
    # needs to be set. 
    LP_ID=`config-get config-user`
    if [[ -n $LP_ID ]]; then
	bzr launchpad-login $LP_ID
    fi
    PKEY=`config-get config-private-key`
    if [[ -n $PKEY ]]; then
        # Set up the .ssh directory.
        mkdir ~/.ssh
        chmod 700 ~/.ssh
        echo "$PKEY" | uudecode -o ~/.ssh/lp_key
    fi
    bzr branch --use-existing-dir $CONFIG_URL "$BUILDBOT_DIR"
    chown -R ubuntu:ubuntu "$BUILDBOT_DIR"
fi

# Restart buildbot if it is running.
PIDFILE="$BUILDBOT_DIR"/twistd.pid
if [ -f $PIDFILE ]; then
  BUILDBOT_PID=`cat $PIDFILE`
  if kill -0 $BUILDBOT_PID; then
    # Buildbot is running, reconfigure it.
    juju-log "Reconfiguring buildbot"
    buildbot reconfig "$BUILDBOT_DIR"
    juju-log "Buildbot reconfigured"
  fi
fi

juju-log "<-- config-changed"