File:  [LON-CAPA] / loncom / build / Attic / parse.pl
Revision 1.26: download - view: text, annotated - select for diffs
Tue Jan 23 16:12:56 2001 UTC (23 years, 5 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
making sure a /home/www directory is created -Scott

    1: #!/usr/bin/perl
    2: 
    3: # Scott Harrison
    4: # November 2000
    5: 
    6: # Read in loncapa tags and metagroup tags
    7: 
    8: # ---------------------------------------------- Read in command line arguments
    9: my ($file,$mode)=@ARGV;
   10: 
   11: # ---------------------------------------------------- Read in master data file
   12: open IN,"<$file";
   13: my @lines=<IN>;
   14: close IN;
   15: my $info1=join('',@lines);
   16: my $info2=$info1; # value to allow for meta data group retrieval
   17: 
   18: # ------------------------------------------------------- Make default settings
   19: my $distribution="redhat6.2";
   20: my $date=`date +'%B %e, %Y'`; chop $date;
   21: my $buildhost=`hostname`; chop $buildhost;
   22: # file category mappings
   23: my %fcm=(
   24: 	 'conf' => 'configurable',
   25: 	 'graphic file' => 'graphicfile',
   26: 	 'handler' => 'handler',
   27: 	 'interface file' => 'interfacefile',
   28: 	 'symbolic link' => 'link',
   29: 	 'root script' => 'rootscript',
   30: 	 'script' => 'script',
   31: 	 'setuid script' => 'setuid',
   32: 	 'static conf' => 'static',
   33: 	 'system file' => 'systemfile',
   34: 	 );
   35: 
   36: # ---------------------------------------------------- Parse the marked up data
   37: my %info; # big data storage object
   38: while ($info1=~/\<loncapa\s+(.*?)\>/isg) {
   39:     my $keystring=$1;
   40:     # In the parsing of LON-CAPA tags, remove boundary white-space,
   41:     # and handle quotation commands.
   42:     my %hash=map {my ($key,$value)=split(/\=(?!")|\=(?=\s*"[^"]*"[^"]*$)/);
   43:                                    $value=~s/^"//;
   44:  				   $value=~s/"$//;
   45:                                    (uc($key),$value);}
   46:              split(/\s+(?=\w+\s*\=)/,$keystring);
   47:     # Handle the different types of commands
   48:     if (uc($hash{'TYPE'}) eq "OWNERSHIP") {
   49:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHMOD'}=$hash{'CHMOD'};
   50:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHOWN'}=$hash{'CHOWN'};
   51:     }
   52:     elsif (uc($hash{'TYPE'}) eq "DEVOWNERSHIP") {
   53:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHMOD'}=$hash{'CHMOD'};
   54:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHOWN'}=$hash{'CHOWN'};
   55:     }
   56:     elsif (uc($hash{'TYPE'}) eq "RPM") {
   57:         $hash{'VALUE'}=~s/\\n/\n/g;
   58:         $info{$hash{'TYPE'}}{$hash{'NAME'}}=$hash{'VALUE'};
   59:     }
   60:     elsif (uc($hash{'TYPE'}) eq "DIRECTORY") {
   61:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=
   62:                                                        $hash{'CATEGORY'};
   63:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'DESCRIPTION'}=
   64:                                $hash{'DESCRIPTION'} if $hash{'DESCRIPTION'};
   65:     }
   66:     elsif (uc($hash{'TYPE'}) eq "LOCATION") {
   67:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=                               $hash{'CATEGORY'};
   68:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'LINKTO'}=                               $hash{'LINKTO'};
   69:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'SOURCE'}=                                               $hash{'SOURCE'};
   70:         # get surrounding metagroup information
   71:         my $ckeystring=$keystring; $ckeystring=~s/(SOURCE\=\"[^"]*)\*/$1\\\*/g;
   72:         $ckeystring=~s/(TARGET\=\"[^"]*)\*/$1\\\*/g;
   73:         $info2=~/.*\<(?:metagroup|metasupergroup)\>(.*?)\<loncapa\s+$ckeystring\>(.*?)\<\/(?:metagroup|metasupergroup)\>/is;
   74: 	my $data=$1.$2;
   75:         my @meta=('description','build','dependencies','files','note');
   76:         foreach my $m (@meta) {
   77: 	    if ($data=~/\<($m)\>(.*?)\<\/$m\>/sgi) {
   78: 		my ($key,$value)=($1,$2);
   79: 		$info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{uc($key)}=
   80: 		                                                    $value;
   81: 	    }
   82:         }
   83:     }
   84:     else {
   85:         warn("WARNING: this tag text will be ignored since it cannot be understood\n---> $keystring\n");
   86:     }
   87: }
   88: 
   89: my $a;
   90: my @directories;
   91: if ($mode eq "HTML") {
   92:     $a=&begin_description_page;
   93:     print $a;
   94:     $a=&make_rpm_description_block;
   95:     print $a;
   96:     @directories=&determine_directory_structure;
   97:     $a=&make_directory_structure_description_block(\@directories);
   98:     print $a;
   99:     $a=&make_file_type_ownership_and_permissions_description_block;
  100:     print $a;
  101:     $a=&make_directory_and_file_structure_description_block(\@directories);
  102:     print $a;
  103:     $a=&end_description_page;
  104:     print $a;
  105: }
  106: elsif ($mode eq "SPEC") {
  107:     my $out=$info{'RPM'}{'Name'} . '-' . $info{'RPM'}{'Version'} . '.spec';
  108:     open OUT,">$out";
  109:     $a=&make_rpm_spec_block;
  110:     print OUT $a;
  111:     $a=&make_rpm_build_block;
  112:     print OUT $a;
  113:     @directories=&determine_directory_structure;
  114:     $a=&make_directory_structure_spec_block(\@directories);
  115:     print OUT $a;
  116:     $a=&make_directory_and_file_structure_spec_block(\@directories);
  117:     print OUT $a;
  118:     $a=&end_spec_page;
  119:     print OUT $a;
  120:     close OUT;
  121: }
  122: elsif ($mode eq "LCMakefile") {
  123:     @directories=&determine_directory_structure;
  124:     $a=&make_directory_LCMakefile_segment(\@directories);
  125:     print $a;
  126:     $a=&make_files_LCMakefile_segment(\@directories);
  127:     print $a;
  128:     $a=&make_links_LCMakefile_segment(\@directories);
  129:     print $a;
  130: }
  131: elsif ($mode eq "BinaryRoot") {
  132:     mkdir "BinaryRoot",0755;
  133:     open OUT,">Makefile.BinaryRoot";
  134:     @directories=&determine_directory_structure;
  135:     $a=&make_directory_binaryroot_segment(\@directories);
  136:     print OUT $a;
  137:     $a=&make_files_binaryroot_segment(\@directories);
  138:     print OUT $a;
  139:     $a=&make_links_binaryroot_segment(\@directories);
  140:     print OUT $a;
  141:     close OUT;
  142:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' directories`;
  143:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' files`;
  144:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' links`;
  145:     open OUT,">base_file_list.txt";
  146:     $a=&make_file_list(\@directories);
  147:     print OUT $a;
  148:     close OUT;
  149:     open OUT,">setup_file_list.txt";
  150:     print OUT "BinaryRoot/etc/passwd\n";
  151:     close OUT;
  152:     open OUT,">BinaryRoot/etc/passwd";
  153:     print OUT<<END;
  154: root::0:0:root:/root:/bin/bash
  155: bin:!!:1:1:bin:/bin:
  156: daemon:!!:2:2:daemon:/sbin:
  157: adm:!!:3:4:adm:/var/adm:
  158: lp:!!:4:7:lp:/var/spool/lpd:
  159: sync:!!:5:0:sync:/sbin:/bin/sync
  160: shutdown:!!:6:0:shutdown:/sbin:/sbin/shutdown
  161: halt:!!:7:0:halt:/sbin:/sbin/halt
  162: mail:!!:8:12:mail:/var/spool/mail:
  163: news:!!:9:13:news:/var/spool/news:
  164: uucp:!!:10:14:uucp:/var/spool/uucp:
  165: operator:!!:11:0:operator:/root:
  166: games:!!:12:100:games:/usr/games:
  167: gopher:!!:13:30:gopher:/usr/lib/gopher-data:
  168: ftp:!!:14:50:FTP User:/home/ftp:
  169: nobody:!!:99:99:Nobody:/:
  170: www:!!:500:500:www:/home/www:/bin/bash
  171: END
  172: close OUT;
  173:     open OUT,">>setup_file_list.txt";
  174:     print OUT "BinaryRoot/etc/hosts.deny\n";
  175:     close OUT;
  176:     open OUT,">BinaryRoot/etc/hosts.deny";
  177:     print OUT<<END;
  178: ALL: ALL
  179: END
  180: close OUT;
  181:     
  182:     `install -d BinaryRoot/etc/pam.d`;
  183:     `install -o 500 -g 500 -m 0700 -d BinaryRoot/home/www`;
  184:     open OUT,">>setup_file_list.txt";
  185:     print OUT "BinaryRoot/etc/pam.d/passwd\n";
  186:     close OUT;
  187:     open OUT,">BinaryRoot/etc/pam.d/passwd";
  188:     print OUT<<END;
  189: #%PAM-1.0
  190: auth       required     /lib/security/pam_pwdb.so shadow nullok
  191: account    required     /lib/security/pam_pwdb.so
  192: password   required     /lib/security/pam_cracklib.so retry=3
  193: password   required     /lib/security/pam_pwdb.so use_authtok nullok
  194: END
  195: close OUT;
  196:     open OUT,">>setup_file_list.txt";
  197:     print OUT "BinaryRoot/etc/pam.d/login\n";
  198:     close OUT;
  199:     open OUT,">BinaryRoot/etc/pam.d/login";
  200:     print OUT<<END;
  201: #%PAM-1.0
  202: auth       required     /lib/security/pam_securetty.so
  203: auth       required     /lib/security/pam_pwdb.so shadow nullok
  204: auth       required     /lib/security/pam_nologin.so
  205: account    required     /lib/security/pam_pwdb.so
  206: password   required     /lib/security/pam_cracklib.so
  207: password   required     /lib/security/pam_pwdb.so nullok use_authtok
  208: session    required     /lib/security/pam_pwdb.so
  209: session    optional     /lib/security/pam_console.so
  210: END
  211: close OUT;
  212: 
  213: }
  214: elsif ($mode eq "status") {
  215:     $a=&begin_description_page('status');
  216:     print $a;
  217:     $a=&make_rpm_description_block('status');
  218:     print $a;
  219:     @directories=&determine_directory_structure('status');
  220:     $a=&make_directory_structure_description_block(\@directories,'status');
  221:     print $a;
  222:     $a=&make_file_type_ownership_and_permissions_description_block('status');
  223:     print $a;
  224:     $a=&make_directory_and_file_structure_description_block(\@directories,'status');
  225:     print $a;
  226:     $a=&end_description_page('status');
  227:     print $a;
  228: }
  229: elsif ($mode eq "update") {
  230: }
  231: elsif ($mode eq "configinstall") {
  232:     @directories=&determine_directory_structure;
  233:     $a=&make_files_configinstall_segment(\@directories);
  234:     print $a;
  235:     $a=&make_files_configpermissions_segment(\@directories);
  236:     print $a;
  237: }
  238: elsif ($mode eq "install") {
  239:     @directories=&determine_directory_structure;
  240:     $a=&make_directory_install_segment(\@directories);
  241:     print $a;
  242:     $a=&make_files_install_segment(\@directories);
  243:     print $a;
  244:     $a=&make_links_install_segment(\@directories);
  245:     print $a;
  246: }
  247: elsif ($mode eq "build") {
  248:     @directories=&determine_directory_structure;
  249:     $a=&make_files_build_segment(\@directories);
  250:     print $a;
  251: }
  252: 
  253: # ------------------------------------------------------ a list of file targets
  254: sub make_file_list {
  255:     my ($dirs)=@_;
  256:     my $description;
  257:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  258:     foreach my $d (@$dirs) {
  259: 	# set other values
  260: 	$description.=<<END;
  261: BinaryRoot/$d
  262: END
  263: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  264: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  265: 	# find files that are contained in this directory
  266: 	my @files;
  267: 	my @filesfull;
  268: 	foreach my $f (@allfiles) {
  269: 	    if ($f=~/^$d\/([^\/]+)$/) {
  270: 		push @files,$1;
  271: 		push @filesfull,$f;
  272: 	    }
  273: 	}
  274: 	# render starting HTML formatting elements
  275: 	if (@files) {
  276:         }
  277: 	my $pwd=`pwd`; chop $pwd;
  278: 	if (@files) {
  279:             foreach my $i (0..$#files) {
  280: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  281: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  282: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  283: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  284: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  285: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  286: 		my $rot="/".$filesfull[$i];
  287: 		if ($rot=~/\*/) {
  288: 		    $rot=~s/[^\/]+$// if $rot=~/\*/;
  289: 		    my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
  290: 		    chop $listing;
  291: 		    my @list=split(/\s+/,$listing);
  292: 		    my $rot2;
  293: 		    foreach my $l (@list) {
  294: 			$l=~s/^\s*//; $l=~s/\s*$//;
  295: 			$rot2.="BinaryRoot$rot$l\n" if length($l);
  296: 		    }
  297: 		    chop $rot2;
  298: 		    $rot=$rot2;
  299: 		}
  300: 		else {
  301: 		    $rot="BinaryRoot$rot";
  302: 		}
  303: 		if ($category eq "conf") {
  304: 		    $rot.=" # config";
  305: 		}
  306: 		$description.=<<END;
  307: $rot
  308: END
  309: 	    }
  310: 	}
  311:     }
  312:     $description.=<<END;
  313: 
  314: END
  315:     return $description;
  316: }
  317: 
  318: # --------------------------------- Commands to make BinaryRoot directories
  319: sub make_directory_binaryroot_segment {
  320:     my ($dirs)=@_;
  321:     my $description=<<END;
  322: directories:
  323: END
  324:     foreach my $d (@$dirs) {
  325: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  326: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  327: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  328: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  329: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  330: 	my ($owner,$group)=split(/\:/,$devchown);
  331: 	my $own=$devchown; $own=~s/\:/\,/;
  332: 	$description.=<<END;
  333: \tinstall -o $owner -g $group -m $devchmod -d \$(TARGET)/$d
  334: END
  335:     }
  336:     $description.=<<END;
  337: 
  338: END
  339:     return $description;
  340: }
  341: 
  342: # --------------------------------------- Commands to make BinaryRoot files
  343: sub make_files_binaryroot_segment {
  344:     my ($dirs)=@_;
  345:     my $description=<<END;
  346: files:
  347: END
  348:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  349:     foreach my $d (@$dirs) {
  350: 	# set other values
  351: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  352: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  353: 	# find files that are contained in this directory
  354: 	my @files;
  355: 	my @filesfull;
  356: 	foreach my $f (@allfiles) {
  357: 	    if ($f=~/^$d\/([^\/]+)$/) {
  358: 		push @files,$1;
  359: 		push @filesfull,$f;
  360: 	    }
  361: 	}
  362: 	# render starting HTML formatting elements
  363: 	if (@files) {
  364: 	    $description.=<<END;
  365: \t# $d $dirdescription
  366: END
  367:         }
  368: 	if (@files) {
  369:             foreach my $i (0..$#files) {
  370: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  371: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  372: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  373: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  374: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  375: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  376: 		my $rot=$filesfull[$i];
  377: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  378: 		my ($owner,$group)=split(/\:/,$devchown);
  379: 		$description.=<<END if $category ne 'symbolic link';
  380: \tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  381: END
  382: 	    }
  383: 	}
  384:     }
  385:     $description.=<<END;
  386: 
  387: END
  388:     return $description;
  389: }
  390: 
  391: # ------------------------------ Commands to make BinaryRoot symbolic links
  392: sub make_links_binaryroot_segment {
  393:     my ($dirs)=@_;
  394:     my $description=<<END;
  395: links:
  396: END
  397:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  398:     foreach my $d (@$dirs) {
  399: 	# find files that are contained in this directory
  400: 	my @files;
  401: 	my @filesfull;
  402: 	foreach my $f (@allfiles) {
  403: 	    if ($f=~/^$d\/([^\/]+)$/) {
  404: 		push @files,$1;
  405: 		push @filesfull,$f;
  406: 	    }
  407: 	}
  408: 	# render starting HTML formatting elements
  409: 	if (@files) {
  410:             foreach my $i (0..$#files) {
  411: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  412: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  413: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  414: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  415: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  416: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  417: 		$description.=<<END if $category eq 'symbolic link';
  418: \tln -s /$linkto \$(TARGET)/$filesfull[$i]
  419: END
  420: 	    }
  421: 	}
  422:     }
  423:     $description.=<<END;
  424: 
  425: END
  426:     return $description;
  427: }
  428: 
  429: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
  430: sub make_directory_LCMakefile_segment {
  431:     my ($dirs)=@_;
  432:     my $description=<<END;
  433: directories:
  434: END
  435:     foreach my $d (@$dirs) {
  436: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  437: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  438: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  439: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  440: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  441: 	my $own=$devchown; $own=~s/\:/\,/;
  442: 	$description.=<<END;
  443: \tinstall -m $devchmod -d \$(SOURCE)/$d \$(ROOT)/$d
  444: END
  445:     }
  446:     $description.=<<END;
  447: 
  448: END
  449:     return $description;
  450: }
  451: 
  452: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
  453: sub make_files_LCMakefile_segment {
  454:     my ($dirs)=@_;
  455:     my $description=<<END;
  456: files:
  457: END
  458:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  459:     foreach my $d (@$dirs) {
  460: 	# set other values
  461: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  462: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  463: 	# find files that are contained in this directory
  464: 	my @files;
  465: 	my @filesfull;
  466: 	foreach my $f (@allfiles) {
  467: 	    if ($f=~/^$d\/([^\/]+)$/) {
  468: 		push @files,$1;
  469: 		push @filesfull,$f;
  470: 	    }
  471: 	}
  472: 	# render starting HTML formatting elements
  473: 	if (@files) {
  474: 	    $description.=<<END;
  475: \t# $d $dirdescription
  476: END
  477:         }
  478: 	if (@files) {
  479:             foreach my $i (0..$#files) {
  480: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  481: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  482: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  483: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  484: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  485: 		my $rot=$filesfull[$i];
  486: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  487: 		$description.=<<END if $category ne 'symbolic link';
  488: \tinstall -m $devchmod \$(SOURCE)/$filesfull[$i] \$(ROOT)/$rot
  489: END
  490: 	    }
  491: 	}
  492:     }
  493:     $description.=<<END;
  494: 
  495: END
  496:     return $description;
  497: }
  498: 
  499: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
  500: sub make_links_LCMakefile_segment {
  501:     my ($dirs)=@_;
  502:     my $description=<<END;
  503: links:
  504: END
  505:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  506:     foreach my $d (@$dirs) {
  507: 	# find files that are contained in this directory
  508: 	my @files;
  509: 	my @filesfull;
  510: 	foreach my $f (@allfiles) {
  511: 	    if ($f=~/^$d\/([^\/]+)$/) {
  512: 		push @files,$1;
  513: 		push @filesfull,$f;
  514: 	    }
  515: 	}
  516: 	# render starting HTML formatting elements
  517: 	if (@files) {
  518:             foreach my $i (0..$#files) {
  519: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  520: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  521: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  522: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  523: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  524: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  525: 		$description.=<<END if $category eq 'symbolic link';
  526: \tln -s /$linkto \$(ROOT)/$filesfull[$i]
  527: END
  528: 	    }
  529: 	}
  530:     }
  531:     $description.=<<END;
  532: 
  533: END
  534:     return $description;
  535: }
  536: 
  537: # --------------------------------- Installation commands to install directories
  538: sub make_directory_install_segment {
  539:     my ($dirs)=@_;
  540:     my $description=<<END;
  541: directories:
  542: END
  543:     foreach my $d (@$dirs) {
  544: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  545: 	my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  546: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  547: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  548: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  549: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  550: 	my ($owner,$group)=split(/\:/,$devchown);
  551: 	my $own=$devchown; $own=~s/\:/\,/;
  552: 	$description.=<<END;
  553: \tinstall -o $owner -g $group -m $devchmod -d \$(TARGET)/$d
  554: END
  555:     }
  556:     $description.=<<END;
  557: 
  558: END
  559:     return $description;
  560: }
  561: 
  562: # ------------------------------------------------------ Commands to build files
  563: sub make_files_build_segment {
  564:     my ($dirs)=@_;
  565:     my $description;
  566:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  567:     my $tab="\t";
  568:     my $sources="all: ";
  569:     foreach my $d (@$dirs) {
  570: 	# set other values
  571: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  572: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  573: 	# find files that are contained in this directory
  574: 	my @files;
  575: 	my @filesfull;
  576: 	foreach my $f (@allfiles) {
  577: 	    if ($f=~/^$d\/([^\/]+)$/) {
  578: 		push @files,$1;
  579: 		push @filesfull,$f;
  580: 	    }
  581: 	}
  582: 	if (@files) {
  583:             foreach my $i (0..$#files) {
  584: 		# if has build information, output appropriate something
  585: 		my $build=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'BUILD'};
  586: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  587: 		$build=~s/^\s+//; $build=~s/\s+$//;
  588: 		if ($build) {
  589: 		    my $dependencies=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DEPENDENCIES'};
  590: 		    my $source2=$source;
  591: 		    $source2=~s/^[^\/]+\///;
  592:  		    $source2="../" . $source2;
  593: 		    $sources.="$source2 ";
  594: 		    my $directory=$build;
  595: 		    $directory=~s/^[^\/]+\///;
  596: 		    $directory=~s/([^\/]+)$//;
  597:  		    $directory="../" . $directory;
  598: 		    my $buildfile=$1;
  599: 		    my $sdir=$source;
  600: 		    $sdir=~s/^[^\/]+\///;
  601: 		    $sdir=~s/([^\/]+)$//;
  602:  		    $sdir="../" . $sdir;
  603: 		    $dependencies=~s/\s+$//;
  604: 		    my $depstat="";
  605: 		    if ($dependencies=~s/\s+\[ALWAYS_RUN_BUILD_COMMAND\]//) {
  606: 			$depstat=" alwaysrun";
  607: 		    }
  608: 		    $dependencies=~s/\s+/ $sdir/gs;
  609: 		    $description.=<<END;
  610: $source2: $dependencies$depstat
  611: ${tab}cd $directory; sh ./$buildfile
  612: 
  613: END
  614: 		}
  615: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  616: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  617: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  618: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  619: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  620: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  621: 		my $rot=$filesfull[$i];
  622: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  623: #		$description.=<<END if $category ne 'symbolic link';
  624: #\tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  625: #END
  626: 	    }
  627: 	}
  628:     }
  629:     $description.=<<END;
  630: alwaysrun:
  631: 
  632: END
  633:     $sources.="\n\n";
  634:     return ($sources . $description);
  635: }
  636: 
  637: # --------------------------------------- Installation commands to install files
  638: sub make_files_install_segment {
  639:     my ($dirs)=@_;
  640:     my $description=<<END;
  641: files:
  642: END
  643:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  644:     foreach my $d (@$dirs) {
  645: 	# set other values
  646: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  647: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  648: 	# find files that are contained in this directory
  649: 	my @files;
  650: 	my @filesfull;
  651: 	foreach my $f (@allfiles) {
  652: 	    if ($f=~/^$d\/([^\/]+)$/) {
  653: 		push @files,$1;
  654: 		push @filesfull,$f;
  655: 	    }
  656: 	}
  657: 	# render starting HTML formatting elements
  658: 	if (@files) {
  659: 	    $description.=<<END;
  660: \t# $d $dirdescription
  661: END
  662:         }
  663: 	if (@files) {
  664:             foreach my $i (0..$#files) {
  665: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  666: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  667: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  668: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  669: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  670: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  671: 		my $rot=$filesfull[$i];
  672: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  673: 		my ($owner,$group)=split(/\:/,$devchown);
  674: 		if ($category ne 'conf') {
  675: 		    $description.=<<END if $category ne 'symbolic link';
  676: \tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  677: END
  678:                 }
  679: 	    }
  680: 	}
  681:     }
  682:     $description.=<<END;
  683: 
  684: END
  685:     return $description;
  686: }
  687: 
  688: # ------ Installation commands to install configuration files (and make backups)
  689: sub make_files_configinstall_segment {
  690:     my ($dirs)=@_;
  691:     my $description=<<END;
  692: configfiles:
  693: END
  694:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  695:     foreach my $d (@$dirs) {
  696: 	# set other values
  697: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  698: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  699: 	# find files that are contained in this directory
  700: 	my @files;
  701: 	my @filesfull;
  702: 	foreach my $f (@allfiles) {
  703: 	    if ($f=~/^$d\/([^\/]+)$/) {
  704: 		push @files,$1;
  705: 		push @filesfull,$f;
  706: 	    }
  707: 	}
  708: 	# render starting HTML formatting elements
  709: 	if (@files) {
  710: 	    $description.=<<END;
  711: \t# $d $dirdescription
  712: END
  713:         }
  714: 	if (@files) {
  715:             foreach my $i (0..$#files) {
  716: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  717: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  718: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  719: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  720: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  721: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  722: 		my $rot=$filesfull[$i];
  723: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  724: 		my ($owner,$group)=split(/\:/,$devchown);
  725: 		if ($category eq 'conf') {
  726: 		    $description.=<<END;
  727: \tinstall -b -S `date +'.\%Y\%m\%d\%H\%M\%S'` -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  728: END
  729:                 }
  730: 	    }
  731: 	}
  732:     }
  733:     $description.=<<END;
  734: 
  735: END
  736:     return $description;
  737: }
  738: 
  739: # ------ Commands to enforce configuration file permissions
  740: sub make_files_configpermissions_segment {
  741:     my ($dirs)=@_;
  742:     my $description=<<END;
  743: configpermissions:
  744: END
  745:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  746:     foreach my $d (@$dirs) {
  747: 	# set other values
  748: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  749: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  750: 	# find files that are contained in this directory
  751: 	my @files;
  752: 	my @filesfull;
  753: 	foreach my $f (@allfiles) {
  754: 	    if ($f=~/^$d\/([^\/]+)$/) {
  755: 		push @files,$1;
  756: 		push @filesfull,$f;
  757: 	    }
  758: 	}
  759: 	# render starting HTML formatting elements
  760: 	if (@files) {
  761: 	    $description.=<<END;
  762: \t# $d $dirdescription
  763: END
  764:         }
  765: 	if (@files) {
  766:             foreach my $i (0..$#files) {
  767: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  768: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  769: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  770: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  771: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  772: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  773: 		my $rot=$filesfull[$i];
  774: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  775: 		my ($owner,$group)=split(/\:/,$devchown);
  776: 		if ($category eq 'conf') {
  777: 		    $description.=<<END;
  778: \tchmod $devchmod \$(TARGET)/$rot
  779: \tchown $devchown \$(TARGET)/$rot
  780: END
  781:                 }
  782: 	    }
  783: 	}
  784:     }
  785:     $description.=<<END;
  786: 
  787: END
  788:     return $description;
  789: }
  790: 
  791: # ------------------------------ Installation commands to install symbolic links
  792: sub make_links_install_segment {
  793:     my ($dirs)=@_;
  794:     my $description=<<END;
  795: links:
  796: END
  797:     chop $description;
  798:     my $description2;
  799:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  800:     foreach my $d (@$dirs) {
  801: 	# find files that are contained in this directory
  802: 	my @files;
  803: 	my @filesfull;
  804: 	foreach my $f (@allfiles) {
  805: 	    if ($f=~/^$d\/([^\/]+)$/) {
  806: 		push @files,$1;
  807: 		push @filesfull,$f;
  808: 	    }
  809: 	}
  810: 	# render starting HTML formatting elements
  811: 	if (@files) {
  812:             foreach my $i (0..$#files) {
  813: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  814: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  815: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  816: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  817: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  818: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  819: 		if ($category eq 'symbolic link') {
  820: 		    $description.=" \$(TARGET)/$filesfull[$i]";
  821: 		    $description2.=<<END;
  822: \$(TARGET)/$filesfull[$i]:
  823: \tln -s /$linkto \$(TARGET)/$filesfull[$i]
  824: 
  825: END
  826:                 }
  827: 	    }
  828: 	}
  829:     }
  830:     $description.=<<END;
  831: 
  832: END
  833:     $description.=$description2;
  834:     return $description;
  835: }
  836: 
  837: # --------------------------------------------------------- Make RPM .spec block
  838: sub make_rpm_spec_block {
  839:     my $pwd=`pwd`; chop $pwd;
  840:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
  841:     my $source=$info{'RPM'}{'Name'} . "-" . $info{'RPM'}{'Version'} . '.tar.gz';
  842:     my $description=<<END;
  843: Summary: $info{'RPM'}{'Summary'}
  844: Name: $info{'RPM'}{'Name'}
  845: Version: $info{'RPM'}{'Version'}
  846: Release: $info{'RPM'}{'Release'}
  847: Vendor: $info{'RPM'}{'Vendor'} 
  848: BuildRoot: $buildroot
  849: Copyright: $info{'RPM'}{'Copyright'}
  850: Group: $info{'RPM'}{'Group'}
  851: Source: $source
  852: AutoReqProv: $info{'RPM'}{'AutoReqProv'}
  853: \%description
  854: $info{'RPM'}{'description'}
  855: 
  856: END
  857:     return $description;
  858: }
  859: 
  860: # --------------------------------------------------- Make RPM build .spec block
  861: sub make_rpm_build_block {
  862:     my $pwd=`pwd`; chop $pwd;
  863:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
  864:     my $sourceroot="$pwd/LON-CAPA-SourceRoot";
  865:     my $description=<<END;
  866: 
  867: \%prep
  868: \%setup
  869: 
  870: \%build
  871: rm -Rf "$buildroot"
  872: 
  873: \%install
  874: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" directories
  875: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" files
  876: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" links
  877: 
  878: \%pre
  879: $info{'RPM'}{'pre'}
  880: 
  881: \%post
  882: \%postun
  883: 
  884: \%files
  885: # \%doc README COPYING ChangeLog LICENSE
  886: END
  887:     return $description;
  888: }
  889: 
  890: # ------------------------------------- Make directory structure RPM .spec block
  891: sub make_directory_structure_spec_block {
  892:     my ($dirs)=@_;
  893:     foreach my $d (@$dirs) {
  894: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  895: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  896: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  897: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  898: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  899: 	my $own=$devchown; $own=~s/\:/\,/;
  900: 	$description.=<<END;
  901: \%dir \%attr($devchmod,$own) /$d
  902: END
  903:     }
  904:     return $description;
  905: }
  906: 
  907: # ---------------------------- Make directory and file structure RPM .spec block
  908: sub make_directory_and_file_structure_spec_block {
  909:     my ($dirs)=@_;
  910:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  911:     foreach my $d (@$dirs) {
  912: 	# set other values
  913: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  914: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  915: 	# find files that are contained in this directory
  916: 	my @files;
  917: 	my @filesfull;
  918: 	foreach my $f (@allfiles) {
  919: 	    if ($f=~/^$d\/([^\/]+)$/) {
  920: 		push @files,$1;
  921: 		push @filesfull,$f;
  922: 	    }
  923: 	}
  924: 	# render starting HTML formatting elements
  925: 	if (@files) {
  926: 	    $description.=<<END;
  927: # $d $dirdescription
  928: END
  929:         }
  930: 	if (@files) {
  931:             foreach my $i (0..$#files) {
  932: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  933: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  934: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  935: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  936: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  937: 		my $own=$devchown; $own=~s/\:/\,/;
  938: 		my $config="";
  939: 		$config="\%config " if $category eq 'conf';
  940: 		$devchmod='-' if $category eq 'symbolic link';
  941: 		$description.=<<END;
  942: $config\%attr($devchmod,$own) /$filesfull[$i]
  943: END
  944: 	    }
  945: 	}
  946:     }
  947:     return $description;
  948: }
  949: 
  950: # ----------------------------------------------------------- End RPM .spec page
  951: sub end_spec_page {
  952: }
  953: 
  954: # ------------------------------------------------------- Begin description page
  955: sub begin_description_page {
  956:     my ($mode)=@_;
  957:     my $description;
  958:     unless ($mode eq 'status') {
  959:     $description=<<END;
  960: <HTML>
  961: <HEAD>
  962: <TITLE>LON-CAPA Software Description Page ($distribution, $date)</TITLE>
  963: </HEAD>
  964: <BODY>
  965: <FONT SIZE=+2>LON-CAPA Software Description Page ($distribution, $date)</FONT>
  966: <BR>Michigan State University
  967: <BR>Learning Online with CAPA
  968: <BR>Contact korte\@lon-capa.org
  969: <UL>
  970: <LI>About this file
  971: <LI>Software Package Description
  972: <LI>Directory Structure
  973: <LI>File Type Ownership and Permissions
  974: <LI>File and Directory Structure
  975: </UL>
  976: <FONT SIZE=+2>About this file</FONT>
  977: <P>
  978: This file is generated dynamically by <TT>parse.pl</TT> as
  979: part of a development compilation process.  See 
  980: http://install.lon-capa.org/compile/index.html for more
  981: information.
  982: </P>
  983: END
  984: }
  985:     else {
  986: 	$description=<<END;
  987: <HTML>
  988: <HEAD>
  989: <TITLE>LON-CAPA Software File System Status Page ($distribution, $date)</TITLE>
  990: </HEAD>
  991: <BODY>
  992: <FONT SIZE=+2>LON-CAPA Software File System Status Page ($distribution, $date)</FONT>
  993: <BR>Michigan State University
  994: <BR>Learning Online with CAPA
  995: <BR>Contact korte\@lon-capa.org
  996: <UL>
  997: <LI>About this file
  998: <LI>Software Package Description
  999: <LI>Directory Structure
 1000: <LI>File Type Ownership and Permissions
 1001: <LI>File and Directory Structure
 1002: </UL>
 1003: <FONT SIZE=+2>About this file</FONT>
 1004: <P>
 1005: This file is generated dynamically by <TT>parse.pl</TT> as
 1006: part of a status checking process.  See http://install.lon-capa.org/
 1007: for more information.
 1008: </P>
 1009: END
 1010:     }
 1011:     return $description;
 1012: 
 1013: }
 1014: 
 1015: # ------------------------------------------------- End description page
 1016: sub end_description_page {
 1017:     my $description=<<END;
 1018: <HR>
 1019: <FONT SIZE=-1>LON-CAPA Software Development Team</FONT>
 1020: </BODY>
 1021: </HTML>
 1022: END
 1023:     return $description;
 1024: }
 1025: 
 1026: # ------------------------------------------------- Make RPM description block
 1027: sub make_rpm_description_block {
 1028:     my ($mode)=@_;
 1029:     my $description;
 1030:     unless ($mode eq 'status') {
 1031:     $description=<<END;
 1032: <FONT SIZE=+2>Rolled in a RedHat 6.2 RPM, $date</FONT>
 1033: <P>
 1034: <TABLE BGCOLOR=#FFFFFF BORDER=0 CELLPADDING=10 CELLSPACING=0>
 1035: <TR><TD>
 1036: <PRE>
 1037: Name        : $info{'RPM'}{'Name'}
 1038: Version     : $info{'RPM'}{'Version'}
 1039: Vendor      : $info{'RPM'}{'Vendor'} 
 1040: Release     : $info{'RPM'}{'Release'}                             
 1041: Build Host  : $buildhost
 1042: Group       : $info{'RPM'}{'Group'}
 1043: License     : $info{'RPM'}{'Copyright'}
 1044: Summary     : $info{'RPM'}{'Summary'}
 1045: Description : 
 1046: $info{'RPM'}{'description'}
 1047: </PRE>
 1048: </TD></TR>
 1049: </TABLE>
 1050: </P>
 1051: END
 1052: }
 1053:     else {
 1054: 	my $exist=`rpm -q LON-CAPA-base 2>/dev/null`;
 1055: 	unless ($exist) {
 1056: 	    $description=<<END;
 1057: <FONT SIZE=+2>No LON-CAPA RPM on the system, (installed ??????)</FONT>
 1058: <P>
 1059: <TABLE BGCOLOR=#FFFFFF BORDER=0 CELLPADDING=10 CELLSPACING=0>
 1060: <TR><TD>
 1061: <FONT SIZE=+3>Error! A LON-CAPA-base RPM
 1062: was never installed on this system!</FONT>
 1063: </TD></TR>
 1064: </TD></TR>
 1065: </TABLE>
 1066: </P>
 1067: END
 1068: 	}
 1069: 	else {
 1070: 	    chop $exist;
 1071: 	    my $rpmname=`rpm -q --queryformat '%{NAME}' LON-CAPA-base`;
 1072: 	    my $rpmversion=`rpm -q --queryformat '%{VERSION}' LON-CAPA-base`;
 1073: 	    my $rpmrelease=`rpm -q --queryformat '%{RELEASE}' LON-CAPA-base`;
 1074: 	    my $idate=`rpm -q --queryformat '%{INSTALLTIME:date}' LON-CAPA-base`;
 1075: 	    my $rpmvendor=`rpm -q --queryformat '%{VENDOR}' LON-CAPA-base`;
 1076: 	    my $rpmbuildhost=`rpm -q --queryformat '%{BUILDHOST}' LON-CAPA-base`;
 1077: 	    my $rpmgroup=`rpm -q --queryformat '%{GROUP}' LON-CAPA-base`;
 1078: 	    my $rpmlicense=`rpm -q --queryformat '%{LICENSE}' LON-CAPA-base`;
 1079: 	    my $rpmsummary=`rpm -q --queryformat '%{SUMMARY}' LON-CAPA-base`;
 1080: 	    my $rpmdescription=`rpm -q --queryformat '%{DESCRIPTION}' LON-CAPA-base`;
 1081: 	    $description=<<END;
 1082: <FONT SIZE=+2>Current RedHat RPM on the system, (installed $idate)</FONT>
 1083: <P>
 1084: <TABLE BGCOLOR=#FFFFFF BORDER=0 CELLPADDING=10 CELLSPACING=0>
 1085: <TR><TD>
 1086: <PRE>
 1087: Name        : $rpmname
 1088: Version     : $rpmversion
 1089: Vendor      : $rpmvendor
 1090: Release     : $rpmrelease
 1091: Build Host  : $rpmbuildhost
 1092: Group       : $rpmgroup
 1093: License     : $rpmlicense
 1094: Summary     : $rpmsummary
 1095: Description : 
 1096: $rpmdescription
 1097: </PRE>
 1098: </TD></TR>
 1099: </TABLE>
 1100: </P>
 1101: END
 1102: }
 1103:     }
 1104:     return $description;
 1105: }
 1106: 
 1107: # ----------------------------------------------- Determine directory structure
 1108: sub determine_directory_structure {
 1109:     my @directories=keys %{$info{'DIRECTORY'}{$distribution}};
 1110:     return (sort @directories);
 1111: }
 1112: 
 1113: 
 1114: # ---------------------------------- Make directory structure description block
 1115: sub make_directory_structure_description_block {
 1116:     my ($dirs,$mode)=@_;
 1117:     my $dirstatus; my $statusheader;
 1118:     my $description=<<END;
 1119: <FONT SIZE=+2>Directory Structure Description, $date</FONT>
 1120: <P>
 1121: The directory structure description below shows only those
 1122: directories which either contain LON-CAPA specific files
 1123: or normally do not exist on a RedHat Linux system (and
 1124: must be generated to allow proper placement of files
 1125: during LON-CAPA run-time operation).
 1126: </P>
 1127: <P>
 1128: <TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0>
 1129: END
 1130:     my $maxcount=0;
 1131:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
 1132:     my %diraccount; # hash to track which directories are accounted for
 1133:     foreach my $file (@allfiles) {
 1134: 	$file=~/^(.*)\/([^\/]+)$/;
 1135: 	$diraccount{$1}=1;
 1136:     }
 1137:     foreach my $d (@$dirs) {
 1138:         my (@matches)=($d=~/\//g);
 1139: 	my $count=scalar(@matches);
 1140: 	$maxcount=$count if $count>$maxcount;
 1141: 	delete $diraccount{$d};
 1142:     }
 1143:     if ($mode eq 'status') {
 1144: 	$statusheader="<TH ALIGN=LEFT BGCOLOR=#FFFFFF>Current Status</TH>";
 1145:     }
 1146:     $description.=<<END;
 1147: <TR>
 1148: $statusheader
 1149: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Category</TH>
 1150: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
 1151: <TH ALIGN=LEFT BGCOLOR=#FFFFFF><FONT COLOR=#FF0000>Development<BR>Permissions</FONT></TH>
 1152: END
 1153:     $description.="<TH ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+1).">Directory Path</TH>\n";
 1154:     if (keys %diraccount) {
 1155: 	$description.= "<TR><TD ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+4)."><I><PRE>Directories that are unaccounted for: \n";
 1156: 	foreach my $d (keys %diraccount) {
 1157: 	    $description.="$d\n";
 1158: 	}
 1159: 	$description.="</PRE></I></TH></TR>\n";
 1160:     }
 1161:     foreach my $d (@$dirs) {
 1162: 	my $dtable=$d;
 1163: 	$dtable=~s/\//\<\/TD\>\<TD\>/g;
 1164: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
 1165: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
 1166: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
 1167: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
 1168: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
 1169: 	if ($mode eq 'status') {
 1170: 	    my $ds=`find /$d -type d -prune -printf "\%m\t\%u\t\%g" 2>/dev/null`;
 1171: 	    unless ($ds) {
 1172: 		$dirstatus='<TD BGCOLOR=#FFFFFF><B><U>MISSING</U></B></TD>';
 1173: 	    }
 1174: 	    else {
 1175: 		my @dss=split(/\t/,$ds);
 1176: 		my $dssz=$dss[0];
 1177: 		$dssz="0" . $dss[0] if length($dss[0])<4;
 1178: 		$dss[0]=$dssz;
 1179: 		$ds="$dss[0] $dss[1]:$dss[2]";
 1180: 		if ($ds eq "$chmod $chown" && $ds eq "$devchmod $devchown") {
 1181: 		    $dirstatus='<TD BGCOLOR=#FFFFFF>runtime+development</TD>';
 1182: 		}
 1183: 		elsif ($ds eq "$chmod $chown") {
 1184: 		    $dirstatus='<TD BGCOLOR=#FFFFFF>runtime</TD>';
 1185: 		}
 1186: 		elsif ($ds eq "$devchmod $devchown") {
 1187: 		    $dirstatus='<TD BGCOLOR=#FFFFFF>development</TD>';
 1188: 		}
 1189: 		else {
 1190: 		    $dirstatus="<TD BGCOLOR=#FFFFFF><B><U>ERROR</U></B><BR>$ds</TD>";
 1191: 		}
 1192: 	    }
 1193: 	}
 1194: 	$description.=<<END;
 1195: <TR>
 1196: $dirstatus
 1197: <TD BGCOLOR=#FFFFFF>$category</TD>
 1198: <TD BGCOLOR=#FFFFFF><TT>$chmod $chown</TT></TD>
 1199: <TD BGCOLOR=#FFFFFF><FONT COLOR=#FF0000><TT>$devchmod $devchown</TT></FONT></TD>
 1200: <TD>
 1201: $dtable
 1202: </TD>
 1203: </TR>
 1204: END
 1205:     }
 1206:     $description.=<<END;
 1207: </TABLE>
 1208: </P>
 1209: END
 1210:     return $description;
 1211: }
 1212: 
 1213: # ------------------- Make file type ownership and permissions description block
 1214: sub make_file_type_ownership_and_permissions_description_block {
 1215:     my ($mode)=@_;
 1216:     my $description=<<END;
 1217: <FONT SIZE=+2>File Type Ownership and Permissions Descriptions, $date</FONT>
 1218: <P>
 1219: This table shows what permissions and ownership settings correspond
 1220: to each kind of file type.
 1221: </P>
 1222: <P>
 1223: <TABLE BORDER=1 CELLPADDING=5 WIDTH=60%>
 1224: <TR>
 1225: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Icon</TH>
 1226: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Type</TH>
 1227: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
 1228: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Development Permissions</TH>
 1229: </TR>
 1230: END
 1231:     foreach my $type (keys %{$info{'OWNERSHIP'}}) {
 1232: 	if (defined($fcm{$type})) {
 1233: 	    my $chmod=$info{'OWNERSHIP'}{$type}{'CHMOD'};
 1234: 	    my $chown=$info{'OWNERSHIP'}{$type}{'CHOWN'};
 1235: 	    my $devchmod=$info{'DEVOWNERSHIP'}{$type}{'CHMOD'};
 1236: 	    my $devchown=$info{'DEVOWNERSHIP'}{$type}{'CHOWN'};
 1237: 	    $description.=<<END;
 1238: <TR>
 1239: <TD><IMG SRC="$fcm{$type}.gif" ALT="$type"></TD>
 1240: <TD>$type</TD>
 1241: <TD><TT>$chmod $chown</TT></TD>
 1242: <TD><TT>$devchmod $devchown</TT></TD>
 1243: </TR>
 1244: END
 1245:         }
 1246:     }
 1247:     $description.=<<END;
 1248: </TABLE>
 1249: </P>
 1250: END
 1251: }
 1252: 
 1253: # ------------------------- Make directory and file structure description block
 1254: sub make_directory_and_file_structure_description_block {
 1255:     my ($dirs,$mode)=@_;
 1256:     my $statusheader; my $filestatus;
 1257:     my $description=<<END;
 1258: <FONT SIZE=+2>Directory and File Structure Description, $date</FONT>
 1259: <P>
 1260: The icons on the left column correspond to the file type
 1261: specified in the second column.  The last column "Notes" shows compilation,
 1262: dependency, and configuration information.  The CVS location
 1263: shows the location of the binary source file (if applicable) needed to
 1264: be copied to the target.  If the binary source file is not at
 1265: the specified location, then the text is shown in 
 1266: <FONT COLOR=#FF0000>red</FONT>.
 1267: </P>
 1268: <P>
 1269: <TABLE BORDER=1 CELLPADDING=5 WIDTH=500>
 1270: END
 1271:     my $counter=0;
 1272:     my @colorindex=("#80FF80","#80FFFF","#FFFF80");
 1273:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
 1274:     foreach my $d (@$dirs) {
 1275: 	# set color
 1276: 	my $color=$colorindex[$counter%3];
 1277: 	# set other values
 1278: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
 1279: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
 1280: 	# find subdirectories that are contained in this directory
 1281: 	my @subdirs;
 1282: 	foreach my $d2 (@$dirs) {
 1283: 	    if ($d2=~/^$d\/([^\/]+)$/) {
 1284: 		push @subdirs,$1;
 1285: 	    }
 1286: 	}
 1287: 	# find files that are contained in this directory
 1288: 	my @files;
 1289: 	my @filesfull;
 1290: 	foreach my $f (@allfiles) {
 1291: 	    if ($f=~/^$d\/([^\/]+)$/) {
 1292: 		push @files,$1;
 1293: 		push @filesfull,$f;
 1294: 	    }
 1295: 	}
 1296: 	# render starting HTML formatting elements
 1297: 	if (@subdirs || @files) {
 1298: 	    my $subdirstring="<BR>* Relevant subdirectories: " . join(", ",@subdirs) if @subdirs;
 1299: 	    $description.=<<END;
 1300: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="directory.gif" ALT="directory">DIRECTORY -- $d $dirdescription
 1301: $subdirstring</FONT></TD></TR>
 1302: END
 1303:         }
 1304: 	else {
 1305: 	    $description.=<<END;
 1306: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="emptydirectory.gif" ALT="empty directory">EMPTY DIRECTORY - $d $dirdescription</FONT></TD></TR>
 1307: END
 1308:         }
 1309: 	if (@files) {
 1310: 	    if ($mode eq 'status') {
 1311: 		$statusheader=<<END;
 1312: <TH BGCOLOR=$color ALIGN=LEFT>Current Status</TH>
 1313: END
 1314: 	    }
 1315: 	    $description.=<<END;
 1316: <TR>
 1317: $statusheader
 1318: <TH BGCOLOR=$color ALIGN=LEFT COLSPAN=2>Type</TH>
 1319: <TH BGCOLOR=$color ALIGN=LEFT>File Name</TH>
 1320: <TH BGCOLOR=$color ALIGN=LEFT>Function</TH>
 1321: <TH BGCOLOR=$color ALIGN=LEFT>CVS Location</TH>
 1322: <TH BGCOLOR=$color ALIGN=LEFT>Notes</TH>
 1323: </TR>
 1324: END
 1325:             foreach my $i (0..$#files) {
 1326: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
 1327: 		my $fdescription=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DESCRIPTION'};
 1328: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
 1329: 		my $note=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'NOTE'};
 1330: 		$note.="<BR>" if $note;
 1331: 		my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
 1332: 		my @E=split(/\s+/,$listing);
 1333: 		$source=~/(.*)\/[^\/]+$/;
 1334: 		my $sd=$1;
 1335: 		my $eflag=0;
 1336: 		foreach my $e (@E) {
 1337: 		    unless (-e "../../$sd/$e") {
 1338: 			$e="<FONT COLOR=#FF0000>$e</FONT>";
 1339: 			$eflag=1;
 1340: 		    }
 1341: 		}
 1342: 		$listing=join("\n",@E);
 1343: 		$listing="<B>listing</B><BR><FONT SIZE=-2>$listing</FONT>" if $listing;
 1344: 		$listing.="<BR>" if $listing;
 1345: 		my $build=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'BUILD'};
 1346: 		$build="<B>build</B><BR>$build" if $build;
 1347: 		$build.="<BR>" if $build;
 1348: 		my $dependencies=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DEPENDENCIES'};
 1349: 		$dependencies="<B>dependencies</B><BR>$dependencies" if $dependencies;
 1350: 		$dependencies.="<BR>" if $dependencies;
 1351: 		unless (-e "../../$source") {
 1352: 		    $source=~/([^\/]+)$/;
 1353: 		    my $s=$1;
 1354: 		    if ($source!~/\*/) {
 1355: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
 1356: 		    }
 1357: 		    elsif ($eflag) {
 1358: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
 1359: 		    }
 1360: 		}
 1361: 		if ($mode eq 'status') {
 1362: 		    $filestatus='';
 1363: 		    my $fs;
 1364: 		    my $listing2=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
 1365: 		    my @E=split(/\s+/,$listing2); shift @E;
 1366: 		    if (@E) {
 1367: 			$fs=`find /$filesfull[$i] -prune -printf "\%m\t\%u\t\%g\n" 2>/dev/null | wc -l`; chop $fs;
 1368: 			if ($fs!=(@E+0)) {
 1369: 			    $ecount=(@E+0);
 1370: 			    $estuff=join(",",@E);
 1371: 			    $filestatus="<TD BGCOLOR=#FFFFFF><B><U>ERROR. SOME FILES ARE MISSING</U></B></TD>";
 1372: 			}
 1373: 			$fs=`find /$filesfull[$i] -prune -printf "\%m\t\%u\t\%g\n" 2>/dev/null | sort | uniq | wc -l`; chop $fs;
 1374: 			if ($fs!=1) {
 1375: 			    $filestatus='<TD BGCOLOR=#FFFFFF><B><U>ERROR. THERE ARE MULTIPLE OWNERSHIPS/PERMISSIONS WHEN ALL THESE FILES SHOULD HAVE THE SAME CONFIGURATION</U></B></TD>';
 1376: 			}
 1377: 			else {
 1378: 			    $fs=`find /$filesfull[$i] -prune -printf "\%m\t\%u\t\%g\n" 2>/dev/null | sort | uniq`; chop $fs;
 1379: 			}
 1380: 		    }
 1381: 		    else {
 1382: 			$fs=`find /$filesfull[$i] -prune -printf "\%m\t\%u\t\%g" 2>/dev/null`;
 1383: 		    }
 1384: 		    my $fsl=`find /$filesfull[$i] -type l -prune -printf "\%m\t\%u\t\%g" 2>/dev/null`;
 1385: 		    unless ($fs || $filestatus) {
 1386: 			$filestatus='<TD BGCOLOR=#FFFFFF><B><U>MISSING</U></B></TD>';
 1387: 		    }
 1388: 		    elsif (!$filestatus) {
 1389: 
 1390: 			$chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
 1391: 			$chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
 1392: 			$devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
 1393: 			$devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
 1394: 
 1395: 			my @fss=split(/\t/,$fs);
 1396: 			my $fssz=$fss[0];
 1397: 			$fssz="0" . $fss[0] if length($fss[0])<4;
 1398: 			$fss[0]=$fssz;
 1399: 			$fs="$fss[0] $fss[1]:$fss[2]";
 1400: 			$s=' ';
 1401: 			if ($fsl) {
 1402: 			    $fs="$fss[1]:$fss[2]";
 1403: 			    $s='';
 1404: 			}
 1405: 			if ($fs eq "$chmod$s$chown" && $fs eq "$devchmod$s$devchown") {
 1406: 			    $filestatus='<TD BGCOLOR=#FFFFFF>runtime+development</TD>';
 1407: 			}
 1408: 			elsif ($fs eq "$chmod$s$chown") {
 1409: 			    $filestatus='<TD BGCOLOR=#FFFFFF>runtime</TD>';
 1410: 			}
 1411: 			elsif ($fs eq "$devchmod$s$devchown") {
 1412: 			    $filestatus='<TD BGCOLOR=#FFFFFF>development</TD>';
 1413: 			}
 1414: 			else {
 1415: 			    $filestatus="<TD BGCOLOR=#FFFFFF><B><U>ERROR</U></B><BR>$fs</TD>";
 1416: 			}
 1417: 		    }
 1418: 		}	    
 1419: 		$description.=<<END;
 1420: <TR>
 1421: $filestatus
 1422: <TD BGCOLOR=#A0A0A0><IMG SRC="$fcm{$category}.gif" ALT="$category"></TD>
 1423: <TD BGCOLOR=$color>$category</TD>
 1424: <TD BGCOLOR=$color>$files[$i]</TD>
 1425: <TD BGCOLOR=$color>$fdescription&nbsp;</TD>
 1426: <TD BGCOLOR=$color>$source</TD>
 1427: <TD BGCOLOR=$color>$note$listing$build$dependencies&nbsp;</TD>
 1428: </TR>
 1429: END
 1430: 	    }
 1431: 	}
 1432: 	$counter++;
 1433:     }
 1434:     $description.=<<END;
 1435: </TABLE>
 1436: </P>
 1437: END
 1438:     return $description;
 1439: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>