~ubuntu-branches/ubuntu/karmic/sbuild/karmic-proposed

« back to all changes in this revision

Viewing changes to lib/Buildd/Conf.pm

  • Committer: Bazaar Package Importer
  • Author(s): Roger Leigh, Roger Leigh
  • Date: 2009-05-17 15:52:53 UTC
  • mfrom: (8.1.7 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090517155253-fbxadfsyaf940ete
Tags: 0.58.3-1
[ Roger Leigh ]
* New release.
* debian/control:
  - Update to Standards Version 3.8.1.
  - Add buildd package.
  - Add libsbuild-perl package.
  - All packages depend upon libsbuild-perl.
* Add support for appending a tag to version numbers (Closes: #475777).
  Thanks to Timothy G Abbott for this patch.
* When using the --help or --version options, don't abort if not
  in the sbuild group (Closes: #523670).  Group membership is now
  only performed after options parsing, and only if required.
* Allow config files to use $HOME (Closes: #524564).  Thanks to
  James Vega for this patch.
* Restore buildd package.
* Split common library functions into new libsbuild-perl package.
* debian/sbuild.(preinst|postinst|postrm):
  - Remove special cases for versions older than oldstable.  Update
    addition and removal of sbuild group to use return value of getent
    rather than parsing getent output.
  - Use addgroup/delgroup in place of adduser/deluser.
  - Use --system when adding and deleting group, to ensure creation
    of a system group.  Migrate existing non-system group and group
    members if the system group is not present.
  - Handle removal of 50sbuild setup script.
* debian/buildd.(preinst|postinst|postrm): Add maintainer scripts for
  buildd package.  Move configuration file from /etc/buildd.conf to
  /etc/buildd/buildd.conf if present.  Also create buildd user and
  group for running the buildd daemon.
* Sbuild::Conf: Don't default MAINTAINER_NAME to $DEBEMAIL if unset
  in the configuration file (Closes: #520158).
* /etc/schroot/setup.d/50sbuild: Remove.  The setup tasks performed by
  this script are now handled internally by sbuild.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# Conf.pm: configuration library for buildd
3
3
# Copyright © 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
4
4
# Copyright © 2005 Ryan Murray <rmurray@debian.org>
5
 
# Copyright © 2006-2008 Roger Leigh <rleigh@debian.org>
 
5
# Copyright © 2006-2009 Roger Leigh <rleigh@debian.org>
6
6
#
7
7
# This program is free software: you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
24
24
 
25
25
use strict;
26
26
use warnings;
27
 
use Cwd qw(cwd);
28
 
use Buildd;
 
27
 
 
28
use Sbuild::ConfBase;
 
29
use Sbuild::Sysconfig;
29
30
 
30
31
BEGIN {
31
32
    use Exporter ();
32
33
    our (@ISA, @EXPORT);
33
34
 
34
 
    @ISA = qw(Exporter);
 
35
    @ISA = qw(Exporter Sbuild::ConfBase);
35
36
 
36
 
    @EXPORT = qw($HOME $arch $max_build $nice_level $idle_sleep_time
37
 
                 $min_free_space @take_from_dists @no_auto_build
38
 
                 $no_build_regex $build_regex @weak_no_auto_build
39
 
                 $delay_after_give_back $pkg_log_keep $pkg_log_keep
40
 
                 $build_log_keep $daemon_log_rotate $daemon_log_send
41
 
                 $daemon_log_keep $warning_age $error_mail_window
42
 
                 $statistics_period $sshcmd $wanna_build_user
43
 
                 $no_warn_pattern $should_build_msgs apt_get sudo
44
 
                 $autoclean_interval $secondary_daemon_threshold
45
 
                 $admin_mail $statistics_mail $dupload_to
46
 
                 $dupload_to_non_us $dupload_to_security
47
 
                 $log_queued_messages $wanna_build_dbbase read);
 
37
    @EXPORT = qw($reread_config);
48
38
}
49
39
 
50
 
sub read_file ($\$);
51
 
sub read ();
52
 
sub convert_sshcmd ();
53
 
sub init ();
54
 
 
55
40
my $reread_config = 0;
56
41
 
57
 
# Originally from the main namespace.
58
 
(our $HOME = $ENV{'HOME'})
59
 
    or die "HOME not defined in environment!\n";
60
 
# Configuration files.
61
 
my $config_global = "/etc/buildd.conf";
62
 
my $config_user = "$HOME/.builddrc";
63
 
my $config_global_time = 0;
64
 
my $config_user_time = 0;
65
 
 
66
 
# Defaults.
67
 
chomp( our $arch = `dpkg --print-architecture 2>/dev/null` );
68
 
our $max_build = 10;
69
 
our $nice_level = 10;
70
 
our $idle_sleep_time = 5*60;
71
 
our $min_free_space = 50*1024;
72
 
our @take_from_dists = qw();
73
 
our @no_auto_build = ();
74
 
our $no_build_regex = "^(contrib/|non-free/)?non-US/";
75
 
our $build_regex = "";
76
 
our @weak_no_auto_build = ();
77
 
our $delay_after_give_back = 8 * 60; # 8 hours
78
 
our $pkg_log_keep = 7;
79
 
our $build_log_keep = 2;
80
 
our $daemon_log_rotate = 1;
81
 
our $daemon_log_send = 1;
82
 
our $daemon_log_keep = 7;
83
 
our $warning_age = 7;
84
 
our $error_mail_window = 8*60*60;
85
 
our $statistics_period = 7;
86
 
our $sshcmd = "";
87
 
our $sshsocket = "";
88
 
our $wanna_build_user = $Buildd::username;
89
 
our $no_warn_pattern = '^build/(SKIP|REDO|SBUILD-GIVEN-BACK|buildd\.pid|[^/]*.ssh|chroot-[^/]*)$';
90
 
our $should_build_msgs = 1;
91
 
our $apt_get = "/usr/bin/apt-get";
92
 
our $sudo = "/usr/bin/sudo";
93
 
our $autoclean_interval = 86400;
94
 
our $secondary_daemon_threshold = 70;
95
 
our $admin_mail = "USER-porters";
96
 
our $statistics_mail = 'USER-porters';
97
 
our $dupload_to = "anonymous-ftp-master";
98
 
our $dupload_to_non_us = "anonymous-non-us";
99
 
our $dupload_to_security = "security";
100
 
our $log_queued_messages = 0;
101
 
our $wanna_build_dbbase = "$arch/build-db";
102
 
 
103
 
sub ST_MTIME () { 9 }
104
 
 
105
 
sub read_file ($\$) {
106
 
    my $filename = shift;
107
 
    my $time_var = shift;
108
 
    if (-r $filename) {
109
 
        my @stat = stat( $filename );
110
 
        $$time_var = $stat[ST_MTIME];
111
 
        delete $INC{$filename};
112
 
        require $filename;
113
 
    }
114
 
}
115
 
 
116
 
# read conf files
117
 
sub read () {
118
 
    read_file( $config_global, $config_global_time );
119
 
    read_file( $config_user, $config_user_time );
120
 
    convert_sshcmd();
121
 
}
122
 
 
123
 
sub convert_sshcmd () {
124
 
    if ($sshcmd) {
125
 
        if ($sshcmd =~ /-l\s*(\S+)\s+(\S+)/) {
126
 
            ($main::sshuser, $main::sshhost) = ($1, $2);
127
 
        }
128
 
        elsif ($sshcmd =~ /(\S+)\@(\S+)/) {
129
 
            ($main::sshuser, $main::sshhost) = ($1, $2);
130
 
        }
131
 
        else {
132
 
            $sshcmd =~ /(\S+)\s*$/;
133
 
            ($main::sshuser, $main::sshhost) = ("", $1);
134
 
        }
135
 
        if ($sshsocket) {
136
 
            $sshcmd .= " -S $sshsocket";
137
 
        }
138
 
    }
139
 
}
140
 
 
141
 
sub init () {
142
 
    Buildd::Conf::read();
143
 
}
144
 
 
145
 
$SIG{'USR1'} = sub ($) { $reread_config = 1; };
146
 
 
147
 
sub check_reread_config () {
148
 
    my @stat_user = stat( $config_user );
149
 
    my @stat_global = stat( $config_global );
150
 
 
151
 
    if ( $reread_config ||
152
 
        (@stat_user && $config_user_time != $stat_user[ST_MTIME]) ||
153
 
        (@stat_global && $config_global_time != $stat_global[ST_MTIME])) {
154
 
        logger( "My config file has been updated -- rereading it\n" );
155
 
        Buildd::Conf::read();
156
 
        $reread_config = 0;
157
 
    }
 
42
sub init_allowed_keys {
 
43
    my $self = shift;
 
44
 
 
45
    $self->SUPER::init_allowed_keys();
 
46
 
 
47
    my $validate_program = sub {
 
48
        my $self = shift;
 
49
        my $entry = shift;
 
50
        my $key = $entry->{'NAME'};
 
51
        my $program = $self->get($key);
 
52
 
 
53
        die "$key binary is not defined"
 
54
            if !defined($program) || !$program;
 
55
 
 
56
        die "$key binary '$program' does not exist or is not executable"
 
57
            if !-x $program;
 
58
    };
 
59
 
 
60
    my $validate_directory = sub {
 
61
        my $self = shift;
 
62
        my $entry = shift;
 
63
        my $key = $entry->{'NAME'};
 
64
        my $directory = $self->get($key);
 
65
 
 
66
        die "$key directory is not defined"
 
67
            if !defined($directory) || !$directory;
 
68
 
 
69
        die "$key directory '$directory' does not exist"
 
70
            if !-d $directory;
 
71
    };
 
72
 
 
73
    my $validate_ssh = sub {
 
74
        my $self = shift;
 
75
        my $entry = shift;
 
76
 
 
77
# TODO: Provide self, config and entry contexts, which functions to
 
78
# get at needed data.  Provide generic configuration functions.
 
79
#
 
80
        $validate_program->($self, $self->{'KEYS'}->{'SSH'});
 
81
 
 
82
        my $ssh = $self->get('SSH');
 
83
        my $sshuser = $self->get('SSH_USER');
 
84
        my $sshhost = $self->get('SSH_HOST');
 
85
        my @sshoptions = @{$self->get('SSH_OPTIONS')};
 
86
        my $sshsocket = $self->get('SSH_SOCKET');
 
87
 
 
88
        my @command = ();
 
89
 
 
90
        if ($sshhost) {
 
91
            push (@command, $ssh);
 
92
            push (@command, '-l', $sshuser) if $sshuser;
 
93
            push (@command, '-S', $sshsocket) if $sshsocket;
 
94
            push (@command, @sshoptions) if @sshoptions;
 
95
            push (@command, $sshhost);
 
96
        }
 
97
 
 
98
        $self->set('SSH_CMD', \@command);
 
99
    };
 
100
 
 
101
    our $HOME = $self->get('HOME');
 
102
    $main::HOME = $HOME; # TODO: Remove once Buildd.pm uses $conf
 
103
    my $arch = $self->get('ARCH');
 
104
 
 
105
    my %buildd_keys = (
 
106
        'ADMIN_MAIL'                            => {
 
107
            DEFAULT => 'root'
 
108
        },
 
109
        'APT_GET'                               => {
 
110
            CHECK => $validate_program,
 
111
            DEFAULT => $Sbuild::Sysconfig::programs{'APT_GET'}
 
112
        },
 
113
        'AUTOCLEAN_INTERVAL'                    => {
 
114
            DEFAULT => 86400
 
115
        },
 
116
        'BUILD_LOG_KEEP'                        => {
 
117
            DEFAULT => 2
 
118
        },
 
119
        'BUILD_LOG_REGEX'                       => {
 
120
            DEFAULT => undef
 
121
        },
 
122
        'DAEMON_LOG_FILE'                       => {
 
123
            DEFAULT => "$HOME/daemon.log"
 
124
        },
 
125
        'DAEMON_LOG_KEEP'                       => {
 
126
            DEFAULT => 7
 
127
        },
 
128
        'DAEMON_LOG_ROTATE'                     => {
 
129
            DEFAULT => 1
 
130
        },
 
131
        'DAEMON_LOG_SEND'                       => {
 
132
            DEFAULT => 1
 
133
        },
 
134
        'DELAY_AFTER_GIVE_BACK'                 => {
 
135
            DEFAULT => 8 * 60 # 8 hours
 
136
        },
 
137
        'DUPLOAD_TO'                            => {
 
138
            DEFAULT => 'anonymous-ftp-master'
 
139
        },
 
140
        'DUPLOAD_TO_NON_US'                     => {
 
141
            DEFAULT => 'anonymous-non-us'
 
142
        },
 
143
        'DUPLOAD_TO_SECURITY'                   => {
 
144
            DEFAULT => 'security'
 
145
        },
 
146
        'ERROR_MAIL_WINDOW'                     => {
 
147
            DEFAULT => 8*60*60
 
148
        },
 
149
        'IDLE_SLEEP_TIME'                       => {
 
150
            DEFAULT => 5*60
 
151
        },
 
152
        'LOG_QUEUED_MESSAGES'                   => {
 
153
            DEFAULT => 0
 
154
        },
 
155
        'MAX_BUILD'                             => {
 
156
            DEFAULT => 10
 
157
        },
 
158
        'MIN_FREE_SPACE'                        => {
 
159
            DEFAULT => 50*1024
 
160
        },
 
161
        'NICE_LEVEL'                            => {
 
162
            DEFAULT => 10
 
163
        },
 
164
        'NO_AUTO_BUILD'                         => {
 
165
            DEFAULT => []
 
166
        },
 
167
        'BUILD_REGEX'                           => {
 
168
            DEFAULT => ''
 
169
        },
 
170
        'NO_BUILD_REGEX'                        => {
 
171
            DEFAULT => '^(contrib/|non-free/)?non-US/'
 
172
        },
 
173
        'NO_DETACH'                             => {
 
174
            DEFAULT => 0
 
175
        },
 
176
        'NO_WARN_PATTERN'                       => {
 
177
            DEFAULT => '^build/(SKIP|REDO|SBUILD-GIVEN-BACK|buildd\.pid|[^/]*.ssh|chroot-[^/]*)$'
 
178
        },
 
179
        'PIDFILE'                               => {
 
180
# Set once running as a system service.
 
181
#          DEFAULT => "${Sbuild::Sysconfig::paths{'LOCALSTATEDIR'}/run/buildd.pid"
 
182
            DEFAULT => "$HOME/build/buildd.pid"
 
183
        },
 
184
        'PKG_LOG_KEEP'                          => {
 
185
            DEFAULT => 7
 
186
        },
 
187
        'SECONDARY_DAEMON_THRESHOLD'            => {
 
188
            DEFAULT => 70
 
189
        },
 
190
        'SHOULD_BUILD_MSGS'                     => {
 
191
            DEFAULT => 1
 
192
        },
 
193
        'SSH_CMD'                               => {
 
194
            DEFAULT => []
 
195
        },
 
196
        'SSH'                                   => {
 
197
            DEFAULT => $Sbuild::Sysconfig::programs{'SSH'},
 
198
            CHECK => $validate_ssh,
 
199
        },
 
200
        'SSH_USER'                              => {
 
201
            DEFAULT => '',
 
202
            CHECK => $validate_ssh,
 
203
        },
 
204
        'SSH_HOST'                              => {
 
205
            DEFAULT => '',
 
206
            CHECK => $validate_ssh,
 
207
        },
 
208
        'SSH_SOCKET'                            => {
 
209
            DEFAULT => '',
 
210
            CHECK => $validate_ssh,
 
211
        },
 
212
        'SSH_OPTIONS'                           => {
 
213
            DEFAULT => [],
 
214
            CHECK => $validate_ssh,
 
215
        },
 
216
        'STATISTICS_MAIL'                       => {
 
217
            DEFAULT => 'root'
 
218
        },
 
219
        'STATISTICS_PERIOD'                     => {
 
220
            DEFAULT => 7
 
221
        },
 
222
        'SUDO'                                  => {
 
223
            CHECK => $validate_program,
 
224
            DEFAULT => $Sbuild::Sysconfig::programs{'SUDO'}
 
225
        },
 
226
        'TAKE_FROM_DISTS'                       => {
 
227
            DEFAULT => []
 
228
        },
 
229
        'WANNA_BUILD_DBBASE'                    => {
 
230
            DEFAULT => "$arch/build-db"
 
231
        },
 
232
        'WANNA_BUILD_USER'                      => {
 
233
            DEFAULT => $Buildd::username
 
234
        },
 
235
        'WARNING_AGE'                           => {
 
236
            DEFAULT => 7
 
237
        },
 
238
        'WEAK_NO_AUTO_BUILD'                    => {
 
239
            DEFAULT => []
 
240
        },
 
241
        'CONFIG_TIME'                           => {
 
242
            DEFAULT => {}
 
243
        });
 
244
 
 
245
    $self->set_allowed_keys(\%buildd_keys);
 
246
}
 
247
 
 
248
sub read_config {
 
249
    my $self = shift;
 
250
 
 
251
    my $HOME = $self->get('HOME');
 
252
 
 
253
    # Variables are undefined, so config will default to DEFAULT if unset.
 
254
    my $admin_mail = undef;
 
255
    my $apt_get = undef;
 
256
    my $arch = undef;
 
257
    my $autoclean_interval = undef;
 
258
    my $build_log_keep = undef;
 
259
    my $build_regex = undef; # Should this be user settable?
 
260
    my $daemon_log_file = undef;
 
261
    my $daemon_log_keep = undef;
 
262
    my $daemon_log_rotate = undef;
 
263
    my $daemon_log_send = undef;
 
264
    my $delay_after_give_back = undef;
 
265
    my $dupload_to = undef;
 
266
    my $dupload_to_non_us = undef;
 
267
    my $dupload_to_security = undef;
 
268
    my $error_mail_window = undef;
 
269
    my $idle_sleep_time = undef;
 
270
    my $log_queued_messages = undef;
 
271
    my $max_build = undef;
 
272
    my $min_free_space = undef;
 
273
    my $nice_level = undef;
 
274
    my @no_auto_build;
 
275
    my $no_build_regex = undef;
 
276
    my $no_detach = undef;
 
277
    my $no_warn_pattern = undef;
 
278
    my $pidfile = undef;
 
279
    my $pkg_log_keep = undef;
 
280
    my $secondary_daemon_threshold = undef;
 
281
    my $should_build_msgs = undef;
 
282
    my $ssh = undef;
 
283
    my $ssh_user = undef;
 
284
    my $ssh_host = undef;
 
285
    my @ssh_options;
 
286
    my $ssh_socket = undef;
 
287
    my $statistics_mail = undef;
 
288
    my $statistics_period = undef;
 
289
    my $sudo = undef;
 
290
    my @take_from_dists;
 
291
    my $wanna_build_dbbase = undef;
 
292
    my $wanna_build_user = undef;
 
293
    my $warning_age = undef;
 
294
    my @weak_no_auto_build;
 
295
 
 
296
    my $global = $Sbuild::Sysconfig::paths{'BUILDD_CONF'};
 
297
    my $user = "$HOME/.builddrc";
 
298
    my %config_time = ();
 
299
    my $user_time = 0;
 
300
 
 
301
    my $reread = 0;
 
302
 
 
303
    sub ST_MTIME () { 9 }
 
304
 
 
305
    my @config_files = ($global, $user);
 
306
 
 
307
    $reread = 1 if $reread_config;
 
308
 
 
309
    foreach (@config_files) {
 
310
        if (-r $_) {
 
311
            $config_time{$_} = 0;
 
312
            my @stat = stat($_);
 
313
            if (!defined($self->get('CONFIG_TIME')->{$_}) ||
 
314
                $self->get('CONFIG_TIME')->{$_} < $stat[ST_MTIME]) {
 
315
                $config_time{$_} = $stat[ST_MTIME];
 
316
                $reread = 1;
 
317
            }
 
318
        }
 
319
    }
 
320
 
 
321
    # Need to reread all config files, even if one is updated.
 
322
    if ($reread) {
 
323
        foreach (@config_files) {
 
324
            if (-r $_) {
 
325
                my $e = eval `cat "$_"`;
 
326
                if (!defined($e)) {
 
327
                    print STDERR "E: $_: Errors found in configuration file:\n$@";
 
328
                    exit(1);
 
329
                }
 
330
                $self->get('CONFIG_TIME')->{$_} = $config_time{$_};
 
331
            }
 
332
        }
 
333
    }
 
334
 
 
335
    # Set configuration if updated.
 
336
    if ($reread) {
 
337
        $self->set('ADMIN_MAIL', $admin_mail);
 
338
        $self->set('APT_GET', $apt_get);
 
339
        $self->set('ARCH', $arch);
 
340
        $self->set('AUTOCLEAN_INTERVAL', $autoclean_interval);
 
341
        $self->set('BUILD_LOG_KEEP', $build_log_keep);
 
342
        $self->set('BUILD_REGEX', $build_regex);
 
343
        $self->set('DAEMON_LOG_FILE', $daemon_log_file);
 
344
        $self->set('DAEMON_LOG_KEEP', $daemon_log_keep);
 
345
        $self->set('DAEMON_LOG_ROTATE', $daemon_log_rotate);
 
346
        $self->set('DAEMON_LOG_SEND', $daemon_log_send);
 
347
        $self->set('DELAY_AFTER_GIVE_BACK', $delay_after_give_back);
 
348
        $self->set('DUPLOAD_TO', $dupload_to);
 
349
        $self->set('DUPLOAD_TO_NON_US', $dupload_to_non_us);
 
350
        $self->set('DUPLOAD_TO_SECURITY', $dupload_to_security);
 
351
        $self->set('ERROR_MAIL_WINDOW', $error_mail_window);
 
352
        $self->set('IDLE_SLEEP_TIME', $idle_sleep_time);
 
353
        $self->set('LOG_QUEUED_MESSAGES', $log_queued_messages);
 
354
        $self->set('MAX_BUILD', $max_build);
 
355
        $self->set('MIN_FREE_SPACE', $min_free_space);
 
356
        $self->set('NICE_LEVEL', $nice_level);
 
357
        $self->set('NO_AUTO_BUILD', \@no_auto_build)
 
358
            if (@no_auto_build);
 
359
        $self->set('NO_BUILD_REGEX', $no_build_regex);
 
360
        $self->set('NO_DETACH', $no_detach);
 
361
        $self->set('BUILD_REGEX', $build_regex);
 
362
        $self->set('NO_WARN_PATTERN', $no_warn_pattern);
 
363
        $self->set('PIDFILE', $pidfile);
 
364
        $self->set('PKG_LOG_KEEP', $pkg_log_keep);
 
365
        $self->set('SECONDARY_DAEMON_THRESHOLD', $secondary_daemon_threshold);
 
366
        $self->set('SHOULD_BUILD_MSGS', $should_build_msgs);
 
367
        $self->set('SSH', $ssh);
 
368
        $self->set('SSH_USER', $ssh_user);
 
369
        $self->set('SSH_HOST', $ssh_host);
 
370
        $self->set('SSH_OPTIONS', \@ssh_options)
 
371
            if (@ssh_options);
 
372
        $self->set('SSH_SOCKET', $ssh_socket);
 
373
        $self->set('STATISTICS_MAIL', $statistics_mail);
 
374
        $self->set('STATISTICS_PERIOD', $statistics_period);
 
375
        $self->set('SUDO', $sudo);
 
376
        $self->set('TAKE_FROM_DISTS', \@take_from_dists)
 
377
            if (@take_from_dists);
 
378
        $self->set('WANNA_BUILD_DBBASE', $wanna_build_dbbase);
 
379
        $self->set('WANNA_BUILD_USER', $wanna_build_user);
 
380
        $self->set('WARNING_AGE', $warning_age);
 
381
        $self->set('WEAK_NO_AUTO_BUILD', \@weak_no_auto_build)
 
382
            if (@weak_no_auto_build);
 
383
 
 
384
        # Set here to allow user to override.
 
385
        if (-t STDIN && -t STDOUT && $self->get('NO_DETACH')) {
 
386
            $self->set('VERBOSE', 1);
 
387
        }
 
388
    }
 
389
 
158
390
}
159
391
 
160
392
1;