Annotation of loncom/build/make_rpm.pl, revision 1.3
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;
147: if (($type,$size,$octalmode,$user,$group)=find_info($file)) {
148: $octalmode="0" . $octalmode if length($octalmode)<4;
149: if ($pathprefix) {
150: $file=~s/^$pathprefix//;
151: }
152: if ($type eq "files") {
153: push @{$BinaryRootMakefile{$type}},"\tinstall -D -m $octalmode $pathprefix$file $binaryroot$file\n";
154: push @{$Makefile{$type}},"\tinstall -D -m $octalmode \$(SOURCE)$file \$(ROOT)$file\n";
155: push @{$dotspecfile{$type}},"\%attr($octalmode,$user,$group) $file\n";
156: }
157: elsif ($type eq "directories") {
158: push @{$BinaryRootMakefile{$type}},"\tinstall -m $octalmode -d $binaryroot$file\n";
159: push @{$Makefile{$type}},"\tinstall -m $octalmode -d \$(SOURCE)$file \$(ROOT)$file\n";
160: push @{$dotspecfile{$type}},"\%dir \%attr($octalmode,$user,$group) $file\n";
161: }
162: elsif ($type eq "links") {
163: my $link=$size; # I use the size variable to pass the link value from the subroutine find_info
164: $link=~s/^$pathprefix//;
165: push @{$BinaryRootMakefile{$type}},"\tln -s $link $binaryroot$file\n";
166: push @{$Makefile{$type}},"\tln -s $link \$(ROOT)$file\n";
167: push @{$dotspecfile{$type}},"\%attr(-,$user,$group) $file\n";
168: }
169: }
170: }
171:
172: open OUT, ">$tag/SOURCES/LON-CAPA-$tag-$version/Makefile";
173: open OUT2, ">$tag/BinaryRootMakefile";
174: foreach $type ("directories","files","links") {
175: print OUT "$type\:\n";
176: print OUT join("",@{$Makefile{$type}});
177: print OUT "\n";
178: print OUT2 "$type\:\n";
179: print OUT2 join("",@{$BinaryRootMakefile{$type}});
180: print OUT2 "\n";
181: print SPEC join("",@{$dotspecfile{$type}});
182: }
183: close OUT2;
184: close OUT;
185:
186:
187: close SPEC;
188:
189: `make -f $tag/BinaryRootMakefile directories`;
190: `make -f $tag/BinaryRootMakefile files`;
191: `make -f $tag/BinaryRootMakefile links`;
192:
193: print `cd $currentdir/SOURCES; tar czvf LON-CAPA-$tag-$version.tar.gz LON-CAPA-$tag-$version`;
194: 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/.`;
195: print `cd $invokingdir; rm -Rf $tag`;
196:
197: sub find_info {
198: # only look for
199: my ($file)=@_;
200: my $line;
201: if (($line=`find $file -type f -prune`)=~/^$file\n/) {
202: $line=`find $file -type f -prune -printf "\%s\t\%m\t\%u\t\%g"`;
203: return ("files",split(/\t/,$line));
204: }
205: elsif (($line=`find $file -type d -prune`)=~/^$file\n/) {
206: $line=`find $file -type d -prune -printf "\%s\t\%m\t\%u\t\%g"`;
207: return ("directories",split(/\t/,$line));
208: }
209: elsif (($line=`find $file -type l -prune`)=~/^$file\n/) {
210: $line=`find $file -type l -prune -printf "\%h/\%l\t\%m\t\%u\t\%g"`;
211: return ("links",split(/\t/,$line));
212: }
213:
214: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>