2383ff5b8d62a3ac07cf3ef0999f1e9234e36118
[gd/samba-autobuild/.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 idb file
5
6 $PKG = 'samba';
7 $SRCDIR = '../..';
8 $SRCPFX = '.';
9
10 &initpwd;
11 $curdir = $ENV{"PWD"};
12
13 if ($PKG eq "samba_irix") {
14   open(BOOKS,"IDB.books") || die "Unable to open IDB.books file\n";
15   @books = sort idbsort <BOOKS>;
16   close BOOKS;
17 }
18
19 # We don't want the files listed in .cvsignore in the source tree
20 open(IGNORES,"$SRCDIR/source/.cvsignore") || die "Unable to open .cvsignore file\n";
21 while (<IGNORES>) {
22   chop;
23   next if /cvs\.log/;
24   $ignores{$_}++;
25 }
26 close IGNORES;
27
28 # We don't want the files listed in .cvsignore in the source/include tree
29 open(IGNORES,"$SRCDIR/source/include/.cvsignore") || die "Unable to open include/.cvsignore file\n";
30 while (<IGNORES>) {
31   chop;
32   $ignores{$_}++;
33 }
34 close IGNORES;
35
36 # get the names of all the binary files to be installed
37 open(MAKEFILE,"$SRCDIR/source/Makefile") || die "Unable to open Makefile\n";
38 while (not eof(MAKEFILE)) {
39   $_ = <MAKEFILE>;
40   chomp;
41   last if /^# object file lists/ ;
42   if (/^srcdir/) {
43     /^.*=(.*)/;
44     $srcdir = $1;
45   }
46   if (/^builddir/) {
47     /^.*=(.*)/;
48     $builddir = $1;
49   }
50   if (/^SBIN_PROGS/) { @sbinprogs = get_line($_); }
51   if (/^BIN_PROGS1/) { @binprogs1 = get_line($_); }
52   if (/^BIN_PROGS2/) { @binprogs2 = get_line($_); }
53   if (/^BIN_PROGS3/) { @binprogs3 = get_line($_); }
54   if (/^BIN_PROGS/) { @binprogs = get_line($_); }
55   if (/^SCRIPTS/) { @scripts = get_line($_); }
56   if (/^TORTURE_PROGS/) { @tortureprogs = get_line($_); }
57   if (/^SHLIBS/) { @shlibs = get_line($_); }
58 }
59 close MAKEFILE;
60
61 # add my local files to the list of binaries to install
62 @bins = sort byfilename (@sbinprogs,@binprogs,@binprogs1,@binprogs2,@binprogs3,@scripts,("sambalp","smbprint"));
63
64 @nsswitch = sort byfilename (@shlibs);
65
66 # install the swat files
67 chdir "$SRCDIR/source";
68 system("chmod +x ./script/installswat.sh");
69 system("./script/installswat.sh  ../packaging/SGI/swat ./ ../packaging/SGI/swat/using_samba");
70 system("cp -f ../swat/README ../packaging/SGI/swat");
71 chdir $curdir;
72
73 # get a complete list of all files in the tree
74 chdir "$SRCDIR/";
75 &dodir('.');
76 chdir $curdir;
77
78 # the files installed in docs include all the original files in docs plus all
79 # the "*.doc" files from the source tree
80 @docs = sort bynextdir grep (!/CVS/ & (/^source\/.*\.doc$/ | /^docs\/\w/),@allfiles);
81 @docs = grep(!/htmldocs/ & !/manpages/, @docs);
82 @docs = grep(!/docbook/, @docs);
83
84 @libfiles = sort byfilename (grep (/^source\/codepages\/\w/,@allfiles),("packaging/SGI/smb.conf","source/bin/libsmbclient.a","source/bin/libsmbclient.so"));
85
86 @swatfiles = sort grep(/^packaging\/SGI\/swat/, @allfiles);
87 @catman = sort grep(/^packaging\/SGI\/catman/ & !/\/$/, @allfiles);
88 @catman = sort bydirnum @catman;
89
90 # strip out all the generated directories and the "*.o" files from the source
91 # release
92 @allfiles = grep(!/^.*\.o$/ & !/^.*\.po$/ & !/^.*\.po32$/ & !/^.*\.so$/ & !/^source\/bin/ & !/^packaging\/SGI\/bins/ & !/^packaging\/SGI\/catman/ & !/^packaging\/SGI\/html/ & !/^packaging\/SGI\/codepages/ & !/^packaging\/SGI\/swat/, @allfiles);
93
94 open(IDB,"> $curdir/$PKG.idb") || die "Unable to open $PKG.idb for output\n";
95
96 print IDB "f 0644 root sys etc/config/samba $SRCPFX/packaging/SGI/samba.config $PKG.sw.base config(update)\n";
97 print IDB "f 0644 root sys etc/config/winbind $SRCPFX/packaging/SGI/winbindd.config $PKG.sw.base config(update)\n";
98 print IDB "f 0755 root sys etc/init.d/samba $SRCPFX/packaging/SGI/samba.rc $PKG.sw.base\n";
99 print IDB "f 0755 root sys etc/init.d/winbind $SRCPFX/packaging/SGI/winbindd.rc $PKG.sw.base\n";
100 print IDB "l 0000 root sys etc/rc0.d/K36winbind $SRCPFX/packaging/SGI $PKG.sw.base symval(../init.d/winbind)\n";
101 print IDB "l 0000 root sys etc/rc0.d/K37samba $SRCPFX/packaging/SGI $PKG.sw.base symval(../init.d/samba)\n";
102 print IDB "l 0000 root sys etc/rc2.d/S81samba $SRCPFX/packaging/SGI $PKG.sw.base symval(../init.d/samba)\n";
103 print IDB "l 0000 root sys etc/rc2.d/S82winbind $SRCPFX/packaging/SGI $PKG.sw.base symval(../init.d/winbind)\n";
104
105 if ($PKG eq "samba_irix") {
106   print IDB "d 0755 root sys usr/relnotes/samba_irix $SRCPFX/packaging/SGI $PKG.man.relnotes\n";
107   print IDB "f 0644 root sys usr/relnotes/samba_irix/TC relnotes/TC $PKG.man.relnotes\n";
108   print IDB "f 0644 root sys usr/relnotes/samba_irix/ch1.z relnotes/ch1.z $PKG.man.relnotes\n";
109   print IDB "f 0644 root sys usr/relnotes/samba_irix/ch2.z relnotes/ch2.z $PKG.man.relnotes\n";
110   print IDB "f 0644 root sys usr/relnotes/samba_irix/ch3.z relnotes/ch3.z $PKG.man.relnotes\n";
111 }
112 else {
113   @copyfile = grep (/^COPY/,@allfiles);
114   print IDB "d 0755 root sys usr/relnotes/samba $SRCPFX/packaging/SGI $PKG.man.relnotes\n";
115   print IDB "f 0644 root sys usr/relnotes/samba/@copyfile[0] $SRCPFX/@copyfile[0] $PKG.man.relnotes\n";
116   print IDB "f 0644 root sys usr/relnotes/samba/legal_notice.html $SRCPFX/packaging/SGI/legal_notice.html $PKG.man.relnotes\n";
117   print IDB "f 0644 root sys usr/relnotes/samba/samba-relnotes.html $SRCPFX/packaging/SGI/relnotes.html $PKG.man.relnotes\n";
118 }
119
120 print IDB "d 0755 root sys usr/samba $SRCPFX/packaging/SGI $PKG.sw.base\n";
121
122 print IDB "d 0755 root sys usr/samba/bin $SRCPFX/packaging/SGI $PKG.sw.base\n";
123 while(@bins) {
124   $nextfile = shift @bins;
125   ($filename = $nextfile) =~ s/^.*\///;;
126
127   if (index($nextfile,'$')) {
128     if ($filename eq "smbpasswd") {
129       print IDB "f 0755 root sys usr/samba/bin/$filename $SRCPFX/source/$nextfile $PKG.sw.base \n";
130     }
131     elsif ($filename eq "swat") {
132       print IDB "f 4755 root sys usr/samba/bin/$filename $SRCPFX/source/$nextfile $PKG.sw.base 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";
133     }
134     elsif ($filename eq "sambalp") {
135       print IDB "f 0755 root sys usr/samba/bin/$filename $SRCPFX/packaging/SGI/$filename $PKG.sw.base \n";
136     }
137     elsif ($filename eq "smbprint") {
138       print IDB "f 0755 root sys usr/samba/bin/$filename $SRCPFX/packaging/SGI/$filename $PKG.sw.base\n";
139     }
140     elsif ($filename eq "smbd") {
141       print IDB "f 0755 root sys usr/samba/bin/$filename $SRCPFX/source/$nextfile $PKG.sw.base \n";
142       if (-e "$SRCDIR/source/$nextfile.noquota") {
143         print IDB "f 0755 root sys usr/samba/bin/$filename.noquota $SRCPFX/source/$nextfile.noquota $PKG.sw.base \n";
144       }
145       if (-e "$SRCDIR/source/$nextfile.profile") {
146         print IDB "f 0755 root sys usr/samba/bin/$filename.profile $SRCPFX/source/$nextfile.profile $PKG.sw.base \n";
147       }
148     }
149     elsif ($filename eq "nmbd") {
150       print IDB "f 0755 root sys usr/samba/bin/$filename $SRCPFX/source/$nextfile $PKG.sw.base \n";
151       if (-e "$SRCDIR/source/$nextfile.profile") {
152         print IDB "f 0755 root sys usr/samba/bin/$filename.profile $SRCPFX/source/$nextfile.profile $PKG.sw.base \n";
153       }
154     }
155     else {
156       print IDB "f 0755 root sys usr/samba/bin/$filename $SRCPFX/source/$nextfile $PKG.sw.base \n";
157     }
158   }
159 }
160
161 print IDB "d 0755 root sys usr/samba/docs $SRCPFX/docs $PKG.man.doc\n";
162 while (@docs) {
163   $nextfile = shift @docs;
164   ($junk,$file) = split(/\//,$nextfile,2);
165   if (grep(/\/$/,$nextfile)) {
166     $file =~ s/\/$//;
167     $nextfile =~ s/\/$//;
168     print IDB "d 0755 root sys usr/samba/docs/$file $SRCPFX/$nextfile $PKG.man.doc\n";
169   }
170   else {
171     print IDB "f 0644 root sys usr/samba/docs/$file $SRCPFX/$nextfile $PKG.man.doc\n";
172   }
173 }
174
175 print IDB "d 0755 root sys usr/samba/include $SRCPFX/packaging/SGI $PKG.sw.base\n";
176 print IDB "f 0644 root sys usr/samba/include/libsmbclient.h $SRCPFX/source/include/libsmbclient.h $PKG.sw.base\n";
177
178 print IDB "d 0755 root sys usr/samba/lib $SRCPFX/packaging/SGI $PKG.sw.base\n";
179 while (@libfiles) {
180   $nextfile = shift @libfiles;
181   ($file = $nextfile) =~ s/.*\///;
182   if ($file eq "smb.conf") {
183     print IDB "f 0644 root sys usr/samba/lib/$file $SRCPFX/$nextfile $PKG.sw.base config(suggest)\n";
184   } else {
185     print IDB "f 0644 root sys usr/samba/lib/$file $SRCPFX/$nextfile $PKG.sw.base nostrip \n";
186   }
187 }
188
189 print IDB "d 0755 lp sys usr/samba/printer $SRCPFX/packaging/SGI $PKG.sw.base\n";
190 print IDB "d 0755 lp sys usr/samba/printer/W32ALPHA $SRCPFX/packaging/SGI $PKG.sw.base\n";
191 print IDB "d 0755 lp sys usr/samba/printer/W32MIPS $SRCPFX/packaging/SGI $PKG.sw.base\n";
192 print IDB "d 0755 lp sys usr/samba/printer/W32PPC $SRCPFX/packaging/SGI $PKG.sw.base\n";
193 print IDB "d 0755 lp sys usr/samba/printer/W32X86 $SRCPFX/packaging/SGI $PKG.sw.base\n";
194 print IDB "d 0755 lp sys usr/samba/printer/WIN40 $SRCPFX/packaging/SGI $PKG.sw.base\n";
195
196 print IDB "d 0644 root sys usr/samba/private $SRCPFX/packaging/SGI $PKG.sw.base\n";
197 print IDB "f 0600 root sys usr/samba/private/smbpasswd $SRCPFX/packaging/SGI/smbpasswd $PKG.sw.base config(suggest)\n";
198
199 print IDB "d 0755 root sys usr/samba/scripts $SRCPFX/packaging/SGI $PKG.src.samba\n";
200 print IDB "f 0755 root sys usr/samba/scripts/inetd.sh $SRCPFX/packaging/SGI/inetd.sh $PKG.sw.base\n";
201 print IDB "f 0755 root sys usr/samba/scripts/inst.msg $SRCPFX/packaging/SGI/inst.msg $PKG.sw.base exitop(\"chroot \$rbase /usr/samba/scripts/inst.msg\")\n";
202 print IDB "f 0755 root sys usr/samba/scripts/mkprintcap.sh $SRCPFX/packaging/SGI/mkprintcap.sh $PKG.sw.base\n";
203 print IDB "f 0755 root sys usr/samba/scripts/removeswat.sh $SRCPFX/packaging/SGI/removeswat.sh $PKG.sw.base\n";
204 print IDB "f 0755 root sys usr/samba/scripts/startswat.sh $SRCPFX/packaging/SGI/startswat.sh $PKG.sw.base\n";
205
206 print IDB "d 0755 root sys usr/samba/src $SRCPFX/packaging/SGI $PKG.src.samba\n";
207 @sorted = sort(@allfiles);
208 while (@sorted) {
209   $nextfile = shift @sorted;
210   ($file = $nextfile) =~ s/^.*\///;
211   next if grep(/packaging\/SGI/& (/Makefile/ | /samba\.spec/ | /samba\.idb/),$nextfile);
212   next if grep(/source/,$nextfile) && ($ignores{$file});
213   next if ($nextfile eq "CVS");
214   if (grep(/\/$/,$nextfile)) {
215     $nextfile =~ s/\/$//;
216     print IDB "d 0755 root sys usr/samba/src/$nextfile $SRCPFX/$nextfile $PKG.src.samba\n";
217   }
218   else {
219     if (grep((/\.sh$/ | /configure$/ | /configure\.developer/ | /config\.guess/ | /config\.sub/ | /\.pl$/ | /mkman$/ | /pcp\/Install/ | /pcp\/Remove/),$nextfile)) {
220         print IDB "f 0755 root sys usr/samba/src/$nextfile $SRCPFX/$nextfile $PKG.src.samba\n";
221     }
222     else {
223         print IDB "f 0644 root sys usr/samba/src/$nextfile $SRCPFX/$nextfile $PKG.src.samba\n";
224     }
225   }
226 }
227
228 print IDB "d 0755 root sys usr/samba/swat $SRCPFX/packaging/SGI/swat $PKG.sw.base\n";
229 while (@swatfiles) {
230   $nextfile = shift @swatfiles;
231   ($file = $nextfile) =~ s/^packaging\/SGI\/swat\///;
232   next if !$file;
233   if (grep(/\/$/,$file)) {
234     $file =~ s/\/$//;
235     print IDB "d 0755 root sys usr/samba/swat/$file $SRCPFX/packaging/SGI/swat/$file $PKG.sw.base\n";
236   }
237   else {
238     print IDB "f 0444 root sys usr/samba/swat/$file $SRCPFX/packaging/SGI/swat/$file $PKG.sw.base\n";
239   }
240 }
241
242 print IDB "d 0755 root sys usr/samba/var $SRCPFX/packaging/SGI $PKG.sw.base\n";
243 print IDB "d 0755 root sys usr/samba/var/locks $SRCPFX/packaging/SGI $PKG.sw.base\n";
244
245 if ($PKG eq "samba_irix") {
246   while(@books) {
247     $nextfile = shift @books;
248     print IDB $nextfile;
249   }
250 }
251
252 print IDB "d 0755 root sys usr/share/catman/u_man $SRCPFX/packaging/SGI $PKG.man.manpages\n";
253 $olddirnum = "0";
254 while (@catman) {
255   $nextfile = shift @catman;
256   ($file = $nextfile) =~ s/^packaging\/SGI\/catman\///;
257   ($dirnum = $file) =~ s/^[\D]*//;
258   $dirnum =~ s/\.z//;
259   if ($dirnum ne $olddirnum) {
260     print IDB "d 0755 root sys usr/share/catman/u_man/cat$dirnum $SRCPFX/packaging/SGI $PKG.man.manpages\n";
261     $olddirnum = $dirnum;
262   }
263   print IDB "f 0664 root sys usr/share/catman/u_man/cat$dirnum/$file $SRCPFX/$nextfile $PKG.man.manpages\n";
264 }
265
266 if (@nsswitch) {
267   print IDB "d 0755 root sys var/ns/lib $SRCPFX/packaging/SGI $PKG.sw.base\n";
268   while(@nsswitch) {
269     $nextfile = shift @nsswitch;
270     next if $nextfile eq 'libsmbclient';
271     ($filename = $nextfile) =~ s/^.*\///;
272     $filename =~ s/libnss/libns/;
273     print IDB "f 0644 root sys var/ns/lib/$filename $SRCPFX/source/$nextfile $PKG.sw.base \n";
274   }
275 }
276
277 print IDB "d 01777 lp sys var/spool/samba $SRCPFX/packaging/SGI $PKG.sw.base\n";
278
279 close IDB;
280 print "\n\n$PKG.idb file has been created\n";
281
282 sub dodir {
283     local($dir, $nlink) = @_;
284     local($dev,$ino,$mode,$subcount);
285
286     ($dev,$ino,$mode,$nlink) = stat('.') unless $nlink;
287
288     opendir(DIR,'.') || die "Can't open current directory";
289     local(@filenames) = sort readdir(DIR);
290     closedir(DIR);
291
292     if ($nlink ==2) {           # This dir has no subdirectories.
293         for (@filenames) {
294             next if $_ eq '.';
295             next if $_ eq '..';
296             $this =  substr($dir,2)."/$_";
297             push(@allfiles,$this);
298         }
299     }
300     else {
301         $subcount = $nlink -2;
302         for (@filenames) {
303             next if $_ eq '.';
304             next if $_ eq '..';
305             next if $_ eq 'CVS';
306             ($dev,$ino,$mode,$nlink) = lstat($_);
307             $name = "$dir/$_";
308             $this = substr($name,2);
309             $this .= '/' if -d;
310             push(@allfiles,$this);
311             next if $subcount == 0;             # seen all the subdirs?
312
313             next unless -d _;
314
315             chdir $_ || die "Can't cd to $name";
316             &dodir($name,$nlink);
317             chdir '..';
318             --$subcount;
319         }
320     }
321 }
322
323 sub bynextdir {
324   ($f0,$f1) = split(/\//,$a,2);
325   ($f0,$f2) = split(/\//,$b,2);
326   $f1 cmp $f2;
327 }
328
329 sub byfilename {
330   ($f0,$f1) = split(/.*\//,$a,2);
331   if ($f1 eq "") { $f1 = $f0 };
332   ($f0,$f2) = split(/.*\//,$b,2);
333   if ($f2 eq "") { $f2 = $f0 };
334   $f1 cmp $f2;
335 }
336
337 sub bydirnum {
338   ($f1 = $a) =~ s/^.*\///;
339   ($f2 = $b) =~ s/^.*\///;
340   ($dir1 = $a) =~ s/^[\D]*//;
341   ($dir2 = $b) =~ s/^[\D]*//;
342   if (!($dir1 <=> $dir2)) {
343     $f1 cmp $f2;
344   }
345   else {
346     $dir1 <=> $dir2;
347   }
348 }
349
350 sub idbsort {
351   ($f0,$f1,$f2,$f3) = split(/ /,$a,4);
352   ($f0,$f1,$f2,$f4) = split(/ /,$b,4);
353   $f3 cmp $f4;
354 }
355
356 sub get_line {
357   local ($line) = @_;
358
359   $line =~ s/^.*=//;
360   while (($cont = index($line,"\\")) > 0) {
361     $_ = <MAKEFILE>;
362     chomp;
363     s/^\s*/ /;
364     substr($line,$cont,1) = $_;
365   }
366   $line =~ s/\$\(srcdir\)//g;
367   $line =~ s/\$\(builddir\)//g;
368   $line =~ s/\$\(\S*\)\s*//g;
369   $line =~ s/\s\s*/ /g;
370   @line = split(' ',$line);
371   return @line;
372 }
373