Annotation of loncom/build/parse.pl, revision 1.21

1.1       harris41    1: #!/usr/bin/perl
                      2: 
                      3: # Scott Harrison
                      4: # November 2000
                      5: 
1.2       harris41    6: # Read in loncapa tags and metagroup tags
1.1       harris41    7: 
1.4       harris41    8: # ---------------------------------------------- Read in command line arguments
1.1       harris41    9: my ($file,$mode)=@ARGV;
1.2       harris41   10: 
1.4       harris41   11: # ---------------------------------------------------- Read in master data file
1.1       harris41   12: open IN,"<$file";
                     13: my @lines=<IN>;
                     14: close IN;
1.5       harris41   15: my $info1=join('',@lines);
                     16: my $info2=$info1; # value to allow for meta data group retrieval
1.1       harris41   17: 
1.4       harris41   18: # ------------------------------------------------------- Make default settings
                     19: my $distribution="redhat6.2";
                     20: my $date=`date +'%B %e, %Y'`; chop $date;
                     21: my $buildhost=`hostname`; chop $buildhost;
1.5       harris41   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: 	 );
1.4       harris41   35: 
                     36: # ---------------------------------------------------- Parse the marked up data
                     37: my %info; # big data storage object
1.5       harris41   38: while ($info1=~/\<loncapa\s+(.*?)\>/isg) {
1.1       harris41   39:     my $keystring=$1;
1.4       harris41   40:     # In the parsing of LON-CAPA tags, remove boundary white-space,
                     41:     # and handle quotation commands.
1.2       harris41   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);
1.4       harris41   47:     # Handle the different types of commands
1.1       harris41   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") {
1.4       harris41   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'};
1.1       harris41   65:     }
                     66:     elsif (uc($hash{'TYPE'}) eq "LOCATION") {
1.5       harris41   67:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=                               $hash{'CATEGORY'};
1.10      harris41   68:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'LINKTO'}=                               $hash{'LINKTO'};
1.5       harris41   69:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'SOURCE'}=                                               $hash{'SOURCE'};
1.1       harris41   70:         # get surrounding metagroup information
                     71:         my $ckeystring=$keystring; $ckeystring=~s/(SOURCE\=\"[^"]*)\*/$1\\\*/g;
1.5       harris41   72:         $ckeystring=~s/(TARGET\=\"[^"]*)\*/$1\\\*/g;
1.1       harris41   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);
1.9       harris41   79: 		$info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{uc($key)}=
1.4       harris41   80: 		                                                    $value;
1.1       harris41   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: 
1.10      harris41   89: my $a;
                     90: my @directories;
                     91: if ($mode eq "HTML") {
1.4       harris41   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;
1.6       harris41   99:     $a=&make_file_type_ownership_and_permissions_description_block;
                    100:     print $a;
1.4       harris41  101:     $a=&make_directory_and_file_structure_description_block(\@directories);
                    102:     print $a;
                    103:     $a=&end_description_page;
                    104:     print $a;
                    105: }
1.10      harris41  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;
1.14      harris41  124:     $a=&make_directory_LCMakefile_segment(\@directories);
1.10      harris41  125:     print $a;
1.14      harris41  126:     $a=&make_files_LCMakefile_segment(\@directories);
1.10      harris41  127:     print $a;
1.14      harris41  128:     $a=&make_links_LCMakefile_segment(\@directories);
1.10      harris41  129:     print $a;
                    130: }
1.11      harris41  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;
1.21    ! harris41  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:x:0:0:root:/root:/bin/bash
        !           155: bin:x:1:1:bin:/bin:
        !           156: daemon:x:2:2:daemon:/sbin:
        !           157: adm:x:3:4:adm:/var/adm:
        !           158: lp:x:4:7:lp:/var/spool/lpd:
        !           159: sync:x:5:0:sync:/sbin:/bin/sync
        !           160: shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
        !           161: halt:x:7:0:halt:/sbin:/sbin/halt
        !           162: mail:x:8:12:mail:/var/spool/mail:
        !           163: news:x:9:13:news:/var/spool/news:
        !           164: uucp:x:10:14:uucp:/var/spool/uucp:
        !           165: operator:x:11:0:operator:/root:
        !           166: games:x:12:100:games:/usr/games:
        !           167: gopher:x:13:30:gopher:/usr/lib/gopher-data:
        !           168: ftp:x:14:50:FTP User:/home/ftp:
        !           169: nobody:x:99:99:Nobody:/:
        !           170: xfs:x:43:43:X Font Server:/etc/X11/fs:/bin/false
        !           171: gdm:x:42:42::/home/gdm:/bin/bash
        !           172: www:x:500:500:www:/home/www:/bin/bash
        !           173: END
        !           174: close OUT;
        !           175: 
1.11      harris41  176: }
1.10      harris41  177: elsif ($mode eq "status") {
                    178: }
                    179: elsif ($mode eq "update") {
                    180: }
1.16      harris41  181: elsif ($mode eq "configinstall") {
                    182:     @directories=&determine_directory_structure;
                    183:     $a=&make_files_configinstall_segment(\@directories);
                    184:     print $a;
1.17      harris41  185:     $a=&make_files_configpermissions_segment(\@directories);
                    186:     print $a;
1.16      harris41  187: }
1.14      harris41  188: elsif ($mode eq "install") {
                    189:     @directories=&determine_directory_structure;
                    190:     $a=&make_directory_install_segment(\@directories);
                    191:     print $a;
                    192:     $a=&make_files_install_segment(\@directories);
                    193:     print $a;
                    194:     $a=&make_links_install_segment(\@directories);
                    195:     print $a;
1.11      harris41  196: }
1.15      harris41  197: elsif ($mode eq "build") {
                    198:     @directories=&determine_directory_structure;
                    199:     $a=&make_files_build_segment(\@directories);
                    200:     print $a;
                    201: }
1.11      harris41  202: 
                    203: # ------------------------------------------------------ a list of file targets
                    204: sub make_file_list {
                    205:     my ($dirs)=@_;
                    206:     my $description;
                    207:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    208:     foreach my $d (@$dirs) {
                    209: 	# set other values
1.19      harris41  210: 	$description.=<<END;
1.18      harris41  211: BinaryRoot/$d
                    212: END
1.11      harris41  213: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    214: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    215: 	# find files that are contained in this directory
                    216: 	my @files;
                    217: 	my @filesfull;
                    218: 	foreach my $f (@allfiles) {
                    219: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    220: 		push @files,$1;
                    221: 		push @filesfull,$f;
                    222: 	    }
                    223: 	}
                    224: 	# render starting HTML formatting elements
                    225: 	if (@files) {
                    226:         }
1.12      harris41  227: 	my $pwd=`pwd`; chop $pwd;
1.11      harris41  228: 	if (@files) {
                    229:             foreach my $i (0..$#files) {
                    230: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    231: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    232: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    233: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    234: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    235: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
                    236: 		my $rot="/".$filesfull[$i];
                    237: 		if ($rot=~/\*/) {
                    238: 		    $rot=~s/[^\/]+$// if $rot=~/\*/;
                    239: 		    my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
                    240: 		    chop $listing;
                    241: 		    my @list=split(/\s+/,$listing);
                    242: 		    my $rot2;
                    243: 		    foreach my $l (@list) {
                    244: 			$l=~s/^\s*//; $l=~s/\s*$//;
1.12      harris41  245: 			$rot2.="BinaryRoot$rot$l\n" if length($l);
1.11      harris41  246: 		    }
                    247: 		    chop $rot2;
                    248: 		    $rot=$rot2;
1.12      harris41  249: 		}
                    250: 		else {
                    251: 		    $rot="BinaryRoot$rot";
1.11      harris41  252: 		}
1.13      harris41  253: 		if ($category eq "conf") {
                    254: 		    $rot.=" # config";
                    255: 		}
1.11      harris41  256: 		$description.=<<END;
                    257: $rot
                    258: END
                    259: 	    }
                    260: 	}
                    261:     }
                    262:     $description.=<<END;
                    263: 
                    264: END
                    265:     return $description;
                    266: }
                    267: 
                    268: # --------------------------------- Commands to make BinaryRoot directories
                    269: sub make_directory_binaryroot_segment {
                    270:     my ($dirs)=@_;
                    271:     my $description=<<END;
                    272: directories:
                    273: END
                    274:     foreach my $d (@$dirs) {
                    275: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
                    276: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    277: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    278: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    279: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
1.20      harris41  280: 	my ($owner,$group)=split(/\:/,$devchown);
1.11      harris41  281: 	my $own=$devchown; $own=~s/\:/\,/;
                    282: 	$description.=<<END;
1.20      harris41  283: \tinstall -o $owner -g $group -m $devchmod -d \$(TARGET)/$d
1.11      harris41  284: END
                    285:     }
                    286:     $description.=<<END;
                    287: 
                    288: END
                    289:     return $description;
                    290: }
                    291: 
                    292: # --------------------------------------- Commands to make BinaryRoot files
                    293: sub make_files_binaryroot_segment {
                    294:     my ($dirs)=@_;
                    295:     my $description=<<END;
                    296: files:
                    297: END
                    298:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    299:     foreach my $d (@$dirs) {
                    300: 	# set other values
                    301: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    302: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    303: 	# find files that are contained in this directory
                    304: 	my @files;
                    305: 	my @filesfull;
                    306: 	foreach my $f (@allfiles) {
                    307: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    308: 		push @files,$1;
                    309: 		push @filesfull,$f;
                    310: 	    }
                    311: 	}
                    312: 	# render starting HTML formatting elements
                    313: 	if (@files) {
                    314: 	    $description.=<<END;
                    315: \t# $d $dirdescription
                    316: END
                    317:         }
                    318: 	if (@files) {
                    319:             foreach my $i (0..$#files) {
                    320: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    321: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    322: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    323: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    324: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    325: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
                    326: 		my $rot=$filesfull[$i];
                    327: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
1.20      harris41  328: 		my ($owner,$group)=split(/\:/,$devchown);
1.11      harris41  329: 		$description.=<<END if $category ne 'symbolic link';
1.20      harris41  330: \tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
1.11      harris41  331: END
                    332: 	    }
                    333: 	}
                    334:     }
                    335:     $description.=<<END;
                    336: 
                    337: END
                    338:     return $description;
                    339: }
                    340: 
                    341: # ------------------------------ Commands to make BinaryRoot symbolic links
                    342: sub make_links_binaryroot_segment {
                    343:     my ($dirs)=@_;
                    344:     my $description=<<END;
                    345: links:
                    346: END
                    347:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    348:     foreach my $d (@$dirs) {
                    349: 	# find files that are contained in this directory
                    350: 	my @files;
                    351: 	my @filesfull;
                    352: 	foreach my $f (@allfiles) {
                    353: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    354: 		push @files,$1;
                    355: 		push @filesfull,$f;
                    356: 	    }
                    357: 	}
                    358: 	# render starting HTML formatting elements
                    359: 	if (@files) {
                    360:             foreach my $i (0..$#files) {
                    361: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    362: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
                    363: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    364: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    365: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    366: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    367: 		$description.=<<END if $category eq 'symbolic link';
                    368: \tln -s /$linkto \$(TARGET)/$filesfull[$i]
                    369: END
                    370: 	    }
                    371: 	}
                    372:     }
                    373:     $description.=<<END;
                    374: 
                    375: END
                    376:     return $description;
1.10      harris41  377: }
                    378: 
1.14      harris41  379: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
                    380: sub make_directory_LCMakefile_segment {
                    381:     my ($dirs)=@_;
                    382:     my $description=<<END;
                    383: directories:
                    384: END
                    385:     foreach my $d (@$dirs) {
                    386: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
                    387: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    388: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    389: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    390: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    391: 	my $own=$devchown; $own=~s/\:/\,/;
                    392: 	$description.=<<END;
                    393: \tinstall -m $devchmod -d \$(SOURCE)/$d \$(ROOT)/$d
                    394: END
                    395:     }
                    396:     $description.=<<END;
                    397: 
                    398: END
                    399:     return $description;
                    400: }
                    401: 
                    402: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
                    403: sub make_files_LCMakefile_segment {
                    404:     my ($dirs)=@_;
                    405:     my $description=<<END;
                    406: files:
                    407: END
                    408:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    409:     foreach my $d (@$dirs) {
                    410: 	# set other values
                    411: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    412: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    413: 	# find files that are contained in this directory
                    414: 	my @files;
                    415: 	my @filesfull;
                    416: 	foreach my $f (@allfiles) {
                    417: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    418: 		push @files,$1;
                    419: 		push @filesfull,$f;
                    420: 	    }
                    421: 	}
                    422: 	# render starting HTML formatting elements
                    423: 	if (@files) {
                    424: 	    $description.=<<END;
                    425: \t# $d $dirdescription
                    426: END
                    427:         }
                    428: 	if (@files) {
                    429:             foreach my $i (0..$#files) {
                    430: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    431: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    432: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    433: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    434: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    435: 		my $rot=$filesfull[$i];
                    436: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
                    437: 		$description.=<<END if $category ne 'symbolic link';
                    438: \tinstall -m $devchmod \$(SOURCE)/$filesfull[$i] \$(ROOT)/$rot
                    439: END
                    440: 	    }
                    441: 	}
                    442:     }
                    443:     $description.=<<END;
                    444: 
                    445: END
                    446:     return $description;
                    447: }
                    448: 
                    449: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
                    450: sub make_links_LCMakefile_segment {
                    451:     my ($dirs)=@_;
                    452:     my $description=<<END;
                    453: links:
                    454: END
                    455:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    456:     foreach my $d (@$dirs) {
                    457: 	# find files that are contained in this directory
                    458: 	my @files;
                    459: 	my @filesfull;
                    460: 	foreach my $f (@allfiles) {
                    461: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    462: 		push @files,$1;
                    463: 		push @filesfull,$f;
                    464: 	    }
                    465: 	}
                    466: 	# render starting HTML formatting elements
                    467: 	if (@files) {
                    468:             foreach my $i (0..$#files) {
                    469: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    470: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
                    471: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    472: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    473: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    474: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    475: 		$description.=<<END if $category eq 'symbolic link';
                    476: \tln -s /$linkto \$(ROOT)/$filesfull[$i]
                    477: END
                    478: 	    }
                    479: 	}
                    480:     }
                    481:     $description.=<<END;
                    482: 
                    483: END
                    484:     return $description;
                    485: }
                    486: 
1.10      harris41  487: # --------------------------------- Installation commands to install directories
                    488: sub make_directory_install_segment {
                    489:     my ($dirs)=@_;
                    490:     my $description=<<END;
                    491: directories:
                    492: END
                    493:     foreach my $d (@$dirs) {
                    494: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
1.14      harris41  495: 	my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
1.10      harris41  496: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    497: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    498: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    499: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
1.16      harris41  500: 	my ($owner,$group)=split(/\:/,$devchown);
1.10      harris41  501: 	my $own=$devchown; $own=~s/\:/\,/;
                    502: 	$description.=<<END;
1.16      harris41  503: \tinstall -o $owner -g $group -m $devchmod -d \$(TARGET)/$d
1.10      harris41  504: END
                    505:     }
                    506:     $description.=<<END;
                    507: 
                    508: END
                    509:     return $description;
                    510: }
                    511: 
1.15      harris41  512: # ------------------------------------------------------ Commands to build files
                    513: sub make_files_build_segment {
                    514:     my ($dirs)=@_;
                    515:     my $description;
                    516:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    517:     my $tab="\t";
                    518:     my $sources="all: ";
                    519:     foreach my $d (@$dirs) {
                    520: 	# set other values
                    521: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    522: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    523: 	# find files that are contained in this directory
                    524: 	my @files;
                    525: 	my @filesfull;
                    526: 	foreach my $f (@allfiles) {
                    527: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    528: 		push @files,$1;
                    529: 		push @filesfull,$f;
                    530: 	    }
                    531: 	}
                    532: 	if (@files) {
                    533:             foreach my $i (0..$#files) {
                    534: 		# if has build information, output appropriate something
                    535: 		my $build=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'BUILD'};
                    536: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
                    537: 		$build=~s/^\s+//; $build=~s/\s+$//;
                    538: 		if ($build) {
                    539: 		    my $dependencies=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DEPENDENCIES'};
                    540: 		    my $source2=$source;
                    541: 		    $source2=~s/^[^\/]+\///;
                    542:  		    $source2="../" . $source2;
                    543: 		    $sources.="$source2 ";
                    544: 		    my $directory=$build;
                    545: 		    $directory=~s/^[^\/]+\///;
                    546: 		    $directory=~s/([^\/]+)$//;
                    547:  		    $directory="../" . $directory;
                    548: 		    my $buildfile=$1;
                    549: 		    my $sdir=$source;
                    550: 		    $sdir=~s/^[^\/]+\///;
                    551: 		    $sdir=~s/([^\/]+)$//;
                    552:  		    $sdir="../" . $sdir;
                    553: 		    $dependencies=~s/\s+$//;
                    554: 		    my $depstat="";
                    555: 		    if ($dependencies=~s/\s+\[ALWAYS_RUN_BUILD_COMMAND\]//) {
                    556: 			$depstat=" alwaysrun";
                    557: 		    }
                    558: 		    $dependencies=~s/\s+/ $sdir/gs;
                    559: 		    $description.=<<END;
                    560: $source2: $dependencies$depstat
                    561: ${tab}cd $directory; sh ./$buildfile
                    562: 
                    563: END
                    564: 		}
                    565: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    566: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
                    567: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    568: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    569: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    570: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    571: 		my $rot=$filesfull[$i];
                    572: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
                    573: #		$description.=<<END if $category ne 'symbolic link';
1.16      harris41  574: #\tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
1.15      harris41  575: #END
                    576: 	    }
                    577: 	}
                    578:     }
                    579:     $description.=<<END;
                    580: alwaysrun:
                    581: 
                    582: END
                    583:     $sources.="\n\n";
                    584:     return ($sources . $description);
                    585: }
                    586: 
1.10      harris41  587: # --------------------------------------- Installation commands to install files
                    588: sub make_files_install_segment {
                    589:     my ($dirs)=@_;
                    590:     my $description=<<END;
                    591: files:
                    592: END
                    593:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    594:     foreach my $d (@$dirs) {
                    595: 	# set other values
                    596: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    597: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    598: 	# find files that are contained in this directory
                    599: 	my @files;
                    600: 	my @filesfull;
                    601: 	foreach my $f (@allfiles) {
                    602: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    603: 		push @files,$1;
                    604: 		push @filesfull,$f;
                    605: 	    }
                    606: 	}
                    607: 	# render starting HTML formatting elements
                    608: 	if (@files) {
                    609: 	    $description.=<<END;
                    610: \t# $d $dirdescription
                    611: END
                    612:         }
                    613: 	if (@files) {
                    614:             foreach my $i (0..$#files) {
                    615: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
1.14      harris41  616: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
1.10      harris41  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=~/\*/;
1.16      harris41  623: 		my ($owner,$group)=split(/\:/,$devchown);
1.15      harris41  624: 		if ($category ne 'conf') {
                    625: 		    $description.=<<END if $category ne 'symbolic link';
1.16      harris41  626: \tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
                    627: END
                    628:                 }
                    629: 	    }
                    630: 	}
                    631:     }
                    632:     $description.=<<END;
                    633: 
                    634: END
                    635:     return $description;
                    636: }
                    637: 
                    638: # ------ Installation commands to install configuration files (and make backups)
                    639: sub make_files_configinstall_segment {
                    640:     my ($dirs)=@_;
                    641:     my $description=<<END;
                    642: configfiles:
                    643: END
                    644:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    645:     foreach my $d (@$dirs) {
                    646: 	# set other values
                    647: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    648: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    649: 	# find files that are contained in this directory
                    650: 	my @files;
                    651: 	my @filesfull;
                    652: 	foreach my $f (@allfiles) {
                    653: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    654: 		push @files,$1;
                    655: 		push @filesfull,$f;
                    656: 	    }
                    657: 	}
                    658: 	# render starting HTML formatting elements
                    659: 	if (@files) {
                    660: 	    $description.=<<END;
                    661: \t# $d $dirdescription
                    662: END
                    663:         }
                    664: 	if (@files) {
                    665:             foreach my $i (0..$#files) {
                    666: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    667: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
                    668: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    669: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    670: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    671: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    672: 		my $rot=$filesfull[$i];
                    673: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
                    674: 		my ($owner,$group)=split(/\:/,$devchown);
                    675: 		if ($category eq 'conf') {
                    676: 		    $description.=<<END;
                    677: \tinstall -b -S `date +'.\%Y\%m\%d\%H\%M\%S'` -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
1.17      harris41  678: END
                    679:                 }
                    680: 	    }
                    681: 	}
                    682:     }
                    683:     $description.=<<END;
                    684: 
                    685: END
                    686:     return $description;
                    687: }
                    688: 
                    689: # ------ Commands to enforce configuration file permissions
                    690: sub make_files_configpermissions_segment {
                    691:     my ($dirs)=@_;
                    692:     my $description=<<END;
                    693: configpermissions:
                    694: END
                    695:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    696:     foreach my $d (@$dirs) {
                    697: 	# set other values
                    698: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    699: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    700: 	# find files that are contained in this directory
                    701: 	my @files;
                    702: 	my @filesfull;
                    703: 	foreach my $f (@allfiles) {
                    704: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    705: 		push @files,$1;
                    706: 		push @filesfull,$f;
                    707: 	    }
                    708: 	}
                    709: 	# render starting HTML formatting elements
                    710: 	if (@files) {
                    711: 	    $description.=<<END;
                    712: \t# $d $dirdescription
                    713: END
                    714:         }
                    715: 	if (@files) {
                    716:             foreach my $i (0..$#files) {
                    717: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    718: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
                    719: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    720: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    721: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    722: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    723: 		my $rot=$filesfull[$i];
                    724: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
                    725: 		my ($owner,$group)=split(/\:/,$devchown);
                    726: 		if ($category eq 'conf') {
                    727: 		    $description.=<<END;
                    728: \tchmod $devchmod \$(TARGET)/$rot
                    729: \tchown $devchown \$(TARGET)/$rot
1.10      harris41  730: END
1.15      harris41  731:                 }
1.10      harris41  732: 	    }
                    733: 	}
                    734:     }
                    735:     $description.=<<END;
                    736: 
                    737: END
                    738:     return $description;
                    739: }
                    740: 
                    741: # ------------------------------ Installation commands to install symbolic links
                    742: sub make_links_install_segment {
                    743:     my ($dirs)=@_;
                    744:     my $description=<<END;
                    745: links:
                    746: END
1.16      harris41  747:     chop $description;
                    748:     my $description2;
1.10      harris41  749:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    750:     foreach my $d (@$dirs) {
                    751: 	# find files that are contained in this directory
                    752: 	my @files;
                    753: 	my @filesfull;
                    754: 	foreach my $f (@allfiles) {
                    755: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    756: 		push @files,$1;
                    757: 		push @filesfull,$f;
                    758: 	    }
                    759: 	}
                    760: 	# render starting HTML formatting elements
                    761: 	if (@files) {
                    762:             foreach my $i (0..$#files) {
                    763: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    764: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
                    765: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    766: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    767: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    768: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
1.16      harris41  769: 		if ($category eq 'symbolic link') {
                    770: 		    $description.=" \$(TARGET)/$filesfull[$i]";
                    771: 		    $description2.=<<END;
                    772: \$(TARGET)/$filesfull[$i]:
1.14      harris41  773: \tln -s /$linkto \$(TARGET)/$filesfull[$i]
1.16      harris41  774: 
1.10      harris41  775: END
1.16      harris41  776:                 }
1.10      harris41  777: 	    }
                    778: 	}
                    779:     }
                    780:     $description.=<<END;
1.4       harris41  781: 
1.10      harris41  782: END
1.16      harris41  783:     $description.=$description2;
1.10      harris41  784:     return $description;
                    785: }
                    786: 
                    787: # --------------------------------------------------------- Make RPM .spec block
                    788: sub make_rpm_spec_block {
                    789:     my $pwd=`pwd`; chop $pwd;
                    790:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
                    791:     my $source=$info{'RPM'}{'Name'} . "-" . $info{'RPM'}{'Version'} . '.tar.gz';
                    792:     my $description=<<END;
                    793: Summary: $info{'RPM'}{'Summary'}
                    794: Name: $info{'RPM'}{'Name'}
                    795: Version: $info{'RPM'}{'Version'}
                    796: Release: $info{'RPM'}{'Release'}
                    797: Vendor: $info{'RPM'}{'Vendor'} 
                    798: BuildRoot: $buildroot
                    799: Copyright: $info{'RPM'}{'Copyright'}
                    800: Group: $info{'RPM'}{'Group'}
                    801: Source: $source
                    802: AutoReqProv: $info{'RPM'}{'AutoReqProv'}
                    803: \%description
                    804: $info{'RPM'}{'description'}
                    805: 
                    806: END
                    807:     return $description;
                    808: }
                    809: 
                    810: # --------------------------------------------------- Make RPM build .spec block
                    811: sub make_rpm_build_block {
                    812:     my $pwd=`pwd`; chop $pwd;
                    813:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
                    814:     my $sourceroot="$pwd/LON-CAPA-SourceRoot";
                    815:     my $description=<<END;
                    816: 
                    817: \%prep
                    818: \%setup
                    819: 
                    820: \%build
                    821: rm -Rf "$buildroot"
                    822: 
                    823: \%install
                    824: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" directories
                    825: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" files
                    826: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" links
                    827: 
                    828: \%pre
                    829: $info{'RPM'}{'pre'}
                    830: 
                    831: \%post
                    832: \%postun
                    833: 
                    834: \%files
                    835: # \%doc README COPYING ChangeLog LICENSE
                    836: END
                    837:     return $description;
                    838: }
                    839: 
                    840: # ------------------------------------- Make directory structure RPM .spec block
                    841: sub make_directory_structure_spec_block {
                    842:     my ($dirs)=@_;
                    843:     foreach my $d (@$dirs) {
                    844: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
                    845: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    846: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    847: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    848: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    849: 	my $own=$devchown; $own=~s/\:/\,/;
                    850: 	$description.=<<END;
                    851: \%dir \%attr($devchmod,$own) /$d
                    852: END
                    853:     }
                    854:     return $description;
                    855: }
                    856: 
                    857: # ---------------------------- Make directory and file structure RPM .spec block
                    858: sub make_directory_and_file_structure_spec_block {
                    859:     my ($dirs)=@_;
                    860:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    861:     foreach my $d (@$dirs) {
                    862: 	# set other values
                    863: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                    864: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                    865: 	# find files that are contained in this directory
                    866: 	my @files;
                    867: 	my @filesfull;
                    868: 	foreach my $f (@allfiles) {
                    869: 	    if ($f=~/^$d\/([^\/]+)$/) {
                    870: 		push @files,$1;
                    871: 		push @filesfull,$f;
                    872: 	    }
                    873: 	}
                    874: 	# render starting HTML formatting elements
                    875: 	if (@files) {
                    876: 	    $description.=<<END;
                    877: # $d $dirdescription
                    878: END
                    879:         }
                    880: 	if (@files) {
                    881:             foreach my $i (0..$#files) {
                    882: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                    883: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                    884: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                    885: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                    886: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                    887: 		my $own=$devchown; $own=~s/\:/\,/;
                    888: 		my $config="";
                    889: 		$config="\%config " if $category eq 'conf';
                    890: 		$devchmod='-' if $category eq 'symbolic link';
                    891: 		$description.=<<END;
                    892: $config\%attr($devchmod,$own) /$filesfull[$i]
                    893: END
                    894: 	    }
                    895: 	}
                    896:     }
                    897:     return $description;
                    898: }
                    899: 
                    900: # ----------------------------------------------------------- End RPM .spec page
                    901: sub end_spec_page {
                    902: }
                    903: 
                    904: # ------------------------------------------------------- Begin description page
1.4       harris41  905: sub begin_description_page {
                    906:     my $description=<<END;
                    907: <HTML>
                    908: <HEAD>
                    909: <TITLE>LON-CAPA Software Description Page ($distribution, $date)</TITLE>
                    910: </HEAD>
                    911: <BODY>
                    912: <FONT SIZE=+2>LON-CAPA Software Description Page ($distribution, $date)</FONT>
                    913: <BR>Michigan State University
                    914: <BR>Learning Online with CAPA
                    915: <BR>Contact korte\@lon-capa.org
                    916: <UL>
                    917: <LI>About this file
                    918: <LI>Software Package Description
                    919: <LI>Directory Structure
1.7       harris41  920: <LI>File Type Ownership and Permissions
1.4       harris41  921: <LI>File and Directory Structure
                    922: </UL>
                    923: <FONT SIZE=+2>About this file</FONT>
                    924: <P>
                    925: This file is generated dynamically by <TT>parse.pl</TT> as
                    926: part of a development compilation process.  See 
                    927: http://install.lon-capa.org/compile/index.html for more
                    928: information.
                    929: </P>
                    930: END
                    931:     return $description;
                    932: }
                    933: 
                    934: # ------------------------------------------------- End description page
                    935: sub end_description_page {
                    936:     my $description=<<END;
                    937: <HR>
1.5       harris41  938: <FONT SIZE=-1>LON-CAPA Software Development Team</FONT>
1.4       harris41  939: </BODY>
                    940: </HTML>
                    941: END
                    942:     return $description;
                    943: }
                    944: 
                    945: # ------------------------------------------------- Make RPM description block
                    946: sub make_rpm_description_block {
                    947:     my $description=<<END;
                    948: <FONT SIZE=+2>Rolled in a RedHat 6.2 RPM, $date</FONT>
                    949: <P>
                    950: <TABLE BGCOLOR=#FFFFFF BORDER=0 CELLPADDING=10 CELLSPACING=0>
                    951: <TR><TD>
                    952: <PRE>
                    953: Name        : $info{'RPM'}{'Name'}
                    954: Version     : $info{'RPM'}{'Version'}
                    955: Vendor      : $info{'RPM'}{'Vendor'} 
                    956: Release     : $info{'RPM'}{'Release'}                             
                    957: Build Host  : $buildhost
                    958: Group       : $info{'RPM'}{'Group'}
                    959: License     : $info{'RPM'}{'Copyright'}
                    960: Summary     : $info{'RPM'}{'Summary'}
                    961: Description : 
                    962: $info{'RPM'}{'description'}
                    963: </PRE>
                    964: </TD></TR>
                    965: </TABLE>
                    966: </P>
                    967: END
                    968:     return $description;
                    969: }
                    970: 
                    971: # ----------------------------------------------- Determine directory structure
                    972: sub determine_directory_structure {
                    973:     my @directories=keys %{$info{'DIRECTORY'}{$distribution}};
                    974:     return (sort @directories);
                    975: }
1.1       harris41  976: 
1.4       harris41  977: 
                    978: # ---------------------------------- Make directory structure description block
                    979: sub make_directory_structure_description_block {
                    980:     my ($dirs)=@_;
                    981:     my $description=<<END;
                    982: <FONT SIZE=+2>Directory Structure Description, $date</FONT>
                    983: <P>
1.9       harris41  984: The directory structure description below shows only those
                    985: directories which either contain LON-CAPA specific files
                    986: or normally do not exist on a RedHat Linux system (and
                    987: must be generated to allow proper placement of files
                    988: during LON-CAPA run-time operation).
                    989: </P>
                    990: <P>
1.4       harris41  991: <TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0>
                    992: END
                    993:     my $maxcount=0;
1.8       harris41  994:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
                    995:     my %diraccount; # hash to track which directories are accounted for
                    996:     foreach my $file (@allfiles) {
                    997: 	$file=~/^(.*)\/([^\/]+)$/;
                    998: 	$diraccount{$1}=1;
                    999:     }
1.4       harris41 1000:     foreach my $d (@$dirs) {
                   1001:         my (@matches)=($d=~/\//g);
                   1002: 	my $count=scalar(@matches);
                   1003: 	$maxcount=$count if $count>$maxcount;
1.8       harris41 1004: 	delete $diraccount{$d};
1.4       harris41 1005:     }
                   1006:     $description.=<<END;
                   1007: <TR>
                   1008: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Category</TH>
                   1009: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
                   1010: <TH ALIGN=LEFT BGCOLOR=#FFFFFF><FONT COLOR=#FF0000>Development<BR>Permissions</FONT></TH>
                   1011: END
                   1012:     $description.="<TH ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+1).">Directory Path</TH>\n";
1.8       harris41 1013:     if (keys %diraccount) {
                   1014: 	$description.= "<TR><TD ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+4)."><I><PRE>Directories that are unaccounted for: \n";
                   1015: 	foreach my $d (keys %diraccount) {
                   1016: 	    $description.="$d\n";
                   1017: 	}
                   1018: 	$description.="</PRE></I></TH></TR>\n";
                   1019:     }
1.4       harris41 1020:     foreach my $d (@$dirs) {
                   1021: 	my $dtable=$d;
                   1022: 	$dtable=~s/\//\<\/TD\>\<TD\>/g;
                   1023: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
                   1024: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
                   1025: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
                   1026: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
                   1027: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
                   1028: 	$description.=<<END;
                   1029: <TR>
                   1030: <TD BGCOLOR=#FFFFFF>$category</TD>
                   1031: <TD BGCOLOR=#FFFFFF><TT>$chmod $chown</TT></TD>
                   1032: <TD BGCOLOR=#FFFFFF><FONT COLOR=#FF0000><TT>$devchmod $devchown</TT></FONT></TD>
                   1033: <TD>
                   1034: $dtable
                   1035: </TD>
                   1036: </TR>
                   1037: END
                   1038:     }
                   1039:     $description.=<<END;
                   1040: </TABLE>
                   1041: </P>
                   1042: END
                   1043:     return $description;
                   1044: }
                   1045: 
1.6       harris41 1046: # ------------------- Make file type ownership and permissions description block
                   1047: sub make_file_type_ownership_and_permissions_description_block {
                   1048:     my $description=<<END;
                   1049: <FONT SIZE=+2>File Type Ownership and Permissions Descriptions, $date</FONT>
                   1050: <P>
                   1051: This table shows what permissions and ownership settings correspond
                   1052: to each kind of file type.
                   1053: </P>
                   1054: <P>
                   1055: <TABLE BORDER=1 CELLPADDING=5 WIDTH=60%>
                   1056: <TR>
                   1057: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Icon</TH>
                   1058: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Type</TH>
                   1059: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
                   1060: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Development Permissions</TH>
                   1061: </TR>
                   1062: END
                   1063:     foreach my $type (keys %{$info{'OWNERSHIP'}}) {
                   1064: 	if (defined($fcm{$type})) {
                   1065: 	    my $chmod=$info{'OWNERSHIP'}{$type}{'CHMOD'};
                   1066: 	    my $chown=$info{'OWNERSHIP'}{$type}{'CHOWN'};
                   1067: 	    my $devchmod=$info{'DEVOWNERSHIP'}{$type}{'CHMOD'};
                   1068: 	    my $devchown=$info{'DEVOWNERSHIP'}{$type}{'CHOWN'};
                   1069: 	    $description.=<<END;
                   1070: <TR>
                   1071: <TD><IMG SRC="$fcm{$type}.gif" ALT="$type"></TD>
                   1072: <TD>$type</TD>
                   1073: <TD><TT>$chmod $chown</TT></TD>
                   1074: <TD><TT>$devchmod $devchown</TT></TD>
                   1075: </TR>
                   1076: END
                   1077:         }
                   1078:     }
                   1079:     $description.=<<END;
                   1080: </TABLE>
                   1081: </P>
                   1082: END
                   1083: }
                   1084: 
1.4       harris41 1085: # ------------------------- Make directory and file structure description block
                   1086: sub make_directory_and_file_structure_description_block {
                   1087:     my ($dirs)=@_;
                   1088:     my $description=<<END;
                   1089: <FONT SIZE=+2>Directory and File Structure Description, $date</FONT>
1.6       harris41 1090: <P>
                   1091: The icons on the left column correspond to the file type
                   1092: specified in the second column.  The last column "Notes" shows compilation,
1.7       harris41 1093: dependency, and configuration information.  The CVS location
                   1094: shows the location of the binary source file (if applicable) needed to
                   1095: be copied to the target.  If the binary source file is not at
                   1096: the specified location, then the text is shown in 
                   1097: <FONT COLOR=#FF0000>red</FONT>.
1.6       harris41 1098: </P>
1.4       harris41 1099: <P>
1.9       harris41 1100: <TABLE BORDER=1 CELLPADDING=5 WIDTH=500>
1.4       harris41 1101: END
                   1102:     my $counter=0;
                   1103:     my @colorindex=("#80FF80","#80FFFF","#FFFF80");
1.5       harris41 1104:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
1.4       harris41 1105:     foreach my $d (@$dirs) {
                   1106: 	# set color
                   1107: 	my $color=$colorindex[$counter%3];
                   1108: 	# set other values
                   1109: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
                   1110: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
                   1111: 	# find subdirectories that are contained in this directory
                   1112: 	my @subdirs;
                   1113: 	foreach my $d2 (@$dirs) {
1.5       harris41 1114: 	    if ($d2=~/^$d\/([^\/]+)$/) {
1.4       harris41 1115: 		push @subdirs,$1;
                   1116: 	    }
                   1117: 	}
                   1118: 	# find files that are contained in this directory
                   1119: 	my @files;
1.5       harris41 1120: 	my @filesfull;
1.4       harris41 1121: 	foreach my $f (@allfiles) {
1.5       harris41 1122: 	    if ($f=~/^$d\/([^\/]+)$/) {
1.4       harris41 1123: 		push @files,$1;
1.5       harris41 1124: 		push @filesfull,$f;
1.4       harris41 1125: 	    }
                   1126: 	}
                   1127: 	# render starting HTML formatting elements
                   1128: 	if (@subdirs || @files) {
                   1129: 	    my $subdirstring="<BR>* Relevant subdirectories: " . join(", ",@subdirs) if @subdirs;
                   1130: 	    $description.=<<END;
1.5       harris41 1131: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="directory.gif" ALT="directory">DIRECTORY -- $d $dirdescription
                   1132: $subdirstring</FONT></TD></TR>
1.4       harris41 1133: END
                   1134:         }
                   1135: 	else {
                   1136: 	    $description.=<<END;
1.5       harris41 1137: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="emptydirectory.gif" ALT="empty directory">EMPTY DIRECTORY - $d $dirdescription</FONT></TD></TR>
1.4       harris41 1138: END
                   1139:         }
                   1140: 	if (@files) {
                   1141: 	    $description.=<<END;
                   1142: <TR>
1.5       harris41 1143: <TH BGCOLOR=$color ALIGN=LEFT COLSPAN=2>Type</TH>
                   1144: <TH BGCOLOR=$color ALIGN=LEFT>File Name</TH>
                   1145: <TH BGCOLOR=$color ALIGN=LEFT>Function</TH>
                   1146: <TH BGCOLOR=$color ALIGN=LEFT>CVS Location</TH>
                   1147: <TH BGCOLOR=$color ALIGN=LEFT>Notes</TH>
1.4       harris41 1148: </TR>
                   1149: END
1.5       harris41 1150:             foreach my $i (0..$#files) {
                   1151: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
                   1152: 		my $fdescription=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DESCRIPTION'};
                   1153: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
1.9       harris41 1154: 		my $note=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'NOTE'};
                   1155: 		$note.="<BR>" if $note;
                   1156: 		my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
                   1157: 		my @E=split(/\s+/,$listing);
                   1158: 		$source=~/(.*)\/[^\/]+$/;
                   1159: 		my $sd=$1;
                   1160: 		my $eflag=0;
                   1161: 		foreach my $e (@E) {
                   1162: 		    unless (-e "../../$sd/$e") {
                   1163: 			$e="<FONT COLOR=#FF0000>$e</FONT>";
                   1164: 			$eflag=1;
                   1165: 		    }
                   1166: 		}
                   1167: 		$listing=join("\n",@E);
                   1168: 		$listing="<B>listing</B><BR><FONT SIZE=-2>$listing</FONT>" if $listing;
                   1169: 		$listing.="<BR>" if $listing;
                   1170: 		my $build=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'BUILD'};
                   1171: 		$build="<B>build</B><BR>$build" if $build;
                   1172: 		$build.="<BR>" if $build;
                   1173: 		my $dependencies=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DEPENDENCIES'};
                   1174: 		$dependencies="<B>dependencies</B><BR>$dependencies" if $dependencies;
                   1175: 		$dependencies.="<BR>" if $dependencies;
1.7       harris41 1176: 		unless (-e "../../$source") {
                   1177: 		    $source=~/([^\/]+)$/;
                   1178: 		    my $s=$1;
1.9       harris41 1179: 		    if ($source!~/\*/) {
                   1180: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
                   1181: 		    }
                   1182: 		    elsif ($eflag) {
                   1183: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
                   1184: 		    }
1.7       harris41 1185: 		}
1.5       harris41 1186: 		$description.=<<END;
                   1187: <TR>
                   1188: <TD BGCOLOR=#A0A0A0><IMG SRC="$fcm{$category}.gif" ALT="$category"></TD>
                   1189: <TD BGCOLOR=$color>$category</TD>
                   1190: <TD BGCOLOR=$color>$files[$i]</TD>
                   1191: <TD BGCOLOR=$color>$fdescription&nbsp;</TD>
                   1192: <TD BGCOLOR=$color>$source</TD>
1.9       harris41 1193: <TD BGCOLOR=$color>$note$listing$build$dependencies&nbsp;</TD>
1.4       harris41 1194: </TR>
                   1195: END
1.5       harris41 1196: 	    }
                   1197: 	}
1.4       harris41 1198: 	$counter++;
                   1199:     }
                   1200:     $description.=<<END;
                   1201: </TABLE>
                   1202: </P>
                   1203: END
                   1204:     return $description;
                   1205: }

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