#!/usr/bin/perl
# Scott Harrison, September 30
# Automatically generate RPM listing files
# from file listing.
# GNU General Public License, Version 2, June 1991
# See http://www.gnu.org/copyleft/gpl.html.
# 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 <<END;
ERROR: This script only works with a properly installed RPM builder application.
Cannot find /usr/lib/rpm/rpmrc, so cannot generate customized rpmrc file.
Script aborting.
END
}
my ($tag,$version,$configuration_files,$documentation_files,$pathprefix)=@ARGV;
@ARGV=();
if (!$version) {
print "Usage: <TAG> <VERSION> [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,"</usr/lib/rpm/rpmrc") or die("Can't open /usr/lib/rpm/rpmrc");
@lines=<IN>;
close IN;
open (RPMRC,">$tag/SPECS/rpmrc");
foreach $line (@lines) {
if ($line=~/^macrofiles/) {
chop $line;
$line.=":./rpmmacros\n";
}
print RPMRC $line;
}
close RPMRC;
open (RPMMACROS,">$tag/SPECS/rpmmacros");
print RPMMACROS <<END;
\%_topdir $currentdir
\%__spec_install_post \\
/usr/lib/rpm/brp-strip \\
/usr/lib/rpm/brp-strip-comment-note \\
\%{nil}
END
close RPMMACROS;
# This needs to be dynamically based upon doc/otherfiles/rpm_list.txt
# at some point.
my $requires="";
if ($tag eq "setup") {
$requires=<<END;
PreReq: setup
PreReq: passwd
PreReq: util-linux
END
}
elsif ($tag eq "base") {
$requires=<<END;
PreReq: LON-CAPA-setup
PreReq: apache
PreReq: /etc/httpd/conf/access.conf
END
$requires2=<<END;
Requires: LON-CAPA-setup
Requires: raidtools
Requires: ncurses
Requires: popt
Requires: tcsh
Requires: redhat-release
Requires: diffutils
Requires: ed
Requires: dialog
Requires: rmt
Requires: sed
Requires: which
Requires: gawk
Requires: mingetty
Requires: info
Requires: portmap
Requires: openssh-clients
Requires: openssh
Requires: openssh-server
Requires: openssl
Requires: basesystem
Requires: ldconfig
Requires: filesystem
Requires: mktemp
Requires: termcap
Requires: shadow-utils
Requires: libtermcap
Requires: MAKEDEV
Requires: utempter
Requires: bash
Requires: logrotate
Requires: SysVinit
Requires: chkconfig
Requires: textutils
Requires: pwdb
Requires: vixie-cron
Requires: procps
Requires: modutils
Requires: psmisc
Requires: sysklogd
Requires: authconfig
Requires: zlib
Requires: sh-utils
Requires: mailcap
Requires: anacron
Requires: bc
Requires: bdflush
Requires: bind-utils
Requires: cpio
Requires: crontabs
Requires: etcskel
Requires: e2fsprogs
Requires: samba-client
Requires: apache-devel
Requires: autofs
Requires: findutils
Requires: gdbm
Requires: getty_ps
Requires: readline
Requires: glib10
Requires: inetd
Requires: losetup
Requires: gnupg
Requires: gpgp
Requires: urw-fonts
Requires: mailx
Requires: gzip
Requires: ld.so
Requires: less
Requires: passwd
Requires: sysreport
Requires: ncompress
Requires: mount
Requires: lilo
Requires: bzip2
Requires: grep
Requires: memprof
Requires: mars-nwe
Requires: pidentd
Requires: procinfo
Requires: units
Requires: routed
Requires: quota
Requires: pam
Requires: stat
Requires: setserial
Requires: mod_perl
Requires: rootfiles
Requires: nfs-utils
Requires: sendmail
Requires: sharutils
Requires: tmpwatch
Requires: shapecfg
Requires: tcp_wrappers
Requires: unzip
Requires: tetex-dvips
Requires: tetex-afm
Requires: tetex-latex
Requires: xntp3
Requires: rpm
Requires: wu-ftpd
Requires: setup
Requires: glibc
Requires: fileutils
Requires: initscripts
Requires: netatalk
Requires: apache
Requires: bash2
Requires: dev
Requires: samba
Requires: ghostscript
Requires: kernel-headers
Requires: kernel
Requires: linuxconf
Requires: tetex
Requires: tetex-fonts
Requires: util-linux
Requires: vim-common
Requires: perl
Requires: cracklib
Requires: cracklib-dicts
Requires: cdrecord
Requires: ghostscript-fonts
Requires: libgr
Requires: libjpeg
Requires: libpng
Requires: libungif-progs
Requires: libtiff
Requires: libungif
Requires: samba-common
Requires: ImageMagick
Requires: libgr-progs
Requires: man-pages
Requires: tar
Requires: vim-minimal
END
}
else {
$requires=<<END;
Requires: LON-CAPA-base
END
}
open (SPEC,">$tag/SPECS/LON-CAPA-$tag-$version.spec");
print SPEC <<END;
Summary: Files for the $tag component of LON-CAPA.
Name: LON-CAPA-$tag
Version: $version
Release: 1
Vendor: Laboratory for Instructional Technology Education, Division of Science and Mathematics Education, Michigan State University.
BuildRoot: $currentdir/BuildRoot
Copyright: GNU General Public License. Version 2, June 1991. Michigan State University patents may apply.
Group: Utilities/System
Source: LON-CAPA-$tag-$version.tar.gz
AutoReqProv: no
$requires
# requires: filesystem
\%description
This package is automatically generated by the make_rpm.pl perl
script (written by the LON-CAPA development team, www.lon-capa.org,
Scott Harrison). This implements the $tag component for LON-CAPA.
For more on the LON-CAPA project, visit http://www.lon-capa.org/.
\%prep
\%setup
\%build
rm -Rf "$currentdir/BuildRoot"
\%install
make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" directories
make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" files
make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" links
\%pre
echo "***********************************************************************"
echo "LON-CAPA LearningOnline with CAPA"
echo "http://www.lon-capa.org/"
echo "Gerd Kortemeyer, et al"
echo "Laboratory for Instructional Technology Education"
echo "Michigan State University"
echo "General Public License, Version 2, June 1991"
echo "** Michigan State University patents may apply **"
echo " "
echo "This installation assumes an installation of Redhat 6.2"
echo " "
echo "The server computer should be currently connected to the ethernet"
echo " "
echo "The files in this package are only those for the $tag component."
echo "Configuration files are sometimes part of the LON-CAPA-base RPM."
echo "***********************************************************************"
\%post
\%postun
\%files
END
foreach $file (<>) {
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`;
print `cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz LON-CAPA-$tag-$version`;
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/.`;
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));
}
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>