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