make_links.pl 1.34 KB
Newer Older
James A. Treacy's avatar
James A. Treacy committed
1 2
#!/usr/bin/perl -w

3 4 5 6
# This script creates any missing soft links in the Debian html directory
# on master. These links are necessary so that under content negotiation
# there is a default language. For every <file>.en.html there needs to be
# a <file>.html -> <file>.en.html
James A. Treacy's avatar
James A. Treacy committed
7

8 9 10
# Translators shouldn't have any need of this.
# Makefiles in webwml/english/ have already been set up to create these
# links while installing files, so there should be no need to run this.
James A. Treacy's avatar
James A. Treacy committed
11 12 13 14 15 16 17 18 19

$top_dir = "/debian2/web/debian.org";

check_directory($top_dir);

sub check_directory() {
	my ($curdir) = @_;
	my (@dir_list, @fil_list, @parts, $lang, $html, $name);

James A. Treacy's avatar
James A. Treacy committed
20
	print "$curdir\n";
James A. Treacy's avatar
James A. Treacy committed
21
	opendir(DIR, $curdir) or die "can't opendir $curdir: $!";
James A. Treacy's avatar
James A. Treacy committed
22 23 24
	@dir_list = grep { -d "$curdir/$_" and $_ !~ /^..?$/ and ! -l "$curdir/$_" and
			$_ ne "gnome" and $_ ne "OpenHardware" and $_ ne "OpenSource" and
			$_ ne "berlin"} readdir(DIR);
James A. Treacy's avatar
James A. Treacy committed
25 26 27 28 29 30 31 32
	rewinddir DIR;
	@fil_list = grep { -f "$curdir/$_" } readdir(DIR);
	foreach (@dir_list) {
		check_directory("$curdir/$_");
	}
	foreach $file (@fil_list) {
		@parts = split('\.', $file);
		$html = pop @parts;
33
		$lang = pop @parts;
James A. Treacy's avatar
James A. Treacy committed
34 35 36
		$name = join('.', @parts);
		if (defined($html) and $lang =~ /^en$/ and $html eq "html") {
			if ( ! -e "$curdir/$name.html") {
James A. Treacy's avatar
James A. Treacy committed
37
				print "  creating symlink to $curdir/$file\n";
38
				symlink("$file", "$curdir/$name.html");
James A. Treacy's avatar
James A. Treacy committed
39 40 41 42
			}
		}
	}
}