2012-12-07 217 views
0

我想在卸載的時間打印在客戶端的消息一樣,如果錯誤的話,我總是打印,如果是像轉卸載簡單的消息成功則可選.client使用的選項規範文件顯示消息-v則打印(詳細其他明智沒有)RPM創建:在客戶端

rpm -ivh xyz.rpm for install and rpm -ev xyz for uninstall as below. 

#預卸載部

%preun 
Processes=`ps -Ao"%p:%a" --cols 150 | 
egrep "Launcher|rmiregistry" | grep -v grep | cut -d ":" -f1` 
     if [ -n "$Processes" ]; then 
       echo 'xyz is running ,first stop it then uninstall.' > /dev/stderr; 
       exit 1; 
     else 
       echo 'xyz service is not running' >/dev/stdout; 
     fi 

轉卸載的目前上面的代碼印刷每一次。

回答

1

您需要區分%preun中的升級和刪除。

我在*的.spec文件使用此模式:

%preun 

if [ "$1" = "0" ]; then 
    # package removal 
    true; # bash doesn't like 'empty' conditional blocks 
elif [ "$1" = "1" ]; then 
    # package upgrade 
    true; # bash doesn't like 'empty' conditional blocks 
fi 

一些exrta信息:https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Syntax