Linux RPM:安装RPM文件时运行的查看脚本

时间:2020-01-09 10:34:17  来源:igfitidea点击:

添加或删除软件包后,所有rpm软件包都可以运行脚本。
如何在基于rpm的Linux发行版下查看安装前/安装后和卸载rpm文件脚本?

用于rpm命令的选项脚本命令显示软件包特定的脚本,这些脚本在安装和卸载过程中使用。
使用以下命令行选项查看.rpm文件的rpm文件脚本:

rpm -qp --scripts filename.rpm

例如,要列出memcached-1.2.8-1.el5.x86_64.rpm的所有脚本,请输入:

$ rpm -qp --scripts memcached-1.2.8-1.el5.x86_64.rpm

输出示例:

preinstall scriptlet (using /bin/sh):
getent group memcached >/dev/null || groupadd -r memcached
getent passwd memcached >/dev/null || \
useradd -r -g memcached -d /var/run/memcached \
    -s /sbin/nologin -c "Memcached daemon" memcached
exit 0
postinstall scriptlet (using /bin/sh):
/sbin/chkconfig --add memcached
preuninstall scriptlet (using /bin/sh):
if [ "" = 0 ] ; then
    /sbin/service memcached stop > /dev/null 2>&1
    /sbin/chkconfig --del memcached
fi
exit 0
postuninstall scriptlet (using /bin/sh):
if [ "" -ge 1 ]; then
    /sbin/service memcached condrestart > /dev/null 2>&1
fi
exit 0

要查看已安装软件包的脚本,请输入:

# rpm -q --scripts packageName
# rpm -q --scripts httpd

输出示例:

preinstall scriptlet (using /bin/sh):
getent group memcached >/dev/null || groupadd -r memcached
getent passwd memcached >/dev/null || \
useradd -r -g memcached -d /var/run/memcached \
    -s /sbin/nologin -c "Memcached daemon" memcached
exit 0
postinstall scriptlet (using /bin/sh):
/sbin/chkconfig --add memcached
preuninstall scriptlet (using /bin/sh):
if [ "" = 0 ] ; then
    /sbin/service memcached stop > /dev/null 2>&1
    /sbin/chkconfig --del memcached
fi
exit 0
postuninstall scriptlet (using /bin/sh):
if [ "" -ge 1 ]; then
    /sbin/service memcached condrestart > /dev/null 2>&1
fi
exit 0
[root@txvip1 tmp]# rpm -q --scripts httpd
preinstall scriptlet (using /bin/sh):
# Add the "apache" user
/usr/sbin/useradd -c "Apache" -u 48 \
	-s /sbin/nologin -r -d /var/www apache 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
# Register the httpd service
/sbin/chkconfig --add httpd
preuninstall scriptlet (using /bin/sh):
if [  = 0 ]; then
	/sbin/service httpd stop > /dev/null 2>&1
	/sbin/chkconfig --del httpd
fi