File:  [LON-CAPA] / loncom / build / make_rpm.pl
Revision 1.12: download - view: text, annotated - select for diffs
Sat Jan 5 00:48:05 2002 UTC (22 years, 5 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
reducing lengthly lines, adding gpl, fixing commenting -Scott Harrison

    1: #!/usr/bin/perl
    2: 
    3: # The LearningOnline Network with CAPA
    4: # make_rpm.pl - make RedHat package manager file
    5: #
    6: # $Id: make_rpm.pl,v 1.12 2002/01/05 00:48:05 harris41 Exp $
    7: #
    8: # Written by Scott Harrison, harris41@msu.edu
    9: #
   10: # Copyright Michigan State University Board of Trustees
   11: #
   12: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   13: #
   14: # LON-CAPA is free software; you can redistribute it and/or modify
   15: # it under the terms of the GNU General Public License as published by
   16: # the Free Software Foundation; either version 2 of the License, or
   17: # (at your option) any later version.
   18: #
   19: # LON-CAPA is distributed in the hope that it will be useful,
   20: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   21: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22: # GNU General Public License for more details.
   23: #
   24: # You should have received a copy of the GNU General Public License
   25: # along with LON-CAPA; if not, write to the Free Software
   26: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27: #
   28: # /home/httpd/html/adm/gpl.txt
   29: #
   30: # http://www.lon-capa.org/
   31: #
   32: # YEAR=2000
   33: # 9/30,10/2,12/11,12/12,12/21 - Scott Harrison
   34: # YEAR=2001
   35: # 1/8,1/10,1/13,1/23,5/16 - Scott Harrison
   36: # YEAR=2002
   37: # 1/4 - Scott Harrison
   38: #
   39: ###
   40: 
   41: # Automatically generate RPM files
   42: # from file listing.
   43: 
   44: # This script does actually "build" the RPM.
   45: 
   46: # This script also generates and then deletes temporary
   47: # files (and binary root directory tree) to build an RPM with.
   48: 
   49: # I still need to implement the CONFIGURATION_FILES and
   50: # DOCUMENTATION_FILES portion of the command line interface to this
   51: # script.
   52: 
   53: # Take in a file list (from standard input), 
   54: # a description tag and version tag from command line argument
   55: # and temporarily generate a:
   56: #      RPM .spec file
   57: #      RPM Makefile
   58: #      SourceRoot
   59: 
   60: # A resulting .rpm file is generated.
   61: 
   62: unless (-e "/usr/lib/rpm/rpmrc") {
   63:     print <<END;
   64: ERROR: This script only works with a properly installed RPM builder
   65: application.  
   66: Cannot find /usr/lib/rpm/rpmrc, so cannot generate customized rpmrc file.
   67: Script aborting.
   68: END
   69: }
   70: 
   71: my ($tag,$version,$configuration_files,$documentation_files,$pathprefix)=@ARGV;
   72: @ARGV=();
   73: 
   74: if (!$version) {
   75:     print "Usage: <TAG> <VERSION> [CONFIGURATION_FILES] [DOCUMENTATION] ".
   76: 	"[PATHPREFIX]\n";
   77:     print "Standard input provides the list of files to work with.\n";
   78:     print "TAG, required descriptive tag.  For example, a kerberos software ".
   79: 	"package might be tagged as \"krb4\".\n";
   80:     print "VERSION, required version.  Needed to generate version information".
   81: 	" for the RPM.  This should be in the format N.M where N and M are ".
   82: 	"integers.\n";
   83:     print "CONFIGURATION_FILES, optional comma-separated listing of files to ".
   84: 	"be treated as configuration files by RPM (and thus subject to saving".
   85: 	" during RPM upgrades).\n";
   86:     print "DOCUMENTATION, optional comma-separated listing of files to be ".
   87: 	"treated as documentation files by RPM (and thus subject to being ".
   88: 	"placed in the /usr/doc/RPM-NAME directory during RPM installation).".
   89: 	"\n";
   90:     print "PATHPREFIX, optional path to be removed from file listing.  This ".
   91: 	"is in case you are building an RPM from files elsewhere than ".
   92: 	"root-level.  Note, this still depends on a root directory hierarchy ".
   93: 	"after PATHPREFIX.\n";
   94:     exit;
   95: }
   96: 
   97: mkdir $tag,0755;
   98: mkdir "$tag/BuildRoot",0755;
   99: mkdir "$tag/SOURCES",0755;
  100: mkdir "$tag/SOURCES/LON-CAPA-$tag-$version",0755;
  101: mkdir "$tag/SPECS",0755;
  102: mkdir "$tag/BUILD",0755;
  103: mkdir "$tag/SRPMS",0755;
  104: mkdir "$tag/RPMS",0755;
  105: mkdir "$tag/RPMS/i386",0755;
  106: 
  107: my $file;
  108: my $binaryroot="$tag/BinaryRoot";
  109: my ($type,$size,$octalmode,$user,$group);
  110: 
  111: $currentdir=`pwd`; chop $currentdir; $invokingdir=$currentdir;
  112: $currentdir.="/$tag";
  113: 
  114: open (IN,"</usr/lib/rpm/rpmrc") or die("Can't open /usr/lib/rpm/rpmrc");
  115: @lines=<IN>;
  116: close IN;
  117: 
  118: open (RPMRC,">$tag/SPECS/rpmrc");
  119: foreach $line (@lines) {
  120:     if ($line=~/^macrofiles/) {
  121: 	chop $line;
  122: 	$line.=":$currentdir/SPECS/rpmmacros\n";
  123:     }
  124:     print RPMRC $line;
  125: }
  126: close RPMRC;
  127: 
  128: open (RPMMACROS,">$tag/SPECS/rpmmacros");
  129: print RPMMACROS <<END;
  130: \%_topdir $currentdir
  131: \%__spec_install_post    \\
  132:     /usr/lib/rpm/brp-strip \\
  133:     /usr/lib/rpm/brp-strip-comment-note \\
  134: \%{nil}
  135: END
  136: close RPMMACROS;
  137: 
  138: # This needs to be dynamically based upon doc/otherfiles/rpm_list.txt
  139: # at some point.
  140: my $requires="";
  141: if ($tag eq "setup") {
  142:     $requires=<<END;
  143: PreReq: setup
  144: PreReq: passwd
  145: PreReq: util-linux
  146: END
  147: }
  148: elsif ($tag eq "base") {
  149:     $requires=<<END;
  150: PreReq: LON-CAPA-setup
  151: PreReq: apache
  152: PreReq: /etc/httpd/conf/access.conf
  153: END
  154:     $requires2=<<END;
  155: Requires: LON-CAPA-setup
  156: Requires: raidtools
  157: Requires: ncurses
  158: Requires: popt
  159: Requires: tcsh
  160: Requires: redhat-release
  161: Requires: diffutils
  162: Requires: ed
  163: Requires: dialog
  164: Requires: rmt
  165: Requires: sed
  166: Requires: which
  167: Requires: gawk
  168: Requires: mingetty
  169: Requires: info
  170: Requires: portmap
  171: Requires: openssh-clients
  172: Requires: openssh
  173: Requires: openssh-server
  174: Requires: openssl
  175: Requires: basesystem
  176: Requires: ldconfig
  177: Requires: filesystem
  178: Requires: mktemp
  179: Requires: termcap
  180: Requires: shadow-utils
  181: Requires: libtermcap
  182: Requires: MAKEDEV
  183: Requires: utempter
  184: Requires: bash
  185: Requires: logrotate
  186: Requires: SysVinit
  187: Requires: chkconfig
  188: Requires: textutils
  189: Requires: pwdb
  190: Requires: vixie-cron
  191: Requires: procps
  192: Requires: modutils
  193: Requires: psmisc
  194: Requires: sysklogd
  195: Requires: authconfig
  196: Requires: zlib
  197: Requires: sh-utils
  198: Requires: mailcap
  199: Requires: anacron
  200: Requires: bc
  201: Requires: bdflush
  202: Requires: bind-utils
  203: Requires: cpio
  204: Requires: crontabs
  205: Requires: etcskel
  206: Requires: e2fsprogs
  207: Requires: samba-client
  208: Requires: apache-devel
  209: Requires: autofs
  210: Requires: findutils
  211: Requires: gdbm
  212: Requires: getty_ps
  213: Requires: readline
  214: Requires: glib10
  215: Requires: inetd
  216: Requires: losetup
  217: Requires: gnupg
  218: Requires: gpgp
  219: Requires: urw-fonts
  220: Requires: mailx
  221: Requires: gzip
  222: Requires: ld.so
  223: Requires: less
  224: Requires: passwd
  225: Requires: sysreport
  226: Requires: ncompress
  227: Requires: mount
  228: Requires: lilo
  229: Requires: bzip2
  230: Requires: grep
  231: Requires: memprof
  232: Requires: mars-nwe
  233: Requires: pidentd
  234: Requires: procinfo
  235: Requires: units
  236: Requires: routed
  237: Requires: quota
  238: Requires: pam
  239: Requires: stat
  240: Requires: setserial
  241: Requires: mod_perl
  242: Requires: rootfiles
  243: Requires: nfs-utils
  244: Requires: sendmail
  245: Requires: sharutils
  246: Requires: tmpwatch
  247: Requires: shapecfg
  248: Requires: tcp_wrappers
  249: Requires: unzip
  250: Requires: tetex-dvips
  251: Requires: tetex-afm
  252: Requires: tetex-latex
  253: Requires: xntp3
  254: Requires: rpm
  255: Requires: wu-ftpd
  256: Requires: setup
  257: Requires: glibc
  258: Requires: fileutils
  259: Requires: initscripts
  260: Requires: netatalk
  261: Requires: apache
  262: Requires: bash2
  263: Requires: dev
  264: Requires: samba
  265: Requires: ghostscript
  266: Requires: kernel-headers
  267: Requires: kernel
  268: Requires: linuxconf
  269: Requires: tetex
  270: Requires: tetex-fonts
  271: Requires: util-linux
  272: Requires: vim-common
  273: Requires: perl
  274: Requires: cracklib
  275: Requires: cracklib-dicts
  276: Requires: cdrecord
  277: Requires: ghostscript-fonts
  278: Requires: libgr
  279: Requires: libjpeg
  280: Requires: libpng
  281: Requires: libungif-progs
  282: Requires: libtiff
  283: Requires: libungif
  284: Requires: samba-common
  285: Requires: ImageMagick
  286: Requires: libgr-progs
  287: Requires: man-pages
  288: Requires: tar
  289: Requires: vim-minimal
  290: END
  291: }
  292: else {
  293:     $requires=<<END;
  294: Requires: LON-CAPA-base
  295: END
  296: }
  297: open (SPEC,">$tag/SPECS/LON-CAPA-$tag-$version.spec");
  298: 
  299: my $vendor='Laboratory for Instructional Technology Education, Division of '.
  300:     'Science and Mathematics Education, Michigan State University.';
  301: 
  302: print SPEC <<END;
  303: Summary: Files for the $tag component of LON-CAPA.
  304: Name: LON-CAPA-$tag
  305: Version: $version
  306: Release: 1
  307: Vendor: $vendor
  308: BuildRoot: $currentdir/BuildRoot
  309: Copyright: Michigan State University patents may apply.
  310: Group: Utilities/System
  311: Source: LON-CAPA-$tag-$version.tar.gz
  312: AutoReqProv: no
  313: $requires
  314: # requires: filesystem
  315: \%description
  316: This package is automatically generated by the make_rpm.pl perl
  317: script (written by the LON-CAPA development team, www.lon-capa.org,
  318: Scott Harrison). This implements the $tag component for LON-CAPA.
  319: For more on the LON-CAPA project, visit http://www.lon-capa.org/.
  320: 
  321: \%prep
  322: \%setup
  323: 
  324: \%build
  325: rm -Rf "$currentdir/BuildRoot"
  326: 
  327: \%install
  328: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" directories
  329: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" files
  330: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" links
  331: 
  332: \%pre
  333: echo "***********************************************************************"
  334: echo "LON-CAPA  LearningOnline with CAPA"
  335: echo "http://www.lon-capa.org/"
  336: echo "Gerd Kortemeyer, et al"
  337: echo "Laboratory for Instructional Technology Education"
  338: echo "Michigan State University"
  339: echo " "
  340: echo "** Michigan State University patents may apply **"
  341: echo " "
  342: echo "This installation assumes an installation of Redhat 6.2"
  343: echo " "
  344: echo "The server computer should be currently connected to the ethernet"
  345: echo " "
  346: echo "The files in this package are only those for the $tag component."
  347: echo "Configuration files are sometimes part of the LON-CAPA-base RPM."
  348: echo "***********************************************************************"
  349: 
  350: \%post
  351: \%postun
  352: 
  353: \%files
  354: END
  355: 
  356: foreach $file (<>) {
  357:     chop $file;
  358:     my $comment="";
  359:     if ($file=~/\s+\#(.*)$/) {
  360: 	$file=~s/\s+\#(.*)$//;
  361: 	$comment=$1;
  362:     }
  363:     my $config="";
  364:     if ($comment=~/config/i) {
  365: 	$config="\%config ";
  366:     }
  367:     if (($type,$size,$octalmode,$user,$group)=find_info($file)) {
  368: 	$octalmode="0" . $octalmode if length($octalmode)<4;
  369: 	if ($pathprefix) {
  370: 	    $file=~s/^$pathprefix//;
  371: 	}
  372: 	if ($type eq "files") {
  373: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -D -m $octalmode ".
  374: 		"$pathprefix$file $binaryroot$file\n";
  375: 	    push @{$Makefile{$type}},"\tinstall -D -m $octalmode ".
  376: 		"\$(SOURCE)$file \$(ROOT)$file\n";
  377: 	    push @{$dotspecfile{$type}},"$config\%attr($octalmode,$user,".
  378: 		"$group) $file\n";
  379: 	}
  380: 	elsif ($type eq "directories") {
  381: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -m $octalmode -d ".
  382: 		"$binaryroot$file\n";
  383: 	    push @{$Makefile{$type}},"\tinstall -m $octalmode -d ".
  384: 		"\$(SOURCE)$file \$(ROOT)$file\n";
  385: 	    push @{$dotspecfile{$type}},"\%dir \%attr($octalmode,$user,".
  386: 		"$group) $file\n";
  387: 	}
  388: 	elsif ($type eq "links") {
  389: 	    my $link=$size; # I use the size variable to pass the link value
  390:                             # from the subroutine find_info
  391: 	    $link=~s/^$pathprefix//;
  392: 	    push @{$BinaryRootMakefile{$type}},
  393: 	         "\tln -s $link $binaryroot$file\n";
  394: 	    push @{$Makefile{$type}},"\tln -s $link \$(ROOT)$file\n";
  395: 	    push @{$dotspecfile{$type}},"\%attr(-,$user,$group) $file\n";
  396: 	}
  397:     }
  398: }
  399: 
  400: open OUT, ">$tag/SOURCES/LON-CAPA-$tag-$version/Makefile";
  401: open OUT2, ">$tag/BinaryRootMakefile";
  402: foreach $type ("directories","files","links") {
  403:     print OUT "$type\:\n";
  404:     print OUT join("",@{$Makefile{$type}});
  405:     print OUT "\n";
  406:     print OUT2 "$type\:\n";
  407:     print OUT2 join("",@{$BinaryRootMakefile{$type}});
  408:     print OUT2 "\n";
  409:     print SPEC join("",@{$dotspecfile{$type}});
  410: }
  411: close OUT2;
  412: close OUT;
  413: 
  414: 
  415: close SPEC;
  416: 
  417: `make -f $tag/BinaryRootMakefile directories`;
  418: `make -f $tag/BinaryRootMakefile files`;
  419: `make -f $tag/BinaryRootMakefile links`;
  420: 
  421: my $command="cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz ".
  422:     "LON-CAPA-$tag-$version";
  423: print `$command`;
  424: $command="cd $currentdir/SPECS; rpm --rcfile=./rpmrc -ba ".
  425:     "LON-CAPA-$tag-$version.spec; cd ../RPMS/i386; cp ".
  426:     "LON-CAPA-$tag-$version-1.i386.rpm $invokingdir/.";
  427: print `$command`;
  428: print `cd $invokingdir; rm -Rf $tag`;
  429: 
  430: sub find_info {
  431:     # only look for
  432:     my ($file)=@_;
  433:     my $line;
  434:     if (($line=`find $file -type f -prune`)=~/^$file\n/) {
  435: 	$line=`find $file -type f -prune -printf "\%s\t\%m\t\%u\t\%g"`;
  436: 	return ("files",split(/\t/,$line));
  437:     }
  438:     elsif (($line=`find $file -type d -prune`)=~/^$file\n/) {
  439: 	$line=`find $file -type d -prune -printf "\%s\t\%m\t\%u\t\%g"`;
  440: 	return ("directories",split(/\t/,$line));
  441:     }
  442:     elsif (($line=`find $file -type l -prune`)=~/^$file\n/) {
  443: 	$line=`find $file -type l -prune -printf "\%l\t\%m\t\%u\t\%g"`;
  444: 	return ("links",split(/\t/,$line));
  445:     }
  446: 
  447: }

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