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
|
#!/usr/bin/perl -w
# just a little hack to install the man pages in the right directories,
# replacing VERSION with the right version...
use strict;
my @manpages = ("adduser", "adduser.conf", "deluser", "deluser.conf");
my $links;
@{$links->{"adduser"}} = ("addgroup");
@{$links->{"deluser"}} = ("delgroup");
my $version = shift || "VERSION";
my $origdir = shift || "./";
$origdir .= "/" unless($origdir =~ /\/$/);
my $mandir = shift || "/usr/share/man/";
$mandir .= "/" unless($mandir =~ /\/$/);
opendir(DIR, $origdir);
my $file;
foreach $file (readdir(DIR)) {
next unless(-f $origdir.$file);
my($language, $page, $section);
foreach(@manpages) {
if($file =~ /^$_\.[1-8]/) {
$page = $_;
last;
}
}
next unless($page); # this file is not a manpage
next unless ($section = $file) =~ s/^$page\.([1-8]).*/$1/;
($language = $file) =~ s/^$page\.$section\.?//;
my ($destfile, $destdir);
if($language) {
$destdir = $mandir.$language."/man".$section;
$destfile = $destdir."/".$page.".".$section;
my $relfile = $page.".".$section.".gz";
if (not -d $destdir) {
mkdirs($destdir);
}
foreach(@{$links->{$page}}) {
my $linkfile = $mandir.$language."/man".$section."/".$_.".".$section.".gz";
printf("Creating symlink from %s to %s...\n", $destfile, $linkfile);
symlink($relfile, $linkfile);
}
} else {
$destdir = $mandir."/man".$section;
$destfile = $destdir."/".$page.".".$section;
my $relfile = $page.".".$section.".gz";
if (not -d $destdir) {
mkdirs($destdir);
}
foreach(@{$links->{$page}}) {
my $linkfile = $mandir."man".$section."/".$_.".".$section.".gz";
printf("Creating symlink from %s to %s...\n", $destfile, $linkfile);
symlink($relfile, $linkfile);
}
}
printf("Installing manpage %s%s in %s...\n", $page, $language ? "(".$language.")" : "", $destfile);
open(IN, "<$origdir$file");
open(OUT, ">$destfile") or die "can't open $destfile: $!\n";
while(<IN>) {
$_ =~ s/VERSION/$version/g;
print OUT $_;
}
close(IN);
close(OUT);
printf("Compressing and setting permissions for %s...\n", $destfile);
system("/bin/gzip", "-9n", $destfile);
chmod(0644, $destfile.".gz");
}
closedir(DIR);
sub mkdirs {
my (@dirs) = @_;
system('install', '-o', 'root', '-g', 'root', '-d', '-m0755', '--', @dirs) == 0
or die("exec install -d @dirs failed");
}
|