我正在尝试在rpm.spec文件中查找%pre/%post scriptlet的最佳实践。
具体地说,我有一个安装非常复杂的系统。在其他事情中,它需要做很多“安全增强的Linux”定制,iptable编辑,用户创建(带密码)和"chown"-ing等等。
问题是在哪里做这件事?应该将其放入pre/post scriptlet中吗?最佳实践似乎是将它们保留为simple as possible and definitely don't make it interactive。
我注意到Postgres安装程序(和其他一些)做了一个“手动后安装”步骤,根用户需要运行一个脚本来做某些事情,比如设置postgres用户的密码等。你可以在下面rpm打印的位置看到:To initialize, run /etc/init.d/postgres-9.1-openscg start as root user.
下面是提取的scriptlet:
rpm -qp --scripts postgres-9.1.2-1.i386.openscg.rpm预安装scriptlet (使用/bin/sh):
if [ "$1" = "2" ]; then
#Perform maintenance tasks before server upgrade begins.
#Determine if server is running, stops it.
/etc/init.d/postgres-9.1-openscg status &> /dev/null
if [ "$?" = "0" ];
then
/etc/init.d/postgres-9.1-openscg stop
touch /tmp/pg_9.1.stopped
fi
fi安装后scriptlet (使用/bin/sh):
if type "/usr/bin/chcon" &> /dev/null ; then
/usr/bin/chcon -t textrel_shlib_t $RPM_INSTALL_PREFIX/lib/libedit.so &> /dev/null
fi
#Create a soft link to init script
if [ ! -f /etc/init.d/postgres-9.1-openscg ]
then
ln -s $RPM_INSTALL_PREFIX/bin/postgres-9.1-openscg /etc/init.d/postgres-9.1-openscg
fi
#In case of upgrade, dump environment values file
#if [ "$1" = "2" ];
#then
#Fix for psql dumb terminal issue
LD_PRELOAD_VALUE=""
for libreadline in `find -L /lib -type f -name libreadline.\* 2> /dev/null`
do
LD_PRELOAD_VALUE="$libreadline:$LD_PRELOAD_VALUE"
done
if [ x"$LD_PRELOAD_VALUE" != x"" ];
then
LD_PRELOAD_VALUE="export LD_PRELOAD=$LD_PRELOAD_VALUE"
fi
#Dump environment values
cat <<ENVEOF > $RPM_INSTALL_PREFIX/pg91-openscg.env
#!/bin/bash
$LD_PRELOAD_VALUE
export PGHOME=$RPM_INSTALL_PREFIX
export PGDATA=$RPM_INSTALL_PREFIX/data
export PATH=$RPM_INSTALL_PREFIX/bin:\$PATH
export LD_LIBRARY_PATH=$RPM_INSTALL_PREFIX/lib:\$LD_LIBRARY_PATH
export PGUSER=postgres
export PGDATABASE=postgres
ENVEOF
#Determine port from postgresql.conf
PGPORT_VALUE=""
if [ -f $RPM_INSTALL_PREFIX/data/postgresql.conf ]; then
PGPORT_VALUE=`grep "port =" $RPM_INSTALL_PREFIX/data/postgresql.conf | sed -e "s/^.*port[[:space:]]=[[:space:]]\([0-9]\+\).*$/\1/"`
PGPORT_VALUE="export PGPORT=$PGPORT_VALUE"
cat <<ENVEOF >> $RPM_INSTALL_PREFIX/pg91-openscg.env
$PGPORT_VALUE
ENVEOF
fi
#fi
# If it is an upgrade, and we stopped a running server, start it.
if [ "$1" = "2" -a -f /tmp/pg_9.1.stopped ];
then
rm /tmp/pg_9.1.stopped
/etc/init.d/postgres-9.1-openscg start
fi
if [ "$1" = "1" ];
then
echo "PostgreSQL 9.1 is now installed in $RPM_INSTALL_PREFIX."
echo
echo "To initialize, run /etc/init.d/postgres-9.1-openscg start"
echo "as root user."
fi
if [ "$1" = "2" ];
then
echo "PostgreSQL 9.1 is upgraded in $RPM_INSTALL_PREFIX."
fi预卸载scriptlet (使用/bin/sh):
if [ "$1" = "0" ]; then
#Action is uninstallation, not called due to upgrade of a new package
#Determine if server is running, stops it.
/etc/init.d/postgres-9.1-openscg status &> /dev/null
if [ "$?" = "0" ];
then
echo "Attempting to stop server..."
/etc/init.d/postgres-9.1-openscg stop
fi
echo "Attempting to update server startup status..."
if type "/sbin/chkconfig" &> /dev/null ; then
/sbin/chkconfig --del postgres-9.1-openscg
fi
fi卸载后scriptlet (使用/bin/sh):
if [ "$1" = "0" ]; then
#Action is uninstallation, not called due to upgrade of a new package
rm /etc/init.d/postgres-9.1-openscg
echo "Uninstallation complete."
fi发布于 2013-09-25 13:47:49
如果您指的是在安装RPM时与用户交互相关的最佳实践,这是毫无疑问的。不要这样做。在scriptlet中执行任何不需要用户交互的操作,并告诉用户在安装后运行脚本,或者在应用程序的第一次运行中获取所有信息。
https://stackoverflow.com/questions/18967389
复制相似问题