アプリケーションパッケージ開発者ガイド

再配置の対応

さまざまなパッケージに対して、アーキテクチャーおよびバージョンごとに一意であることが保証されるベースディレクトリを選択できますが、これによって不要なディレクトリ階層が作成されます。たとえば、SPARC ベースおよび x86 ベースのプロセッサ用の製品では、次のようにプロセッサとバージョンごとにベースディレクトリを編成できます。

ベースディレクトリ 

バージョンおよびプロセッサ 

/opt/SUNWstuf/sparc/1.0

バージョン 1.0、SPARC 

/opt/SUNWstuf/sparc/1.2

バージョン 1.2、SPARC 

/opt/SUNWstuf/x86/1.0

バージョン 1.0、x86 

これでも問題なく動作しますが、名前と数値が管理者にとって意味を持つように扱っています。より適切なアプローチは、管理者に説明して許可された後、これを自動的に実行することです。

つまり、設計者がパッケージのすべてのジョブを実行できます。管理者が手動で実行する必要はありません。設計者は任意のベースディレクトリを割り当て、postinstall スクリプトで透過的に適切なクライアントリンクを確立できます。また、pkgadd コマンドを使用して、パッケージのすべてまたは一部を postinstall スクリプトでクライアントにインストールすることもできます。このパッケージについて通知する必要があるユーザーまたはクライアントを管理者に確認して、PATH 環境変数と /etc ファイルを自動的に更新することもできます。これは、パッケージのインストール時に行った操作が削除時にすべて元に戻される限り許容されます。

ベースディレクトリの調査

インストール時にベースディレクトリを制御する方法は 2 通りあります。1 つ目の方法は、Solaris 2.5 および互換リリースのみに新しいパッケージをインストールする場合に最適です。この方法では、管理者に非常に有用なデータを提供し、複数のバージョンおよびアーキテクチャーのインストールをサポートし、最小限の作業で実行できます。2 つ目の方法は任意のパッケージで使用でき、構築パラメータに対する request スクリプト固有の制御を使用してインストールを実行します。

BASEDIR パラメータの使用

checkinstall スクリプトは、インストール時に適切なベースディレクトリを選択できます。つまり、ベースディレクトリをディレクトリツリー内の低い位置に配置できます。この例では、/opt/SUNWstuf/opt/SUNWstuf.1/opt/SUNWstuf.2 という形式でベースディレクトリを順に増加させます。管理者は、pkginfo コマンドを使用して、各ベースディレクトリにインストールするアーキテクチャーおよびバージョンを決定できます。

SUNWstuf パッケージ (要素となるユーティリティーのセットが含まれる) でこの方法を使用する場合、pkginfo ファイルおよび pkgmap ファイルは次のようになります。

pkginfo ファイル

# pkginfo file
PKG=SUNWstuf
NAME=software stuff 
ARCH=sparc
VERSION=1.0.0,REV=1.0.5
CATEGORY=application
DESC=a set of utilities that do stuff
BASEDIR=/opt/SUNWstuf
VENDOR=Sun Microsystems, Inc.
HOTLINE=Please contact your local service provider
EMAIL=
MAXINST=1000
CLASSES=none daemon
PSTAMP=hubert990707141632

pkgmap ファイル

: 1 1758
1 d none EZstuf 0775 root bin
1 f none EZstuf/dirdel 0555 bin bin 40 773 751310229
1 f none EZstuf/usrdel 0555 bin bin 40 773 751310229
1 f none EZstuf/filedel 0555 bin bin 40 773 751310229
1 d none HRDstuf 0775 root bin
1 f none HRDstuf/mksmart 0555 bin bin 40 773 751310229
1 f none HRDstuf/mktall 0555 bin bin 40 773 751310229
1 f none HRDstuf/mkcute 0555 bin bin 40 773 751310229
1 f none HRDstuf/mkeasy 0555 bin bin 40 773 751310229
1 d none /etc	? ? ?
1 d none /etc/rc2.d ? ? ?
1 f daemon /etc/rc2.d/S70dostuf 0744 root sys 450 223443
1 i pkginfo 348 28411 760740163
1 i postinstall 323 26475 751309908
1 i postremove 402 33179 751309945
1 i preinstall 321 26254 751310019
1 i preremove 320 26114 751309865
1 i i.daemon 509 39560 752978103
1 i r.daemon 320 24573 742152591

例 — BASEDIR を調査する分析スクリプト

x86 版の SUNWstuf がすでにサーバーの /opt/SUNWstuf にインストールされていると仮定します。管理者が pkgadd コマンドを使用して SPARC 版をインストールする場合、request スクリプトは x86 版を検出して、インストールに関して管理者と対話する必要があります。


注 –

checkinstall スクリプトでは管理者と対話しなくてもベースディレクトリを調査できますが、このような勝手な処理が頻繁に実行されると、プロセスに対する管理者の信頼を失います。


この状況を処理するパッケージの request スクリプトおよび checkinstall スクリプトは、次のようになっています。

request スクリプト

# request script
for SUNWstuf to walk the BASEDIR parameter.
 
PATH=/usr/sadm/bin:${PATH}	# use admin utilities
 
GENMSG="The base directory $LOCAL_BASE already contains a \
different architecture or version of $PKG."
 
OLDMSG="If the option \"-a none\" was used, press the  \
key and enter an unused base directory when it is requested."
 
OLDPROMPT="Do you want to overwrite this version? "
 
OLDHELP="\"y\" will replace the installed package, \"n\" will \
stop the installation."
 
SUSPEND="Suspending installation at user request using error \
code 1."
 
MSG="This package could be installed at the unused base directory $WRKNG_BASE."
 
PROMPT="Do you want to use to the proposed base directory? "
 
HELP="A response of \"y\" will install to the proposed directory and continue,
\"n\" will request a different directory. If the option \"-a none\" was used,
press the  key and enter an unused base directory when it is requested."
 
DIRPROMPT="Select a preferred base directory ($WRKNG_BASE) "
 
DIRHELP="The package $PKG will be installed at the location entered."
 
NUBD_MSG="The base directory has changed. Be sure to update \
any applicable search paths with the actual location of the \
binaries which are at $WRKNG_BASE/EZstuf and $WRKNG_BASE/HRDstuf."
 
OldSolaris=""
Changed=""
Suffix="0"
 
#
# Determine if this product is actually installed in the working
# base directory.
#
Product_is_present () {
	  if [ -d $WRKNG_BASE/EZstuf -o -d $WRKNG_BASE/HRDstuf ]; then
		    return 1
	  else
		    return 0
	  fi
}
 
if [ ${BASEDIR} ]; then
	  # This may be an old version of Solaris. In the latest Solaris
	  # CLIENT_BASEDIR won't be defined yet. In older version it is.
	  if [ ${CLIENT_BASEDIR} ]; then
		    LOCAL_BASE=$BASEDIR
		    OldSolaris="true"
	  else	# The base directory hasn't been processed yet
		    LOCAL_BASE=${PKG_INSTALL_ROOT}$BASEDIR
fi
 
WRKNG_BASE=$LOCAL_BASE
 
	# See if the base directory is already in place and walk it if
	# possible
while [ -d ${WRKNG_BASE} -a Product_is_present ]; do
		 # There is a conflict
		 # Is this an update of the same arch & version?
		 if [ ${UPDATE} ]; then
			   exit 0	# It's out of our hands.
		 else
			   # So this is a different architecture or
			   # version than what is already there.
			   # Walk the base directory
			   Suffix=`expr $Suffix + 1`
			   WRKNG_BASE=$LOCAL_BASE.$Suffix
			   Changed="true"
		 fi
done
 
	# So now we can propose a base directory that isn't claimed by
	# any of our other versions.
if [ $Changed ]; then
		 puttext "$GENMSG"
		 if [ $OldSolaris ]; then
			   puttext "$OLDMSG"
			   result=`ckyorn -Q -d "a" -h "$OLDHELP" -p "$OLDPROMPT"`
			   if [ $result="n" ]; then
				     puttext "$SUSPEND"
				     exit 1	# suspend installation
			   else
				     exit 0
			   fi
		 else	# The latest functionality is available
			   puttext "$MSG"
			   result=`ckyorn -Q -d "a" -h "$HELP" -p "$PROMPT"`
			   if [ $? -eq 3]; then
				     echo quitinstall >> $1
				     exit 0
			   fi
 
			   if [ $result="n" ]; then
				     WRKNG_BASE=`ckpath -ayw -d "$WRKNG_BASE" \
				     -h "$DIRHELP" -p "$DIRPROMPT"`
			   else if [ $result="a" ]
				     exit 0
			   fi
		    fi
		    echo "BASEDIR=$WRKNG_BASE" >> $1
		    puttext "$NUBD_MSG"
	  fi
fi
exit 0

checkinstall スクリプト

# checkinstall
script for SUNWstuf to politely suspend
 
grep quitinstall $1
if [ $? -eq 0 ]; then
	exit 3		# politely suspend installation
fi
 
exit 0

このアプローチは、ベースディレクトリが単に /opt だった場合には正常に機能しません。/opt を調査するのは困難であるため、このパッケージは BASEDIR をより正確に呼び出す必要があります。実際、マウントスキーマによっては不可能な場合もあります。この例では、/opt の下に新しいディレクトリを作成してベースディレクトリを調査しています。これによって問題が発生することはありません。

この例では request スクリプトと checkinstall スクリプトを使用しています。ただし、2.5 リリースより前のバージョンの Solaris では checkinstall スクリプトを実行することはできません。この例の checkinstall スクリプトは、quitinstall という文字列形式の非公開メッセージに応答して、インストールをていねいに停止するために使用されます。Solaris 2.3 リリースでこのスクリプトを実行する場合、checkinstall スクリプトは無視され、request スクリプトはエラーメッセージを表示してインストールを停止します。

Solaris 2.5 および互換リリースより前では、BASEDIR パラメータは読み取り専用パラメータであり、request スクリプトで変更することはできません。このため、(条件付きの CLIENT_BASEDIR 環境変数をテストして) 旧バージョンの SunOS オペレーティングシステムが検出された場合、request スクリプトには継続するか終了するかの 2 つのオプションしかありません。

相対パラメータ型パスの使用

ソフトウェア製品が旧バージョンの SunOS オペレーティングシステムにインストールされる可能性がある場合、request スクリプトで必要な作業をすべて実行する必要があります。このアプローチを使用すると、複数のディレクトリを操作することもできます。追加のディレクトリが必要な場合、簡単に管理できる製品を提供するには、単一のベースディレクトリの下にディレクトリを含める必要があります。BASEDIR パラメータでは最新の Solaris リリースで使用できる粒度のレベルは提供されませんが、request スクリプトを使用してパラメータ型パスを操作することで、パッケージからベースディレクトリを調査できます。pkginfo ファイルおよび pkgmap ファイルは次のようになります。

pkginfo ファイル

# pkginfo file
PKG=SUNWstuf
NAME=software stuff 
ARCH=sparc
VERSION=1.0.0,REV=1.0.5
CATEGORY=application
DESC=a set of utilities that do stuff
BASEDIR=/opt
SUBBASE=SUNWstuf
VENDOR=Sun Microsystems, Inc.
HOTLINE=Please contact your local service provider
EMAIL=
MAXINST=1000
CLASSES=none daemon
PSTAMP=hubert990707141632

pkgmap ファイル

: 1 1758
1 d none $SUBBASE/EZstuf 0775 root bin
1 f none $SUBBASE/EZstuf/dirdel 0555 bin bin 40 773 751310229
1 f none $SUBBASE/EZstuf/usrdel 0555 bin bin 40 773 751310229
1 f none $SUBBASE/EZstuf/filedel 0555 bin bin 40 773 751310229
1 d none $SUBBASE/HRDstuf 0775 root bin
1 f none $SUBBASE/HRDstuf/mksmart 0555 bin bin 40 773 751310229
1 f none $SUBBASE/HRDstuf/mktall 0555 bin bin 40 773 751310229
1 f none $SUBBASE/HRDstuf/mkcute 0555 bin bin 40 773 751310229
1 f none $SUBBASE/HRDstuf/mkeasy 0555 bin bin 40 773 751310229
1 d none /etc	? ? ?
1 d none /etc/rc2.d ? ? ?
1 f daemon /etc/rc2.d/S70dostuf 0744 root sys 450 223443
1 i pkginfo 348 28411 760740163
1 i postinstall 323 26475 751309908
1 i postremove 402 33179 751309945
1 i preinstall 321 26254 751310019
1 i preremove 320 26114 751309865
1 i i.daemon 509 39560 752978103
1 i r.daemon 320 24573 742152591

この例は完璧ではありません。pkginfo -r コマンドではインストールベースに /opt が返されますが、これは非常にあいまいです。多くのパッケージが /opt にありますが、少なくともこれは意味のあるディレクトリです。前の例と同様、次の例でも複数のアーキテクチャーおよびバージョンをサポートしています。request スクリプトは、特定のパッケージの要件に合わせて、適切な依存関係を解決することができます。

例 — 相対パラメータ型パスを調査する request スクリプト

# request script
for SUNWstuf to walk a parametric path
 
PATH=/usr/sadm/bin:${PATH}	# use admin utilities
 
MSG="The target directory $LOCAL_BASE already contains \
different architecture or version of $PKG. This package \
could be installed at the unused target directory $WRKNG_BASE."
 
PROMPT="Do you want to use to the proposed directory? "
 
HELP="A response of \"y\" will install to the proposed directory \
and continue, \"n\" will request a different directory. If \
the option \"-a none\" was used, press the <RETURN> key and \
enter an unused base directory when it is requested."
 
DIRPROMPT="Select a relative target directory under $BASEDIR/"
 
DIRHELP="The package $PKG will be installed at the location entered."
 
SUSPEND="Suspending installation at user request using error \
code 1."
 
NUBD_MSG="The location of this package is not the default. Be \
sure to update any applicable search paths with the actual \
location of the binaries which are at $WRKNG_BASE/EZstuf \
and $WRKNG_BASE/HRDstuf."
 
Changed=""
Suffix="0"
 
#
# Determine if this product is actually installed in the working
# base directory.
#
Product_is_present () {
	  if [ -d $WRKNG_BASE/EZstuf -o -d $WRKNG_BASE/HRDstuf ]; then
		    return 1
	  else
		    return 0
 
	  fi
}
 
if [ ${BASEDIR} ]; then
	  # This may be an old version of Solaris. In the latest Solaris
	  # CLIENT_BASEDIR won't be defined yet. In older versions it is.
	  if [ ${CLIENT_BASEDIR} ]; then
		    LOCAL_BASE=$BASEDIR/$SUBBASE
	  else	# The base directory hasn't been processed yet
		    LOCAL_BASE=${PKG_INSTALL_ROOT}$BASEDIR/$SUBBASE
	  fi
 
WRKNG_BASE=$LOCAL_BASE
 
# See if the base directory is already in place and walk it if
# possible
while [ -d ${WRKNG_BASE} -a Product_is_present ]; do
		 # There is a conflict
		 # Is this an update of the same arch & version?
		 if [ ${UPDATE} ]; then
			   exit 0	# It's out of our hands.
		 else
			   # So this is a different architecture or
			   # version than what is already there.
			   # Walk the base directory
			   Suffix=`expr $Suffix + 1`
			   WRKNG_BASE=$LOCAL_BASE.$Suffix
			   Changed="true"
		 fi
done
 
# So now we can propose a base directory that isn't claimed by
# any of our other versions.
if [ $Changed ]; then
		 puttext "$MSG"
		 result=`ckyorn -Q -d "a" -h "$HELP" -p "$PROMPT"`
		 if [ $? -eq 3 ]; then
			   puttext "$SUSPEND"
			   exit 1
		 fi
 
		 if [ $result="n" ]; then
			   WRKNG_BASE=`ckpath -lyw -d "$WRKNG_BASE" -h "$DIRHELP" \
			   -p "$DIRPROMPT"`
 
		    elif [ $result="a" ]; then
			       exit 0
		    else
			       exit 1
		    fi
		    echo SUBBASE=$SUBBASE.$Suffix >> $1
		    puttext "$NUBD_MSG"
	  fi
fi
exit 0