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