Update file for automatically generating a release
[sfrench/samba-autobuild/.git] / packaging / SGI / idb.pl
1 #!/usr/bin/perl
2
3 # This perl script automatically generates the samba.idb file
4
5 $curdir = $ENV{"PWD"};
6
7 # get a complete list of all files in the tree
8 chdir '../../';
9 &dodir('.');
10 chdir $curdir;
11
12 # We don't want the files listed in .cvsignore in the source tree
13 open(IGNORES,"../../source/.cvsignore");
14 while (<IGNORES>) {
15   chop;
16   $ignores{$_}++;
17 }
18 close IGNORES;
19
20 # get the names of all the binary files to be installed
21 open(MAKEFILE,"Makefile");
22 @makefile = <MAKEFILE>;
23 @sprogs = grep(/^SPROGS /,@makefile);
24 @progs1 = grep(/^PROGS1 /,@makefile);
25 @progs = grep(/^PROGS /,@makefile);
26 @scripts = grep(/^SCRIPTS /,@makefile);
27 @codepage = grep(/^CODEPAGELIST/,@makefile);
28 close MAKEFILE;
29
30 if (@sprogs) {
31   @sprogs[0] =~ s/^.*\=//;
32   @sprogs[0] =~ s/^.*\)//;
33   @sprogs = split(' ',@sprogs[0]);
34 }
35 if (@progs) {
36   @progs[0] =~ s/^.*\=//;
37   @progs[0] =~ s/^.*\)//;
38   @progs = split(' ',@progs[0]);
39 }
40 if (@progs1) {
41   @progs1[0] =~ s/^.*\=//;
42   @progs1[0] =~ s/^.*\)//;
43   @progs1 = split(' ',@progs1[0]);
44 }
45 if (@scripts) {
46   @scripts[0] =~ s/^.*\=//;
47   @scripts[0] =~ s/^.*\)//;
48   @scripts = split(' ',@scripts[0]);
49 }
50 if (@codepage) {
51   @codepage[0] =~ s/^.*\=//;
52   @codepage[0] =~ s/^.*\)//;
53   chdir '../../source';
54   # if we have codepages we need to create them for the package
55   system("./installcp.sh . ../packaging/SGI/codepage . @codepage[0]");
56   chdir $curdir;
57   @codepage = sort split(' ',@codepage[0]);
58 }
59
60 # add my local files to the list of binaries to install
61 @bins = sort (@sprogs,@progs,@progs1,@scripts,("psfixes.pl","sambalp","smbprint"));
62
63 # the files installed in docs include all the original files in docs plus all
64 # the "*.doc" files from the source tree
65 @docs = sort byfilename grep (!/^docs\/$/ & (/^source\/.*\.doc$/ | /^docs\//),@allfiles);
66
67 @catman = sort grep(/^packaging\/SGI\/catman/ & !/\/$/, @allfiles);
68 @catman = sort bydirnum @catman;
69
70 # strip out all the generated directories and the "*.o" files from the source
71 # release
72 @allfiles = grep(!/^.*\.o$/ & !/^packaging\/SGI\/bins/ & !/^packaging\/SGI\/catman/ & !/^packaging\/SGI\/html/ & !/^packaging\/SGI\/codepage/, @allfiles);
73
74 open(IDB,">samba.idb");
75
76 print IDB "f 0644 root sys etc/config/samba packaging/SGI/samba.config samba.sw.base config(update)\n";
77 print IDB "f 0755 root sys etc/init.d/samba packaging/SGI/samba.rc samba.sw.base\n";
78 print IDB "l 0000 root sys etc/rc0.d/K39samba packaging/SGI samba.sw.base symval(../init.d/samba)\n";
79 print IDB "l 0000 root sys etc/rc2.d/S81samba packaging/SGI samba.sw.base symval(../init.d/samba)\n";
80
81 @copyfile = grep (/^COPY/,@allfiles);
82 print IDB "d 0755 root sys usr/relnotes/samba packaging/SGI samba.man.relnotes\n";
83 print IDB "f 0644 root sys usr/relnotes/samba/@copyfile[0] @copyfile[0] samba.man.relnotes\n";
84 print IDB "f 0644 root sys usr/relnotes/samba/legal_notice.html packaging/SGI/legal_notice.html samba.man.relnotes\n";
85 print IDB "f 0644 root sys usr/relnotes/samba/samba-relnotes.html packaging/SGI/relnotes.html samba.man.relnotes\n";
86
87 print IDB "d 0755 root sys usr/samba packaging/SGI samba.sw.base\n";
88 print IDB "f 0444 root sys usr/samba/README packaging/SGI/README samba.sw.base\n";
89
90 print IDB "d 0755 root sys usr/samba/bin packaging/SGI samba.sw.base\n";
91 while(@bins) {
92   $nextfile = shift @bins;
93   if ($nextfile eq "smbpasswd") {
94     print IDB "f 4555 root sys usr/samba/bin/$nextfile source/$nextfile samba.sw.base\n";
95   }
96   elsif ($nextfile eq "psfixes.pl") {
97     print IDB "f 0755 root sys usr/samba/bin/$nextfile packaging/SGI/$nextfile samba.sw.base\n";
98   }
99   elsif ($nextfile eq "sambalp") {
100     print IDB "f 0755 root sys usr/samba/bin/$nextfile packaging/SGI/$nextfile samba.sw.base\n";
101   }
102   elsif ($nextfile eq "smbprint") {
103     print IDB "f 0755 root sys usr/samba/bin/$nextfile packaging/SGI/$nextfile samba.sw.base\n";
104   }
105   else {
106     print IDB "f 0755 root sys usr/samba/bin/$nextfile source/$nextfile samba.sw.base\n";
107   }
108 }
109
110 print IDB "d 0755 root sys usr/samba/docs docs samba.man.doc\n";
111 while (@docs) {
112   $nextfile = shift @docs;
113   next if ($nextfile eq "CVS");
114   ($junk,$file) = split(/\//,$nextfile,2);
115   if (grep(/\/$/,$nextfile)) {
116     chop $nextfile;
117     chop $file;
118     print IDB "d 0755 root sys usr/samba/docs/$file $nextfile samba.man.doc\n";
119   }
120   else {
121     print IDB "f 0644 root sys usr/samba/docs/$file $nextfile samba.man.doc\n";
122   }
123 }
124
125 print IDB "f 0755 root sys usr/samba/inetd.sh packaging/SGI/inetd.sh samba.sw.base\n";
126 print IDB "d 0755 root sys usr/samba/lib packaging/SGI samba.sw.base\n";
127 if (@codepage) {
128   print IDB "d 0755 root sys usr/samba/lib/codepage packaging/SGI samba.sw.base\n";
129   while (@codepage) {
130     $nextpage = shift @codepage;
131     print IDB "f 0644 root sys usr/samba/lib/codepage/codepage.$nextpage packaging/SGI/codepage/codepage.$nextpage samba.sw.base\n";
132   }
133 }
134 print IDB "f 0644 root sys usr/samba/lib/smb.conf packaging/SGI/smb.conf samba.sw.base config(update)\n";
135 print IDB "f 0755 root sys usr/samba/mkprintcap.sh packaging/SGI/mkprintcap.sh samba.sw.base exitop(/usr/samba/mkprintcap.sh) removeop(rm /usr/samba/printcap)\n";
136
137 print IDB "d 0755 root sys usr/samba/src packaging/SGI samba.src.samba\n";
138 while (@allfiles) {
139   $nextfile = shift @allfiles;
140   ($file = $nextfile) =~ s/^.*\///;
141   next if grep(/packaging\/SGI/& (/Makefile/ | /samba\.spec/ | /samba\.idb/),$nextfile);
142   next if grep(/source/,$nextfile) && ($ignores{$file});
143   next if ($nextfile eq "CVS");
144   if (grep(/\/$/,$nextfile)) {
145     chop $nextfile;
146     print IDB "d 0755 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
147   }
148   else {
149     if (grep(/SGI/ & (/\.sh$/ | /\.pl$/ | /mkman$/),$nextfile)) {
150         print IDB "f 0755 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
151     }
152     else {
153         print IDB "f 0644 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
154     }
155   }
156 }
157
158 print IDB "d 0755 root sys usr/samba/var packaging/SGI samba.sw.base\n";
159 print IDB "d 0755 root sys usr/samba/var/locks packaging/SGI samba.sw.base\n";
160
161 print IDB "d 0755 root sys usr/share/catman/u_man packaging/SGI samba.man.manpages\n";
162 $olddirnum = "0";
163 while (@catman) {
164   $nextfile = shift @catman;
165   ($file = $nextfile) =~ s/^packaging\/SGI\/catman\///;
166   ($dirnum = $file) =~ s/^[\D]*//;
167   $dirnum =~ s/\.Z//;
168   if ($dirnum ne $olddirnum) {
169     print IDB "d 0755 root sys usr/share/catman/u_man/cat$dirnum packaging/SGI samba.man.manpages\n";
170     $olddirnum = $dirnum;
171   }
172   print IDB "f 0664 root sys usr/share/catman/u_man/cat$dirnum/$file $nextfile samba.man.manpages\n";
173 }
174
175 close IDB;
176 print "\n\nsamba.idb file has been created\n";
177
178 sub dodir {
179     local($dir, $nlink) = @_;
180     local($dev,$ino,$mode,$subcount);
181
182     ($dev,$ino,$mode,$nlink) = stat('.') unless $nlink;
183
184     opendir(DIR,'.') || die "Can't open $dir";
185     local(@filenames) = sort readdir(DIR);
186     closedir(DIR);
187
188     if ($nlink ==2) {           # This dir has no subdirectories.
189         for (@filenames) {
190             next if $_ eq '.';
191             next if $_ eq '..';
192             $this =  substr($dir,2)."/$_";
193             push(@allfiles,$this);
194         }
195     }
196     else {
197         $subcount = $nlink -2;
198         for (@filenames) {
199             next if $_ eq '.';
200             next if $_ eq '..';
201             next if $_ eq 'CVS';
202             ($dev,$ino,$mode,$nlink) = lstat($_);
203             $name = "$dir/$_";
204             $this = substr($name,2);
205             $this .= '/' if -d;
206             push(@allfiles,$this);
207             next if $subcount == 0;             # seen all the subdirs?
208
209             next unless -d _;
210
211             chdir $_ || die "Can't cd to $name";
212             &dodir($name,$nlink);
213             chdir '..';
214             --$subcount;
215         }
216     }
217 }
218
219 sub byfilename {
220   ($f0,$f1) = split(/\//,$a,2);
221   ($f0,$f2) = split(/\//,$b,2);
222   $f1 cmp $f2;
223 }
224
225 sub bydirnum {
226   ($f1 = $a) =~ s/^.*\///;
227   ($f2 = $b) =~ s/^.*\///;
228   ($dir1 = $a) =~ s/^[\D]*//;
229   ($dir2 = $b) =~ s/^[\D]*//;
230   if (!($dir1 <=> $dir2)) {
231     $f1 cmp $f2;
232   }
233   else {
234     $dir1 <=> $dir2;
235   }
236 }