#!/usr/bin/perl # The LearningOnline Network with CAPA # make_rpm.pl - make RedHat package manager file # # $Id: make_rpm.pl,v 1.12 2002/01/05 00:48:05 harris41 Exp $ # # Written by Scott Harrison, harris41@msu.edu # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # # YEAR=2000 # 9/30,10/2,12/11,12/12,12/21 - Scott Harrison # YEAR=2001 # 1/8,1/10,1/13,1/23,5/16 - Scott Harrison # YEAR=2002 # 1/4 - Scott Harrison # ### # Automatically generate RPM files # from file listing. # This script does actually "build" the RPM. # This script also generates and then deletes temporary # files (and binary root directory tree) to build an RPM with. # I still need to implement the CONFIGURATION_FILES and # DOCUMENTATION_FILES portion of the command line interface to this # script. # Take in a file list (from standard input), # a description tag and version tag from command line argument # and temporarily generate a: # RPM .spec file # RPM Makefile # SourceRoot # A resulting .rpm file is generated. unless (-e "/usr/lib/rpm/rpmrc") { print < [CONFIGURATION_FILES] [DOCUMENTATION] ". "[PATHPREFIX]\n"; print "Standard input provides the list of files to work with.\n"; print "TAG, required descriptive tag. For example, a kerberos software ". "package might be tagged as \"krb4\".\n"; 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"; 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"; 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"; 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"; exit; } mkdir $tag,0755; mkdir "$tag/BuildRoot",0755; mkdir "$tag/SOURCES",0755; mkdir "$tag/SOURCES/LON-CAPA-$tag-$version",0755; mkdir "$tag/SPECS",0755; mkdir "$tag/BUILD",0755; mkdir "$tag/SRPMS",0755; mkdir "$tag/RPMS",0755; mkdir "$tag/RPMS/i386",0755; my $file; my $binaryroot="$tag/BinaryRoot"; my ($type,$size,$octalmode,$user,$group); $currentdir=`pwd`; chop $currentdir; $invokingdir=$currentdir; $currentdir.="/$tag"; open (IN,"; close IN; open (RPMRC,">$tag/SPECS/rpmrc"); foreach $line (@lines) { if ($line=~/^macrofiles/) { chop $line; $line.=":$currentdir/SPECS/rpmmacros\n"; } print RPMRC $line; } close RPMRC; open (RPMMACROS,">$tag/SPECS/rpmmacros"); print RPMMACROS <$tag/SPECS/LON-CAPA-$tag-$version.spec"); my $vendor='Laboratory for Instructional Technology Education, Division of '. 'Science and Mathematics Education, Michigan State University.'; print SPEC <) { chop $file; my $comment=""; if ($file=~/\s+\#(.*)$/) { $file=~s/\s+\#(.*)$//; $comment=$1; } my $config=""; if ($comment=~/config/i) { $config="\%config "; } if (($type,$size,$octalmode,$user,$group)=find_info($file)) { $octalmode="0" . $octalmode if length($octalmode)<4; if ($pathprefix) { $file=~s/^$pathprefix//; } if ($type eq "files") { push @{$BinaryRootMakefile{$type}},"\tinstall -D -m $octalmode ". "$pathprefix$file $binaryroot$file\n"; push @{$Makefile{$type}},"\tinstall -D -m $octalmode ". "\$(SOURCE)$file \$(ROOT)$file\n"; push @{$dotspecfile{$type}},"$config\%attr($octalmode,$user,". "$group) $file\n"; } elsif ($type eq "directories") { push @{$BinaryRootMakefile{$type}},"\tinstall -m $octalmode -d ". "$binaryroot$file\n"; push @{$Makefile{$type}},"\tinstall -m $octalmode -d ". "\$(SOURCE)$file \$(ROOT)$file\n"; push @{$dotspecfile{$type}},"\%dir \%attr($octalmode,$user,". "$group) $file\n"; } elsif ($type eq "links") { my $link=$size; # I use the size variable to pass the link value # from the subroutine find_info $link=~s/^$pathprefix//; push @{$BinaryRootMakefile{$type}}, "\tln -s $link $binaryroot$file\n"; push @{$Makefile{$type}},"\tln -s $link \$(ROOT)$file\n"; push @{$dotspecfile{$type}},"\%attr(-,$user,$group) $file\n"; } } } open OUT, ">$tag/SOURCES/LON-CAPA-$tag-$version/Makefile"; open OUT2, ">$tag/BinaryRootMakefile"; foreach $type ("directories","files","links") { print OUT "$type\:\n"; print OUT join("",@{$Makefile{$type}}); print OUT "\n"; print OUT2 "$type\:\n"; print OUT2 join("",@{$BinaryRootMakefile{$type}}); print OUT2 "\n"; print SPEC join("",@{$dotspecfile{$type}}); } close OUT2; close OUT; close SPEC; `make -f $tag/BinaryRootMakefile directories`; `make -f $tag/BinaryRootMakefile files`; `make -f $tag/BinaryRootMakefile links`; my $command="cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz ". "LON-CAPA-$tag-$version"; print `$command`; $command="cd $currentdir/SPECS; rpm --rcfile=./rpmrc -ba ". "LON-CAPA-$tag-$version.spec; cd ../RPMS/i386; cp ". "LON-CAPA-$tag-$version-1.i386.rpm $invokingdir/."; print `$command`; print `cd $invokingdir; rm -Rf $tag`; sub find_info { # only look for my ($file)=@_; my $line; if (($line=`find $file -type f -prune`)=~/^$file\n/) { $line=`find $file -type f -prune -printf "\%s\t\%m\t\%u\t\%g"`; return ("files",split(/\t/,$line)); } elsif (($line=`find $file -type d -prune`)=~/^$file\n/) { $line=`find $file -type d -prune -printf "\%s\t\%m\t\%u\t\%g"`; return ("directories",split(/\t/,$line)); } elsif (($line=`find $file -type l -prune`)=~/^$file\n/) { $line=`find $file -type l -prune -printf "\%l\t\%m\t\%u\t\%g"`; return ("links",split(/\t/,$line)); } }