⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0219-0221.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 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="0215-0218.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0222-0224.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-219"><P>Page 219</P></A>







<P>None of these approaches are very appealing, are they? Some software just doesn't relocate

very well. In general, the following things are warning signs that relocation is going to be a problem:

</P>



<UL>

<LI>          The software

contains one or more files that must be installed in specific directories.

<LI>          The software refers to system files using relative paths (which is really just another

way of saying that the software must be installed in a particular directory).

</UL>



<P>If these kinds of issues crop up, making the software relocatable is going to be tough.

</P>



<H4><A NAME="ch15_ 6">

15.3.3. The Relocatable Software Is Referenced by Other Software

</A></H4>



<P>Even assuming that the software is written so that it can be put in a relocatable package,

there still might be a problem, which relates not to the relocatable software itself, but to other

programs that reference the relocatable software.

</P>



<P>For example, there are times when a package needs to execute other programs. This might

include backup software that needs to send mail, or a communications program that needs to

compress files. If these underlying programs were relocatable, and not installed where other

packages expect them, they would be of little use.

</P>



<P>Granted, this isn't a common problem, but it can happen. And for the package builder

interested in building relocatable packages, it's an issue that needs to be explored.

Unfortunately, this type of problem can be the hardest to find.

</P>



<P>If, however, a software product has been found to be relocatable, the mechanics of

actually building a relocatable package are pretty straightforward. Let's give it a try.

</P>



<H3><A NAME="ch15_ 7">

15.4. Building a Relocatable Package

</A></H3>



<P>For this example, we'll use our tried-and-true

cdplayer application. Let's start by reviewing the spec file for possible problems:

</P>

<!-- CODE //-->

<PRE>

#

# Sample spec file for cdplayer app...

#

Summary:A CD player app that rocks!

Name: cdplayer

...

%files

%doc README

/usr/local/bin/cdp

/usr/local/bin/cdplay

%doc /usr/local/man/man1/cdp.1

%config /etc/cdp-config

</PRE>

<!-- END CODE //-->



<P>Everything looks all right, except for the

%files list. There are files in /usr/local/bin, a

man page in /usr/local/man/man1, and a config file in

/etc. The prefix /usr/local would work pretty well, except for that

cdp-config file.

</P>



<A NAME="PAGENUM-220"><P>Page 220</P></A>







<P>For the sake of this first build, we'll declare the config file unnecessary and remove it from

the %files list. We'll then add a prefix tag line, setting the prefix to

/usr/local. After these changes are made, let's try a build:

</P>

<!-- CODE //-->

<PRE>

# rpm -ba cdplayer-1.0.spec

* Package: cdplayer

+ umask 022

+ echo Executing: %prep

Executing: %prep

+ cd /usr/src/redhat/BUILD

+ cd /usr/src/redhat/BUILD

+ rm -rf cdplayer-1.0

+ gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz

...

Binary Packaging: cdplayer-1.0-1

Package Prefix = usr/local

File doesn't match prefix (usr/local): /usr/doc/cdplayer-1.0-1

File not found: /usr/doc/cdplayer-1.0-1

Build failed.

#

</PRE>

<!-- END CODE //-->



<P>The build proceeded normally up to the point of actually creating the binary package.

The Package Prefix = usr/local line confirms that RPM picked up our prefix tag line. But

the build stopped&#151;and on a file called

/usr/doc/cdplayer-1.0-1. But that file isn't even in <BR>

the %files list. What's going on?

</P>



<P>Take a closer look at the %files list. See the line that reads

%doc README? In section 13.6.1 in Chapter 13, &quot;Inside the Spec File,&quot; we discussed how the

%doc directive creates a directory under /usr/doc. That's the file that killed the build&#151;the directory created by the

%doc directive.

</P>



<P>Let's temporarily remove that line from the

%files list and try again:

</P>



<!-- CODE //-->

<PRE>

# rpm -ba cdplayer-1.0.spec

* Package: cdplayer

+ umask 022

+ echo Executing: %prep

Executing: %prep

+ cd /usr/src/redhat/BUILD

+ cd /usr/src/redhat/BUILD

+ rm -rf cdplayer-1.0

+ gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz

...

Binary Packaging: cdplayer-1.0-1

Package Prefix = usr/local

Finding dependencies...

Requires (2): libc.so.5 libncurses.so.2.0

bin/cdp

bin/cdplay

man/man1/cdp.1

90 blocks

Generating signature: 0

Wrote: /usr/src/redhat/RPMS/i386/cdplayer-1.0-1.i386.rpm

+ umask 022

+ echo Executing: %clean



</PRE>

<!-- END CODE //-->



<A NAME="PAGENUM-221"><P>Page 221</P></A>



<!-- CODE //-->

<PRE>



Executing: %clean

+ cd /usr/src/redhat/BUILD

+ cd cdplayer-1.0

+ exit 0

Source Packaging: cdplayer-1.0-1

cdplayer-1.0.spec

cdplayer-1.0.tgz

82 blocks

Generating signature: 0

Wrote: /usr/src/redhat/SRPMS/cdplayer-1.0-1.src.rpm

#

</PRE>

<!-- END CODE //-->



<P>The build completed normally. Note how the files to be placed in the binary package file

are listed, minus the prefix /usr/local. Some of you might be wondering why the

cdp.1 file didn't cause problems. After all, it had a

%doc directive, too. The answer lies in the way the file

was specified. Since the file was specified using an absolute path, and that path started with

the prefix /usr/local, there was no problem. A more complete discussion of the

%doc directive can be found in section 13.6.1 in Chapter 13.

</P>



<H4>

15.4.1. Tying Up the Loose Ends

</H4>



<P>In the course of building this package, we ran into two hitches:

</P>



<UL>

<LI>          The config

file cdp-config couldn't be installed in /etc.

<LI>          The

README file could not be packaged using the %doc directive.

</UL>



<P>Both of these issues are due to the fact that the files' paths do not start with the default

prefix path /usr/local. Does this mean that this package cannot be relocated? Possibly, but there

are two options to consider. The first option is to review

the prefix.  For our example, if we chose the prefix

/usr instead of /usr/local, the README file could be packaged using the

%doc directive since the default documentation directory is

/usr/doc. Another approach would be to use the

%docdir directive to define another documentation-holding directory somewhere along

the prefix path. (For more information on the

%docdir directive, see section 13.6.2 in Chapter 13.)

</P>



<P>This approach wouldn't work for /etc/cdp-config, though. To package that file, we'd need

to resort to more extreme measures. Basically, this approach would

entail packaging the file in an acceptable directory (something under

/usr/local) and using the %post postinstall script

to move the file to /etc. Pointing a symlink at the config file is another possibility.

</P>



<P>Of course, this approach has some problems. First, you'll need to write a

%postun script to undo what the %post script does. (Install and erase-time scripts have an environment

variable, RPM_INSTALL_PREFIX, that can be used to write scripts that are able to act appropriately if

the package is relocated. See section 13.3.2 in Chapter 13 for more information.) A

%verifyscript that made sure the files were in place would be nice, too. Second, because the file or

symlink wasn't installed by RPM, there's no entry for it in the RPM database. This reduces the

utility of RPM's -c and -d options when issuing queries. Finally, if you actually move files

around

</P>



<P><CENTER>

<a href="0215-0218.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0222-0224.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -