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