<div dir="ltr">Doing it in a script is one more step. The point of this endavour is to make the setup as simple as possible.<div><br></div><div>On that note, the awkward newgrp step afterwards still irks me.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 21, 2017 at 8:43 AM, Geert Stappers <span dir="ltr"><<a href="mailto:stappers@stappers.nl" target="_blank">stappers@stappers.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, May 20, 2017 at 11:34:37PM +0200, Michael Stapelberg wrote:<br>
><br>
> Find attached the first draft of my suggestion. I implemented it as a<br>
> separate package purely so that I can build it more quickly, but I assume<br>
> we???d want to fold this into src:sbuild eventually.<br>
><br>
> The resulting package (I built it using dpkg-buildpackage -b) depends on<br>
> sbuild, schroot, debootstrap, perl-base, lintian. Upon installation, it<br>
> will create an unstable sbuild schroot, modify its configuration, add all<br>
> users to sbuild and create a modified ~/.sbuildrc for all users.<br>
><br>
> If you want to read through the entire behavior, I recommend the<br>
> entrypoints debian/postinst and update-sbuild-chroots.<br>
<br>
the debian/postinst now here inline<br>
<br>
<br>
#!/bin/sh<br>
<br>
set -e<br>
<br>
#DEBHELPER#<br>
<br>
# TODO: make this package pass piuparts<br>
<br>
# Add to group sbuild all “dynamically allocated user accounts”; see<br>
# <a href="https://www.debian.org/doc/debian-policy/ch-opersys.html" rel="noreferrer" target="_blank">https://www.debian.org/doc/<wbr>debian-policy/ch-opersys.html</a><br>
for user in $(getent passwd | perl -F: -nlE '$F[2] >= 1000 && $F[2] <= 59999 && say $F[0]')<br>
do<br>
    # Strictly speaking, we should use sbuild-adduser, but sbuild-adduser prints<br>
    # setup instructions to STDERR which do not make sense in the context of<br>
    # this package. Filtering STDERR is cumbersome, so we call adduser directly.<br>
    adduser --quiet -- "$user" sbuild<br>
done<br>
<br>
# TODO: maybe add a “setup” suffix into the generated chroot name for easier trouble-shooting (we’ll immediately know who created the chroot initially)<br>
<br>
# Create a chroot if it does not already exist<br>
chroot="unstable-$(dpkg --print-architecture)-sbuild"<br>
if ! schroot -i -c chroot:${chroot} >/dev/null 2>&1<br>
then<br>
    sbuild-createchroot \<br>
        --include=eatmydata,ccache,<wbr>gnupg \<br>
        unstable \<br>
        /srv/chroot/${chroot} \<br>
        <a href="http://deb.debian.org/debian" rel="noreferrer" target="_blank">http://deb.debian.org/debian</a><br>
<br>
    # At this point, sbuild-createchroot created an schroot configuration with a<br>
    # random suffix, e.g. /etc/schroot/chroot.d/<wbr>unstable-amd64-sbuild-pyViYe. As<br>
    # sbuild-createchroot recommends, we rename that file before making<br>
    # adjustments.<br>
    mv /etc/schroot/chroot.d/${<wbr>chroot}-* /etc/schroot/chroot.d/${<wbr>chroot}<br>
fi<br>
<br>
# schroot config customizations:<br>
config=/etc/schroot/chroot.d/$<wbr>{chroot}<br>
tmp=$(mktemp ${config}-XXXXXX.dpkg-tmp)<br>
trap 'rm -f "${tmp}"' TERM INT EXIT QUIT<br>
<br>
grep -v -E '^(aliases|command-prefix)=' "${config}" > "${tmp}"<br>
<br>
# For convenience, treat UNRELEASED as an alias for unstable (so that<br>
# debian/changelog files containing UNRELEASED do not need to be modified before<br>
# building). Also sid, because it is short to type when specifying -d.<br>
echo "aliases=UNRELEASED,sid" >> "${tmp}"<br>
<br>
# Enable eatmydata: occasionally losing a test build is preferable over longer<br>
# build times and disk wear.<br>
echo "command-prefix=eatmydata" >> "${tmp}"<br>
<br>
chmod 644 "${tmp}"<br>
mv "${tmp}" "${config}"<br>
<br>
# Copy a modified example sbuildrc config file<br>
for homedir in $(getent passwd | perl -F: -nlE '$F[2] >= 1000 && $F[2] <= 59999 && say $F[5]')<br>
do<br>
    userconfig="${homedir}/.<wbr>sbuildrc"<br>
    if [ ! -e "${userconfig}" ]<br>
    then<br>
        (grep -v -E "^(# don't remove this|1;\$)" /usr/share/doc/sbuild/<wbr>examples/example.sbuildrc && cat /usr/share/doc/sbuild-debian-<wbr>setup/sbuildrc) > "${userconfig}"<br>
    fi<br>
done<br>
<br>
# bind-mount the apt archive cache into chroots, so that packages are downloaded<br>
# only once. The assumption is that users will not typically have a local apt<br>
# mirror or caching proxy.<br>
if ! grep -q '^/var/cache/apt/archives' /etc/schroot/sbuild/fstab<br>
then<br>
    echo "/var/cache/apt/archives /var/cache/apt/archives none rw,bind 0 0" \<br>
         >>/etc/schroot/sbuild/fstab<br>
fi<br>
<br>
if [ ! -e "/etc/schroot/setup.d/04tmpfs" ]<br>
then<br>
    echo ""<br>
    echo "  If you can spare the RAM, you can enable building in tmpfs using:"<br>
    echo ""<br>
    echo "    sudo ln -s /etc/schroot/setup-available.<wbr>d/overlays-in-tmpfs /etc/schroot/setup.d/04tmpfs"<br>
    echo ""<br>
fi<br>
<br>
exit 0<br>
<br>
> I tested this package on my notebook, which is a Debian installation on<br>
> which I never had sbuild installed, so I???m reasonably confident that the<br>
> package works ??? at least to the point that one gets an sbuild installation<br>
> that builds packages.<br>
><br>
> I???d be happy about any feedback. Thanks!<br>
<br>
<br>
What was/is the idea of doing this in an additional packages?<br>
Why not in an additional script?<br>
<br>
<br>
Groeten<br>
<span class="HOEnZb"><font color="#888888">Geert Stappers<br>
--<br>
Leven en laten leven<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Best regards,<br>Michael</div>
</div>