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

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: 
1.2       harris41   10: # This script does actually "build" the RPM.
1.1       harris41   11: 
1.2       harris41   12: # This script also generates and then deletes temporary
1.1       harris41   13: # files (and binary root directory tree) to build an RPM with.
                     14: 
                     15: # I still need to implement the CONFIGURATION_FILES and
                     16: # DOCUMENTATION_FILES portion of the command line interface to this
                     17: # script.
                     18: 
                     19: # Take in a file list (from standard input), 
                     20: # a description tag and version tag from command line argument
1.2       harris41   21: # and temporarily generate a:
1.1       harris41   22: #      RPM .spec file
                     23: #      RPM Makefile
                     24: #      SourceRoot
1.2       harris41   25: 
                     26: # A resulting .rpm file is generated.
1.1       harris41   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=();
1.3       harris41   38: 
1.1       harris41   39: if (!$version) {
                     40:     print "Usage: <TAG> <VERSION> [CONFIGURATION_FILES] [DOCUMENTATION] [PATHPREFIX]\n";
                     41:     print "Standard input provides the list of files to work with.\n";
                     42:     print "TAG, required descriptive tag.  For example, a kerberos software package might be tagged as \"krb4\".\n";
                     43:     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";
                     44:     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";
                     45:     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";
                     46:     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";
                     47:     exit;
                     48: }
                     49: 
                     50: mkdir $tag,0755;
                     51: mkdir "$tag/BuildRoot",0755;
                     52: mkdir "$tag/SOURCES",0755;
                     53: mkdir "$tag/SOURCES/LON-CAPA-$tag-$version",0755;
                     54: mkdir "$tag/SPECS",0755;
                     55: mkdir "$tag/BUILD",0755;
                     56: mkdir "$tag/SRPMS",0755;
                     57: mkdir "$tag/RPMS",0755;
                     58: mkdir "$tag/RPMS/i386",0755;
                     59: 
                     60: my $file;
                     61: my $binaryroot="$tag/BinaryRoot";
                     62: my ($type,$size,$octalmode,$user,$group);
                     63: 
                     64: $currentdir=`pwd`; chop $currentdir; $invokingdir=$currentdir; $currentdir.="/$tag";
                     65: 
                     66: open (IN,"</usr/lib/rpm/rpmrc") or die("Can't open /usr/lib/rpm/rpmrc");
                     67: @lines=<IN>;
                     68: close IN;
                     69: 
                     70: open (RPMRC,">$tag/SPECS/rpmrc");
                     71: foreach $line (@lines) {
                     72:     if ($line=~/^macrofiles/) {
                     73: 	chop $line;
                     74: 	$line.=":./rpmmacros\n";
                     75:     }
                     76:     print RPMRC $line;
                     77: }
                     78: close RPMRC;
                     79: 
                     80: open (RPMMACROS,">$tag/SPECS/rpmmacros");
                     81: print RPMMACROS <<END;
                     82: \%_topdir $currentdir
                     83: \%__spec_install_post    \\
                     84:     /usr/lib/rpm/brp-strip \\
                     85:     /usr/lib/rpm/brp-strip-comment-note \\
                     86: \%{nil}
                     87: END
                     88: close RPMMACROS;
                     89: 
1.7       harris41   90: # This needs to be dynamically based upon doc/otherfiles/rpm_list.txt
                     91: # at some point.
                     92: my $requires="";
                     93: if ($tag eq "setup") {
                     94:     $requires=<<END;
1.8       harris41   95: PreReq: setup
1.9     ! harris41   96: PreReq: passwd
        !            97: PreReq: util-linux
1.7       harris41   98: END
                     99: }
                    100: elsif ($tag eq "base") {
                    101:     $requires=<<END;
1.8       harris41  102: PreReq: LON-CAPA-setup
                    103: PreReq: apache
                    104: PreReq: /etc/httpd/conf/access.conf
                    105: END
                    106:     $requires2=<<END;
                    107: Requires: LON-CAPA-setup
1.7       harris41  108: Requires: raidtools
                    109: Requires: ncurses
                    110: Requires: popt
                    111: Requires: tcsh
                    112: Requires: redhat-release
                    113: Requires: diffutils
                    114: Requires: ed
                    115: Requires: dialog
                    116: Requires: rmt
                    117: Requires: sed
                    118: Requires: which
                    119: Requires: gawk
                    120: Requires: mingetty
                    121: Requires: info
                    122: Requires: portmap
                    123: Requires: openssh-clients
                    124: Requires: openssh
                    125: Requires: openssh-server
                    126: Requires: openssl
                    127: Requires: basesystem
                    128: Requires: ldconfig
                    129: Requires: filesystem
                    130: Requires: mktemp
                    131: Requires: termcap
                    132: Requires: shadow-utils
                    133: Requires: libtermcap
                    134: Requires: MAKEDEV
                    135: Requires: utempter
                    136: Requires: bash
                    137: Requires: logrotate
                    138: Requires: SysVinit
                    139: Requires: chkconfig
                    140: Requires: textutils
                    141: Requires: pwdb
                    142: Requires: vixie-cron
                    143: Requires: procps
                    144: Requires: modutils
                    145: Requires: psmisc
                    146: Requires: sysklogd
                    147: Requires: authconfig
                    148: Requires: zlib
                    149: Requires: sh-utils
                    150: Requires: mailcap
                    151: Requires: anacron
                    152: Requires: bc
                    153: Requires: bdflush
                    154: Requires: bind-utils
                    155: Requires: cpio
                    156: Requires: crontabs
                    157: Requires: etcskel
                    158: Requires: e2fsprogs
                    159: Requires: samba-client
                    160: Requires: apache-devel
                    161: Requires: autofs
                    162: Requires: findutils
                    163: Requires: gdbm
                    164: Requires: getty_ps
                    165: Requires: readline
                    166: Requires: glib10
                    167: Requires: inetd
                    168: Requires: losetup
                    169: Requires: gnupg
                    170: Requires: gpgp
                    171: Requires: urw-fonts
                    172: Requires: mailx
                    173: Requires: gzip
                    174: Requires: ld.so
                    175: Requires: less
                    176: Requires: passwd
                    177: Requires: sysreport
                    178: Requires: ncompress
                    179: Requires: mount
                    180: Requires: lilo
                    181: Requires: bzip2
                    182: Requires: grep
                    183: Requires: memprof
                    184: Requires: mars-nwe
                    185: Requires: pidentd
                    186: Requires: procinfo
                    187: Requires: units
                    188: Requires: routed
                    189: Requires: quota
                    190: Requires: pam
                    191: Requires: stat
                    192: Requires: setserial
                    193: Requires: mod_perl
                    194: Requires: rootfiles
                    195: Requires: nfs-utils
                    196: Requires: sendmail
                    197: Requires: sharutils
                    198: Requires: tmpwatch
                    199: Requires: shapecfg
                    200: Requires: tcp_wrappers
                    201: Requires: unzip
                    202: Requires: tetex-dvips
                    203: Requires: tetex-afm
                    204: Requires: tetex-latex
                    205: Requires: xntp3
                    206: Requires: rpm
                    207: Requires: wu-ftpd
                    208: Requires: setup
                    209: Requires: glibc
                    210: Requires: fileutils
                    211: Requires: initscripts
                    212: Requires: netatalk
                    213: Requires: apache
                    214: Requires: bash2
                    215: Requires: dev
                    216: Requires: samba
                    217: Requires: ghostscript
                    218: Requires: kernel-headers
                    219: Requires: kernel
                    220: Requires: linuxconf
                    221: Requires: tetex
                    222: Requires: tetex-fonts
                    223: Requires: util-linux
                    224: Requires: vim-common
                    225: Requires: perl
                    226: Requires: cracklib
                    227: Requires: cracklib-dicts
                    228: Requires: cdrecord
                    229: Requires: ghostscript-fonts
                    230: Requires: libgr
                    231: Requires: libjpeg
                    232: Requires: libpng
                    233: Requires: libungif-progs
                    234: Requires: libtiff
                    235: Requires: libungif
                    236: Requires: samba-common
                    237: Requires: ImageMagick
                    238: Requires: libgr-progs
                    239: Requires: man-pages
                    240: Requires: tar
                    241: Requires: vim-minimal
                    242: END
                    243: }
                    244: else {
                    245:     $requires=<<END;
                    246: Requires: LON-CAPA-base
                    247: END
                    248: }
1.1       harris41  249: open (SPEC,">$tag/SPECS/LON-CAPA-$tag-$version.spec");
                    250: 
                    251: print SPEC <<END;
                    252: Summary: Files for the $tag component of LON-CAPA.
                    253: Name: LON-CAPA-$tag
                    254: Version: $version
                    255: Release: 1
                    256: Vendor: Laboratory for Instructional Technology Education, Division of Science and Mathematics Education, Michigan State University.
                    257: BuildRoot: $currentdir/BuildRoot
                    258: Copyright: GNU General Public License. Version 2, June 1991.  Michigan State University patents may apply.
                    259: Group: Utilities/System
                    260: Source: LON-CAPA-$tag-$version.tar.gz
                    261: AutoReqProv: no
1.7       harris41  262: $requires
1.1       harris41  263: # requires: filesystem
                    264: \%description
                    265: This package is automatically generated by the make_rpm.pl perl
                    266: script (written by the LON-CAPA development team, www.lon-capa.org,
                    267: Scott Harrison). This implements the $tag component for LON-CAPA.
                    268: For more on the LON-CAPA project, visit http://www.lon-capa.org/.
                    269: 
                    270: \%prep
                    271: \%setup
                    272: 
                    273: \%build
                    274: rm -Rf "$currentdir/BuildRoot"
                    275: 
                    276: \%install
                    277: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" directories
                    278: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" files
                    279: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" links
                    280: 
                    281: \%pre
                    282: echo "***********************************************************************"
                    283: echo "LON-CAPA  LearningOnline with CAPA"
                    284: echo "http://www.lon-capa.org/"
                    285: echo "Gerd Kortemeyer, et al"
                    286: echo "Laboratory for Instructional Technology Education"
                    287: echo "Michigan State University"
                    288: echo "General Public License, Version 2, June 1991"
                    289: echo "** Michigan State University patents may apply **"
                    290: echo " "
                    291: echo "This installation assumes an installation of Redhat 6.2"
                    292: echo " "
                    293: echo "The server computer should be currently connected to the ethernet"
                    294: echo " "
                    295: echo "The files in this package are only those for the $tag component."
                    296: echo "Configuration files are sometimes part of the LON-CAPA-base RPM."
                    297: echo "***********************************************************************"
                    298: 
                    299: \%post
                    300: \%postun
                    301: 
                    302: \%files
                    303: END
                    304: 
                    305: foreach $file (<>) {
                    306:     chop $file;
1.4       harris41  307:     my $comment="";
                    308:     if ($file=~/\s+\#(.*)$/) {
                    309: 	$file=~s/\s+\#(.*)$//;
                    310: 	$comment=$1;
                    311:     }
                    312:     my $config="";
                    313:     if ($comment=~/config/i) {
                    314: 	$config="\%config ";
                    315:     }
1.1       harris41  316:     if (($type,$size,$octalmode,$user,$group)=find_info($file)) {
                    317: 	$octalmode="0" . $octalmode if length($octalmode)<4;
                    318: 	if ($pathprefix) {
                    319: 	    $file=~s/^$pathprefix//;
                    320: 	}
                    321: 	if ($type eq "files") {
                    322: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -D -m $octalmode $pathprefix$file $binaryroot$file\n";
                    323: 	    push @{$Makefile{$type}},"\tinstall -D -m $octalmode \$(SOURCE)$file \$(ROOT)$file\n";
1.4       harris41  324: 	    push @{$dotspecfile{$type}},"$config\%attr($octalmode,$user,$group) $file\n";
1.1       harris41  325: 	}
                    326: 	elsif ($type eq "directories") {
                    327: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -m $octalmode -d $binaryroot$file\n";
                    328: 	    push @{$Makefile{$type}},"\tinstall -m $octalmode -d \$(SOURCE)$file \$(ROOT)$file\n";
                    329: 	    push @{$dotspecfile{$type}},"\%dir \%attr($octalmode,$user,$group) $file\n";
                    330: 	}
                    331: 	elsif ($type eq "links") {
                    332: 	    my $link=$size; # I use the size variable to pass the link value from the subroutine find_info
                    333: 	    $link=~s/^$pathprefix//;
                    334: 	    push @{$BinaryRootMakefile{$type}},"\tln -s $link $binaryroot$file\n";
                    335: 	    push @{$Makefile{$type}},"\tln -s $link \$(ROOT)$file\n";
                    336: 	    push @{$dotspecfile{$type}},"\%attr(-,$user,$group) $file\n";
                    337: 	}
                    338:     }
                    339: }
                    340: 
                    341: open OUT, ">$tag/SOURCES/LON-CAPA-$tag-$version/Makefile";
                    342: open OUT2, ">$tag/BinaryRootMakefile";
                    343: foreach $type ("directories","files","links") {
                    344:     print OUT "$type\:\n";
                    345:     print OUT join("",@{$Makefile{$type}});
                    346:     print OUT "\n";
                    347:     print OUT2 "$type\:\n";
                    348:     print OUT2 join("",@{$BinaryRootMakefile{$type}});
                    349:     print OUT2 "\n";
                    350:     print SPEC join("",@{$dotspecfile{$type}});
                    351: }
                    352: close OUT2;
                    353: close OUT;
                    354: 
                    355: 
                    356: close SPEC;
                    357: 
                    358: `make -f $tag/BinaryRootMakefile directories`;
                    359: `make -f $tag/BinaryRootMakefile files`;
                    360: `make -f $tag/BinaryRootMakefile links`;
                    361: 
                    362: print `cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz LON-CAPA-$tag-$version`;
                    363: 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/.`;
1.5       harris41  364: print `cd $invokingdir; rm -Rf $tag`;
1.1       harris41  365: 
                    366: sub find_info {
                    367:     # only look for
                    368:     my ($file)=@_;
                    369:     my $line;
                    370:     if (($line=`find $file -type f -prune`)=~/^$file\n/) {
                    371: 	$line=`find $file -type f -prune -printf "\%s\t\%m\t\%u\t\%g"`;
                    372: 	return ("files",split(/\t/,$line));
                    373:     }
                    374:     elsif (($line=`find $file -type d -prune`)=~/^$file\n/) {
                    375: 	$line=`find $file -type d -prune -printf "\%s\t\%m\t\%u\t\%g"`;
                    376: 	return ("directories",split(/\t/,$line));
                    377:     }
                    378:     elsif (($line=`find $file -type l -prune`)=~/^$file\n/) {
1.6       harris41  379: 	$line=`find $file -type l -prune -printf "\%l\t\%m\t\%u\t\%g"`;
1.1       harris41  380: 	return ("links",split(/\t/,$line));
                    381:     }
                    382: 
                    383: }

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