~cjwatson/launchpad-buildd/improve-depwait

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
#
# Copyright 2010,2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# Buildd Slave tool to generate translation templates. Boiler plate code
# copied from sbuild-package.

# Expects build id as arg 1.
# Expects branch url as arg 2.
# Expects output tarball name as arg 3.

# Must run as user with password-less sudo ability.

exec 2>&1

export LANG=C LC_ALL=C

CHMOD=/bin/chmod
CHROOT=/usr/sbin/chroot
CP=/bin/cp
INSTALL=/usr/bin/install
MKDIR=/bin/mkdir
SU=/bin/su
SUDO=/usr/bin/sudo
TOUCH=/usr/bin/touch

BUILDID=$1
BRANCH_URL=$2
RESULT_NAME=$3

BUILDD_HOME=/usr/share/launchpad-buildd
BUILDD_LIB=/usr/lib/launchpad-buildd
SLAVEBIN=$BUILDD_HOME/slavebin
BUILD_CHROOT="$HOME/build-$BUILDID/chroot-autobuild"
USER=$(whoami)

# Debug output.
echo "Running as $USER for build $BUILDID on $BRANCH_URL."
echo "Results expected in $RESULT_NAME."

BUILDD_PACKAGE=lpbuildd
POTTERY=$BUILDD_PACKAGE/pottery
# The script should be smarter about detecting the python version.
PYMODULES=/usr/lib/pymodules/python2.7
echo -n "Default Python in the chroot is: "
$BUILD_CHROOT/usr/bin/python --version

GENERATE_SCRIPT=$PYMODULES/$POTTERY/generate_translation_templates.py

debug_exec() {
   echo "Executing '$1'..."
   $1 || echo "Got error $? from '$1'."
}

# Copy pottery files to chroot.
debug_exec "$SUDO $MKDIR -vp $BUILD_CHROOT$PYMODULES/$BUILDD_PACKAGE"
debug_exec "$SUDO $TOUCH $BUILD_CHROOT$PYMODULES/$BUILDD_PACKAGE/__init__.py"
debug_exec "$SUDO $CP -vr $BUILDD_LIB/$POTTERY $BUILD_CHROOT$PYMODULES/$BUILDD_PACKAGE"
debug_exec "$SUDO $CHMOD -v -R go+rX $BUILD_CHROOT$PYMODULES/$BUILDD_PACKAGE"
debug_exec "$SUDO $CHMOD -v 755 $BUILD_CHROOT$GENERATE_SCRIPT"

# Enter chroot, switch back to unprivileged user, execute the generate script.
$SUDO $CHROOT $BUILD_CHROOT \
  $SU - $USER \
    -c "PYTHONPATH=$PYMODULES $GENERATE_SCRIPT $BRANCH_URL $RESULT_NAME"