File: generate_di_list

package info (click to toggle)
debian-cd 3.1.13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,244 kB
  • sloc: sh: 4,925; perl: 3,730; makefile: 387
file content (107 lines) | stat: -rwxr-xr-x 3,165 bytes parent folder | download
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
101
102
103
104
105
106
107
#!/usr/bin/perl -w
# Generate a list of packages required for debian-installer
# This script makes use of the following variables that need to be preset:
# MIRROR, DI_CODENAME, BASEDIR
die "Missing \$MIRROR variable" unless $ENV{MIRROR};
die "Missing \$DI_CODENAME variable" unless $ENV{DI_CODENAME};
die "Missing \$BASEDIR variable" unless $ENV{BASEDIR};
die "Missing \$ARCHES variable" unless $ENV{ARCHES};

# Early exit if we're building a source-only CD
exit 0 if $ENV{ARCHES} =~ /^\s*source\s*$/;

my @ARCHES;
if ( $ENV{ARCHES} ) {
    push @ARCHES, 'i386' if $ENV{ARCHES} =~ /[^\s]i386[\s\$]/;
    push @ARCHES, 'amd64' if $ENV{ARCHES} =~ /[^\s]amd64[\s\$]/;
    push @ARCHES, grep { !/^(source|i386|amd64)$/ } split /\s+/, $ENV{ARCHES};
}
@ARCHES = qw{i386 amd64} unless @ARCHES;

my @VARIANTS;
if ( $ENV{VARIANTS} ) {
    @VARIANTS = split(" ", $ENV{VARIANTS});
}

my $DATE=`date`;
chomp $DATE;
open(OUT, ">debian-installer") || die "write: $!";
print OUT << "EOF";
/* List of udebs to be included so that debian-installer works fine 
 *
 * This list can be generated with the command:
 * ../tools/generate_di_list
 *
 * DO NOT EDIT THIS FILE, edit the above script
 *
 * Last update: $DATE
 */
EOF

my @common_excludes = read_exclude("exclude-udebs");
my $mirror_path = "$ENV{MIRROR}/dists/$ENV{DI_CODENAME}";
my @components = qw(main);
push @components, 'contrib' if $ENV{CONTRIB};
push @components, 'non-free' if $ENV{NONFREE};
push @components, 'local' if $ENV{LOCAL};

foreach my $arch (@ARCHES) {
	(my $cpparch = $arch) =~ s/-/_/g;
    my $output = '';
    for my $component ( @components ) {
        my $packagefile="$mirror_path/$component/debian-installer/binary-$arch/Packages.gz";
        if ( $component eq 'local' and $ENV{LOCALDEBS} ) {
            $packagefile="$ENV{LOCALDEBS}/dists/$ENV{DI_CODENAME}/local/debian-installer/binary-$arch/Packages.gz";
        }
        if (! -f $packagefile) {
            print "Missing package file for $arch/$component.\n";
            next;
        }

        my @exclude = @common_excludes;
        push @exclude, read_exclude("exclude-udebs-$arch")
            if -e exclude_path("exclude-udebs-$arch");

        foreach my $udeb (map { chomp; $_ } `zcat $packagefile | awk '/^Package:/ {print \$2}'`) {
            $output .= "$udeb\n" unless grep { $udeb =~ /^${_}$/ } @exclude;
        }
    }
    next unless $output;
    print OUT "#ifdef ARCH_$cpparch\n";
    print OUT $output;
    print OUT "#endif /* ARCH_$cpparch */\n";
}

sub read_exclude {
	my $file=exclude_path(shift);
    unless ( open (IN, "<$file") ) {
       warn "failed to read exclude file $file";
       return;
    }
	my @ret;
	while (<IN>) {
		chomp;
		s/^#.*//;
		next unless length;
		my ($pkg,@cond) = split(" ", $_);
		my $skip = 0;
		foreach my $cond ( @cond ) {
		    if ($cond =~ /^!(.*)/) {
			$skip = 1 if grep { $_ eq $1 } @VARIANTS;
		    } else {
			$skip = 1 unless grep { $_ eq $cond } @VARIANTS;
		    }
		}
		next if $skip;
		$pkg=quotemeta($pkg);
		$pkg=~s/\\\*/.*/g;
		push @ret, $pkg;
	}
	close IN;
	return @ret;
}

sub exclude_path {
	my $file=shift;
	return "$ENV{BASEDIR}/data/$ENV{DI_CODENAME}/$file";
}