Annotation of loncom/build/make_rpm.pl, revision 1.4
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:
90: open (SPEC,">$tag/SPECS/LON-CAPA-$tag-$version.spec");
91:
92: print SPEC <<END;
93: Summary: Files for the $tag component of LON-CAPA.
94: Name: LON-CAPA-$tag
95: Version: $version
96: Release: 1
97: Vendor: Laboratory for Instructional Technology Education, Division of Science and Mathematics Education, Michigan State University.
98: BuildRoot: $currentdir/BuildRoot
99: Copyright: GNU General Public License. Version 2, June 1991. Michigan State University patents may apply.
100: Group: Utilities/System
101: Source: LON-CAPA-$tag-$version.tar.gz
102: AutoReqProv: no
103: # requires: filesystem
104: \%description
105: This package is automatically generated by the make_rpm.pl perl
106: script (written by the LON-CAPA development team, www.lon-capa.org,
107: Scott Harrison). This implements the $tag component for LON-CAPA.
108: For more on the LON-CAPA project, visit http://www.lon-capa.org/.
109:
110: \%prep
111: \%setup
112:
113: \%build
114: rm -Rf "$currentdir/BuildRoot"
115:
116: \%install
117: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" directories
118: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" files
119: make ROOT="\$RPM_BUILD_ROOT" SOURCE="$currentdir/BinaryRoot" links
120:
121: \%pre
122: echo "***********************************************************************"
123: echo "LON-CAPA LearningOnline with CAPA"
124: echo "http://www.lon-capa.org/"
125: echo "Gerd Kortemeyer, et al"
126: echo "Laboratory for Instructional Technology Education"
127: echo "Michigan State University"
128: echo "General Public License, Version 2, June 1991"
129: echo "** Michigan State University patents may apply **"
130: echo " "
131: echo "This installation assumes an installation of Redhat 6.2"
132: echo " "
133: echo "The server computer should be currently connected to the ethernet"
134: echo " "
135: echo "The files in this package are only those for the $tag component."
136: echo "Configuration files are sometimes part of the LON-CAPA-base RPM."
137: echo "***********************************************************************"
138:
139: \%post
140: \%postun
141:
142: \%files
143: END
144:
145: foreach $file (<>) {
146: chop $file;
1.4 ! harris41 147: my $comment="";
! 148: if ($file=~/\s+\#(.*)$/) {
! 149: $file=~s/\s+\#(.*)$//;
! 150: $comment=$1;
! 151: }
! 152: my $config="";
! 153: if ($comment=~/config/i) {
! 154: $config="\%config ";
! 155: }
1.1 harris41 156: if (($type,$size,$octalmode,$user,$group)=find_info($file)) {
157: $octalmode="0" . $octalmode if length($octalmode)<4;
158: if ($pathprefix) {
159: $file=~s/^$pathprefix//;
160: }
161: if ($type eq "files") {
162: push @{$BinaryRootMakefile{$type}},"\tinstall -D -m $octalmode $pathprefix$file $binaryroot$file\n";
163: push @{$Makefile{$type}},"\tinstall -D -m $octalmode \$(SOURCE)$file \$(ROOT)$file\n";
1.4 ! harris41 164: push @{$dotspecfile{$type}},"$config\%attr($octalmode,$user,$group) $file\n";
1.1 harris41 165: }
166: elsif ($type eq "directories") {
167: push @{$BinaryRootMakefile{$type}},"\tinstall -m $octalmode -d $binaryroot$file\n";
168: push @{$Makefile{$type}},"\tinstall -m $octalmode -d \$(SOURCE)$file \$(ROOT)$file\n";
169: push @{$dotspecfile{$type}},"\%dir \%attr($octalmode,$user,$group) $file\n";
170: }
171: elsif ($type eq "links") {
172: my $link=$size; # I use the size variable to pass the link value from the subroutine find_info
173: $link=~s/^$pathprefix//;
174: push @{$BinaryRootMakefile{$type}},"\tln -s $link $binaryroot$file\n";
175: push @{$Makefile{$type}},"\tln -s $link \$(ROOT)$file\n";
176: push @{$dotspecfile{$type}},"\%attr(-,$user,$group) $file\n";
177: }
178: }
179: }
180:
181: open OUT, ">$tag/SOURCES/LON-CAPA-$tag-$version/Makefile";
182: open OUT2, ">$tag/BinaryRootMakefile";
183: foreach $type ("directories","files","links") {
184: print OUT "$type\:\n";
185: print OUT join("",@{$Makefile{$type}});
186: print OUT "\n";
187: print OUT2 "$type\:\n";
188: print OUT2 join("",@{$BinaryRootMakefile{$type}});
189: print OUT2 "\n";
190: print SPEC join("",@{$dotspecfile{$type}});
191: }
192: close OUT2;
193: close OUT;
194:
195:
196: close SPEC;
197:
198: `make -f $tag/BinaryRootMakefile directories`;
199: `make -f $tag/BinaryRootMakefile files`;
200: `make -f $tag/BinaryRootMakefile links`;
201:
202: print `cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz LON-CAPA-$tag-$version`;
203: 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.4 ! harris41 204: # print `cd $invokingdir; rm -Rf $tag`;
1.1 harris41 205:
206: sub find_info {
207: # only look for
208: my ($file)=@_;
209: my $line;
210: if (($line=`find $file -type f -prune`)=~/^$file\n/) {
211: $line=`find $file -type f -prune -printf "\%s\t\%m\t\%u\t\%g"`;
212: return ("files",split(/\t/,$line));
213: }
214: elsif (($line=`find $file -type d -prune`)=~/^$file\n/) {
215: $line=`find $file -type d -prune -printf "\%s\t\%m\t\%u\t\%g"`;
216: return ("directories",split(/\t/,$line));
217: }
218: elsif (($line=`find $file -type l -prune`)=~/^$file\n/) {
219: $line=`find $file -type l -prune -printf "\%h/\%l\t\%m\t\%u\t\%g"`;
220: return ("links",split(/\t/,$line));
221: }
222:
223: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>