summaryrefslogtreecommitdiffstats
path: root/bin/sbuild-debian-developer-setup
blob: fa9fb518c15356f26421d31f6455f8df81733e74 (plain)
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
#!/usr/bin/perl
#
# Set up sbuild so that packages for Debian unstable can be built and
# maintenance is done automatically via a daily update cronjob.
# Copyright © 2017 Michael Stapelberg <stapelberg@debian.org>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
#######################################################################

use strict;
use warnings;
use v5.10;
use Getopt::Long;
use Sbuild qw(help_text);

my $dist = "debian";
my $suite = "unstable";
chomp(my $arch = `dpkg --print-architecture`);

my @options = (
    'distribution=s' => \$dist,
    'suite=s' => \$suite,
    'arch=s' => \$arch,
    'help' => sub { help_text(1, "sbuild-debian-developer-setup") },
    );
GetOptions(@options);

if (!defined($ENV{SUDO_USER})) {
    die "Please run sudo $0";
}

system("adduser", "--", $ENV{SUDO_USER}, "sbuild") == 0
    or die "adduser failed: $?";

sub chroot_exists {
    system("schroot -i -c chroot:$suite-$arch-sbuild >/dev/null 2>&1") == 0
}

if (!chroot_exists()) {
    my @aliases = ();
    if ( $suite eq "unstable" || $suite eq "sid" ) {
        @aliases = ( "--alias=UNRELEASED", "--alias=UNRELEASED-$arch-sbuild" );
        if ( $suite eq "unstable" ) {
            push @aliases, "--alias=sid";
        }
        if ( $suite eq "sid" ) {
            push @aliases, "--alias=unstable";
        }
    }
    system("sbuild-createchroot",
	   "--command-prefix=eatmydata",
	   "--include=eatmydata",
	   @aliases,
	   "$suite",
	   "/srv/chroot/$suite-$arch-sbuild",
	   "http://localhost:3142/deb.debian.org/debian") == 0
	       or die "sbuild-createchroot failed: $!";
} else {
    say "chroot $suite-$arch-sbuild already exists";
}

say "Your current user is now part of the sbuild group (no need to run sbuild-adduser) and a chroot environment exists in /srv/chroot/$suite-$arch-sbuild";

say "Now run `newgrp sbuild', or log out and log in again.";