Get the command in the rpm spec
Greg Swift
gregswift at gmail.com
Wed Nov 27 03:55:14 UTC 2013
So oddly enough you are the second person to bring this up in the last week
(other @dayjob).
So generally speaking here are some things:
a) rpm -i installs the software regardless [1]
b) rpm -U installs or upgrades. which makes it generally more useful.
c) most people recommend using yum directly rather than rpm these days,
similar to dpkg vs apt. it supports local installs natively, and behaves
as expected in most cases. yum install installs but not if there is an
existing package and yum upgrade doesn't install, just upgrades installed
packages.
d) if your weren't using a versioned directory the -i would break because
the filename would be the same, and thus the packages would conflict.
So other notes about your spec:
a) defining Package, Rev and Rel is redundant. when you put those in Name,
Version, and Release they are exposed as %{name}, %{version}, and
%{release} respectively.
b) just because you can references files directly from various parts of
our system doesn't mean its a good practice. you should have source files,
preferably a tarball that you extract in %prep section. Even if you aren't
'building' something in the %build section.
take that for what its worth.
-greg
[1] tbh i thought it told you that the package was already installed. But
I stopped using -i almost immediately, in favor of -U
another reference:
http://www.techblogistech.com/2011/07/the-difference-between-rpm-uvh-and-rpm-ivh-or-how-to-install-packages-in-rhel-centos-or-fedora/
On Tue, Nov 26, 2013 at 9:19 PM, Zheng, Wendy <wendy.zheng at emc.com> wrote:
> What’s the best practice when installing new version of software if the
> rpm supports installing multiple versions? Looks like the user has to use
> “rpm -U” command to do that. Because it’s not allowed to uninstall the
> software in %pre section, if the user uses “rpm -i” command to install
> software, there will be multiple versions installed on the system.
>
>
>
> Following is a spec example. I use it to build out 2 packages:
> Software-1.0-1.rpm and Software-2.0-1.rpm (change the Rev from 1.0 to 2.0)
>
>
>
> %define Package Software
>
> %define Rev 1.0
>
> %define Rel 1
>
> %define ViewName NightlyLinux
>
> %define UserName admin
>
> %define TempArea /tmp/%{Rev}
>
> %define __strip /bin/true
>
> Summary: Software
>
> Name: %{Package}
>
> Version: %{Rev}
>
> Release: %{Rel}
>
> License: ABC Corp.
>
> Group: Utilities/System
>
> Distribution: ABC Corp.
>
> Vendor: ABC Corp.
>
> Packager: ABC Corp.
>
> AutoReqProv: no
>
> BuildRoot: /tmp/linux/%{Rev}
>
>
>
> %description
>
> Software
>
>
>
> %prep
>
>
>
> %build
>
>
>
> %install
>
> install -m 775 -d $RPM_BUILD_ROOT/opt
>
> install -m 775 -d $RPM_BUILD_ROOT/opt/software-%{Rev}
>
> install -m 755 /emc/zhengw2/test/software.sh
> $RPM_BUILD_ROOT/opt/software-%{Rev}/software.sh
>
>
>
> %clean
>
>
>
> %pre
>
> echo "$1 in pre"
>
>
>
> %post
>
> echo "$1 in post"
>
>
>
>
>
> %preun
>
> echo "$1 in preun"
>
>
>
> %postun
>
> echo "$1 in postun"
>
>
>
> %files
>
> %defattr (-,root,root)
>
> %dir /opt/software-%{Rev}
>
> /opt/software-%{Rev}/software.sh
>
>
>
>
>
> Here is what I got:
>
>
>
> When installing the Software-1.0-1, it’s first time to install, $1 is 1,
> which is correct:
>
> **** # rpm -ivh Software-1.0-1.x86_64.rpm
>
> Preparing... ###########################################
> [100%]
>
> 1 in pre
>
> 1:Software ###########################################
> [100%]
>
> 1 in post
>
>
>
> Then I install Software-2.0-1, it’s the second time to install, $1 is 2,
> even though I’m using “rpm -i” command:
>
> **** # rpm -ivh Software-2.0-1.x86_64.rpm
>
> Preparing... ###########################################
> [100%]
>
> 2 in pre
>
> 1:Software ###########################################
> [100%]
>
> 2 in post
>
>
>
> Because I’ve installed 2 versions, there are 2 folders under /opt,
> Software-1.0 and Software-2.0.
>
> Then I uninstall 2.0 and try with “rpm -U” command, $1 is 2, same as when
> I’m using “rpm -i” command:
>
> **** # rpm -e Software-2.0-1
>
> 1 in preun
>
> 1 in postun
>
> **** # rpm -q Software
>
> Software-1.0-1
>
> **** # rpm -Uvh Software-2.0-1.x86_64.rpm
>
> Preparing... ###########################################
> [100%]
>
> 2 in pre
>
> 1:Software ###########################################
> [100%]
>
> 2 in post
>
> 1 in preun
>
> 1 in postun
>
>
>
> So in my case, $1 cannot be used to distinguish which command “rpm -i” or
> “rpm -U” is using.
>
>
>
> Thanks,
>
> Wendy
>
>
>
>
>
>
>
> *From:* Greg Swift [mailto:gregswift at gmail.com]
> *Sent:* 2013年11月27日 1:30
> *To:* General discussion about the RPM package manager
> *Cc:* Zheng, Wendy
> *Subject:* Re: Get the command in the rpm spec
>
>
>
> So... i think you need to step back and take a different approach. RPM
> shouldn't be leaving the old version the the filesystem regardless of what
> you are doing. Can you share your spec ?
>
>
>
> On Tue, Nov 26, 2013 at 10:43 AM, Zheng, Wendy <wendy.zheng at emc.com>
> wrote:
>
> Hi all,
>
> Really sorry that I didn't receive the previous response and resend the
> question again.
>
> In this case, I'm maintaining a rpm package which installs the software
> with version number in its installation path. But now, the software owner
> doesn't want multiple versions be installed on the machine. Removing the
> version number in the installation path costs much effort, so I'm seeking
> for a solution to stop the user from using "rpm -i" command and suggest him
> to use "rpm -U" or "rpm -F" when he installs a new version to the machine
> with a older one installed.
>
> Then I try to use the $1 in %pre to distinguish between install and
> upgrade. But I notice it doesn't work as the doc described because we allow
> multiple version of software install here. For example, software 1.0 is
> installed on the machine under path /opt/software-1.0. Now the user tries
> to install software 2.0. Because the software will be installed under path
> /opt/software-2.0, the use can install 2.0 with "rpm -i", "rpm -U" and "rpm
> -F" command. In this case, the value of $1 is 2 no matter which command is
> used. So in this case, I need to know the exact command the user is using
> instead of how many instances are installed on the system.
>
> The description of $1 says that, when install, $1==1. This is true when
> only one version of software is allowed, because in this case, the second
> "rpm -i" command will fails to install because conflicts with previous
> version.
>
> Best Regards,
> Wendy
> ________________________________________
> From: Zheng, Wendy
> Sent: Tuesday, November 26, 2013 4:38 PM
> To: rpm-list at lists.rpm.org
> Subject: Get the command in the rpm spec
>
>
> Hi expertise,
>
> I’m a newbie in RPM. I’m working on creating a RPM package which only one
> instance is allowed to install on users machine. Then I need to check
> whether there is other version of the software installed on the machine
> before installation (I’m writing some scripts in %pre section). Then I use
> the $1 variable to check for it. But I notice that no matter the user is
> running “rpm -i” command or “rpm -U”, $1 will always return 2 (if there is
> already one instance installed on the machine). But in fact I only need to
> stop the user when he’s running “rpm -i”, because “rpm -U” will remove the
> old versions after install.
> Then my question is, how can I know which command (“rpm -i” or “rpm -U”)
> the user is using in the rpm spec? Or do you have any other suggestion to
> this solution?
>
> Best Regards,
> Wendy Zheng
>
> _______________________________________________
> Rpm-list mailing list
> Rpm-list at lists.rpm.org
> http://lists.rpm.org/mailman/listinfo/rpm-list
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-list/attachments/20131126/b977366e/attachment-0001.html>
More information about the Rpm-list
mailing list