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