このケーススタディーでは、インストール時にデータベースファイルを作成し、パッケージの削除時にデータベースのコピーを保存します。
このケーススタディーでは、次の手法の実例を示します。
クラスおよびクラスアクションスクリプトを使用して、オブジェクトのさまざまなセットに対して特別なアクションを実行する
詳細については、「クラスアクションスクリプトの書き込み」を参照してください。
space ファイルを使用して、このパッケージを正しくインストールするには追加のスペースが必要であることを pkgadd コマンドに通知する
space ファイルについては、「ターゲットシステムでの追加領域の予約」を参照してください。
installf コマンドを使用して、prototype および pkgmap ファイルで定義されていないファイルをインストールする。
このケーススタディーに従って、インストール時にデータベースファイルを作成し、削除時にコピーを保存するには、次の作業を完了する必要があります。
3 つのクラスを定義します。
このケーススタディーで使用するパッケージには、CLASSES パラメータで次の 3 つのクラスを定義しておく必要があります。
標準クラスである none。これには、サブディレクトリ bin にある一連のプロセスが含まれています。
admin クラス。これには、実行可能ファイル config と、データファイルを格納したディレクトリが含まれています。
cfgdata クラス。これには、ディレクトリが含まれています。
パッケージを、全体として再配置可能にします。
prototype ファイルに、スラッシュまたは環境変数で始まるパス名が存在しないことに注目してください。このことは、これらが全体として再配置可能であることを示しています。
データベースファイルに必要なスペースのサイズを計算し、パッケージとともに配信する space ファイルを作成します。このファイルは pkgadd コマンドに対して、パッケージが追加スペースを必要とすることを通知し、そのサイズを指定します。
admin クラス用のクラスアクションスクリプト (i.admin) を作成します。
サンプルのスクリプトでは、admin クラスに属するデータファイルを使用して、データベースを初期化しています。この作業を実行するために、スクリプトは次の処理を実行します。
ソースデータファイルを、その適切なターゲットにコピーします。
config.data という名前の空ファイルを作成し、cfgdata のクラスに割り当てます。
bin/config コマンド (パッケージとともに提供され、すでにインストールされている) を実行し、admin クラスに属するデータファイルを使用して、データベースファイル config.data を生成します。
installf -f コマンドを実行し、config.data のインストールをファイナライズします。
削除時に、admin クラスに対して特別なアクションは必要ないため、削除クラスアクションスクリプトは作成されません。つまり、admin クラスのすべてのファイルとディレクトリは、システムから削除されます。
cfgdata クラス用の削除クラスアクションスクリプト (r.cfgdata) を作成します。
この削除スクリプトは、データベースファイルが削除される前に、そのコピーを作成します。インストール時に、このクラスに対して特別なアクションは必要ないため、インストールクラスアクションスクリプトは必要ありません。
削除スクリプトへの入力は、削除するパス名のリストです。パス名は、常にアルファベットの逆順に表示されます。この削除スクリプトは、ファイルを $PKGSAV というディレクトリにコピーします。すべてのパス名が処理されると、スクリプトは先頭のパス名に戻り、cfgdata クラスに関連付けられたすべてのディレクトリとファイルを削除します。
この削除スクリプトが実行されると、その結果として、config.data が $PKGSAV にコピーされ、次に config.data ファイルとデータディレクトリが削除されます。
PKG=krazy NAME=KrAzY Applications CATEGORY=applications BASEDIR=/opt ARCH=SPARC VERSION=Version 1 CLASSES=none cfgdata admin |
i pkginfo i request i i.admin i r.cfgdata d none bin 555 root sys f none bin/process1 555 root other f none bin/process2 555 root other f none bin/process3 555 root other f admin bin/config 500 root sys d admin cfg 555 root sys f admin cfg/datafile1 444 root sys f admin cfg/datafile2 444 root sys f admin cfg/datafile3 444 root sys f admin cfg/datafile4 444 root sys d cfgdata data 555 root sys |
# extra space required by config data which is # dynamically loaded onto the system data 500 1 |
# PKGINST parameter provided by installation service # BASEDIR parameter provided by installation service while read src dest do cp $src $dest || exit 2 done # if this is the last time this script will be executed # during the installation, do additional processing here. if [ "$1" = ENDOFCLASS ] then # our config process will create a data file based on any changes # made by installing files in this class; make sure the data file # is in class `cfgdata' so special rules can apply to it during # package removal. installf -c cfgdata $PKGINST $BASEDIR/data/config.data f 444 root sys || exit 2 $BASEDIR/bin/config > $BASEDIR/data/config.data || exit 2 installf -f -c cfgdata $PKGINST || exit 2 fi exit 0 |
ここでは、クラスアクションスクリプトで installf が使用される珍しい例が示されています。space ファイルを使用して、対象のファイルシステム上でスペースを予約しているため、この新しいファイルは、pkgmap ファイルに含まれていない場合でも、安全に追加されます。
# the product manager for this package has suggested that # the configuration data is so valuable that it should be # backed up to $PKGSAV before it is removed! while read path do # path names appear in reverse lexical order. mv $path $PKGSAV || exit 2 rm -f $path || exit 2 done exit 0 |