このケーススタディーでは、パッケージのインストール中に、インストール先マシンに存在しているファイルを変更します。ここでは、3 種類の変更方法のうちの 1 つを使用します。ほかの 2 つの方法については、「標準クラスとクラスアクションスクリプトを使用したファイルの変更」および「build クラスを使用したファイルの変更」を参照してください。変更する対象のファイルは、/etc/inittab です。
このケーススタディーでは、次の手法の実例を示します。
sed クラスを使用する
sed クラスの詳細については、「sed クラススクリプト」を参照してください。
postinstall スクリプトを使用する
このスクリプトの詳細については、「手続きスクリプトの書き込み」を参照してください。
インストール時に /etc/inittab を変更するには、sed クラスを使用して、次の作業を完了する必要があります。
sed クラススクリプトを prototype ファイルに追加します。
スクリプトの名前は、編集対象ファイルの名前である必要があります。このケースでは、編集対象のファイルが /etc/inittab であるため、sed スクリプトの名前も /etc/inittab となります。sed スクリプトのモード、所有者、およびグループには必要条件はありません (サンプルの prototype ではクエスチョンマークで表されています)。sed スクリプトのファイルタイプは e (編集可能であることを表す) である必要があります。
CLASSES パラメータに sed クラスを含めます。
例として示したファイルでは、インストールされるクラスは sed だけです。ただし、必要に応じて、任意の数のクラスを指定することができます。
sed クラスアクションスクリプトを作成します。
/etc/inittab は動的ファイルで、パッケージをインストールする時点での内容を知る方法がないため、必要な動作を指定した /etc/inittab のコピーをパッケージで提供することはできません。しかし、sed スクリプトを使用することで、パッケージのインストール時に /etc/inittab ファイルを変更できます。
postinstall スクリプトを作成します。
init q コマンドを実行して、/etc/inittab が変更されたことをシステムに通知する必要があります。この例で、そのアクションを実行できるのは、postinstall スクリプトだけです。サンプルの postinstall スクリプトは、init q コマンドの実行だけを行なっています。
この方法でインストール中に /etc/inittab を編集する場合、欠点が 1 つあります。それは、init q コマンドを実行するだけのために、完全なスクリプト (postinstall スクリプト) を提供する必要があるという点です。
PKG=case4 NAME=Case Study #4 CATEGORY=applications BASEDIR=/opt ARCH=SPARC VERSION=Version 1d05 CLASSES=sed |
i pkginfo i postinstall e sed /etc/inittab ? ? ? |
!remove # remove all entries from the table that are associated # with this package, though not necessarily just # with this package instance /^[^:]*:[^:]*:[^:]*:[^#]*#ROBOT$/d !install # remove any previous entry added to the table # for this particular change /^[^:]*:[^:]*:[^:]*:[^#]*#ROBOT$/d # add the needed entry at the end of the table; # sed(1) does not properly interpret the '$a' # construct if you previously deleted the last # line, so the command # $a\ # rb:023456:wait:/usr/robot/bin/setup #ROBOT # will not work here if the file already contained # the modification. Instead, you will settle for # inserting the entry before the last line! $i\ rb:023456:wait:/usr/robot/bin/setup #ROBOT |
# make init re-read inittab /sbin/init q || exit 2 exit 0 |