a211322fa988ef2faa9c5584a07205d32a338d04
[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,"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 ./installcp.sh");
48   system("./installcp.sh . ../packaging/SGI/codepages . @codepage[0]");
49   chdir $curdir;
50   @codepage = sort split(' ',@codepage[0]);
51 }
52 # install the swat files
53 chdir '../../source';
54 system("chmod +x ./installswat.sh");
55 system("./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 (@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
99   if (index($nextfile,'$')) {
100     if ($nextfile eq "smbpasswd") {
101       print IDB "f 0755 root sys usr/samba/bin/$nextfile source/$nextfile samba.sw.base\n";
102     }
103     elsif ($nextfile eq "findsmb") {
104       print IDB "f 0755 root sys usr/samba/bin/$nextfile packaging/SGI/$nextfile samba.sw.base\n";
105     }
106     elsif ($nextfile eq "swat") {
107       print IDB "f 4755 root sys usr/samba/bin/$nextfile source/$nextfile samba.sw.base\n";
108     }
109     elsif ($nextfile eq "sambalp") {
110       print IDB "f 0755 root sys usr/samba/bin/$nextfile packaging/SGI/$nextfile samba.sw.base\n";
111     }
112     elsif ($nextfile eq "smbprint") {
113       print IDB "f 0755 root sys usr/samba/bin/$nextfile packaging/SGI/$nextfile samba.sw.base\n";
114     }
115     else {
116       print IDB "f 0755 root sys usr/samba/bin/$nextfile source/$nextfile samba.sw.base\n";
117     }
118   }
119 }
120
121 print IDB "d 0755 root sys usr/samba/docs/ docs samba.man.doc\n";
122 while (@docs) {
123   $nextfile = shift @docs;
124   next if ($nextfile eq "CVS");
125   ($junk,$file) = split(/\//,$nextfile,2);
126   if (grep(/\/$/,$nextfile)) {
127     print IDB "d 0755 root sys usr/samba/docs/$file $nextfile samba.man.doc\n";
128   }
129   else {
130     print IDB "f 0644 root sys usr/samba/docs/$file $nextfile samba.man.doc\n";
131   }
132 }
133
134 print IDB "f 0755 root sys usr/samba/inetd.sh packaging/SGI/inetd.sh samba.sw.base\n";
135 print IDB "d 0755 root sys usr/samba/lib/ packaging/SGI samba.sw.base\n";
136 if (@codepage) {
137   print IDB "d 0755 root sys usr/samba/lib/codepages packaging/SGI samba.sw.base\n";
138   while (@codepage) {
139     $nextpage = shift @codepage;
140     print IDB "f 0644 root sys usr/samba/lib/codepages/codepage.$nextpage packaging/SGI/codepages/codepage.$nextpage samba.sw.base\n";
141   }
142 }
143 print IDB "f 0644 root sys usr/samba/lib/smb.conf packaging/SGI/smb.conf samba.sw.base config(update)\n";
144 print IDB "f 0755 root sys usr/samba/mkprintcap.sh packaging/SGI/mkprintcap.sh samba.sw.base\n";
145
146 print IDB "d 0644 root sys usr/samba/private/ packaging/SGI samba.sw.base\n";
147 print IDB "f 0600 root sys usr/samba/private/smbpasswd packaging/SGI/smbpasswd samba.sw.base config(update)\n";
148 print IDB "d 0755 root sys usr/samba/src/ packaging/SGI samba.src.samba\n";
149 @sorted = sort(@allfiles);
150 while (@sorted) {
151   $nextfile = shift @sorted;
152   ($file = $nextfile) =~ s/^.*\///;
153   next if grep(/packaging\/SGI/& (/Makefile/ | /samba\.spec/ | /samba\.idb/),$nextfile);
154   next if grep(/source/,$nextfile) && ($ignores{$file});
155   next if ($nextfile eq "CVS");
156   if (grep(/\/$/,$nextfile)) {
157     print IDB "d 0755 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
158   }
159   else {
160     if (grep((/\.sh$/ | /\.pl$/ | /mkman$/),$nextfile)) {
161         print IDB "f 0755 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
162     }
163     else {
164         print IDB "f 0644 root sys usr/samba/src/$nextfile $nextfile samba.src.samba\n";
165     }
166   }
167 }
168
169 print IDB "f 0755 root sys usr/samba/startswat.sh packaging/SGI/startswat.sh samba.sw.base\n";
170 print IDB "d 0755 root sys usr/samba/swat/ packaging/SGI/swat samba.sw.base\n";
171 while (@swatfiles) {
172   $nextfile = shift @swatfiles;
173   ($file = $nextfile) =~ s/^packaging\/SGI\/swat\///;
174   next if !$file;
175   if (grep(/\/$/,$file)) {
176     print IDB "d 0755 root sys usr/samba/swat/$file packaging/SGI/swat/$file samba.sw.base\n";
177   }
178   else {
179     print IDB "f 0444 root sys usr/samba/swat/$file packaging/SGI/swat/$file samba.sw.base\n";
180   }
181 }
182
183 print IDB "d 0755 root sys usr/samba/var/ packaging/SGI samba.sw.base\n";
184 print IDB "d 0755 root sys usr/samba/var/locks/ packaging/SGI samba.sw.base\n";
185
186 print IDB "d 0755 root sys usr/share/catman/u_man/ packaging/SGI samba.man.manpages\n";
187 $olddirnum = "0";
188 while (@catman) {
189   $nextfile = shift @catman;
190   ($file = $nextfile) =~ s/^packaging\/SGI\/catman\///;
191   ($dirnum = $file) =~ s/^[\D]*//;
192   $dirnum =~ s/\.Z//;
193   if ($dirnum ne $olddirnum) {
194     print IDB "d 0755 root sys usr/share/catman/u_man/cat$dirnum packaging/SGI samba.man.manpages\n";
195     $olddirnum = $dirnum;
196   }
197   print IDB "f 0664 root sys usr/share/catman/u_man/cat$dirnum/$file $nextfile samba.man.manpages\n";
198 }
199
200 close IDB;
201 print "\n\nsamba.idb file has been created\n";
202
203 sub dodir {
204     local($dir, $nlink) = @_;
205     local($dev,$ino,$mode,$subcount);
206
207     ($dev,$ino,$mode,$nlink) = stat('.') unless $nlink;
208
209     opendir(DIR,'.') || die "Can't open $dir";
210     local(@filenames) = sort readdir(DIR);
211     closedir(DIR);
212
213     if ($nlink ==2) {           # This dir has no subdirectories.
214         for (@filenames) {
215             next if $_ eq '.';
216             next if $_ eq '..';
217             $this =  substr($dir,2)."/$_";
218             push(@allfiles,$this);
219         }
220     }
221     else {
222         $subcount = $nlink -2;
223         for (@filenames) {
224             next if $_ eq '.';
225             next if $_ eq '..';
226             next if $_ eq 'CVS';
227             ($dev,$ino,$mode,$nlink) = lstat($_);
228             $name = "$dir/$_";
229             $this = substr($name,2);
230             $this .= '/' if -d;
231             push(@allfiles,$this);
232             next if $subcount == 0;             # seen all the subdirs?
233
234             next unless -d _;
235
236             chdir $_ || die "Can't cd to $name";
237             &dodir($name,$nlink);
238             chdir '..';
239             --$subcount;
240         }
241     }
242 }
243
244 sub byfilename {
245   ($f0,$f1) = split(/\//,$a,2);
246   ($f0,$f2) = split(/\//,$b,2);
247   $f1 cmp $f2;
248 }
249
250 sub bydirnum {
251   ($f1 = $a) =~ s/^.*\///;
252   ($f2 = $b) =~ s/^.*\///;
253   ($dir1 = $a) =~ s/^[\D]*//;
254   ($dir2 = $b) =~ s/^[\D]*//;
255   if (!($dir1 <=> $dir2)) {
256     $f1 cmp $f2;
257   }
258   else {
259     $dir1 <=> $dir2;
260   }
261 }