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