📄 0222-0224.html
字号:
<HTML>
<HEAD>
<TITLE>Maximum RPM (RPM):Making a Relocatable Package:EarthWeb Inc.-</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311054 //-->
<!-- TITLE=Maximum RPM (RPM)//-->
<!-- AUTHOR=Edward Bailey//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=15 //-->
<!-- PAGES=0215-0224 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0219-0221.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch16/0225-0228.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-222"><P>Page 222</P></A>
<P>
using the %post script, the files you move will not verify properly, and when the package
is erased, your users will get some disconcerting messages when RPM can't find the moved
files to erase them. If you have to resort to these kinds of tricks, it's probably best to forget trying
to make the package relocatable.
</P>
<H4><A NAME="ch15_ 8">
15.4.2. Test-Driving a Relocatable Package
</A></H4>
<P>Looks like cdplayer is a poor candidate for being made relocatable. However, since we did
get a hamstrung version to build successfully, we can use it to show how to test a relocatable
package. First, let's see if the binary package file's prefix has been recorded properly. We can do
this by using the --queryformat option to RPM's query mode:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -qp --queryformat `%{DEFAULTPREFIX}\n' cdplayer-1.0-1.i386.rpm
/usr/local
#
</PRE>
<!-- END CODE SNIP //-->
<P>The DEFAULTPREFIX tag directs RPM to display the prefix used during the build. As we can
see, it's /usr/local, just as we intended. The
--queryformat option is discussed in section 5.2.2
of Chapter 5, "Getting Information About Packages."
</P>
<P>So it looks like we have a relocatable package. Let's try a couple installs and see if we really
can install it in different locations. First, let's try a regular install with no prefix specified:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -Uvh cdplayer-1.0-1.i386.rpm
cdplayer ##################################################
#
</PRE>
<!-- END CODE SNIP //-->
<P>That seemed to work well enough. Let's see if the files went where we intended:
</P>
<!-- CODE //-->
<PRE>
# ls -al /usr/local/bin
total 558
-rwxr-xr-x 1 root root 40739 Oct 7 13:23 cdp*
lrwxrwxrwx 1 root root 18 Oct 7 13:40 cdplay -> /usr/local/bin/cdp*
...
# ls -al /usr/local/man/man1
total 9
-rwxr-xr-x 1 root root 4550 Oct 7 13:23 cdp.1*
...
#
</PRE>
<!-- END CODE //-->
<P>Looks good. Let's erase the package and reinstall it with a different prefix:
</P>
<!-- CODE //-->
<PRE>
# rpm -e cdplayer
# rpm -Uvh --prefix /usr/foonly/blather cdplayer-1.0-1.i386.rpm
cdplayer ##################################################
#
</PRE>
<!-- END CODE //-->
<P>Note that directories foonly and blather didn't exist prior to installing
cdplayer.
</P>
<A NAME="PAGENUM-223"><P>Page 223</P></A>
<P>RPM has another tag that can be used with the
--queryformat option. It's called INSTALLPREFIX, and using
it displays the prefix under which a package was installed. Let's give it a try:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -q --queryformat `%{INSTALLPREFIX}\n' cdplayer
/usr/foonly/blather
#
</PRE>
<!-- END CODE SNIP //-->
<P>As you can see, it displays the prefix you entered on the command line. Let's see if the
files were installed as directed:
</P>
<!-- CODE //-->
<PRE>
# cd /usr/foonly/blather/
# ls -al
total 2
drwxr-xr-x 2 root root 1024 Oct 7 13:45 bin/
drwxr-xr-x 3 root root 1024 Oct 7 13:45 man/
#
</PRE>
<!-- END CODE //-->
<P>So far, so good—the proper directories are there. Let's look at the man page first:
</P>
<!-- CODE //-->
<PRE>
# cd /usr/foonly/blather/man/man1/
# ls -al
total 5
-rwxr-xr-x 1 root root 4550 Oct 7 13:23 cdp.1*
#
</PRE>
<!-- END CODE //-->
<P>That looks okay. Now on to the files in bin:
</P>
<!-- CODE //-->
<PRE>
# cd /usr/foonly/blather/bin
# ls -al
total 41
-rwxr-xr-x 1 root root 40739 Oct 7 13:23 cdp*
lrwxrwxrwx 1 root root 18 Oct 7 13:45 cdplay -> /usr/local/bin/cdp
#
</PRE>
<!-- END CODE //-->
<P>Uh-oh. That cdplay symlink isn't right. What happened? If we look at
cdplayer's makefile, we see the answer:
</P>
<!-- CODE SNIP //-->
<PRE>
install: cdp cdp.1.Z
...
ln -s /usr/local/bin/cdp /usr/local/bin/cdplay
</PRE>
<!-- END CODE SNIP //-->
<P>Ah, when the software is installed during RPM's build process, the makefile sets up the
symbolic link. Looking back at the %files list, we see
cdplay listed. RPM blindly packaged the symlink, complete with its nonrelocatable string. This is why we
mentioned absolute symlinks as a prime example of nonrelocatable software.
</P>
<P>Fortunately, this problem isn't that difficult to fix. All we need to do is change the line in
the makefile that creates the symlink from this:
</P>
<!-- CODE SNIP //-->
<PRE>
ln -s /usr/local/bin/cdp /usr/local/bin/cdplay
</PRE>
<!-- END CODE SNIP //-->
<P>to this:
</P>
<!-- CODE SNIP //-->
<PRE>
ln -s ./cdp /usr/local/bin/cdplay
</PRE>
<!-- END CODE SNIP //-->
<P>Now cdplay will always point to cdp, no matter where it's installed. When building
relocatable packages, relative symlinks are your friend!
</P>
<A NAME="PAGENUM-224"><P>Page 224</P></A>
<P>After rebuilding the package, let's see if our modifications have the desired effect. First, a
normal install with the default prefix:
</P>
<!-- CODE //-->
<PRE>
# rpm -Uvh --nodeps cdplayer-1.0-1.i386.rpm
cdplayer ##################################################
# cd /usr/local/bin/
# ls -al cdplay
lrwxrwxrwx 1 root root 18 Oct 8 22:32 cdplay -> ./cdp*
</PRE>
<!-- END CODE //-->
<P>Next, we'll try a second install using the
--prefix option (after we first delete the original
package):
</P>
<!-- CODE //-->
<PRE>
# rpm -e cdplayer
# rpm -Uvh --nodeps --prefix /a/dumb/prefix cdplayer-1.0-1.i386.rpm
cdplayer ##################################################
# cd /a/dumb/prefix/bin/
# ls -al cdplay
lrwxrwxrwx 1 root root 30 Oct 8 22:34 cdplay -> ./cdp*
#
</PRE>
<!-- END CODE //-->
<P>As you can see, the trickiest part about building relocatable packages is making sure the
software you're packaging is up to the task. Once that part of the job is done, the actual
modifications are straightforward.
</P>
<BR><BR>
<P><CENTER>
<a href="0219-0221.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch16/0225-0228.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -