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