View scripts which run when installing using RPM file

When using RPM (Redhat Package Manager) for installing a package or application, we just use the following syntax and get the things done!

rpm -ivh {package-file.rpm}

However, never realize what happens in the background.

For those who are curious to know this, they can get the details of the script which execute while using rpm files with an additional switch for the rpm command. You can use the –scripts option/switch while querying a package file or and installed package.

The following are a few example to explain this.

Find scripts which will run when installing a RPM package file

So I am trying to install ntop 3.3 using rpm file ntop-3.3.8-2.el4.rf.x86_64.rpm. The following command will provide me the script which will execute when installing this package file:

[[email protected] ~]# rpm -qp –scripts ntop-3.3.8-2.el4.rf.x86_64.rpm


preinstall scriptlet (using /bin/sh):
if ! /usr/bin/id ntop &>/dev/null; then
    /usr/sbin/useradd -M -s /sbin/nologin -r ntop &>/dev/null || \
        logger -t ntop/rpm "Unexpected error adding user \"ntop\". Abort installation."
postinstall scriptlet (using /bin/sh):
/sbin/chkconfig --add ntop
/sbin/ldconfig 2>/dev/null

if /usr/bin/id ntop &>/dev/null; then
    /usr/sbin/usermod -s /sbin/nologin -c "ntop user" -g ntop \
        -d /var/ntop ntop &>/dev/null || \
        logger -t ntop/rpm "Unexpected error modifying user \"ntop\". Abort installation."
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ]; then
    /sbin/service ntop stop &>/dev/null || :
    /sbin/chkconfig --del ntop
postuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ]; then
    /usr/sbin/userdel ntop || logger -t ntop/rpm "User \"ntop\" could not be deleted."
    /usr/sbin/groupdel ntop || logger -t ntop/rpm "Group \"ntop\" could not be deleted."

if [ $1 -ge 1 ]; then
    /sbin/service ntop condrestart &>/dev/null || :
/sbin/ldconfig 2>/dev/null

Find scripts which ran for installation of a RPM package

You can use the same switch for querying an installed rpm package. Taking an example for postfix-2.2.10-1.RHEL4.2 installed on the system, I will try to find the scripts which executed.

[[email protected] ~]# rpm -q –scripts postfix-2.2.10-1.RHEL4.2


preinstall scriptlet (using /bin/sh):
# Add user and groups if necessary
/usr/sbin/groupadd -g 90 -r postdrop 2>/dev/null
/usr/sbin/groupadd -g 89 -r postfix 2>/dev/null
/usr/sbin/groupadd -g 12 -r mail 2>/dev/null
/usr/sbin/useradd -d /var/spool/postfix -s /sbin/nologin -g postfix -G mail -M -r -u 89 postfix 2>/dev/null
exit 0
postinstall scriptlet (using /bin/sh):
umask 022

/sbin/chkconfig --add postfix

# upgrade configuration files if necessary
sh /etc/postfix/post-install \
   config_directory=/etc/postfix \
   daemon_directory=/usr/libexec/postfix \
   command_directory=/usr/sbin \
   mail_owner=postfix \
   setgid_group=postdrop \
   manpage_directory=/usr/share/man \
   sample_directory=/usr/share/doc/postfix-2.2.10/samples \
   readme_directory=/usr/share/doc/postfix-2.2.10/README_FILES \

/usr/sbin/alternatives --install /usr/sbin/sendmail mta /usr/sbin/sendmail.postfix 30 \
        --slave /usr/bin/mailq mta-mailq /usr/bin/mailq.postfix \
        --slave /usr/bin/newaliases mta-newaliases /usr/bin/newaliases.postfix \
        --slave /etc/pam.d/smtp mta-pam /etc/pam.d/smtp.postfix \
        --slave /usr/bin/rmail mta-rmail /usr/bin/rmail.postfix \
   --slave /usr/lib/sendmail mta-sendmail /usr/lib/sendmail.postfix \
        --slave /usr/share/man/man1/mailq.1.gz mta-mailqman /usr/share/man/man1/mailq.postfix.1.gz \
        --slave /usr/share/man/man1/newaliases.1.gz mta-newaliasesman /usr/share/man/man1/newaliases.postfix.1.gz \
        --slave /usr/share/man/man8/sendmail.8.gz mta-sendmailman /usr/share/man/man1/sendmail.postfix.1.gz \
        --slave /usr/share/man/man5/aliases.5.gz mta-aliasesman /usr/share/man/man5/aliases.postfix.5.gz \
   --initscript postfix
preuninstall scriptlet (using /bin/sh):
umask 022

if [ "$1" = 0 ]; then
    # stop postfix silently, but only if it's running
    /sbin/service postfix stop &>/dev/null
    /sbin/chkconfig --del postfix
    /usr/sbin/alternatives --remove mta /usr/sbin/sendmail.postfix

exit 0
postuninstall scriptlet (using /bin/sh):
if [ "$1" != 0 ]; then
   /sbin/service postfix condrestart 2>&1 > /dev/null
exit 0

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.