~ubuntu-branches/ubuntu/oneiric/sbuild/oneiric

« back to all changes in this revision

Viewing changes to lib/Buildd/Conf.pm

  • Committer: Bazaar Package Importer
  • Author(s): Lorenzo De Liso
  • Date: 2011-05-01 16:55:16 UTC
  • mfrom: (8.1.19 upstream) (3.3.17 sid)
  • Revision ID: james.westby@ubuntu.com-20110501165516-8g3uwrnhv2bzjt8y
Tags: 0.62.2-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/patches/do-not-install-debfoster-into-chroots.patch: 
    do not install debfoster into the chroots because it is in universe and 
    not needed for package building itself.
  - debian/patches/run-pre-build-hooks-as-root.patch: 
    run pre-build hooks as root (Closes: #607228)
* Now that the package uses a patch system, don't modify the files directly;
  instead, put the changes in the respective patches and add the DEP-3
  patch tagging guidelines to them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
use Buildd::UploadQueueConf qw();
30
30
use Sbuild::ConfBase;
31
31
use Sbuild::Sysconfig;
32
 
use Sbuild::DB::ClientConf qw();
 
32
use Buildd::ClientConf qw();
33
33
 
34
34
BEGIN {
35
35
    use Exporter ();
42
42
 
43
43
our $reread_config = 0;
44
44
 
45
 
sub new ();
46
45
sub setup ($);
47
46
sub read ($);
48
47
 
49
 
sub new () {
50
 
    my $conf = Sbuild::ConfBase->new();
 
48
sub new {
 
49
    my $conf = Sbuild::ConfBase->new(@_);
51
50
    Buildd::Conf::setup($conf);
52
51
    Buildd::Conf::read($conf);
53
52
 
98
97
 
99
98
    my %buildd_keys = (
100
99
        'ADMIN_MAIL'                            => {
101
 
            DEFAULT => 'root'
 
100
            TYPE => 'STRING',
 
101
            VARNAME => 'admin_mail',
 
102
            GROUP => 'Mail',
 
103
            DEFAULT => 'root',
 
104
            HELP => 'email address for admin'
102
105
        },
103
106
        'APT_GET'                               => {
 
107
            TYPE => 'STRING',
 
108
            VARNAME => 'apt_get',
 
109
            GROUP => 'Programs',
104
110
            CHECK => $validate_program,
105
 
            DEFAULT => 'apt-get'
106
 
        },
107
 
        'AUTOCLEAN_INTERVAL'                    => {
108
 
            DEFAULT => 86400
 
111
            DEFAULT => 'apt-get',
 
112
            HELP => 'Path to apt-get binary'
109
113
        },
110
114
        'BUILD_LOG_KEEP'                        => {
111
 
            DEFAULT => 2
112
 
        },
113
 
        'BUILD_LOG_REGEX'                       => {
114
 
            DEFAULT => undef
 
115
            TYPE => 'NUMERIC',
 
116
            VARNAME => 'build_log_keep',
 
117
            GROUP => 'Watcher',
 
118
            DEFAULT => 2,
 
119
            HELP => 'Number of days until build logs are archived'
115
120
        },
116
121
        'DAEMON_LOG_FILE'                       => {
117
 
            DEFAULT => "$HOME/daemon.log"
 
122
            TYPE => 'STRING',
 
123
            VARNAME => 'daemon_log_file',
 
124
            GROUP => 'Daemon',
 
125
            DEFAULT => "$HOME/daemon.log",
 
126
            HELP => 'Main buildd daemon log file'
118
127
        },
119
128
        'DAEMON_LOG_KEEP'                       => {
120
 
            DEFAULT => 7
 
129
            TYPE => 'NUMERIC',
 
130
            VARNAME => 'daemon_log_keep',
 
131
            GROUP => 'Watcher',
 
132
            DEFAULT => 7,
 
133
            HELP => 'Number of days until old daemon logs are archived in a .tar.gz file'
121
134
        },
122
135
        'DAEMON_LOG_ROTATE'                     => {
123
 
            DEFAULT => 1
 
136
            TYPE => 'NUMERIC',
 
137
            VARNAME => 'daemon_log_rotate',
 
138
            GROUP => 'Watcher',
 
139
            DEFAULT => 1,
 
140
            HELP => 'Number how many days until daemon logs are rotated (one is kept as daemon.log.old, others are moved to old-logs and gzipped)'
124
141
        },
125
142
        'DAEMON_LOG_SEND'                       => {
126
 
            DEFAULT => 1
 
143
            TYPE => 'BOOL',
 
144
            VARNAME => 'daemon_log_send',
 
145
            GROUP => 'Watcher',
 
146
            DEFAULT => 1,
 
147
            HELP => 'email rotated daemon logs to the admin?'
127
148
        },
128
149
        'DELAY_AFTER_GIVE_BACK'                 => {
129
 
            DEFAULT => 8 * 60 # 8 hours
 
150
            TYPE => 'NUMERIC',
 
151
            VARNAME => 'delay_after_give_back',
 
152
            GROUP => 'Daemon',
 
153
            DEFAULT => 8 * 60, # 8 hours
 
154
            HELP => 'Time to avoid packages that have automatically been given back by sbuild (in minutes)'
130
155
        },
131
156
        'ERROR_MAIL_WINDOW'                     => {
132
 
            DEFAULT => 8*60*60
 
157
            TYPE => 'NUMERIC',
 
158
            VARNAME => 'error_mail_window',
 
159
            GROUP => 'Mail',
 
160
            DEFAULT => 8*60*60,
 
161
            HELP => 'If more than five error mails are received within the specified time (in seconds), do not forward (to avoid possible mail loops)'
133
162
        },
134
163
        'IDLE_SLEEP_TIME'                       => {
135
 
            DEFAULT => 5*60
 
164
            TYPE => 'NUMERIC',
 
165
            VARNAME => 'idle_sleep_time',
 
166
            GROUP => 'Daemon',
 
167
            DEFAULT => 5*60,
 
168
            HELP => 'Time to sleep when idle (in seconds) between wanna-build --list=needs-build calls)'
136
169
        },
137
170
        'LOG_QUEUED_MESSAGES'                   => {
138
 
            DEFAULT => 0
 
171
            TYPE => 'BOOL',
 
172
            VARNAME => 'log_queued_messages',
 
173
            GROUP => 'Mail',
 
174
            DEFAULT => 0,
 
175
            HELP => 'Log success messages from upload queue daemon?'
139
176
        },
140
177
        'MIN_FREE_SPACE'                        => {
141
 
            DEFAULT => 50*1024
 
178
            TYPE => 'NUMERIC',
 
179
            VARNAME => 'min_free_space',
 
180
            GROUP => 'Daemon',
 
181
            DEFAULT => 50*1024,
 
182
            HELP => 'Minimum free space (in KiB) on build filesystem'
142
183
        },
143
184
        'NICE_LEVEL'                            => {
144
 
            DEFAULT => 10
 
185
            TYPE => 'NUMERIC',
 
186
            VARNAME => 'nice_level',
 
187
            GROUP => 'Build options',
 
188
            DEFAULT => 10,
 
189
            HELP => 'Nice level to run sbuild.  Dedicated build daemons should not be niced.'
145
190
        },
146
191
        'NO_DETACH'                             => {
147
 
            DEFAULT => 0
 
192
            TYPE => 'BOOL',
 
193
            VARNAME => 'no_detach',
 
194
            GROUP => 'Daemon',
 
195
            DEFAULT => 0,
 
196
            HELP => 'Disable becoming a daemon, for debugging purposes.  Set to 1 to stop daemonising, otherwise set to 0 to become a daemon.'
148
197
        },
149
198
        'NO_WARN_PATTERN'                       => {
150
 
            DEFAULT => '^build/(SKIP|REDO|SBUILD-GIVEN-BACK|buildd\.pid|[^/]*.ssh|chroot-[^/]*|current-[^/]*)$'
 
199
            TYPE => 'STRING',
 
200
            VARNAME => 'no_warn_pattern',
 
201
            GROUP => 'Watcher',
 
202
            DEFAULT => '^build/(SKIP|REDO|SBUILD-GIVEN-BACK|buildd\.pid|[^/]*.ssh|chroot-[^/]*|current-[^/]*)$',
 
203
            HELP => 'Don\'t complain about old files if they match the regexp.'
151
204
        },
152
205
        'PIDFILE'                               => {
 
206
            TYPE => 'STRING',
 
207
            VARNAME => 'pidfile',
 
208
            GROUP => 'Daemon',
153
209
# Set once running as a system service.
154
210
#          DEFAULT => "${Sbuild::Sysconfig::paths{'LOCALSTATEDIR'}/run/buildd.pid"
155
 
            DEFAULT => "$HOME/build/buildd.pid"
 
211
            DEFAULT => "$HOME/build/buildd.pid",
 
212
            HELP => 'PID file to identify running daemon.'
156
213
        },
157
214
        'PKG_LOG_KEEP'                          => {
158
 
            DEFAULT => 7
159
 
        },
160
 
        'SECONDARY_DAEMON_THRESHOLD'            => {
161
 
            DEFAULT => 70
 
215
            TYPE => 'NUMERIC',
 
216
            VARNAME => 'pkg_log_keep',
 
217
            GROUP => 'Watcher',
 
218
            DEFAULT => 7,
 
219
            HELP => 'Number of days until to package logs are archived'
162
220
        },
163
221
        'SHOULD_BUILD_MSGS'                     => {
164
 
            DEFAULT => 1
 
222
            TYPE => 'BOOL',
 
223
            VARNAME => 'should_build_msgs',
 
224
            GROUP => 'Daemon',
 
225
            DEFAULT => 1,
 
226
            HELP => 'Should buildd send "Should I build" messages?'
165
227
        },
166
228
        'STATISTICS_MAIL'                       => {
167
 
            DEFAULT => 'root'
 
229
            TYPE => 'STRING',
 
230
            VARNAME => 'statistics_mail',
 
231
            GROUP => 'Watcher',
 
232
            DEFAULT => 'root',
 
233
            HELP => 'email address for statistics summaries'
168
234
        },
169
235
        'STATISTICS_PERIOD'                     => {
170
 
            DEFAULT => 7
 
236
            TYPE => 'NUMERIC',
 
237
            VARNAME => 'statistics_period',
 
238
            GROUP => 'Watcher',
 
239
            DEFAULT => 7,
 
240
            HELP => 'Period for statistic summaries (days)'
171
241
        },
172
242
        'SUDO'                                  => {
 
243
            TYPE => 'STRING',
 
244
            VARNAME => 'sudo',
 
245
            GROUP => 'Programs',
173
246
            CHECK => $validate_program,
174
 
            DEFAULT => 'sudo'
 
247
            DEFAULT => 'sudo',
 
248
            HELP => 'Path to sudo binary'
175
249
        },
176
250
        'WARNING_AGE'                           => {
177
 
            DEFAULT => 7
 
251
            TYPE => 'NUMERIC',
 
252
            VARNAME => 'warning_age',
 
253
            GROUP => 'Watcher',
 
254
            DEFAULT => 7,
 
255
            HELP => 'Age (in days) after which a warning is issued for files in upload and dirs in build'
178
256
        },
179
257
        'CONFIG_TIME'                           => {
180
 
            DEFAULT => {}
 
258
            TYPE => 'NUMERIC',
 
259
            VARNAME => 'config_time',
 
260
            GROUP => '__INTERNAL',
 
261
            DEFAULT => {},
 
262
            HELP => 'Time configuration was last read'
181
263
        },
182
264
        'DISTRIBUTIONS'                         => {
183
 
            DEFAULT => []
 
265
            TYPE => 'ARRAY:HASH:SCALAR',
 
266
            VARNAME => 'distributions',
 
267
            GROUP => 'Build options',
 
268
            DEFAULT => [],
 
269
            IGNORE_DEFAULT => 1, # Don't dump class to config
 
270
            HELP => 'List of distributions that buildd should take packages from',
 
271
            EXAMPLE =>
 
272
'$distributions = [
 
273
        {
 
274
                # name of the suite to build (also used to query wanna-build)
 
275
                dist_name => ["unstable", "testing"],
 
276
 
 
277
                # architecture to be built (will be passed to sbuild and can be
 
278
                # used to compute wanna_build_db_name
 
279
                built_architecture => undef,
 
280
 
 
281
                # host on which wanna-build is run
 
282
                wanna_build_ssh_host => "buildd.debian.org",
 
283
 
 
284
                # user as who we are going to connect to the host running wanna-build
 
285
                wanna_build_ssh_user => "buildd_arch",
 
286
 
 
287
                # SSH control socket path for ssh -S option
 
288
                wanna_build_ssh_socket => "",
 
289
 
 
290
                # Additional SSH options used when connecting
 
291
                wanna_build_ssh_options => [],
 
292
 
 
293
                # database used for wanna-build
 
294
                wanna_build_db_name => "arch/build-db",
 
295
 
 
296
                # Username to use for wanna-build.
 
297
                wanna_build_db_user => $Buildd::username,
 
298
 
 
299
                # Local queue directory where binaries are stored before uploaded
 
300
                # by dupload. You need to configure this directory in
 
301
                # @upload_queues to get packages uploaded from there.
 
302
                dupload_local_queue_dir => "upload",
 
303
 
 
304
                # list of packages which shouldn\'t be picked up by buildd
 
305
                no_auto_build => [],
 
306
 
 
307
                # list of packages which should only be taken if there absolutely
 
308
                # nothing else to do (probably packages included in no_auto_build
 
309
                # because they take too long)
 
310
                weak_no_auto_build => [],
 
311
 
 
312
                # regex used to filter out unwanted packages:
 
313
                #no_build_regex => "^(contrib/|non-free/)?non-US/",
 
314
 
 
315
                # regex used to filter packages to build:
 
316
                #build_regex => "",
 
317
 
 
318
                # mail addr of buildd admin handling packages from this distribution
 
319
                logs_mailed_to => $admin_mail,
 
320
 
 
321
                # schroot name (or alias) of the chrooted environment to use for
 
322
                # building (will be passed to sbuild). sbuild\'s default is
 
323
                # the first of $distribution-$arch-sbuild, $distribution-sbuild,
 
324
                # $distribution-$arch and $distribution.
 
325
                sbuild_chroot => undef,
 
326
 
 
327
        }
 
328
];'
184
329
        },
185
330
        'UPLOAD_QUEUES'                         => {
186
 
            DEFAULT => []
 
331
            TYPE => 'ARRAY:HASH:SCALAR',
 
332
            VARNAME => 'upload_queues',
 
333
            GROUP => 'Uploader',
 
334
            DEFAULT => [],
 
335
            IGNORE_DEFAULT => 1, # Don't dump class to config
 
336
            HELP => 'Package upload queues',
 
337
            EXAMPLE =>
 
338
'$upload_queues = [
 
339
        {
 
340
                # Local queue directory where binaries are stored before uploaded
 
341
                # by dupload.
 
342
                dupload_local_queue_dir => "upload",
 
343
 
 
344
                # Upload site for buildd-upload to pass to dupload(1); see
 
345
                # /etc/dupload.conf for possible values.
 
346
                dupload_archive_name => "anonymous-ftp-master",
187
347
        },
188
 
        );
 
348
 
 
349
        {
 
350
                # Local queue directory where binaries are stored before uploaded
 
351
                # by dupload.
 
352
                dupload_local_queue_dir => "upload-security",
 
353
 
 
354
                # Upload site for buildd-upload to pass to dupload(1); see
 
355
                # /etc/dupload.conf for possible values.
 
356
                dupload_archive_name => "security",
 
357
        }
 
358
];'
 
359
        });
189
360
 
190
361
    $conf->set_allowed_keys(\%buildd_keys);
191
 
    Sbuild::DB::ClientConf::setup($conf);
 
362
    Buildd::ClientConf::setup($conf);
192
363
}
193
364
 
194
365
sub read ($) {
196
367
 
197
368
    my $HOME = $conf->get('HOME');
198
369
 
199
 
    # Variables are undefined, so config will default to DEFAULT if unset.
200
 
    my $admin_mail = undef;
201
 
    my $apt_get = undef;
202
 
    my $arch = undef;
203
 
    my $autoclean_interval = undef;
204
 
    my $build_log_keep = undef;
205
 
    my $daemon_log_file = undef;
206
 
    my $daemon_log_keep = undef;
207
 
    my $daemon_log_rotate = undef;
208
 
    my $daemon_log_send = undef;
209
 
    my $delay_after_give_back = undef;
210
 
    my $error_mail_window = undef;
211
 
    my $idle_sleep_time = undef;
212
 
    my $log_queued_messages = undef;
213
 
    my $max_build = undef;
214
 
    my $min_free_space = undef;
215
 
    my $nice_level = undef;
216
 
    my $no_detach = undef;
217
 
    my $no_warn_pattern = undef;
218
 
    my $pidfile = undef;
219
 
    my $pkg_log_keep = undef;
220
 
    my $secondary_daemon_threshold = undef;
221
 
    my $should_build_msgs = undef;
222
 
    my $ssh = undef;
223
 
    my $statistics_mail = undef;
224
 
    my $statistics_period = undef;
225
 
    my $sudo = undef;
226
 
    my $wanna_build_db_name = undef;
227
 
    my $wanna_build_db_user = undef;
228
 
    my $wanna_build_ssh_user = undef;
229
 
    my $wanna_build_ssh_host = undef;
230
 
    my $wanna_build_ssh_socket = undef;
231
 
    my $wanna_build_ssh_options = undef;
232
 
    my $warning_age = undef;
233
 
    my @distributions;
234
 
    my $defaults;
235
 
    my @upload_queues;
236
 
 
237
 
    #legacy fields:
238
 
    my @weak_no_auto_build;
239
 
    my $mail_to = undef;
240
 
    my %mail_to = ();
241
 
    my $mail_from = undef;
242
 
    my $build_regex = undef; # Should this be user settable?
243
 
    my @no_auto_build;
244
 
    my $no_build_regex = undef;
245
 
    my $dupload_to = undef;
246
 
    my $dupload_to_non_us = undef;
247
 
    my $dupload_to_security = undef;
248
 
    my @take_from_dists;
249
 
    my $sshcmd;
250
 
    my $sshsocket;
251
 
    my $wanna_build_user;
252
 
    my $wanna_build_dbbase;
253
 
 
254
370
    my $global = $Sbuild::Sysconfig::paths{'BUILDD_CONF'};
255
371
    my $user = "$HOME/.builddrc";
256
372
    my %config_time = ();
276
392
        }
277
393
    }
278
394
 
279
 
    # Need to reread all config files, even if one is updated.
 
395
    # For compatibility only.  Non-scalars are deprecated.
 
396
    my $deprecated_init = <<END;
 
397
# Variables are undefined, so config will default to DEFAULT if unset.
 
398
my \$defaults;
 
399
my \@distributions;
 
400
undef \@distributions;
 
401
my \@upload_queues;
 
402
undef \@upload_queues;
 
403
 
 
404
#legacy fields:
 
405
my \@weak_no_auto_build;
 
406
undef \@weak_no_auto_build;
 
407
my \$build_regex = undef; # Should this be user settable?
 
408
my \@no_auto_build;
 
409
undef \@no_auto_build;
 
410
my \$no_build_regex = undef;
 
411
my \@take_from_dists;
 
412
undef \@take_from_dists;
 
413
my \$sshcmd = undef;
 
414
my \$sshsocket = undef;
 
415
my \$wanna_build_user = undef;
 
416
my \$wanna_build_dbbase = undef;
 
417
END
 
418
 
 
419
    my $deprecated_setup = '';
 
420
 
 
421
    my $custom_setup = <<END;
 
422
if (\$sshcmd && \$sshcmd =~ /^\\s*(\\S+)\\s+(.+)/) {
 
423
    my \$rest = \$2;
 
424
    \$conf->set('SSH', \$1);
 
425
 
 
426
    #Try to pry the user out:
 
427
    if (\$rest =~ /(-l\\s*(\\S+))\\s+/) {
 
428
        \$wanna_build_ssh_user = \$2;
 
429
        #purge this from the rest:
 
430
        \$rest =~ s/\\Q\$1//;
 
431
    } elsif (\$rest =~ /\\s+(\\S+)\@/) {
 
432
        \$wanna_build_ssh_user = \$1;
 
433
        \$rest =~ s/\\Q\$1\\E\@//;
 
434
    }
 
435
 
 
436
    #Hope that the last argument is the host:
 
437
    if (\$rest =~ /\\s+(\\S+)\\s*\$/) {
 
438
        \$wanna_build_ssh_host = \$1;
 
439
        \$rest =~ s/\\Q\$1//;
 
440
    }
 
441
 
 
442
    #rest should be options:
 
443
    if (\$rest !~ /\\s*/) {
 
444
        \$wanna_build_ssh_options = [split \$rest];
 
445
    }
 
446
}
 
447
 
 
448
if (\$sshsocket) {
 
449
    \$wanna_build_ssh_socket = \$sshsocket;
 
450
}
 
451
 
 
452
if (\$wanna_build_user) {
 
453
    \$wanna_build_db_user = \$wanna_build_user;
 
454
}
 
455
 
 
456
if (\$wanna_build_dbbase) {
 
457
    \$wanna_build_db_name = \$wanna_build_dbbase;
 
458
}
 
459
 
 
460
#Convert old config, if needed:
 
461
my \@distributions_info;
 
462
if (\@take_from_dists) {
 
463
    for my \$dist (\@take_from_dists) {
 
464
        my \%entry;
 
465
 
 
466
        \$entry{DIST_NAME} = \$dist;
 
467
        \$entry{SSH} = \$ssh;
 
468
 
 
469
        if (\$dist =~ /security/) {
 
470
            \$entry{DUPLOAD_LOCAL_QUEUE_DIR} = 'upload-security';
 
471
        }
 
472
        if (\$build_regex) {
 
473
            \$entry{BUILD_REGEX} = \$build_regex;
 
474
        }
 
475
        if (\$no_build_regex) {
 
476
            \$entry{NO_BUILD_REGEX} = \$build_regex;
 
477
        }
 
478
        if (\@no_auto_build) {
 
479
            \$entry{NO_AUTO_BUILD} = \\\@no_auto_build;
 
480
        }
 
481
        if (\@weak_no_auto_build) {
 
482
            \$entry{WEAK_NO_AUTO_BUILD} = \\\@weak_no_auto_build;
 
483
        }
 
484
 
 
485
        \$entry{WANNA_BUILD_DB_NAME} = \$wanna_build_db_name;
 
486
        \$entry{WANNA_BUILD_DB_USER} = \$wanna_build_db_user;
 
487
        \$entry{WANNA_BUILD_SSH_HOST} = \$wanna_build_ssh_host;
 
488
        \$entry{WANNA_BUILD_SSH_USER} = \$wanna_build_ssh_user;
 
489
        \$entry{WANNA_BUILD_SSH_SOCKET} = \$wanna_build_ssh_socket;
 
490
        \$entry{WANNA_BUILD_SSH_OPTIONS} = \$wanna_build_ssh_options;
 
491
                \$entry{WANNA_BUILD_API} = 0;
 
492
 
 
493
        my \$dist_config = Buildd::DistConf::new_hash(CHECK=>$conf->{'CHECK'},
 
494
                                                      HASH=>\\\%entry);
 
495
 
 
496
        push \@distributions_info, \$dist_config;
 
497
    }
 
498
} else {
 
499
    for my \$raw_entry (\@distributions) {
 
500
        my \%entry;
 
501
        my \@dist_names;
 
502
 
 
503
        #Find out for which distributions this entry is intended:
 
504
        for my \$key (keys \%\$raw_entry) {
 
505
            if (uc(\$key) eq "DIST_NAME") {
 
506
                if (ref(\$raw_entry->{\$key}) eq "ARRAY") {
 
507
                    push \@dist_names, \@{\$raw_entry->{\$key}};
 
508
                } else {
 
509
                    push \@dist_names, \$raw_entry->{\$key};
 
510
                }
 
511
            }
 
512
        }
 
513
 
 
514
        for my \$key (keys \%\$raw_entry) {
 
515
            if (uc(\$key) ne "DIST_NAME") {
 
516
                \$entry{uc(\$key)} = \$raw_entry->{\$key};
 
517
            }
 
518
        }
 
519
 
 
520
                for my \$key (keys \%\$defaults) {
 
521
                    if (uc(\$key) ne "DIST_NAME" && not defined \$entry{uc(\$key)}) {
 
522
                        \$entry{uc(\$key)} = \$defaults->{\$key};
 
523
                    }
 
524
                }
 
525
 
 
526
                \$entry{WANNA_BUILD_API} //= 1;
 
527
 
 
528
 
 
529
        #We need this to pass this to Buildd::Client:
 
530
                \$entry{SSH} = \$ssh;
 
531
 
 
532
        #Make one entry per distribution, it's easier later on:
 
533
        for my \$dist (\@dist_names) {
 
534
            \$entry{'DIST_NAME'} = \$dist;
 
535
                    my \$dist_config = Buildd::DistConf::new_hash(\\\%entry);
 
536
                    push \@distributions_info, \$dist_config;
 
537
        }
 
538
    }
 
539
}
 
540
 
 
541
\$conf->set('DISTRIBUTIONS', \\\@distributions_info);
 
542
 
 
543
if (\@upload_queues) {
 
544
    my \@upload_queue_configs;
 
545
    for my \$raw_entry (\@upload_queues) {
 
546
        my \%entry;
 
547
        for my \$key (keys \%\$raw_entry) {
 
548
            \$entry{uc(\$key)} = \$raw_entry->{\$key};
 
549
        }
 
550
 
 
551
        my \$queue_config = Buildd::UploadQueueConf::new_hash(CHECK=>$conf->{'CHECK'},
 
552
                                                              HASH=>\\\%entry);
 
553
 
 
554
        push \@upload_queue_configs, \$queue_config;
 
555
    }
 
556
    \$conf->set('UPLOAD_QUEUES', \\\@upload_queue_configs);
 
557
} else {
 
558
    push \@{\$conf->get('UPLOAD_QUEUES')},
 
559
        Buildd::UploadQueueConf::new_hash(CHECK=>$conf->{'CHECK'},
 
560
                                          HASH=>
 
561
            {
 
562
                DUPLOAD_LOCAL_QUEUE_DIR => 'upload',
 
563
                DUPLOAD_ARCHIVE_NAME    => 'anonymous-ftp-master'
 
564
            }
 
565
        ),
 
566
        Buildd::UploadQueueConf::new_hash(CHECK=>$conf->{'CHECK'},
 
567
                                          HASH=>
 
568
            {
 
569
                DUPLOAD_LOCAL_QUEUE_DIR => 'upload-security',
 
570
                DUPLOAD_ARCHIVE_NAME    => 'security'
 
571
            }
 
572
        );
 
573
}
 
574
 
 
575
# Set here to allow user to override.
 
576
if (-t STDIN && -t STDOUT && \$conf->get('NO_DETACH')) {
 
577
    \$conf->_set_default('VERBOSE', 1);
 
578
} else {
 
579
    \$conf->_set_default('VERBOSE', 0);
 
580
}
 
581
END
 
582
 
 
583
    $conf->read(\@config_files, $deprecated_init, $deprecated_setup,
 
584
                $custom_setup);
 
585
 
 
586
    # Update times
280
587
    if ($reread) {
281
588
        foreach (@config_files) {
282
589
            if (-r $_) {
283
 
                my $e = eval `cat "$_"`;
284
 
                if (!defined($e)) {
285
 
                    print STDERR "E: $_: Errors found in configuration file:\n$@";
286
 
                    exit(1);
287
 
                }
288
590
                $conf->get('CONFIG_TIME')->{$_} = $config_time{$_};
289
591
            }
290
592
        }
291
 
 
292
 
        # Set configuration if updated.
293
 
        $conf->set('ADMIN_MAIL', $admin_mail);
294
 
        $conf->set('APT_GET', $apt_get);
295
 
        $conf->set('ARCH', $arch);
296
 
        $conf->set('AUTOCLEAN_INTERVAL', $autoclean_interval);
297
 
        $conf->set('BUILD_LOG_KEEP', $build_log_keep);
298
 
        $conf->set('DAEMON_LOG_FILE', $daemon_log_file);
299
 
        $conf->set('DAEMON_LOG_KEEP', $daemon_log_keep);
300
 
        $conf->set('DAEMON_LOG_ROTATE', $daemon_log_rotate);
301
 
        $conf->set('DAEMON_LOG_SEND', $daemon_log_send);
302
 
        $conf->set('DELAY_AFTER_GIVE_BACK', $delay_after_give_back);
303
 
        $conf->set('ERROR_MAIL_WINDOW', $error_mail_window);
304
 
        $conf->set('IDLE_SLEEP_TIME', $idle_sleep_time);
305
 
        $conf->set('LOG_QUEUED_MESSAGES', $log_queued_messages);
306
 
        $conf->set('MIN_FREE_SPACE', $min_free_space);
307
 
        $conf->set('NICE_LEVEL', $nice_level);
308
 
        $conf->set('NO_DETACH', $no_detach);
309
 
        $conf->set('NO_WARN_PATTERN', $no_warn_pattern);
310
 
        $conf->set('PIDFILE', $pidfile);
311
 
        $conf->set('PKG_LOG_KEEP', $pkg_log_keep);
312
 
        $conf->set('SECONDARY_DAEMON_THRESHOLD', $secondary_daemon_threshold);
313
 
        $conf->set('SHOULD_BUILD_MSGS', $should_build_msgs);
314
 
        $conf->set('SSH', $ssh);
315
 
        $conf->set('STATISTICS_MAIL', $statistics_mail);
316
 
        $conf->set('STATISTICS_PERIOD', $statistics_period);
317
 
        $conf->set('SUDO', $sudo);
318
 
        $conf->set('WARNING_AGE', $warning_age);
319
 
 
320
 
        if ($sshcmd && $sshcmd =~ /^\s*(\S+)\s+(.+)/) {
321
 
            my $rest = $2;
322
 
            $conf->set('SSH', $1);
323
 
 
324
 
            #Try to pry the user out:
325
 
            if ($rest =~ /(-l\s*(\S+))\s+/) {
326
 
                $wanna_build_ssh_user = $2;
327
 
                #purge this from the rest:
328
 
                $rest =~ s/\Q$1//;
329
 
            } elsif ($rest =~ /\s+(\S+)\@/) {
330
 
                $wanna_build_ssh_user = $1;
331
 
                $rest =~ s/\Q$1\E\@//;
332
 
            }
333
 
 
334
 
            #Hope that the last argument is the host:
335
 
            if ($rest =~ /\s+(\S+)\s*$/) {
336
 
                $wanna_build_ssh_host = $1;
337
 
                $rest =~ s/\Q$1//;
338
 
            }
339
 
 
340
 
            #rest should be options:
341
 
            if ($rest !~ /\s*/) {
342
 
                $wanna_build_ssh_options = [split $rest];
343
 
            }
344
 
        }
345
 
 
346
 
        if ($sshsocket) {
347
 
            $wanna_build_ssh_socket = $sshsocket;
348
 
        }
349
 
 
350
 
        if ($wanna_build_user) {
351
 
            $wanna_build_db_user = $wanna_build_user;
352
 
        }
353
 
 
354
 
        if ($wanna_build_dbbase) {
355
 
            $wanna_build_db_name = $wanna_build_dbbase;
356
 
        }
357
 
 
358
 
        #Convert old config, if needed:
359
 
        my @distributions_info; 
360
 
        if (@take_from_dists) {
361
 
            for my $dist (@take_from_dists) {
362
 
                my %entry;
363
 
 
364
 
                $entry{DIST_NAME} = $dist;
365
 
                $entry{SSH} = $ssh;
366
 
 
367
 
                if ($dist =~ /security/) {
368
 
                    $entry{DUPLOAD_LOCAL_QUEUE_DIR} = 'upload-security';
369
 
                }
370
 
                if ($build_regex) {
371
 
                    $entry{BUILD_REGEX} = $build_regex;
372
 
                }
373
 
                if ($no_build_regex) {
374
 
                    $entry{NO_BUILD_REGEX} = $build_regex;
375
 
                }
376
 
                if (@no_auto_build) {
377
 
                    $entry{NO_AUTO_BUILD} = \@no_auto_build;
378
 
                }
379
 
                if (@weak_no_auto_build) {
380
 
                    $entry{WEAK_NO_AUTO_BUILD} = \@weak_no_auto_build;
381
 
                }
382
 
 
383
 
                $entry{WANNA_BUILD_DB_NAME} = $wanna_build_db_name;
384
 
                $entry{WANNA_BUILD_DB_USER} = $wanna_build_db_user;
385
 
                $entry{WANNA_BUILD_SSH_HOST} = $wanna_build_ssh_host;
386
 
                $entry{WANNA_BUILD_SSH_USER} = $wanna_build_ssh_user;
387
 
                $entry{WANNA_BUILD_SSH_SOCKET} = $wanna_build_ssh_socket;
388
 
                $entry{WANNA_BUILD_SSH_OPTIONS} = $wanna_build_ssh_options;
389
 
                $entry{WANNA_BUILD_API} = 0;
390
 
 
391
 
                my $dist_config = Buildd::DistConf::new_hash(\%entry);
392
 
 
393
 
                push @distributions_info, $dist_config;
394
 
            }
395
 
        } else {
396
 
            for my $raw_entry (@distributions) {
397
 
                my %entry;
398
 
                my @dist_names;
399
 
 
400
 
                #Find out for which distributions this entry is intended:
401
 
                for my $key (keys %$raw_entry) {
402
 
                    if (uc($key) eq "DIST_NAME") {
403
 
                        if (ref($raw_entry->{$key}) eq "ARRAY") {
404
 
                            push @dist_names, @{$raw_entry->{$key}};
405
 
                        } else {
406
 
                            push @dist_names, $raw_entry->{$key};
407
 
                        }
408
 
                    }
409
 
                }
410
 
 
411
 
                for my $key (keys %$raw_entry) {
412
 
                    if (uc($key) ne "DIST_NAME") {
413
 
                        $entry{uc($key)} = $raw_entry->{$key};
414
 
                    }
415
 
                }
416
 
 
417
 
                for my $key (keys %$defaults) {
418
 
                    if (uc($key) ne "DIST_NAME" && not defined $entry{uc($key)}) {
419
 
                        $entry{uc($key)} = $defaults->{$key};
420
 
                    }
421
 
                }
422
 
 
423
 
                $entry{WANNA_BUILD_API} //= 1;
424
 
 
425
 
 
426
 
                #We need this to pass this to Sbuild::DB::Client:
427
 
                $entry{SSH} = $ssh;
428
 
 
429
 
                #Make one entry per distribution, it's easier later on:
430
 
                for my $dist (@dist_names) {
431
 
                    $entry{'DIST_NAME'} = $dist;
432
 
                    my $dist_config = Buildd::DistConf::new_hash(\%entry);
433
 
                    push @distributions_info, $dist_config;
434
 
                } 
435
 
            }
436
 
        }
437
 
 
438
 
        $conf->set('DISTRIBUTIONS', \@distributions_info);
439
 
 
440
 
        if (@upload_queues) {
441
 
            my @upload_queue_configs;
442
 
            for my $raw_entry (@upload_queues) {
443
 
                my %entry;
444
 
                for my $key (keys %$raw_entry) {
445
 
                    $entry{uc($key)} = $raw_entry->{$key};
446
 
                }
447
 
 
448
 
                my $queue_config = Buildd::UploadQueueConf::new_hash(\%entry);
449
 
 
450
 
                push @upload_queue_configs, $queue_config;
451
 
            }
452
 
            $conf->set('UPLOAD_QUEUES', \@upload_queue_configs);
453
 
        } else {
454
 
            push @{$conf->get('UPLOAD_QUEUES')},
455
 
                Buildd::UploadQueueConf::new_hash(
456
 
                    {
457
 
                        DUPLOAD_LOCAL_QUEUE_DIR => 'upload',
458
 
                        DUPLOAD_ARCHIVE_NAME    => 'anonymous-ftp-master'
459
 
                    }
460
 
                ),
461
 
                Buildd::UploadQueueConf::new_hash(
462
 
                    {
463
 
                        DUPLOAD_LOCAL_QUEUE_DIR => 'upload-security',
464
 
                        DUPLOAD_ARCHIVE_NAME    => 'security'
465
 
                    }
466
 
                );
467
 
        }
468
 
 
469
 
        # Set here to allow user to override.
470
 
        if (-t STDIN && -t STDOUT && $conf->get('NO_DETACH')) {
471
 
            $conf->set('VERBOSE', 1);
472
 
        }
473
593
    }
474
 
 
475
594
}
476
595
 
477
596
1;