LoginSignup
9
4

More than 5 years have passed since last update.

pre,post,preun,postunの$1の値

Last updated at Posted at 2016-10-06

pre,post,preun,postunの$1の値

command pre post preun postun
rpm -i 1 1 - -
rpm -e - - 0 0
rpm -U 2 2 1 1

rpm -Uの実行順序

  1. rpm -i 新しいrpmパッケージ
  2. rpm -e 古いrpmパッケージ

参考

SPECファイルの分岐処理


# 以下rpmのインストール、アンインストール時の処理を指定する。
# rpmパッケージの中身を配置する前に処理される内容。
%pre

if [ $1 = 1 ]; then
    # rpm -iのときに処理される内容
    :
    echo "rpm -i pre"
elif [ $1 = 2 ]; then
    # rpm -Uのときに処理される内容
    :
    echo "rpm -U pre"
fi

# rpmパッケージの中身を配置した後に処理される内容。
%post

if [ $1 = 1 ]; then
    # rpm -iのときに処理される内容
    :
    echo "rpm -i post"
elif [ $1 = 2 ]; then
    # rpm -Uのときに処理される内容
    :
    echo "rpm -U post"
fi

# インストールしたファイルを削除する前に処理される内容。
%preun

if [ $1 = 0 ]; then
    # rpm -eのときに処理される内容
    :
    echo "rpm -e preun"
elif [ $1 = 1 ]; then
    # rpm -Uのときに処理される内容
    :
    echo "rpm -U preun"
fi

# インストールしたファイルを削除した後に処理される内容。
%postun

if [ $1 = 0 ]; then
    # rpm -eのときに処理される内容
    :
    echo "rpm -e postun"
elif [ $1 = 1 ]; then
    # rpm -Uのときに処理される内容
    :
    echo "rpm -U postun"
fi


上記内容をSPECファイルに書いて、rpmコマンドを実行


[root@todanano ~]# rpm --prefix=/root/mytest -ivh MyPakcage-01.00-00.el6.x86_64.rpm
Preparing...                ########################################### [100%]
rpm -i pre
   1:MyPakcage              ########################################### [100%]
rpm -i post
[root@todanano ~]# rpm -e MyPakcage
rpm -e preun
rpm -e postun
[root@todanano ~]# rpm --prefix=/root/mytest -ivh MyPakcage-01.00-00.el6.x86_64.rpm
Preparing...                ########################################### [100%]
rpm -i pre
   1:MyPakcage              ########################################### [100%]
rpm -i post
[root@todanano ~]# rpm --prefix=/root/mytest -Uvh MyPakcage-01.00-01.el6.x86_64.rpm
Preparing...                ########################################### [100%]
rpm -U pre
   1:MyPakcage              ########################################### [100%]
rpm -U post
rpm -U preun
rpm -U postun
[root@todanano ~]#
[root@todanano ~]#
[root@todanano ~]# rpm -e MyPakcage
rpm -e preun
rpm -e postun
[root@todanano ~]#
[root@todanano ~]#
[root@todanano ~]#

ちなみに、インストールされていない状態で-Uでインストールすると

[root@todanano ~]# rpm -e MyPackage
rpm -e preun
rpm -e postun
[root@todanano ~]#
[root@todanano ~]# rpm --prefix=/root/g3test -Uvh MyPackage.rpm
Preparing...                ########################################### [100%]
rpm -i pre
   1:MyPackage              ########################################### [100%]
rpm -i post
[root@todanano ~]#

というように、-Uだけど、-iとしてインストール処理が走る。

純粋なインストールのタイミングだけ何かする処理があるが、
いきなり-Uでインストールしてくることを考慮して、、、、
というようなことを考える必要は無さそう(・ω・

9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4