first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[kai/samba.git] / packaging / SGI / idb.pl
1 #!/usr/bin/perl
2 require "pwd.pl" || die "Required pwd.pl not found";
3
4 # This perl script automatically generates the samba.idb file
5
6 &initpwd;
7 $curdir = $ENV{"PWD"};
8
9 # We don't want the files listed in .cvsignore in the source tree
10 open(IGNORES,"../../source/.cvsignore") || die "Unable to open .cvsignore file\n";
11 while (<IGNORES>) {
12   chop;
13   next if /cvs\.log/;
14   $ignores{$_}++;
15 }
16 close IGNORES;
17
18 # We don't want the files listed in .cvsignore in the source/include tree
19 open(IGNORES,"../../source/include/.cvsignore") || die "Unable to open include/.cvsignore file\n";
20 while (<IGNORES>) {
21   chop;
22   $ignores{$_}++;
23 }
24 close IGNORES;
25
26 # get the names of all the binary files to be installed
27 open(MAKEFILE,"../../source/Makefile") || die "Unable to open Makefile\n";
28 @makefile = <MAKEFILE>;
29 @sprogs = grep(/^SPROGS /,@makefile);
30 @progs1 = grep(/^PROGS1 /,@makefile);
31 @progs2 = grep(/^PROGS2 /,@makefile);
32 @mprogs = grep(/^MPROGS /,@makefile);
33 @progs = grep(/^PROGS /,@makefile);
34 @scripts = grep(/^SCRIPTS /,@makefile);
35 @codepage = grep(/^CODEPAGELIST/,@makefile);
36 close MAKEFILE;
37
38 if (@sprogs) {
39   @sprogs[0] =~ s/^.*\=//;
40   @sprogs = split(' ',@sprogs[0]);
41 }
42 if (@progs) {
43   @progs[0] =~ s/^.*\=//;
44   @progs[0] =~ s/\$\(\S+\)\s//g;
45   @progs = split(' ',@progs[0]);
46 }
47 if (@mprogs) {
48   @mprogs[0] =~ s/^.*\=//;
49   @mprogs = split(' ',@mprogs[0]);
50 }
51 if (@progs1) {
52   @progs1[0] =~ s/^.*\=//;
53   @progs1 = split(' ',@progs1[0]);
54 }
55 if (@progs2) {
56   @progs2[0] =~ s/^.*\=//;
57   @progs2 = split(' ',@progs2[0]);
58 }
59 if (@scripts) {
60   @scripts[0] =~ s/^.*\=//;
61   @scripts[0] =~ s/\$\(srcdir\)\///g;
62   @scripts = split(' ',@scripts[0]);
63 }
64 if (@codepage) {
65   @codepage[0] =~ s/^.*\=//;
66   chdir '../../source';
67   # if we have codepages we need to create them for the package
68   system("chmod +x ./script/installcp.sh");
69   system("./script/installcp.sh . . ../packaging/SGI/codepages ./bin @codepage[0]");
70   chdir $curdir;
71   @codepage = sort split(' ',@codepage[0]);
72 }
73 # install the swat files
74 chdir '../../source';
75 system("chmod +x ./script/installswat.sh");
76 system("./script/installswat.sh  ../packaging/SGI/swat ./");
77 system("cp ../swat/README ../packaging/SGI/swat");
78 chdir $curdir;
79
80 # add my local files to the list of binaries to install
81 @bins = sort byfilename (@sprogs,@progs,@progs1,@progs2,@mprogs,@scripts,("/findsmb","/sambalp","/smbprint"));
82
83 # get a complete list of all files in the tree
84 chdir '../../';
85 &dodir('.');
86 chdir $curdir;
87
88 # the files installed in docs include all the original files in docs plus all
89 # the "*.doc" files from the source tree
90 @docs = sort byfilename grep (!/^docs\/$/ & (/^source\/.*\.doc$/ | /^docs\//),@allfiles);
91
92 @swatfiles = sort grep(/^packaging\/SGI\/swat/, @allfiles);
93 @catman = sort grep(/^packaging\/SGI\/catman/ & !/\/$/, @allfiles);
94 @catman = sort bydirnum @catman;
95
96 # strip out all the generated directories and the "*.o" files from the source
97 # release
98 @allfiles = grep(!/^.*\.o$/ & !/^.*\.po$/ & !/^.*\.po32$/ & !/^source\/bin/ & !/^packaging\/SGI\/bins/ & !/^packaging\/SGI\/catman/ & !/^packaging\/SGI\/html/ & !/^packaging\/SGI\/codepages/ & !/^packaging\/SGI\/swat/, @allfiles);
99
100 open(IDB,">samba.idb") || die "Unable to open samba.idb for output\n";
101
102 print IDB "f 0644 root sys etc/config/samba packaging/SGI/samba.config samba.sw.base config(update)\n";
103 print IDB "f 0755 root sys etc/init.d/samba packaging/SGI/samba.rc samba.sw.base\n";
104 print IDB "l 0000 root sys etc/rc0.d/K39samba packaging/SGI samba.sw.base symval(../init.d/samba)\n";
105 print IDB "l 0000 root sys etc/rc2.d/S81samba packaging/SGI samba.sw.base symval(../init.d/samba)\n";
106
107 @copyfile = grep (/^COPY/,@allfiles);
108 print IDB "d 0755 root sys usr/relnotes/samba packaging/SGI samba.man.relnotes\n";
109 print IDB "f 0644 root sys usr/relnotes/samba/@copyfile[0] @copyfile[0] samba.man.relnotes\n";
110 print IDB "f 0644 root sys usr/relnotes/samba/legal_notice.html packaging/SGI/legal_notice.html samba.man.relnotes\n";
111 print IDB "f 0644 root sys usr/relnotes/samba/samba-relnotes.html packaging/SGI/relnotes.html samba.man.relnotes\n";
112
113 print IDB "d 0755 root sys usr/samba packaging/SGI samba.sw.base\n";
114 print IDB "f 0444 root sys usr/samba/README packaging/SGI/README samba.sw.base\n";
115
116 print IDB "d 0755 root sys usr/samba/bin packaging/SGI samba.sw.base\n";
117 while(@bins) {
118   $nextfile = shift @bins;
119   ($filename = $nextfile) =~ s/^.*\///;;
120
121   if (index($nextfile,'$')) {
122     if ($filename eq "smbpasswd") {
123       print IDB "f 0755 root sys usr/samba/bin/$filename source/$nextfile samba.sw.base nostrip\n";
124     }
125     elsif ($filename eq "findsmb") {
126       print IDB "f 0755 root sys usr/samba/bin/$filename packaging/SGI/$filename samba.sw.base\n";
127     }
128     elsif ($filename eq "swat") {
129       print IDB "f 4755 root sys usr/samba/bin/$filename source/$nextfile samba.sw.base nostrip preop(\"chroot \$rbase /etc/init.d/samba stop\") exitop(\"chroot \$rbase /usr/samba/scripts/startswat.sh\") removeop(\"chroot \$rbase /sbin/cp /etc/inetd.conf /etc/inetd.conf.O ; chroot \$rbase /sbin/sed -e '/^swat/D' -e '/^#SWAT/D' /etc/inetd.conf.O >/etc/inetd.conf; /etc/killall -HUP inetd || true\")\n";
130     }
131     elsif ($filename eq "sambalp") {
132       print IDB "f 0755 root sys usr/samba/bin/$filename packaging/SGI/$filename samba.sw.base nostrip\n";
133     }
134     elsif ($filename eq "smbprint") {
135       print IDB "f 0755 root sys usr/samba/bin/$filename packaging/SGI/$filename samba.sw.base\n";
136     }
137     else {
138       print IDB "f 0755 root sys usr/samba/bin/$filename source/$nextfile samba.sw.base nostrip\n";
139     }
140   }
141 }
142
143 print IDB "d 0755 root sys usr/samba/docs docs samba.man.doc\n";
144 while (@docs) {
145   $nextfile = shift @docs;
146   next if ($nextfile eq "CVS");
147   ($junk,$file) = split(/\//,$nextfile,2);
148   if (grep(/\/$/,$nextfile)) {
149     $file =~ s/\/$//;
150     $nextfile =~ s/\/$//;
151     print IDB "d 0755 root sys usr/samba/docs/$file $nextfile samba.man.doc\n";
152   }
153   else {
154     print IDB "f 0644 root sys usr/samba/docs/$file $nextfile samba.man.doc\n";
155   }
156 }
157
158 print IDB "d 0755 root sys usr/samba/lib packaging/SGI samba.sw.base\n";
159 if (@codepage) {
160   print IDB "d 0755 root sys usr/samba/lib/codepages packaging/SGI samba.sw.base\n";
161   while (@codepage) {
162     $nextpage = shift @codepage;
163     print IDB "f 0644 root sys usr/samba/lib/codepages/codepage.$nextpage packaging/SGI/codepages/codepage.$nextpage samba.sw.base\n";
164   }
165 }
166 print IDB "f 0644 root sys usr/samba/lib/smb.conf packaging/SGI/smb.conf samba.sw.base config(suggest)\n";
167
168 print IDB "d 0644 root sys usr/samba/private packaging/SGI samba.sw.base\n";
169 print IDB "f 0600 root sys usr/samba/private/smbpasswd packaging/SGI/smbpasswd samba.sw.base config(suggest)\n";
170
171 print IDB "d 0755 root sys usr/samba/scripts packaging/SGI samba.src.samba\n";
172 print IDB "f 0755 root sys usr/samba/scripts/inetd.sh packaging/SGI/inetd.sh samba.sw.base\n";
173 print IDB "f 0755 root sys usr/samba/scripts/inst.msg packaging/SGI/inst.msg samba.sw.base exitop(\"chroot \$rbase /usr/samba/scripts/inst.msg\")\n";
174 print IDB "f 0755 root sys usr/samba/scripts/mkprintcap.sh packaging/SGI/mkprintcap.sh samba.sw.base\n";
175 print IDB "f 0755 root sys usr/samba/scripts/removeswat.sh packaging/SGI/removeswat.sh samba.sw.base\n";
176 print IDB "f 0755 root sys usr/samba/scripts/startswat.sh packaging/SGI/startswat.sh samba.sw.base\n";
177
178 print IDB "d 0755 root sys usr/samba/src packaging/SGI samba.src.samba\n";
179 @sorted = sort(@allfiles);
180 while (@sorted) {
181   $nextfile = shift @sorted;
182   ($file = $nextfile) =~ s/^.*\///;
183   next if grep(/packaging\/SGI/& (/Makefile/ | /samba\.spec/ | /samba\.idb/),$nextfile);
184   next if grep(/source/,$nextfile) && ($ignores{$file});
185   next if ($nextfile eq "CVS");
186   if (grep(/\/$/,$nextfile)) {
187     $nextfile =~ s/\/$//;
188     print IDB "d 0755 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
189   }
190   else {
191     if (grep((/\.sh$/ | /configure$/ | /configure\.developer/ | /config\.guess/ | /config\.sub/ | /\.pl$/ | /mkman$/),$nextfile)) {
192         print IDB "f 0755 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
193     }
194     else {
195         print IDB "f 0644 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
196     }
197   }
198 }
199
200 print IDB "d 0755 root sys usr/samba/swat packaging/SGI/swat samba.sw.base\n";
201 while (@swatfiles) {
202   $nextfile = shift @swatfiles;
203   ($file = $nextfile) =~ s/^packaging\/SGI\/swat\///;
204   next if !$file;
205   if (grep(/\/$/,$file)) {
206     $file =~ s/\/$//;
207     print IDB "d 0755 root sys usr/samba/swat/$file packaging/SGI/swat/$file samba.sw.base\n";
208   }
209   else {
210     print IDB "f 0444 root sys usr/samba/swat/$file packaging/SGI/swat/$file samba.sw.base\n";
211   }
212 }
213
214 print IDB "d 0755 root sys usr/samba/var packaging/SGI samba.sw.base\n";
215 print IDB "d 0755 root sys usr/samba/var/locks packaging/SGI samba.sw.base\n";
216 print IDB "f 0644 root sys usr/samba/var/locks/STATUS..LCK packaging/SGI/STATUS..LCK samba.sw.base\n";
217
218 print IDB "d 0755 root sys usr/share/catman/u_man packaging/SGI samba.man.manpages\n";
219 $olddirnum = "0";
220 while (@catman) {
221   $nextfile = shift @catman;
222   ($file = $nextfile) =~ s/^packaging\/SGI\/catman\///;
223   ($dirnum = $file) =~ s/^[\D]*//;
224   $dirnum =~ s/\.z//;
225   if ($dirnum ne $olddirnum) {
226     print IDB "d 0755 root sys usr/share/catman/u_man/cat$dirnum packaging/SGI samba.man.manpages\n";
227     $olddirnum = $dirnum;
228   }
229   print IDB "f 0664 root sys usr/share/catman/u_man/cat$dirnum/$file $nextfile samba.man.manpages\n";
230 }
231
232 close IDB;
233 print "\n\nsamba.idb file has been created\n";
234
235 sub dodir {
236     local($dir, $nlink) = @_;
237     local($dev,$ino,$mode,$subcount);
238
239     ($dev,$ino,$mode,$nlink) = stat('.') unless $nlink;
240
241     opendir(DIR,'.') || die "Can't open $dir";
242     local(@filenames) = sort readdir(DIR);
243     closedir(DIR);
244
245     if ($nlink ==2) {           # This dir has no subdirectories.
246         for (@filenames) {
247             next if $_ eq '.';
248             next if $_ eq '..';
249             $this =  substr($dir,2)."/$_";
250             push(@allfiles,$this);
251         }
252     }
253     else {
254         $subcount = $nlink -2;
255         for (@filenames) {
256             next if $_ eq '.';
257             next if $_ eq '..';
258             next if $_ eq 'CVS';
259             ($dev,$ino,$mode,$nlink) = lstat($_);
260             $name = "$dir/$_";
261             $this = substr($name,2);
262             $this .= '/' if -d;
263             push(@allfiles,$this);
264             next if $subcount == 0;             # seen all the subdirs?
265
266             next unless -d _;
267
268             chdir $_ || die "Can't cd to $name";
269             &dodir($name,$nlink);
270             chdir '..';
271             --$subcount;
272         }
273     }
274 }
275
276 sub byfilename {
277   ($f0,$f1) = split(/\//,$a,2);
278   ($f0,$f2) = split(/\//,$b,2);
279   $f1 cmp $f2;
280 }
281
282 sub bydirnum {
283   ($f1 = $a) =~ s/^.*\///;
284   ($f2 = $b) =~ s/^.*\///;
285   ($dir1 = $a) =~ s/^[\D]*//;
286   ($dir2 = $b) =~ s/^[\D]*//;
287   if (!($dir1 <=> $dir2)) {
288     $f1 cmp $f2;
289   }
290   else {
291     $dir1 <=> $dir2;
292   }
293 }