OSDN Git Service

[JM:01042] [POST:RO] at at.allow.5
[linuxjm/jm.git] / dist / script / configure.perl
1 #!/usr/bin/perl
2 use Env qw (PATH LANG);
3 use strict 'vars';
4 use Encode qw (decode);
5 use utf8;
6
7 #
8 # %pw は global 変数.
9 #
10 my ($MANROOT, $PACK, $OWNER, $GROUP,
11     @released, %ppage, @pl, $ans);
12
13 my $PKGLIST = "script/pkgs.list";
14 my @pack_method = ("none", "gzip", "bzip2", "compress");
15 my $podsec = "1";
16
17 #
18 # インストール情報
19 #
20 print "[INSTALLATION INFORMATION]\n";
21 print "(just Return if you accept default)\n";
22
23 do{
24     $MANROOT = "/usr/share/man/$LANG";
25     print "   Install directory   [$MANROOT] ?: ";
26     $ans = <STDIN>; chomp $ans;
27     if ($ans ne "") {$MANROOT = $ans;}
28
29     print "   compress manual with..\n";
30     for my $i (0 .. $#pack_method){
31         print "      $i: $pack_method[$i]\n";
32     }
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]}
38
39     $OWNER = "root";
40     print "   uname of page owner [$OWNER] ?: ";
41     $ans = <STDIN>; chomp $ans;
42     if ($ans ne "") {$OWNER = $ans;}
43
44     $GROUP = "root";
45     print "   group of page owner [$GROUP] ?: ";
46     $ans = <STDIN>; chomp $ans;
47     if ($ans ne "") {$GROUP = $ans;}
48
49     print "\n";
50     print "   Directory:    $MANROOT\n";
51     print "   Compression:  $PACK\n";
52     print "   Page uid/gid: $OWNER/$GROUP\n";
53     print "\n";
54     do {
55         print "All OK? (Yes, [C]ontinue / No, [R]eselect) : ";
56         $ans = <STDIN>; chomp $ans;
57     } until ($ans =~ /^[yYnNcCrR]/);
58
59 } until ($ans =~ /^[yYcC]/);
60
61 #
62 # パッケージデータの読み込み (ファイルの先にあるほうが
63 # 後の conflict 解消の時に前の候補になる)。
64 #
65 my $i = 0;
66 open PL, $PKGLIST || die "cannot open $PKGLIST";
67 while(<PL>) {
68     $_ = decode('utf-8', $_);
69     chomp;
70     if (m/^\#/){next;}
71
72     my @l = split /[ \t]+/;
73     push @pl, $l[0];
74     if ($l[1] =~ /Y.*/){
75         $main::pw{$l[0]} = $i;
76     } else {
77         $main::pw{$l[0]} = -1;
78     }
79     ++$i;
80 }
81 close(PL);
82
83 #
84 # インストールするパッケージの選択
85 # インストールしない奴は優先度 $pw{$name} を -1 にする。
86 #
87 print "\n\n";
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";
91
92 do{
93     for $i (0 .. $#pl){
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;}
99     }
100
101     do {
102         print "All OK? (Yes, [C]ontinue / No, [R]eselect) : ";
103         $ans = <STDIN>; chomp $ans;
104     } until ($ans =~ /[yYnNcCrR].*/);
105
106 } until ($ans =~ /^[yYcC]/);
107
108 #
109 # translation_list からインストールすべきファイルを取得.
110 #
111 open TL, "cat `find manual/ -name translation_list -print` |";
112 while(<TL>) {
113     $_ = decode('utf-8', $_);
114     if (/^×/ || /^▲/ || /^△/ || /^●/ || /^※/ || /^$/) { next; }
115     chomp;
116     my @l = split /:/;
117     $l[1] =~ s/ /_/e;
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);
122 }
123 close(TL);
124
125 #
126 # 優先度順ソート.
127 #
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];
132 }
133
134 #
135 # conflict の数 $nc を勘定.
136 #
137 my $nc = 0;
138 foreach my $key (keys %ppage) {
139     if (@{$ppage{$key}} < 2) {next;}
140     $nc++;
141 }
142
143 #
144 # conflict しているファイルからインストールするものを選ぶ.
145 #
146 print "\n\n";
147 print "[RESOLVE CONFLICTS]\n";
148 print "(just Return if you accept item 0)\n";
149
150 do{
151     my $i = 0;
152     foreach my $key (sort keys %ppage) {
153         if (@{$ppage{$key}} < 2) { next; }
154         my $page = $key;
155         $page =~ s/:/./;
156
157         # $cf は最終要素の index.
158         #
159         my $cf = $#{$ppage{$key}};
160         my $nf = $cf + 1;
161
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";
165         }
166         print "   Which to install? (0..$cf) : ";
167
168         $ans = <STDIN>; chomp $ans;
169         if ($ans eq "") {$ans = 0};
170         if ($ans < 0 || $ans > $cf) { $ans = 0 };
171
172         #swap   
173         my $tmp = ${$ppage{$key}}[0];
174         ${$ppage{$key}}[0] = ${$ppage{$key}}[$ans];
175         ${$ppage{$key}}[$ans] = $tmp;
176
177         print "   ${$ppage{$key}}[0]/$key is selected.\n\n";
178         $i++;
179     }
180
181     do {
182         print "All OK? (Yes, [C]ontinue / No, [R]eselect) : ";
183         $ans = <STDIN>; chomp $ans;
184     } until ($ans =~ /^[yYnNcCrR]/);
185
186 } until ($ans =~ /^[yYcC]/);
187
188 #
189 # インストールスクリプトを作る。
190 # インストール先は $MANROOT, 圧縮は $pack.
191 #
192 print "\n\ncreating installation script...";
193 open (ISS, ">installman.sh") || die "cannot create installman.sh\n";
194
195 print ISS "#!/bin/sh\n";
196
197 print ISS "mkdir -p $MANROOT;";
198 print ISS "chown $OWNER.$GROUP $MANROOT\n";
199 for $i (1..9){
200     print ISS "mkdir -p $MANROOT/man$i;";
201     print ISS "chown $OWNER.$GROUP $MANROOT/man$i\n";
202 }
203 print ISS "\n";
204
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";
210
211     print ISS "echo -n install $pkg: $name.$sec .. \n";
212     print ISS "install -o $OWNER -g $GROUP -m 644 $mansrc $mandst\n";
213
214     if ($PACK ne "none"){
215         print ISS "echo -n $PACK .. \n";
216         print ISS "$PACK -f $mandst/$name.$sec\n";
217     }
218
219     print ISS "echo done.\n\n";
220 }
221 close(ISS);
222
223 print "done\n";
224 print "now you can \"make install\" as user $OWNER.\n";
225
226
227 #######################################
228 # sort by pkg, senction and name
229 #
230 sub by_sec_name {
231     my @af = split /:/, $a;
232     my @bf = split /:/, $b;
233
234     ($main::pw{$af[0]} <=> $main::pw{$bf[0]}) ||
235         ($af[2] <=> $bf[2]) || ($af[1] cmp $bf[1]);
236 }
237