2

I have build a package_version_1.rpm. Now im trying to build a package_version_2.rpm. Default behavior of the RPM will remove any file from package_version_1.rpm that is not upgraded from package_version_2.rpm. To achieve what i want i must install the package like that:

sudo rpm -i --nopreun --nopostun package_version_2.rpm

but this is not what i want. Im looking to find a solution to escape preun and postun from inside the .spec file.

After some research for example (and ofc almost any post in stackoverflow with keywords "RPM .spec preun postun"):

http://meinit.nl/rpm-spec-prepostpreunpostun-argument-values https://www.ibm.com/developerworks/library/l-rpm2/

i find out that with that command: rpm --showrc prints out all macros. I export them to a txt file to be easy to search and i try to experiment. I create case's in preun and postun and im trying to find a solution to disable preun and postun in case of upgrade. I try every possible idea that i had but no luck.

In case section you can see some of my attemps...

%define debug_package %{nil}
%global _python_bytecompile_errors_terminate_build 0
%define _binaries_in_noarch_packages_terminate_build 0

%preun
# this runs before remove the package
echo '###################################################################'
echo 'Run preun package_version_1.rpm'
case "$1" in
  0)
    echo 'case 0 preun'
    # This is an uninstallation.
  ;;
  1)
    # %systemd_postun %{nil}
    # systemd_user_preun %{nil}
    echo 'case 1 preun'
    # systemctl --nopreun
    exit 0
  ;;
esac
echo '###################################################################'

%postun
# this runs after the package has be removed
echo '###################################################################'
echo 'Run postun package_version_1.rpm'
case "$1" in
  0)
    echo 'case 0 postun'
    # This is an uninstallation.
  ;;
  1)
    # %systemd_postun %{nil}
    # systemd_user_postun   %{nil}
    echo 'case 1 postun'
    # systemctl --nopostun
    exit 0
  ;;
esac
echo '###################################################################'

any help will be appreciated

Chris
  • 21
  • 3
  • 1
    Pretty sure you can't. Why don't you just include the new files in the new RPM? If you're worried about size, create a deltarpm as well. – Aaron D. Marasco Mar 02 '18 at 23:55
  • Thank you for the comment and sorry for the delay.. Size is not exactly my problem. – Chris Mar 05 '18 at 16:48

2 Answers2

0

One super-hackish way to try:

  • Requires(pre): mypackage = 1.0
  • In pre scriptlet:
    • mkdir -p %{_localstatedir}/lib/rpm-state/mypackage ( ref )
    • copy files you want to "keep" from 1.0
  • In posttrans scriptlet:
    • move files you wanted back to where they belong
    • rmdir the temp folder

Note: This is bad and will break a few things (mainly verification and file-package ownership) because you are effectively putting the files in place outside of the rpm database. You are also requiring the two package versions to be installed in two separate transactions with no way to go straight to version 2 from a fresh OS install.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39
  • File package ownership it’s not really important in my situation. About the rpm database, it’s the only thing I try not to break, else I have done the copy files etc with python, (more easy for me, the rpm package it’s a new story for me...) Anyway your idea about requires als preinstalled it’s not bad and If i have to do it manually copy/place files I will try it. Thank you for your time. – Chris Mar 05 '18 at 22:59
0

You can export some environment variable in %post scriptlet or can update some flag in external file. On the basis of that environment variable or flag you can decide what should be done in %preun or %postun scriptlets.

Note : But %preun and %postun will invoked from previous (old) package, so this solution will work only when you upgrade after build with these changes. Suppose you made suggested changes in package version 2, so solution will work when you upgrade from version 2 to any higher version

Anil Agrawal
  • 2,748
  • 1
  • 24
  • 31