In this example, our spec file will have the following three source tags: [1]
source: source-zero.tar.gz source1: source-one.tar.gz source2: source-two.tar.gz
To unpack the first source is not difficult; all that is required is to use% setup without parameters:
%setup
This creates the following set of commands:
cd /usr/src/redhat/BUILD rm -rf cdplayer-1.0 gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf - if [ $? -ne 0 ]; then exit $? fi cd cdplayer-1.0 cd /usr/src/redhat/BUILD/cdplayer-1.0 chown -R root.root . chmod -R a+rX,gw,ow .
....
Now add the second source file. It is more interesting here. First, we need to determine which source tag (and therefore which source file) we are talking about. Therefore, we need to use the -a or -b option, depending on the characteristics of the original archive. In this example, let's say that -a is the option we want. By adding this option, plus "1" to point to the source file specified in the source1 tag, we have:
%setup -a 1
Since we have already seen that using the -a or -b option leads to duplicate decompression, we need to disable the default decompression by adding the -T option:
%setup -T -a 1
Then we need to make sure that the top-level directory is not deleted. Otherwise, the first source file that we just unzipped will disappear. This means that we need to enable the -D option to prevent this from happening. By adding this final version and now including the full macro in our% prep script, we now have:
%setup %setup -T -D -a 1
This will result in the following commands:
cd /usr/src/redhat/BUILD rm -rf cdplayer-1.0 gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf - if [ $? -ne 0 ]; then exit $? fi cd cdplayer-1.0 cd /usr/src/redhat/BUILD/cdplayer-1.0 chown -R root.root . chmod -R a+rX,gw,ow . cd /usr/src/redhat/BUILD cd cdplayer-1.0 gzip -dc /usr/src/redhat/SOURCES/source-one.tar.gz | tar -xvvf - if [ $? -ne 0 ]; then exit $? fi cd /usr/src/redhat/BUILD/cdplayer-1.0 chown -R root.root . chmod -R a+rX,gw,ow .
So far so good. Let me include the last source file, but with this, we say that it needs to be unzipped in the cdplayer-1.0 subdirectory called the database. Can we use% setup in this case?
We could if source-two.tgz created a database subdirectory. If not, then this will need to be done manually. For the purposes of our example, suppose that source-two.tgz was not created to include a database subdirectory, so we will have to do it ourselves. Here is our% prep script now:
%setup %setup -T -D -a 1 mkdir database cd database gzip -dc /usr/src/redhat/SOURCES/source-two.tar.gz | tar -xvvf -
Here's the result of the script:
cd /usr/src/redhat/BUILD rm -rf cdplayer-1.0 gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf - if [ $? -ne 0 ]; then exit $? fi cd cdplayer-1.0 cd /usr/src/redhat/BUILD/cdplayer-1.0 chown -R root.root . chmod -R a+rX,gw,ow . cd /usr/src/redhat/BUILD cd cdplayer-1.0 gzip -dc /usr/src/redhat/SOURCES/source-one.tar.gz | tar -xvvf - if [ $? -ne 0 ]; then exit $? fi mkdir database cd database gzip -dc /usr/src/redhat/SOURCES/source-two.tar.gz | tar -xvvf -
The three commands we added to unpack the last set of sources were added at the end of the% prep script.