~cjwatson/launchpad-buildd/snapcraft

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
#!/bin/sh
#
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# Buildd Slave tool to mount a chroot

# Expects build id as arg 1, makes build-id to contain the build

# Needs SUDO to be set to a sudo instance for passwordless access

SUDO=/usr/bin/sudo
BUILDID="$1"
GREP=/bin/grep
CUT=/usr/bin/cut
XARGS=/usr/bin/xargs
SORT=/usr/bin/sort

set -e

exec 2>&1

echo "Unmounting chroot for build $BUILDID..."

# binfmt-support adds a mount under /proc, which means that our first
# pass at umounting fails unless we reverse the list.  Leave the while
# loop in just to handle pathological cases, too.
COUNT=0
while $GREP -q "$HOME/build-$BUILDID/chroot-autobuild" /proc/mounts; do
    COUNT=$(($COUNT+1))
    if [ $COUNT -ge 20 ]; then
    	echo "failed to umount $HOME/build-$BUILDID/chroot-autobuild"
	if [ -x /usr/bin/lsof ]; then
	    /usr/bin/lsof "$HOME/build-$BUILDID/chroot-autobuild"
	fi
	exit 1
    fi
    $GREP "$HOME/build-$BUILDID/chroot-autobuild" /proc/mounts | \
	  $CUT -d\  -f2 | LANG=C $SORT -r | $XARGS -r -n 1 $SUDO umount || sleep 1
done