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

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.7       harris41   96: END
                     97: }
                     98: elsif ($tag eq "base") {
                     99:     $requires=<<END;
1.8     ! harris41  100: PreReq: LON-CAPA-setup
        !           101: PreReq: apache
        !           102: PreReq: /etc/httpd/conf/access.conf
        !           103: END
        !           104:     $requires2=<<END;
        !           105: Requires: LON-CAPA-setup
1.7       harris41  106: Requires: raidtools
                    107: Requires: ncurses
                    108: Requires: popt
                    109: Requires: tcsh
                    110: Requires: redhat-release
                    111: Requires: diffutils
                    112: Requires: ed
                    113: Requires: dialog
                    114: Requires: rmt
                    115: Requires: sed
                    116: Requires: which
                    117: Requires: gawk
                    118: Requires: mingetty
                    119: Requires: info
                    120: Requires: portmap
                    121: Requires: openssh-clients
                    122: Requires: openssh
                    123: Requires: openssh-server
                    124: Requires: openssl
                    125: Requires: basesystem
                    126: Requires: ldconfig
                    127: Requires: filesystem
                    128: Requires: mktemp
                    129: Requires: termcap
                    130: Requires: shadow-utils
                    131: Requires: libtermcap
                    132: Requires: MAKEDEV
                    133: Requires: utempter
                    134: Requires: bash
                    135: Requires: logrotate
                    136: Requires: SysVinit
                    137: Requires: chkconfig
                    138: Requires: textutils
                    139: Requires: pwdb
                    140: Requires: vixie-cron
                    141: Requires: procps
                    142: Requires: modutils
                    143: Requires: psmisc
                    144: Requires: sysklogd
                    145: Requires: authconfig
                    146: Requires: zlib
                    147: Requires: sh-utils
                    148: Requires: mailcap
                    149: Requires: anacron
                    150: Requires: bc
                    151: Requires: bdflush
                    152: Requires: bind-utils
                    153: Requires: cpio
                    154: Requires: crontabs
                    155: Requires: etcskel
                    156: Requires: e2fsprogs
                    157: Requires: samba-client
                    158: Requires: apache-devel
                    159: Requires: autofs
                    160: Requires: findutils
                    161: Requires: gdbm
                    162: Requires: getty_ps
                    163: Requires: readline
                    164: Requires: glib10
                    165: Requires: inetd
                    166: Requires: losetup
                    167: Requires: gnupg
                    168: Requires: gpgp
                    169: Requires: urw-fonts
                    170: Requires: mailx
                    171: Requires: gzip
                    172: Requires: ld.so
                    173: Requires: less
                    174: Requires: passwd
                    175: Requires: sysreport
                    176: Requires: ncompress
                    177: Requires: mount
                    178: Requires: lilo
                    179: Requires: bzip2
                    180: Requires: grep
                    181: Requires: memprof
                    182: Requires: mars-nwe
                    183: Requires: pidentd
                    184: Requires: procinfo
                    185: Requires: units
                    186: Requires: routed
                    187: Requires: quota
                    188: Requires: pam
                    189: Requires: stat
                    190: Requires: setserial
                    191: Requires: mod_perl
                    192: Requires: rootfiles
                    193: Requires: nfs-utils
                    194: Requires: sendmail
                    195: Requires: sharutils
                    196: Requires: tmpwatch
                    197: Requires: shapecfg
                    198: Requires: tcp_wrappers
                    199: Requires: unzip
                    200: Requires: tetex-dvips
                    201: Requires: tetex-afm
                    202: Requires: tetex-latex
                    203: Requires: xntp3
                    204: Requires: rpm
                    205: Requires: wu-ftpd
                    206: Requires: setup
                    207: Requires: glibc
                    208: Requires: fileutils
                    209: Requires: initscripts
                    210: Requires: netatalk
                    211: Requires: apache
                    212: Requires: bash2
                    213: Requires: dev
                    214: Requires: samba
                    215: Requires: ghostscript
                    216: Requires: kernel-headers
                    217: Requires: kernel
                    218: Requires: linuxconf
                    219: Requires: tetex
                    220: Requires: tetex-fonts
                    221: Requires: util-linux
                    222: Requires: vim-common
                    223: Requires: perl
                    224: Requires: cracklib
                    225: Requires: cracklib-dicts
                    226: Requires: cdrecord
                    227: Requires: ghostscript-fonts
                    228: Requires: libgr
                    229: Requires: libjpeg
                    230: Requires: libpng
                    231: Requires: libungif-progs
                    232: Requires: libtiff
                    233: Requires: libungif
                    234: Requires: samba-common
                    235: Requires: ImageMagick
                    236: Requires: libgr-progs
                    237: Requires: man-pages
                    238: Requires: tar
                    239: Requires: vim-minimal
                    240: END
                    241: }
                    242: else {
                    243:     $requires=<<END;
                    244: Requires: LON-CAPA-base
                    245: END
                    246: }
1.1       harris41  247: open (SPEC,">$tag/SPECS/LON-CAPA-$tag-$version.spec");
                    248: 
                    249: print SPEC <<END;
                    250: Summary: Files for the $tag component of LON-CAPA.
                    251: Name: LON-CAPA-$tag
                    252: Version: $version
                    253: Release: 1
                    254: Vendor: Laboratory for Instructional Technology Education, Division of Science and Mathematics Education, Michigan State University.
                    255: BuildRoot: $currentdir/BuildRoot
                    256: Copyright: GNU General Public License. Version 2, June 1991.  Michigan State University patents may apply.
                    257: Group: Utilities/System
                    258: Source: LON-CAPA-$tag-$version.tar.gz
                    259: AutoReqProv: no
1.7       harris41  260: $requires
1.1       harris41  261: # requires: filesystem
                    262: \%description
                    263: This package is automatically generated by the make_rpm.pl perl
                    264: script (written by the LON-CAPA development team, www.lon-capa.org,
                    265: Scott Harrison). This implements the $tag component for LON-CAPA.
                    266: For more on the LON-CAPA project, visit http://www.lon-capa.org/.
                    267: 
                    268: \%prep
                    269: \%setup
                    270: 
                    271: \%build
                    272: rm -Rf "$currentdir/BuildRoot"
                    273: 
                    274: \%install
                    275: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" directories
                    276: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" files
                    277: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" links
                    278: 
                    279: \%pre
                    280: echo "***********************************************************************"
                    281: echo "LON-CAPA  LearningOnline with CAPA"
                    282: echo "http://www.lon-capa.org/"
                    283: echo "Gerd Kortemeyer, et al"
                    284: echo "Laboratory for Instructional Technology Education"
                    285: echo "Michigan State University"
                    286: echo "General Public License, Version 2, June 1991"
                    287: echo "** Michigan State University patents may apply **"
                    288: echo " "
                    289: echo "This installation assumes an installation of Redhat 6.2"
                    290: echo " "
                    291: echo "The server computer should be currently connected to the ethernet"
                    292: echo " "
                    293: echo "The files in this package are only those for the $tag component."
                    294: echo "Configuration files are sometimes part of the LON-CAPA-base RPM."
                    295: echo "***********************************************************************"
                    296: 
                    297: \%post
                    298: \%postun
                    299: 
                    300: \%files
                    301: END
                    302: 
                    303: foreach $file (<>) {
                    304:     chop $file;
1.4       harris41  305:     my $comment="";
                    306:     if ($file=~/\s+\#(.*)$/) {
                    307: 	$file=~s/\s+\#(.*)$//;
                    308: 	$comment=$1;
                    309:     }
                    310:     my $config="";
                    311:     if ($comment=~/config/i) {
                    312: 	$config="\%config ";
                    313:     }
1.1       harris41  314:     if (($type,$size,$octalmode,$user,$group)=find_info($file)) {
                    315: 	$octalmode="0" . $octalmode if length($octalmode)<4;
                    316: 	if ($pathprefix) {
                    317: 	    $file=~s/^$pathprefix//;
                    318: 	}
                    319: 	if ($type eq "files") {
                    320: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -D -m $octalmode $pathprefix$file $binaryroot$file\n";
                    321: 	    push @{$Makefile{$type}},"\tinstall -D -m $octalmode \$(SOURCE)$file \$(ROOT)$file\n";
1.4       harris41  322: 	    push @{$dotspecfile{$type}},"$config\%attr($octalmode,$user,$group) $file\n";
1.1       harris41  323: 	}
                    324: 	elsif ($type eq "directories") {
                    325: 	    push @{$BinaryRootMakefile{$type}},"\tinstall -m $octalmode -d $binaryroot$file\n";
                    326: 	    push @{$Makefile{$type}},"\tinstall -m $octalmode -d \$(SOURCE)$file \$(ROOT)$file\n";
                    327: 	    push @{$dotspecfile{$type}},"\%dir \%attr($octalmode,$user,$group) $file\n";
                    328: 	}
                    329: 	elsif ($type eq "links") {
                    330: 	    my $link=$size; # I use the size variable to pass the link value from the subroutine find_info
                    331: 	    $link=~s/^$pathprefix//;
                    332: 	    push @{$BinaryRootMakefile{$type}},"\tln -s $link $binaryroot$file\n";
                    333: 	    push @{$Makefile{$type}},"\tln -s $link \$(ROOT)$file\n";
                    334: 	    push @{$dotspecfile{$type}},"\%attr(-,$user,$group) $file\n";
                    335: 	}
                    336:     }
                    337: }
                    338: 
                    339: open OUT, ">$tag/SOURCES/LON-CAPA-$tag-$version/Makefile";
                    340: open OUT2, ">$tag/BinaryRootMakefile";
                    341: foreach $type ("directories","files","links") {
                    342:     print OUT "$type\:\n";
                    343:     print OUT join("",@{$Makefile{$type}});
                    344:     print OUT "\n";
                    345:     print OUT2 "$type\:\n";
                    346:     print OUT2 join("",@{$BinaryRootMakefile{$type}});
                    347:     print OUT2 "\n";
                    348:     print SPEC join("",@{$dotspecfile{$type}});
                    349: }
                    350: close OUT2;
                    351: close OUT;
                    352: 
                    353: 
                    354: close SPEC;
                    355: 
                    356: `make -f $tag/BinaryRootMakefile directories`;
                    357: `make -f $tag/BinaryRootMakefile files`;
                    358: `make -f $tag/BinaryRootMakefile links`;
                    359: 
                    360: print `cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz LON-CAPA-$tag-$version`;
                    361: 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  362: print `cd $invokingdir; rm -Rf $tag`;
1.1       harris41  363: 
                    364: sub find_info {
                    365:     # only look for
                    366:     my ($file)=@_;
                    367:     my $line;
                    368:     if (($line=`find $file -type f -prune`)=~/^$file\n/) {
                    369: 	$line=`find $file -type f -prune -printf "\%s\t\%m\t\%u\t\%g"`;
                    370: 	return ("files",split(/\t/,$line));
                    371:     }
                    372:     elsif (($line=`find $file -type d -prune`)=~/^$file\n/) {
                    373: 	$line=`find $file -type d -prune -printf "\%s\t\%m\t\%u\t\%g"`;
                    374: 	return ("directories",split(/\t/,$line));
                    375:     }
                    376:     elsif (($line=`find $file -type l -prune`)=~/^$file\n/) {
1.6       harris41  377: 	$line=`find $file -type l -prune -printf "\%l\t\%m\t\%u\t\%g"`;
1.1       harris41  378: 	return ("links",split(/\t/,$line));
                    379:     }
                    380: 
                    381: }

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