How does zypper configure from rpm?

Hi,
a bit of an odd question, but I was wondering how zypper installs and configures apps from the rpm. For example, if I install sddm (simple desktop display manager), not only do the various files get installed in /lib, /share etc as they are listed in the rpm files but also the sddm user and group gets created, the folder /var/lib/sddm gets created, permissions get set and a few other things.

At first I thought there is some script in the rpm that gets detected and run during the install but I can find any such thing in the rpm.

How does zypper do these extra configurations? Where are the scripts or what controls it?

Thanks,
Chris.

I do not know about this specific case, but it is quite normal for an RPM to have “after installation” scripts that will then be run. But because you say (though not prove/show) that there isn’t such a script within this specific RPM package I do not know.

Hi,

There is a script and it is called a specfile, files the end is .spec but it is not included in a normal rpm. have a look at OBS and you will see some examples of a spec files.
Also at software.opensuse.org you can follow the links and for the packages and you will see the spec files.

https://build.opensuse.org/package/show/openSUSE%3AFactory/sddm
https://build.opensuse.org/package/view_file/openSUSE:Factory/sddm/sddm.spec?expand=1

I hope that helps.

I am not sure that is what he means. He does not mean any specifications while building it, but scripts that are inside an RPM and that are run at e.g. installation and de-installation.

man rpm

talks about

… %pre, %post, %preun, %postun %pretrans, and %posttrans scriptlet(s).

You can check the rpm with the --scripts option, for instance:

bruno@LT_B:~/Downloads> rpm -q --scripts libblkid1-2.29.2-8.1.x86_64.rpm
postinstall program: /sbin/ldconfig
postuninstall program: /sbin/ldconfig
bruno@LT_B:~/Downloads>

Hi all and thank you for the replies. Using the rpm switch --scripts does indeed show me the spec file pre and post install scriptlet that I was after:

chris@asus-rog:~> rpm -q --scripts lightdm
preinstall scriptlet (using /bin/sh):
/usr/sbin/groupadd -r lightdm 2> /dev/null || :
/usr/sbin/useradd -r -g lightdm -s /bin/false -c "LightDM daemon" \
  -d /var/lib/lightdm lightdm 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
# Special trick: migrate users from lxdm to lightdm
# see https://lists.opensuse.org/opensuse-factory/2016-07/msg00417.html
. /etc/sysconfig/displaymanager
if  -z "$DISPLAYMANAGER" -o "$DISPLAYMANAGER" = "lxdm" ] ; then
    sed -i 's/^DISPLAYMANAGER=".*"/DISPLAYMANAGER="lightdm"/' /etc/sysconfig/displaymanager
fi
postuninstall scriptlet (using /bin/sh):
if  "$1" -eq 0 ]; then
    . /etc/sysconfig/displaymanager
    if  "$DISPLAYMANAGER" == "lightdm" ] ; then
        sed -i 's/^DISPLAYMANAGER="lightdm"/DISPLAYMANAGER=""/' /etc/sysconfig/displaymanager
    fi
fi

However it only works for installed packages. When I tried to examine the sddm package that I only downloaded I got :

chris@asus-rog:~> rpm -q --scripts sddm-0.17.0-lp150.8.1.x86_64.rpm
package sddm-0.17.0-lp150.8.1.x86_64.rpm is not installed
chris@asus-rog:~> ls sddm*
sddm-0.17.0-lp150.8.1.x86_64.rpm
chris@asus-rog:~>

I did find that the sddm spec file is contained in the source rpm folder at https://download.opensuse.org/source/distribution/leap/15.0/repo/oss/src/sddm-0.17.0-lp150.8.1.src.rpm

So I am making an assumption here that when a package gets installed via zypper that the source rpm gets downloaded too so that the spec file is accessed.

But what bugs me now is that since the rpms are deleted after installation, where is the --scripts switch finding the info. I can only assume it is in the rpm database at /var/lib/rpm.

chris@asus-rog:~> ls -al /var/lib/rpm
total 224628
drwxr-xr-x 1 root root       276 Jun  7 20:11 .
drwxr-xr-x 1 root root       846 Aug 16 14:29 ..
drwxr-xr-x 1 root root      1368 Sep  1 12:12 alternatives
-rw-r--r-- 1 root root  15319040 Sep  1 13:06 Basenames
-rw-r--r-- 1 root root     20480 Sep  1 12:12 Conflictname
-rw-r--r-- 1 root root   5652480 Sep  1 13:06 Dirnames
-rw-r--r-- 1 root root     77824 Sep  1 13:06 Group
-rw-r--r-- 1 root root     86016 Sep  1 13:06 Installtid
-rw-r--r-- 1 root root    270336 Sep  1 13:06 Name
-rw-r--r-- 1 root root     57344 Sep  1 12:12 Obsoletename
-rw-r--r-- 1 root root 200830976 Sep  1 13:06 Packages
-rw-r--r-- 1 root root   5943296 Sep  1 13:06 Providename
-rw-r--r-- 1 root root   1069056 Sep  1 13:05 Requirename
-rw-r--r-- 1 root root         0 Mar 12 16:28 .rpm.lock
-rw-r--r-- 1 root root    442368 Sep  1 13:06 Sha1header
-rw-r--r-- 1 root root    274432 Sep  1 13:06 Sigmd5
-rw-r--r-- 1 root root      8192 Sep  1 12:11 Triggername

Is there a guide/howto on how package management process works - what gets downloaded/run/archive/deleted etc? This is just for my idle curiosity as I am playing with “Linux From Scratch” in a virtual machine trying to understand linux a little better.

Thanks,
Chris.

Please a hint for the future.

You said in your first post here

At first I thought there is some script in the rpm that gets detected and run during the install but I can find any such thing in the rpm.

but you failed to tell how that search was done. That left us with the big question, did he use

rpm -q --scripts

or not?

So please, next time always explain in detail what you did and got (preferable by copy/past between CODE tags) and do not only tell vague stories. That is the only way to make others to answer with anything useful.

and on your question to learn more about RPM, apart from

man rpm

there is http://rpm.org/ , really not difficult to find using a search engine on the internet.

Are you sure? This is what I get:

bruno@LT_B:~/Downloads> rpm -q --scripts sddm-0.17.0-lp150.9.3.1.x86_64.rpm
preinstall scriptlet (using /bin/sh):
/usr/sbin/groupadd -r sddm 2> /dev/null || :
/usr/sbin/useradd -r -g sddm -s /bin/false -c "SDDM daemon" \
    -d /var/lib/sddm sddm 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
if  $1 -eq 2 -a -f /etc/sddm.conf ]; then
    # Avoid changing sddm.conf's timestamp if no modifications done
    tempconf="$(mktemp)"

    # SDDM 0.14.0 moved maui into the built-in resources
    # SDDM <= 0.15.0 had no system config dir, so we need to remove the
    # moved configuration options from the old single config file
    sed -e 's/^Current=maui$/Current=/g' \
        -e '\#^DisplayCommand=/etc/X11/xdm/Xsetup#d' \
        -e '\#^MinimumVT=7$#d' \
        -e '\#^ServerPath=/usr/bin/X$#d' \
        -e '\#^SessionCommand=/etc/X11/xdm/Xsession$#d' \
        /etc/sddm.conf > "${tempconf}"

    cmp -s "${tempconf}" "/etc/sddm.conf" || cp "${tempconf}" "/etc/sddm.conf"
    rm "${tempconf}"
fi
/usr/sbin/update-alternatives --install /usr/lib/X11/displaymanagers/default-displaymanager \
  default-displaymanager /usr/lib/X11/displaymanagers/sddm 25
postuninstall scriptlet (using /bin/sh):
 -f /usr/lib/X11/displaymanagers/sddm ] || /usr/sbin/update-alternatives \
  --remove default-displaymanager /usr/lib/X11/displaymanagers/sddm
bruno@LT_B:~/Downloads> 

Using gdm/Gnome here, so sddm is definitely not installed:

bruno@LT_B:~/Downloads> zypper se -iv sddm
Loading repository data...
Reading installed packages...
No matching items found.
bruno@LT_B:~/Downloads> 

Hi everyone,

I discovered why rpm reported no installed package. It was because rpm was run against a downloaded rpm file. If I run against the package name only I get info.

chris@asus-rog:~> rpm -qi --scripts sddm-0.17.0-lp150.8.1.x86_64.rpm
package sddm-0.17.0-lp150.8.1.x86_64.rpm is not installed
chris@asus-rog:~> rpm -qi --scripts sddm
Name        : sddm
Version     : 0.14.0
Release     : 5.1
Architecture: x86_64
Install Date: Wed 14 Mar 2018 04:53:50 PM AWST
Group       : System/GUI/KDE
Size        : 4367555
License     : GPL-2.0+
Signature   : RSA/SHA256, Tue 11 Jul 2017 10:21:15 PM AWST, Key ID b88b2fd43dbdc284
Source RPM  : sddm-0.14.0-5.1.src.rpm
Build Date  : Tue 11 Jul 2017 10:20:55 PM AWST
Build Host  : lamb11
Relocations : (not relocatable)
Packager    : http://bugs.opensuse.org
Vendor      : openSUSE
URL         : https://github.com/sddm/sddm
Summary     : QML-based display manager
Description :
SDDM is a display manager for X11. It uses technologies like QtQuick,
which in turn gives the designer the ability to create animated user
interfaces.
Distribution: openSUSE Leap 42.3
preinstall scriptlet (using /bin/sh):
/usr/sbin/groupadd -r sddm 2> /dev/null || :
/usr/sbin/useradd -r -g sddm -s /bin/false -c "SDDM daemon" \
    -d /var/lib/sddm sddm 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
if  $1 -eq 2 -a -f /etc/sddm.conf ]; then
    sed -i -e 's/^Current=maui$/Current=/g' /etc/sddm.conf
fi


I have browsed the man page and had a quick look at the rpm.org pages - maybe there are more details in that web site. But perhaps in my ignorance I did not explain properly what I was after. I doubt I will ever write an rpm file but I would like to at least understand the processes and flow path of activity (something with block diagrams and arrows;)) of adding and updating a program -

  1. Adding a repo (easy)
  2. How does yast/zypper read the various files in the repo?
  3. Does yast/zypper access the source rpm at the same time to get the spec file when installing a program?
  4. When do the databases in /var/lib/rpm get updated and by what files.
  5. How does yast/zypper detect an updated program? (from the https://download.opensuse.org/update/… site?)
  6. too many questions

Just put this down to curiosity rather than a problem.

Thanks again,
Chris.

Hi,

The backend that zypper is using is called** libzypp** see

the output of

zypper --no-refresh if libzypp

and the docs

https://doc.opensuse.org/projects/libzypp/HEAD/

How that works, i don’t know…

WARNING: the following is an “AFAIK educated guess” open to correction by those that really know how things are done. Use it only as a starting point if you have nothing better than this.

  1. Adding a repo (easy)
  2. How does yast/zypper read the various files in the repo?
    Starts from the metadata in https://download.opensuse.org/update/leap/15.0/oss/repodata/ the main file being xxxx-primary.xml.gz
    A local copy is stored at /var/cache/zypp/raw/repo-update/repodata
    If need be, the metadata tells what is available for download and where to find it.
  3. Does yast/zypper access the source rpm at the same time to get the spec file when installing a program?
    No, unless you actually installed the source files of course.
  4. When do the databases in /var/lib/rpm get updated and by what files.
    I don’t really know, but apparently most files there get updated when you update your system.
  5. How does yast/zypper detect an updated program? (from the https://download.opensuse.org/update/… site?)
    When the metadata shows that a newer version is available compared to what is actually installed on the system.
  6. too many questions

As an addition, I suggest that you try to understand the difference between RPM packages and the tool rpm that manages them and zypper. You can see zypper as one step higher above rpm.

E.g. when you install a package with rpm, it will install it. But when you install it with zypper, zypper will check for the dependencies mentioned in the package and automatic add them to the list of packages to be installed (it will tel you you though to give you the opportunity to bail out). Zypper will detect conflicts (and offer you solutions), etc.

(I talk about zypper here, but the same about YaST > Software management. Both are user interfaces to zypplib, the real workhorse).

On 09/01/2018 09:16 PM, kitman wrote:
>
> Hi all and thank you for the replies. Using the rpm switch --scripts
> does indeed show me the spec file pre and post install scriptlet that I
> was after:
>
>
> Code:
> --------------------
> chris@asus-rog:~> rpm -q --scripts lightdm
> preinstall scriptlet (using /bin/sh):
> /usr/sbin/groupadd -r lightdm 2> /dev/null || :
> /usr/sbin/useradd -r -g lightdm -s /bin/false -c “LightDM daemon”
> -d /var/lib/lightdm lightdm 2> /dev/null || :
> postinstall scriptlet (using /bin/sh):
> # Special trick: migrate users from lxdm to lightdm
> # see https://lists.opensuse.org/opensuse-factory/2016-07/msg00417.html
> . /etc/sysconfig/displaymanager
> if -z “$DISPLAYMANAGER” -o “$DISPLAYMANAGER” = “lxdm” ] ; then
> sed -i 's/^DISPLAYMANAGER="."/DISPLAYMANAGER=“lightdm”/’ /etc/sysconfig/displaymanager
> fi
> postuninstall scriptlet (using /bin/sh):
> if “$1” -eq 0 ]; then
> . /etc/sysconfig/displaymanager
> if “$DISPLAYMANAGER” == “lightdm” ] ; then
> sed -i ‘s/^DISPLAYMANAGER=“lightdm”/DISPLAYMANAGER=""/’ /etc/sysconfig/displaymanager
> fi
> fi
> --------------------
>
> However it only works for installed packages. When I tried to examine
> the sddm package that I only downloaded I got :
>
>
> Code:
> --------------------
> chris@asus-rog:~> rpm -q --scripts sddm-0.17.0-lp150.8.1.x86_64.rpm
> package sddm-0.17.0-lp150.8.1.x86_64.rpm is not installed
> chris@asus-rog:~> ls sddm

> sddm-0.17.0-lp150.8.1.x86_64.rpm
> chris@asus-rog:~>
> --------------------

No, the reason this did not work as you expected is because you did not
tell the ‘rpm’ command to point to a particular file, but instead told it
to look for a package named sddm-0.17.0-lp150.8.1.x86_64.rpm because you
did not tell it to look for a package file with the -p option; assuming
the package is in your current working directory, use this command:


rpm -q --scripts -p sddm-0.17.0-lp150.8.1.x86_64.rpm


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the
forum as I do not use the web interface often.

Sorry, possibly my fault: the 4.14.1 version of rpm in LEAP 15.0 apparently does not need the -p option when the full filename is specified, while it prints info about the installed package when only the package name (e.g. “sddm”) is issued.
Maybe the OP is running LEAP 42.x or uses an older version of rpm.

On 09/03/2018 07:46 AM, OrsoBruno wrote:
>
> Sorry, possibly my fault: the 4.14.1 version of rpm in LEAP 15.0
> apparently does not need the -p option when the full filename is
> specified, while it prints info about the installed package when only
> the package name (e.g. “sddm”) is issued.
> Maybe the OP is running LEAP 42.x or uses an older version of rpm.

That was my guess too, especially after some others’ examples where it did
work magically finding that package; seems like a reasonable enhancement,
assuming the package is not already installed, as that is something I’ve
had to explain to folks about a million times, and that is how my
older-than-Leap-15 laptop works.


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the
forum as I do not use the web interface often.

Hi,

I believe I have nutted this out from your respective answers. I also had a gross misunderstanding on rpm contents.

  1. The downloaded rpm file does in fact contain the scripts. When I initially inspected a manually downloaded rpm file the default application to open it was ark archiver. This does list the file contents to install but I learned from the rpm.org web site that the rpm file structure is not a straight forward archive. That is, other details like specs/scripts are not shown in ark. This is why I was asking the original question.

  2. All details of installed rpms are located in various databases under /var/lib/rpm after the rpms are installed then deleted from /var/cache/zypp/. Don’t touch;)

  3. Yes, I did find the -p switch to open a rpm file directly.

4, Yes, I was testing on a Leap15.0 laptop AND a Leap42.3 desktop so maybe that’s why we got slightly different results.

  1. Zypper/libzypp and rpm are two separate applications that don’t call on each other. But both do use the /var/lib/rpm databases.

So all good now and I thank you for your replies.
Chris.

Maybe I am repeating myself (I am sure I am in general, but maybe even in this thread).
You told us your conclusion (I can not find the scripts), but you failed to tell us what you did to try to find them (by copy/paste of your trial between CODE tags in the post).

On the change to be accused of being unfriendly: this was useless. Nobody can give any sound technical answer on such a “conclusion”. Answers that come to my mind in such a case differ from “did you switch on the system and let it boot” to " was your glass globe broken" and anything before, between and after that. :cry:

I often skip such threads to go for more promising ones.

As one member her once said: “We are non-believers, we want to see computer facts”.

Next time better, because you want to learn and understand things, what is something we love. lol!