Linux RPM: View Script That Run When You Install RPM Files

You can use the rpm command to view the scripts that run when you install an RPM package. RPM packages can contain scripts that run during the installation, upgrade, or removal of the package.

Here’s how to view the installation scripts for an RPM package:

rpm -qp --scripts package.rpm

Replace package.rpm with the name of the RPM package file you want to examine.

For example, to view the installation scripts for the nginx RPM package, you can run the following command:

rpm -qp --scripts nginx-1.14.1-1.el7_4.ngx.x86_64.rpm

Output:

postinstall scriptlet (using /bin/sh):
if [ $1 -eq 1 ] ; then
/sbin/chkconfig --add nginx
elif [ $1 -eq 2 ] ; then
/sbin/service nginx condrestart > /dev/null 2>&1
fi
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ]; then
/sbin/service nginx stop > /dev/null 2>&1
/sbin/chkconfig --del nginx
fi

In this example, the rpm command displays the post-installation and pre-uninstallation scripts for the nginx RPM package. The post-installation script adds the nginx service to the system’s startup scripts, and the pre-uninstallation script stops the nginx service and removes it from the system’s startup scripts.

By examining the scripts that run during the installation, upgrade, or removal of an RPM package, you can better understand the package’s behavior and diagnose any issues that may arise.

Leave a Comment