Annotation of loncom/build/make_rpm.pl, revision 1.1

1.1     ! harris41    1: #!/usr/bin/perl
        !             2: 
        !             3: # Scott Harrison, September 30
        !             4: # Automatically generate RPM listing files
        !             5: # from file listing.
        !             6: 
        !             7: # GNU General Public License, Version 2, June 1991
        !             8: # See http://www.gnu.org/copyleft/gpl.html.
        !             9: 
        !            10: # This file currently does not actually "build" the RPM.
        !            11: # This has to be done with an RPM build environment and
        !            12: # commands like 'rpm -ba'.
        !            13: 
        !            14: # What this file DOES do is generate all the needed
        !            15: # files (and binary root directory tree) to build an RPM with.
        !            16: 
        !            17: # I still need to implement the CONFIGURATION_FILES and
        !            18: # DOCUMENTATION_FILES portion of the command line interface to this
        !            19: # script.
        !            20: 
        !            21: # Take in a file list (from standard input), 
        !            22: # a description tag and version tag from command line argument
        !            23: # and generate a:
        !            24: #      RPM .spec file
        !            25: #      RPM Makefile
        !            26: #      SourceRoot
        !            27: 
        !            28: unless (-e "/usr/lib/rpm/rpmrc") {
        !            29:     print <<END;
        !            30: ERROR: This script only works with a properly installed RPM builder application.  
        !            31: Cannot find /usr/lib/rpm/rpmrc, so cannot generate customized rpmrc file.
        !            32: Script aborting.
        !            33: END
        !            34: }
        !            35: 
        !            36: my ($tag,$version,$configuration_files,$documentation_files,$pathprefix)=@ARGV;
        !            37: @ARGV=();
        !            38: if (!$version) {
        !            39:     print "Usage: <TAG> <VERSION> [CONFIGURATION_FILES] [DOCUMENTATION] [PATHPREFIX]\n";
        !            40:     print "Standard input provides the list of files to work with.\n";
        !            41:     print "TAG, required descriptive tag.  For example, a kerberos software package might be tagged as \"krb4\".\n";
        !            42:     print "VERSION, required version.  Needed to generate version information for the RPM.  This should be in the format N.M where N and M are integers.\n";
        !            43:     print "CONFIGURATION_FILES, optional comma-separated listing of files to be treated as configuration files by RPM (and thus subject to saving during RPM upgrades).\n";
        !            44:     print "DOCUMENTATION, optional comma-separated listing of files to be treated as documentation files by RPM (and thus subject to being placed in the /usr/doc/RPM-NAME directory during RPM installation).\n";
        !            45:     print "PATHPREFIX, optional path to be removed from file listing.  This is in case you are building an RPM from files elsewhere than root-level.  Note, this still depends on a root directory hierarchy after PATHPREFIX.\n";
        !            46:     exit;
        !            47: }
        !            48: 
        !            49: mkdir $tag,0755;
        !            50: mkdir "$tag/BuildRoot",0755;
        !            51: mkdir "$tag/SOURCES",0755;
        !            52: mkdir "$tag/SOURCES/LON-CAPA-$tag-$version",0755;
        !            53: mkdir "$tag/SPECS",0755;
        !            54: mkdir "$tag/BUILD",0755;
        !            55: mkdir "$tag/SRPMS",0755;
        !            56: mkdir "$tag/RPMS",0755;
        !            57: mkdir "$tag/RPMS/i386",0755;
        !            58: 
        !            59: my $file;
        !            60: my $binaryroot="$tag/BinaryRoot";
        !            61: my ($type,$size,$octalmode,$user,$group);
        !            62: 
        !            63: $currentdir=`pwd`; chop $currentdir; $invokingdir=$currentdir; $currentdir.="/$tag";
        !            64: 
        !            65: open (IN,"</usr/lib/rpm/rpmrc") or die("Can't open /usr/lib/rpm/rpmrc");
        !            66: @lines=<IN>;
        !            67: close IN;
        !            68: 
        !            69: open (RPMRC,">$tag/SPECS/rpmrc");
        !            70: foreach $line (@lines) {
        !            71:     if ($line=~/^macrofiles/) {
        !            72: 	chop $line;
        !            73: 	$line.=":./rpmmacros\n";
        !            74:     }
        !            75:     print RPMRC $line;
        !            76: }
        !            77: close RPMRC;
        !            78: 
        !            79: open (RPMMACROS,">$tag/SPECS/rpmmacros");
        !            80: print RPMMACROS <<END;
        !            81: \%_topdir $currentdir
        !            82: \%__spec_install_post    \\
        !            83:     /usr/lib/rpm/brp-strip \\
        !            84:     /usr/lib/rpm/brp-strip-comment-note \\
        !            85: \%{nil}
        !            86: END
        !            87: close RPMMACROS;
        !            88: 
        !            89: open (SPEC,">$tag/SPECS/LON-CAPA-$tag-$version.spec");
        !            90: 
        !            91: print SPEC <<END;
        !            92: Summary: Files for the $tag component of LON-CAPA.
        !            93: Name: LON-CAPA-$tag
        !            94: Version: $version
        !            95: Release: 1
        !            96: Vendor: Laboratory for Instructional Technology Education, Division of Science and Mathematics Education, Michigan State University.
        !            97: BuildRoot: $currentdir/BuildRoot
        !            98: Copyright: GNU General Public License. Version 2, June 1991.  Michigan State University patents may apply.
        !            99: Group: Utilities/System
        !           100: Source: LON-CAPA-$tag-$version.tar.gz
        !           101: AutoReqProv: no
        !           102: # requires: filesystem
        !           103: \%description
        !           104: This package is automatically generated by the make_rpm.pl perl
        !           105: script (written by the LON-CAPA development team, www.lon-capa.org,
        !           106: Scott Harrison). This implements the $tag component for LON-CAPA.
        !           107: For more on the LON-CAPA project, visit http://www.lon-capa.org/.
        !           108: 
        !           109: \%prep
        !           110: \%setup
        !           111: 
        !           112: \%build
        !           113: rm -Rf "$currentdir/BuildRoot"
        !           114: 
        !           115: \%install
        !           116: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" directories
        !           117: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" files
        !           118: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" links
        !           119: 
        !           120: \%pre
        !           121: echo "***********************************************************************"
        !           122: echo "LON-CAPA  LearningOnline with CAPA"
        !           123: echo "http://www.lon-capa.org/"
        !           124: echo "Gerd Kortemeyer, et al"
        !           125: echo "Laboratory for Instructional Technology Education"
        !           126: echo "Michigan State University"
        !           127: echo "General Public License, Version 2, June 1991"
        !           128: echo "** Michigan State University patents may apply **"
        !           129: echo " "
        !           130: echo "This installation assumes an installation of Redhat 6.2"
        !           131: echo " "
        !           132: echo "The server computer should be currently connected to the ethernet"
        !           133: echo " "
        !           134: echo "The files in this package are only those for the $tag component."
        !           135: echo "Configuration files are sometimes part of the LON-CAPA-base RPM."
        !           136: echo "***********************************************************************"
        !           137: 
        !           138: \%post
        !           139: \%postun
        !           140: 
        !           141: \%files
        !           142: END
        !           143: 
        !           144: foreach $file (<>) {
        !           145:     chop $file;
        !           146:     if (($type,$size,$octalmode,$user,$group)=find_info($file)) {
        !           147: 	$octalmode="0" . $octalmode if length($octalmode)<4;
        !           148: 	if ($pathprefix) {
        !           149: 	    $file=~s/^$pathprefix//;
        !           150: 	}
        !           151: 	if ($type eq "files") {
        !           152: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -D -m $octalmode $pathprefix$file $binaryroot$file\n";
        !           153: 	    push @{$Makefile{$type}},"\tinstall -D -m $octalmode \$(SOURCE)$file \$(ROOT)$file\n";
        !           154: 	    push @{$dotspecfile{$type}},"\%attr($octalmode,$user,$group) $file\n";
        !           155: 	}
        !           156: 	elsif ($type eq "directories") {
        !           157: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -m $octalmode -d $binaryroot$file\n";
        !           158: 	    push @{$Makefile{$type}},"\tinstall -m $octalmode -d \$(SOURCE)$file \$(ROOT)$file\n";
        !           159: 	    push @{$dotspecfile{$type}},"\%dir \%attr($octalmode,$user,$group) $file\n";
        !           160: 	}
        !           161: 	elsif ($type eq "links") {
        !           162: 	    my $link=$size; # I use the size variable to pass the link value from the subroutine find_info
        !           163: 	    $link=~s/^$pathprefix//;
        !           164: 	    push @{$BinaryRootMakefile{$type}},"\tln -s $link $binaryroot$file\n";
        !           165: 	    push @{$Makefile{$type}},"\tln -s $link \$(ROOT)$file\n";
        !           166: 	    push @{$dotspecfile{$type}},"\%attr(-,$user,$group) $file\n";
        !           167: 	}
        !           168:     }
        !           169: }
        !           170: 
        !           171: open OUT, ">$tag/SOURCES/LON-CAPA-$tag-$version/Makefile";
        !           172: open OUT2, ">$tag/BinaryRootMakefile";
        !           173: foreach $type ("directories","files","links") {
        !           174:     print OUT "$type\:\n";
        !           175:     print OUT join("",@{$Makefile{$type}});
        !           176:     print OUT "\n";
        !           177:     print OUT2 "$type\:\n";
        !           178:     print OUT2 join("",@{$BinaryRootMakefile{$type}});
        !           179:     print OUT2 "\n";
        !           180:     print SPEC join("",@{$dotspecfile{$type}});
        !           181: }
        !           182: close OUT2;
        !           183: close OUT;
        !           184: 
        !           185: 
        !           186: close SPEC;
        !           187: 
        !           188: `make -f $tag/BinaryRootMakefile directories`;
        !           189: `make -f $tag/BinaryRootMakefile files`;
        !           190: `make -f $tag/BinaryRootMakefile links`;
        !           191: 
        !           192: print `cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz LON-CAPA-$tag-$version`;
        !           193: print `cd $currentdir/SPECS; rpm --rcfile=./rpmrc -ba LON-CAPA-$tag-$version.spec; cd ../RPMS/i386; cp LON-CAPA-$tag-$version-1.i386.rpm $invokingdir/.`;
        !           194: print `cd $invokingdir; rm -Rf $tag`;
        !           195: 
        !           196: sub find_info {
        !           197:     # only look for
        !           198:     my ($file)=@_;
        !           199:     my $line;
        !           200:     if (($line=`find $file -type f -prune`)=~/^$file\n/) {
        !           201: 	$line=`find $file -type f -prune -printf "\%s\t\%m\t\%u\t\%g"`;
        !           202: 	return ("files",split(/\t/,$line));
        !           203:     }
        !           204:     elsif (($line=`find $file -type d -prune`)=~/^$file\n/) {
        !           205: 	$line=`find $file -type d -prune -printf "\%s\t\%m\t\%u\t\%g"`;
        !           206: 	return ("directories",split(/\t/,$line));
        !           207:     }
        !           208:     elsif (($line=`find $file -type l -prune`)=~/^$file\n/) {
        !           209: 	$line=`find $file -type l -prune -printf "\%h/\%l\t\%m\t\%u\t\%g"`;
        !           210: 	return ("links",split(/\t/,$line));
        !           211:     }
        !           212: 
        !           213: }

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