gpt4 book ai didi

linux - RPM %post 小脚本最佳实践

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:23:59 26 4
gpt4 key购买 nike

我正在尝试找出 rpm.spec 文件中 %pre/%post 小脚本的最佳实践。

具体来说,我有一个安装非常复杂的系统。除其他外,它需要做很多“安全增强型 Linux”定制、iptable 编辑、用户创建(使用密码)和“chown”-ing 等。

问题是在哪里做这个?这应该放在前/后 scriptlet 中吗?最佳做法似乎是将这些保留为 simple as possible and definitely don't make it interactive .

我注意到 Postgres 安装程序(和其他一些)执行“手动安装后”步骤,root 用户需要运行脚本来执行某些操作,例如设置 postgres 用户的密码等。您可以在下方看到它rpm 打印如下:To initialize, run/etc/init.d/postgres-9.1-openscg start as root user.

以下是提取的脚本:

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

安装后脚本(使用/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

预卸载脚本(使用/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

卸载后脚本(使用/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

最佳答案

如果您指的是 RPM 安装时与用户交互相关的最佳实践,那毫无疑问。不要这样做。在 Scriptlet 中执行任何不需要用户交互的操作,或者告诉用户在安装后运行脚本,或者在应用程序首次运行时获取所有信息。

关于linux - RPM %post 小脚本最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18967389/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com