home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / samba-1.9.18p7.tar.gz / samba-1.9.18p7.tar / samba-1.9.18p7 / packaging / SGI / idb.pl < prev    next >
Perl Script  |  1998-05-08  |  8KB  |  238 lines

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