2 use Env qw (PATH LANG);
4 use Encode qw (decode);
10 my ($MANROOT, $PACK, $OWNER, $GROUP,
11 @released, %ppage, @pl, $ans);
13 my $PKGLIST = "script/pkgs.list";
14 my @pack_method = ("none", "gzip", "bzip2", "compress");
20 print "[INSTALLATION INFORMATION]\n";
21 print "(just Return if you accept default)\n";
24 $MANROOT = "/usr/share/man/$LANG";
25 print " Install directory [$MANROOT] ?: ";
26 $ans = <STDIN>; chomp $ans;
27 if ($ans ne "") {$MANROOT = $ans;}
29 print " compress manual with..\n";
30 for my $i (0 .. $#pack_method){
31 print " $i: $pack_method[$i]\n";
33 print " select [0..$#pack_method] : ";
34 $ans = <STDIN>; chomp $ans;
35 if ($ans eq "") {$ans = 0;}
36 if ($ans < 0 || $ans > $#pack_method) {$PACK = $pack_method[0]}
37 else {$PACK = $pack_method[$ans]}
40 print " uname of page owner [$OWNER] ?: ";
41 $ans = <STDIN>; chomp $ans;
42 if ($ans ne "") {$OWNER = $ans;}
45 print " group of page owner [$GROUP] ?: ";
46 $ans = <STDIN>; chomp $ans;
47 if ($ans ne "") {$GROUP = $ans;}
50 print " Directory: $MANROOT\n";
51 print " Compression: $PACK\n";
52 print " Page uid/gid: $OWNER/$GROUP\n";
55 print "All OK? (Yes, [C]ontinue / No, [R]eselect) : ";
56 $ans = <STDIN>; chomp $ans;
57 } until ($ans =~ /^[yYnNcCrR]/);
59 } until ($ans =~ /^[yYcC]/);
62 # パッケージデータの読み込み (ファイルの先にあるほうが
63 # 後の conflict 解消の時に前の候補になる)。
66 open PL, $PKGLIST || die "cannot open $PKGLIST";
68 $_ = decode('utf-8', $_);
72 my @l = split /[ \t]+/;
75 $main::pw{$l[0]} = $i;
77 $main::pw{$l[0]} = -1;
85 # インストールしない奴は優先度 $pw{$name} を -1 にする。
88 print "[INSTALL PACKAGE SELECTION]\n";
89 print "(just Return if you accept default choice)\n";
90 print "(you can change the default by editing script/pkgs.list)\n";
94 my $qstr = ($main::pw{$pl[$i]} > -1) ? "[Y/n]" : "[y/N]";
95 printf " [%2d/%2d] %-15s %s ?: ", $i, $#pl, $pl[$i], $qstr;
96 $ans = <STDIN>; chomp $ans;
97 if ($ans =~ /[Yy].*/) { $main::pw{$pl[$i]} = $i;}
98 if ($ans =~ /[Nn].*/) { $main::pw{$pl[$i]} = -1;}
102 print "All OK? (Yes, [C]ontinue / No, [R]eselect) : ";
103 $ans = <STDIN>; chomp $ans;
104 } until ($ans =~ /[yYnNcCrR].*/);
106 } until ($ans =~ /^[yYcC]/);
109 # translation_list からインストールすべきファイルを取得.
111 open TL, "cat `find manual/ -name translation_list -print` |";
113 $_ = decode('utf-8', $_);
114 if (/^×/ || /^▲/ || /^△/ || /^●/ || /^※/ || /^$/) { next; }
118 if ($main::pw{$l[1]} == -1) {next;}
119 (my $sec, my $osec) = split /=>/, $l[5];
120 if ($sec eq "pod"){$sec = $podsec;}
121 push @released, join(":", $l[1], $l[4], $sec);
128 @released = sort by_sec_name @released;
129 for $i (0 .. $#released){
130 my @l = split /:/, $released[$i];
131 push @{ $ppage{"$l[1]:$l[2]"} }, $l[0];
135 # conflict の数 $nc を勘定.
138 foreach my $key (keys %ppage) {
139 if (@{$ppage{$key}} < 2) {next;}
144 # conflict しているファイルからインストールするものを選ぶ.
147 print "[RESOLVE CONFLICTS]\n";
148 print "(just Return if you accept item 0)\n";
152 foreach my $key (sort keys %ppage) {
153 if (@{$ppage{$key}} < 2) { next; }
159 my $cf = $#{$ppage{$key}};
162 print " [$i/$nc] There are $nf pages for $page:\n";
163 for my $j (0 .. $cf){
164 print " $j: in ${$ppage{$key}}[$j]\n";
166 print " Which to install? (0..$cf) : ";
168 $ans = <STDIN>; chomp $ans;
169 if ($ans eq "") {$ans = 0};
170 if ($ans < 0 || $ans > $cf) { $ans = 0 };
173 my $tmp = ${$ppage{$key}}[0];
174 ${$ppage{$key}}[0] = ${$ppage{$key}}[$ans];
175 ${$ppage{$key}}[$ans] = $tmp;
177 print " ${$ppage{$key}}[0]/$key is selected.\n\n";
182 print "All OK? (Yes, [C]ontinue / No, [R]eselect) : ";
183 $ans = <STDIN>; chomp $ans;
184 } until ($ans =~ /^[yYnNcCrR]/);
186 } until ($ans =~ /^[yYcC]/);
190 # インストール先は $MANROOT, 圧縮は $pack.
192 print "\n\ncreating installation script...";
193 open (ISS, ">installman.sh") || die "cannot create installman.sh\n";
195 print ISS "#!/bin/sh\n";
197 print ISS "mkdir -p $MANROOT;";
198 print ISS "chown $OWNER.$GROUP $MANROOT\n";
200 print ISS "mkdir -p $MANROOT/man$i;";
201 print ISS "chown $OWNER.$GROUP $MANROOT/man$i\n";
205 foreach my $key (sort keys %ppage) {
206 (my $name, my $sec) = split /:/, $key;
207 my $pkg = ${$ppage{$key}}[0];
208 my $mansrc = "manual/$pkg/man$sec/$name.$sec";
209 my $mandst = "$MANROOT/man$sec";
211 print ISS "echo -n install $pkg: $name.$sec .. \n";
212 print ISS "install -o $OWNER -g $GROUP -m 644 $mansrc $mandst\n";
214 if ($PACK ne "none"){
215 print ISS "echo -n $PACK .. \n";
216 print ISS "$PACK -f $mandst/$name.$sec\n";
219 print ISS "echo done.\n\n";
224 print "now you can \"make install\" as user $OWNER.\n";
227 #######################################
228 # sort by pkg, senction and name
231 my @af = split /:/, $a;
232 my @bf = split /:/, $b;
234 ($main::pw{$af[0]} <=> $main::pw{$bf[0]}) ||
235 ($af[2] <=> $bf[2]) || ($af[1] cmp $bf[1]);