~canonical-launchpad-branches/launchpad-buildd/trunk

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# Post install script

set -e
set -u

USER=${BUILDD_USER:-buildd}
BUILDDGID=${BUILDD_GID:-2501}
BUILDDUID=${BUILDD_UID:-2001}

make_buildd()
{
 /usr/share/launchpad-buildd/buildd-genconfig --name=default --host=0.0.0.0 --port=8221 --snap-proxy-port=8222 > \
  /etc/launchpad-buildd/default
 echo Default buildd created.
}

case "$1" in
    configure)
	getent group buildd >/dev/null 2>&1 ||
                addgroup --gid $BUILDDGID buildd

	getent passwd buildd >/dev/null 2>&1 ||
        adduser --ingroup buildd --disabled-login --gecos 'Buildd user' \
                --uid $BUILDDUID ${USER}
        adduser --quiet buildd sbuild
        adduser --quiet buildd lxd

	SUDO_VERSION=$(sudo -V | sed -n '/^Sudo version/s/.* //p')
	if dpkg --compare-versions $SUDO_VERSION lt 1.7 ||
	   ! grep -q '^#includedir /etc/sudoers.d' /etc/sudoers; then
		grep -q ^${USER} /etc/sudoers ||
		    echo "${USER}  ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
	else
		if ! sudo -l -U ${USER} | grep -q '(ALL) NOPASSWD: ALL' ||
		   ! sudo -l -U ${USER} | grep -q umask_override; then
		    cat << EOF >> /etc/sudoers.d/buildd
Defaults:buildd umask_override
Defaults>buildd umask_override

${USER}  ALL=(ALL) NOPASSWD: ALL
%buildd ALL=(buildd) NOPASSWD: ALL, (root) NOPASSWD: /bin/su - buildd
%lpbuildd ALL=(ALL) NOPASSWD: ALL
EOF
		fi
		chmod 440 /etc/sudoers.d/buildd
		chown root:root /etc/sudoers.d/buildd
	fi

        install -d -o${USER} -m0755 /home/${USER}

	if [ "x$2" != "x" ]; then
		if dpkg --compare-versions "$2" lt 127; then
			# .lp-sbuildrc is no longer used.
			rm -f /home/${USER}/.lp-sbuildrc
			# .sbuildrc used to be a normal file, but nowadays it's a
			# symlink.
			rm -f /home/${USER}/.sbuildrc
		fi
	fi

	# Create ~buildd/.sbuildrc if needed
	if [ ! -f /home/${USER}/.sbuildrc ]; then
		ln -s /usr/share/launchpad-buildd/sbuildrc /home/${USER}/.sbuildrc
	fi

	# Prepare a default buildd...
	test -e /etc/launchpad-buildd/default || make_buildd

	# Create any missing directories and chown them appropriately
	test -d /home/${USER}/filecache-default || mkdir /home/${USER}/filecache-default
	chown $USER:buildd /home/${USER}/filecache-default

	chown $USER:buildd /var/log/launchpad-buildd

	# Check for the presence of the /etc/source-dependencies file
	# which sbuild will rant about the absence of...
	test -e /etc/source-dependencies || touch /etc/source-dependencies

	# Now check if we're upgrading a previous version...
	if [ "x$2" != "x" ]; then
	    for CONFIG in $(ls /etc/launchpad-buildd/* \
	                  | grep -v "^-" | grep -v "~$"); do
		/usr/share/launchpad-buildd/upgrade-config $2 $CONFIG
	    done
	    if dpkg --compare-versions "$2" lt 124; then
		# we used to ship /etc/sbuild.conf, but we moved it to
		# /usr/share and, frankly, don't care if you modified it
		rm -f /etc/sbuild.conf
	    fi
	fi

	# Configure systemd-timesyncd to use the buildd NTP service
	if which systemd >/dev/null 2>&1; then
	    eval `grep ntphost /etc/launchpad-buildd/default | sed 's/ //g'`
	    if [ "$ntphost" ]; then
		mkdir -p /etc/systemd/timesyncd.conf.d
		cat << EOF > /etc/systemd/timesyncd.conf.d/00-launchpad-buildd.conf
[Time]
NTP=$ntphost
EOF
	    fi
	fi

	# Configure LXD if necessary
	if [ ! -e /var/lib/lxd/server.key ]; then
	    lxd init --auto || true
	    sudo -Hu "$USER" lxc list >/dev/null || true
	fi

	;;
    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

#DEBHELPER#

exit 0