File: sbuild-debian-developer-setup

package info (click to toggle)
sbuild 0.91.5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,832 kB
  • sloc: perl: 18,718; sh: 1,210; python: 823; sql: 797; lisp: 304; makefile: 293
file content (100 lines) | stat: -rwxr-xr-x 3,209 bytes parent folder | download | duplicates (5)
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
#!/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 $host_arch = `dpkg --print-architecture`);
my $arch = $host_arch;

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

print "Deprecated: Note that this uses the schroot backend which is no\n";
print "longer used on the Debian buildds. Please switch to the unshare\n";
print "backend. It does not need any prior setup nor regular cron jobs.\n";
print "You can do that by running sbuild --chroot-mode=unshare.\n";
print "Don't run newgrp sbuild for the unshare backend as it will break\n";
print "the unshare calls.\n";

my $username;

if (defined($ENV{SUDO_USER}) && defined($ENV{DOAS_USER})) {
	die("Both SUDO_USER and DOAS_USER are set, this is unexpected, aborting!");
}

$username //= $ENV{SUDO_USER};
$username //= $ENV{DOAS_USER};
if (!defined($username)) {
	die "Please run sudo/doas $0";
}

system("adduser", "--", $username, "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     = ();
	my $is_unstable = $suite eq "unstable" || $suite eq "sid";
	my $othersuite  = $suite eq "unstable" ? "sid" : "unstable";
	if ($is_unstable) {
		push @aliases, "--alias=$othersuite-$arch-sbuild";
		push @aliases, "--alias=UNRELEASED-$arch-sbuild";
		if ($arch eq $host_arch) {
			push @aliases, "--alias=UNRELEASED";
			push @aliases, "--alias=$othersuite";
		}
	}
	my @cmd = (
		"sbuild-createchroot",
		"--command-prefix=eatmydata",
		"--include=eatmydata",
		@aliases,
		"--arch=$arch",
		"$suite",
		"/srv/chroot/$suite-$arch-sbuild",
		"http://localhost:3142/deb.debian.org/debian"
	);
	say "Running:\n    \$ @cmd";
	system(@cmd) == 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.";