4
# Author : Manoj Srivastava ( srivasta@tiamat.datasync.com )
5
# Created On : Wed Mar 4 15:11:47 1998
6
# Created On Node : tiamat.datasync.com
7
# Last Modified By : Manoj Srivastava
8
# Last Modified On : Tue May 19 11:25:32 1998
9
# Last Machine Used: tiamat.datasync.com
11
# Status : Unknown, Use with caution!
14
# This file is designed to go into /usr/lib/apt/methods/setup
19
#printf STDERR "DEBUG: Arguments $ARGV[0];$ARGV[1];$ARGV[2];\n";
22
# Handle the arguments
26
my $config_file = '/etc/apt/sources.list';
28
my $boldon=`setterm -bold on`;
29
my $boldoff=`setterm -bold off`;
31
my @known_types = ('deb');
32
my @known_access = ('http', 'ftp', 'file');
33
my @typical_distributions = ('stable', 'unstable', 'frozen', 'non-US');
34
my @typical_components = ('main', 'contrib', 'non-free');
36
my %known_access = map {($_,$_)} @known_access;
37
my %typical_distributions = map {($_,$_)} @typical_distributions;
39
# Read the config file, creating source records
44
die "Required parameter Filename Missing" unless
47
open (CONFIG, "$params{'Filename'}") ||
48
die "Could not open $params{'Filename'}: $!";
52
my ($type, $urn, $distribution, $components) =
53
m/^\s*(\S+)\s+(\S+)\s+(\S+)\s*(?:\s+(\S.*))?$/o;
54
$rec->{'Type'} = $type;
56
$rec->{'Distribution'} = $distribution;
57
$rec->{'Components'} = $components;
65
# write the config file; writing out the current set of source records
71
die "Required parameter Filename Missing" unless
73
die "Required parameter Config Missing" unless
76
open (CONFIG, ">$params{'Filename'}") ||
77
die "Could not open $params{'Filename'} for writing: $!";
78
for $rec (@{$params{'Config'}}) {
79
my $line = "$rec->{'Type'} $rec->{'URN'} $rec->{'Distribution'} ";
80
$line .= "$rec->{'Components'}" if $rec->{'Components'};
82
print CONFIG $line unless $Seen{$line}++;
87
# write the config file; writing out the current set of source records
93
die "Required parameter Config Missing" unless
96
for $rec (@{$params{'Config'}}) {
99
my $line = "$rec->{'Type'} " if $rec->{'Type'};
100
$line .= "$rec->{'URN'} " if $rec->{'URN'};
101
$line .= "$rec->{'Distribution'} " if $rec->{'Distribution'};
102
$line .= "$rec->{'Components'}" if $rec->{'Components'};
104
print $line unless $Seen{$line}++;
108
# Ask for and add a source record
113
my ($type, $urn, $distribution, $components);
115
if ($params{'Default'}) {
116
($type, $urn, $distribution, $components) =
117
$params{'Default'} =~ m/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S.*)$/o;
121
$urn = "http://http.us.debian.org/debian" unless $urn;
122
$distribution = "stable" unless $distribution;
123
$components = "main contrib non-free" unless $components;
126
$rec->{'Type'} = 'deb';
133
print "$boldon URL [$urn]: $boldoff";
137
$answer =~ s/\s*//og;
139
if ($answer =~ /^\s*$/o) {
140
$rec->{'URN'} = $urn;
144
my ($scheme) = $answer =~ /^\s*([^:]+):/o;
145
if (! defined $known_access{$scheme}) {
146
print "Unknown access scheme $scheme in $answer\n";
147
print " The available access methods known to me are\n";
148
print join (' ', @known_access), "\n";
152
$rec->{'URN'} = $answer;
160
print " Please give the distribution tag to get or a path to the\n";
161
print " package file ending in a /. The distribution\n";
162
print " tags are typically something like:$boldon ";
163
print join(' ', @typical_distributions), "$boldoff\n";
165
print "$boldon Distribution [$distribution]:$boldoff ";
168
$answer =~ s/\s*//og;
170
if ($answer =~ /^\s*$/o) {
171
$rec->{'Distribution'} = $distribution;
172
$rec->{'Components'} = &get_components($components);
174
elsif ($answer =~ m|/$|o) {
175
$rec->{'Distribution'} = "$answer";
176
$rec->{'Components'} = "";
179
# A distribution tag, eh?
180
warn "$answer does not seem to be a typical distribution tag\n"
181
unless defined $typical_distributions{$answer};
183
$rec->{'Distribution'} = "$answer";
184
$rec->{'Components'} = &get_components($components);
195
print " Please give the components to get\n";
196
print " The components are typically something like:$boldon ";
197
print join(' ', @typical_components), "$boldoff\n";
199
print "$boldon Components [$default]:$boldoff ";
202
$answer =~ s/\s+/ /og;
204
if ($answer =~ /^\s*$/o) {
218
if (-e $config_file) {
219
@Oldconfig = &read_config('Filename' => $config_file)
222
print "\t$boldon Set up a list of distribution source locations $boldoff \n";
225
print " Please give the base URL of the debian distribution.\n";
226
print " The access schemes I know about are:$boldon ";
227
print join (' ', @known_access), "$boldoff\n";
228
# print " The mirror scheme is special that it does not specify the\n";
229
# print " location of a debian archive but specifies the location\n";
230
# print " of a list of mirrors to use to access the archive.\n";
232
print " For example:\n";
233
print " file:/mnt/debian,\n";
234
print " ftp://ftp.debian.org/debian,\n";
235
print " http://ftp.de.debian.org/debian,\n";
236
# print " and the special mirror scheme,\n";
237
# print " mirror:http://www.debian.org/archivemirrors \n";
242
if ($Oldconfig[$index]) {
243
push (@Config, &get_source('Default' => $Oldconfig[$index++]));
246
push (@Config, &get_source());
249
print "$boldon Would you like to add another source?[y/N]$boldoff ";
250
my $answer = <STDIN>;
252
$answer =~ s/\s+/ /og;
253
if ($answer =~ /^\s*$/o) {
256
elsif ($answer !~ m/\s*y/io) {
265
if (-e $config_file) {
266
my @Oldconfig = &read_config('Filename' => $config_file);
268
print "$boldon I see you already have a source list.$boldoff\n";
269
print "-" x 72, "\n";
270
&print_config('Config' => \@Oldconfig);
271
print "-" x 72, "\n";
272
print "$boldon Do you wish to change (overwrite) it?[y/N]$boldoff ";
273
my $answer = <STDIN>;
275
$answer =~ s/\s+/ /og;
276
exit 0 unless $answer =~ m/\s*y/io;
278
# OK. They want to be here.
279
my @Config = &get_sources();
280
#&print_config('Config' => \@Config);
281
&write_config('Config' => \@Config, 'Filename' => $config_file);