HAYAGUI

MacOS X 10.4 + PackageMakerのインストーラでスクリプトを動かす

はじめに

PackageMakerでインストールする時に、以下のスクリプトを動かすことができます。

  • preflight : インストールプロセスの前に実行するスクリプト
  • postflight : インストールプロセスの後に実行するスクリプト
  • preinstall : ひとつのパッケージをインストールする前に実行するスクリプト。アップグレードの時は実行しない。
  • postinstall : ひとつのパッケージをインストールした後に実行するスクリプト。アップグレードの時は実行しない。
  • preupgrade : ひとつのパッケージをアップグレードする前に実行するスクリプト。インストールの時は実行しない。
  • posupgrade : ひとつのパッケージをアップグレードした後に実行するスクリプト。インストールの時は実行しない。

今回は、前回作成した hello をインストールするインストーラに、これらのスクリプトを入れてみて、起動するタイミングを確認します。
参考:

スクリプト保存ディレクトリ

スクリプトを保存する作業ディレクトリは、インストールするファイルを保存するディレクトリと別にしておきます。

前回は kenz のホームディレクトリに work を作成して、そこにインストールするファイルを置いていましたが、work の下に resource ディレクトリを作ってスクリプトはそこに置くようにしました。以前の work 以下のファイルは、root というディレクトリを作って workの内容を移動しました。

ibg4:~/work kenz$ tree -L 1
.
|-- hello
|-- hello.c
|-- hello.pkg
|-- hello.pmproj
|-- resource
`-- root
PackageMakerの設定ではこんな感じ。

スクリプトを作る

Perlで書いてもいいようですが、シェルスクリプトで書いてみました。 /var/tmp に date を書くスクリプトです。
ibg4:~/work/resource kenz$ vi preinstall
ibg4:~/work/resource kenz$ cat preinstall 
#!/bin/sh
date > /var/tmp/preinstall
ibg4:~/work/resource kenz$ chmod 755 preinstall 
ibg4:~/work/resource kenz$ ./preinstall 
ibg4:~/work/resource kenz$ cat /var/tmp/preinstall 
Sat Jun 10 23:31:45 JST 2006
ibg4:~/work/resource kenz$ 
このような内容で6つのファイルを作ります。
ibg4:~/work/resource kenz$ pwd
/Users/kenz/work/resource
ibg4:~/work/resource kenz$ ls
postflight      postupgrade     preinstall
postinstall     preflight       preupgrade
ibg4:~/work/resource kenz$

インストールする前に

/var/tmp ディレクトリ内のゴミを削除します。
ibg4:~/work/resource kenz$ cd /var/tmp
ibg4:/var/tmp kenz$ sudo rm -Rf *
Password:
ibg4:/var/tmp kenz$ ls
新規インストールの環境にするため、過去のインストール情報を削除します。
ibg4:/var/tmp kenz$ rm -Rf /Library/Receipts/hello.pkg/
ibg4:/var/tmp kenz$ 

インストールしてみる

PackageMaker のメニューの「Project」「View Install Log」を選択すると、インストール経過をログとして見ることができます。
そこのメニュー内にある「Build and Run...」で起動します。

インストーラを起動すると、以下のようなログを表示します。環境チェックだね。

Jun 10 23:33:07 ibg4 : @(#)PROGRAM:Install  PROJECT:Install-137  DEVELOPER:root  BUILT:Jan 23 2006 20:09:15\n
Jun 10 23:33:08 ibg4 : @(#)PROGRAM:Installer  PROJECT:Installer-86  DEVELOPER:root  BUILT:Sep  2 2005 14:24:50\n
Jun 10 23:33:08 ibg4 : Hardware: PowerBook6,3 @ 799 MHz, 640 MB
Jun 10 23:33:08 ibg4 : Running OS Build: 8I127
Jun 10 23:33:08 ibg4 : helloworld Installation Log
Jun 10 23:33:08 ibg4 : Opened from: /Users/kenz/work/hello.pkg
Jun 10 23:33:08 ibg4 : It took 0.246552 seconds to load 7 UI sections
Jun 10 23:33:09 ibg4 : It took 2.309777 seconds to finish launching.
Jun 10 23:33:12 ibg4 : Distribution: helloworld
Jun 10 23:33:12 ibg4 : Installation checks completed successfully.
「ようこそ画面」、「インストールするハードディスク選択画面」、「インストール確認画面」まではなにも変化せず。「ユーザ認証」を通ってインストールが行われると、以下のようなログが表示されます。
「script」と書いてある行を強調しています。
Jun 10 23:34:18 ibg4 : admin auth received to install
Jun 10 23:34:18 ibg4 : ================================================================================
Jun 10 23:34:18 ibg4 : User picked Easy Install
Jun 10 23:34:18 ibg4 : Choices selected for installation:
Jun 10 23:34:18 ibg4 : 	インストール: "helloworld"
Jun 10 23:34:18 ibg4 : 		hello.pkg : com.hayagui.hello : 0.1.0.0.1
Jun 10 23:34:18 ibg4 : ================================================================================
Jun 10 23:34:18 ibg4 : It took 0.001926 seconds to summarize the package selections.
Jun 10 23:34:18 ibg4 : Starting installation:
Jun 10 23:34:18 ibg4 : Preparing volume "tiger" for installation
Jun 10 23:34:18 ibg4 : Configuring volume "tiger"
Jun 10 23:34:19 ibg4 : Preparing local booted disk
Jun 10 23:34:19 ibg4 : Create temporary directory "/private/tmp/hello.pkg.964jIuFYX"
Jun 10 23:34:20 ibg4 : run preflight script for helloworld
Jun 10 23:34:20 ibg4 : Processing helloworld:
Jun 10 23:34:20 ibg4 : 	Initialize patching
Jun 10 23:34:20 ibg4 : 	Determining files to install
Jun 10 23:34:20 ibg4 : 	Evaluating versions of bundles
Jun 10 23:34:20 ibg4 : 	Evaluating custom file version checking
Jun 10 23:34:20 ibg4 : 	Configuring deferred files
Jun 10 23:34:20 ibg4 : 	Assembling temporary receipt
Jun 10 23:34:20 ibg4 : 	Performing pre-extraction actions
Jun 10 23:34:20 ibg4 : ==== It took 0.091728 seconds to check for prebinding
Jun 10 23:34:20 ibg4 : 	run preinstall script for helloworld
Jun 10 23:34:21 ibg4 : 	Creating destination path
Jun 10 23:34:21 ibg4 : 	Extracting files
Jun 10 23:34:21 ibg4 : 	4 files looked up in 0.00 seconds. 4 files written in 0.05 seconds.
Jun 10 23:34:21 ibg4 : 	0 kilobytes installed.
Jun 10 23:34:21 ibg4 : 	run postinstall script for helloworld
Jun 10 23:34:21 ibg4 : 	Performing post-extraction actions
Jun 10 23:34:21 ibg4 : 	Assembling receipt
Jun 10 23:34:22 ibg4 : run postflight script for helloworld
Jun 10 23:34:22 ibg4 : Removing temporary directory "/private/tmp/hello.pkg.964jIuFYX"
Jun 10 23:34:22 ibg4 : Finalize disk "tiger"
Jun 10 23:34:22 ibg4 : Notifying system of updated components
Jun 10 23:34:22 ibg4 : TOTAL: Packages report 4 files, 4 actual files written
Jun 10 23:34:23 ibg4 : Private/Total = (6.4MB, 64.9MB),  Heap/Total = (2.3MB, 17.7MB),  Regions(malloc, private) = (27, 29)
Jun 10 23:34:23 ibg4 : It took 3.959505 seconds to successfully install "helloworld" (1 pkg(s))
Jun 10 23:34:23 ibg4 : 	It took 1.027555 seconds to Configuring volume "tiger" (dm prepare*disk)
Jun 10 23:34:23 ibg4 : 	It took 0.102860 seconds to Create temporary directory "/private/tmp/hello.pkg.964jIuFYX"
Jun 10 23:34:23 ibg4 : 	It took 0.277659 seconds to run preflight script for helloworld
Jun 10 23:34:23 ibg4 : 	It took 2.234006 seconds to Install helloworld: 24 elements
Jun 10 23:34:23 ibg4 : 		It took 2.185545 seconds to successfully Install package helloworld
Jun 10 23:34:23 ibg4 : 			It took 0.379718 seconds to Assembling temporary receipt
Jun 10 23:34:23 ibg4 : 			It took 0.169384 seconds to Collect path info (ATS, Sec Equiv, Kext, Pref Panes)
Jun 10 23:34:23 ibg4 : 			It took 0.196009 seconds to run preinstall script for helloworld
Jun 10 23:34:23 ibg4 : 			It took 0.352003 seconds to Write files
Jun 10 23:34:23 ibg4 : 			It took 0.197903 seconds to run postinstall script for helloworld
Jun 10 23:34:23 ibg4 : 			It took 0.839983 seconds to Assembling receipt
Jun 10 23:34:23 ibg4 : 	It took 0.198383 seconds to run postflight script for helloworld
Jun 10 23:34:23 ibg4 : 	It took 0.090401 seconds to Removing temporary directory "/private/tmp/hello.pkg.964jIuFYX"
Jun 10 23:34:23 ibg4 : Jun 10 23:34:23 ibg4 : Summary Information
Jun 10 23:34:23 ibg4 : Type           Elapsed time (sec)
Jun 10 23:34:23 ibg4 :           patch           0.000184
Jun 10 23:34:23 ibg4 :          script           0.869954
Jun 10 23:34:23 ibg4 :            zero           0.239220
Jun 10 23:34:23 ibg4 :         extract           0.352003
Jun 10 23:34:23 ibg4 :          config           0.187538
Jun 10 23:34:23 ibg4 :         receipt           1.219701
Jun 10 23:34:23 ibg4 :            disk           1.042444
Jun 10 23:34:23 ibg4 :         install           2.234006
Jun 10 23:34:23 ibg4 : Jun 10 23:34:23 ibg4 : Starting installation:
Jun 10 23:34:23 ibg4 : Finalizing installation.
Jun 10 23:34:24 ibg4 : Private/Total = (6.4MB, 65.2MB),  Heap/Total = (2.3MB, 17.7MB),  Regions(malloc, private) = (27, 32)
Jun 10 23:34:24 ibg4 : It took 0.263910 seconds to successfully End of Install Jobs
Jun 10 23:34:24 ibg4 : 	It took 0.060187 seconds to Send End Jobs Did End notification "Finishing end-of-install jobs."
Jun 10 23:34:24 ibg4 : 	It took 0.178406 seconds to Send Install Completed notification "Finished install."
Jun 10 23:34:24 ibg4 : Jun 10 23:34:24 ibg4 : Summary Information
Jun 10 23:34:24 ibg4 : Type           Elapsed time (sec)
Jun 10 23:34:24 ibg4 :            zero           0.263910

インストール終了。

/var/tmp ディレクトリを見ると、ちゃんと作成されていました。

ibg4:~/work/resource kenz$ ls -lat /var/tmp/
total 32
drwxrwxrwt    7 root  wheel  238 Jun 10 23:34 .
-rw-r--r--    1 root  wheel   29 Jun 10 23:34 postflight
-rw-r--r--    1 root  wheel   29 Jun 10 23:34 postinstall
-rw-r--r--    1 kenz  wheel   29 Jun 10 23:34 preinstall
-rw-r--r--    1 root  wheel   29 Jun 10 23:34 preflight
drwxr-xr-x   24 root  wheel  816 Jun 10 13:05 ..
ibg4:~/work/resource kenz$ 

ibg4:~/work/resource kenz$ cat /var/tmp/preflight 
Sat Jun 10 23:34:20 JST 2006
ibg4:~/work/resource kenz$ cat /var/tmp/preinstall 
Sat Jun 10 23:34:21 JST 2006
ibg4:~/work/resource kenz$ cat /var/tmp/postinstall 
Sat Jun 10 23:34:21 JST 2006
ibg4:~/work/resource kenz$ cat /var/tmp/postflight  
Sat Jun 10 23:34:22 JST 2006
ibg4:~/work/resource kenz$ 

続いて、同じバージョンをインストールしてみます。アップグレードの処理が走るはずです。
Jun 10 23:40:46 ibg4 : @(#)PROGRAM:Install  PROJECT:Install-137  DEVELOPER:root  BUILT:Jan 23 2006 20:09:15\n
Jun 10 23:40:46 ibg4 : @(#)PROGRAM:Installer  PROJECT:Installer-86  DEVELOPER:root  BUILT:Sep  2 2005 14:24:50\n
Jun 10 23:40:46 ibg4 : Hardware: PowerBook6,3 @ 799 MHz, 640 MB
Jun 10 23:40:46 ibg4 : Running OS Build: 8I127
Jun 10 23:40:47 ibg4 : helloworld Installation Log
Jun 10 23:40:47 ibg4 : Opened from: /Users/kenz/work/hello.pkg
Jun 10 23:40:47 ibg4 : It took 0.104505 seconds to load 7 UI sections
Jun 10 23:40:48 ibg4 : It took 1.701841 seconds to finish launching.
Jun 10 23:40:50 ibg4 : Distribution: helloworld
Jun 10 23:40:50 ibg4 : Installation checks completed successfully.
Jun 10 23:41:10 ibg4 : admin auth received to install
Jun 10 23:41:10 ibg4 : ================================================================================
Jun 10 23:41:10 ibg4 : User picked Easy Install
Jun 10 23:41:10 ibg4 : Choices selected for installation:
Jun 10 23:41:10 ibg4 : 	アップグレード: "helloworld"
Jun 10 23:41:10 ibg4 : 		hello.pkg : com.hayagui.hello : 0.1.0.0.1
Jun 10 23:41:10 ibg4 : ================================================================================
Jun 10 23:41:10 ibg4 : It took 0.001823 seconds to summarize the package selections.
Jun 10 23:41:10 ibg4 : Starting installation:
Jun 10 23:41:10 ibg4 : Preparing volume "tiger" for installation
Jun 10 23:41:10 ibg4 : Configuring volume "tiger"
Jun 10 23:41:11 ibg4 : Preparing local booted disk
Jun 10 23:41:11 ibg4 : Create temporary directory "/private/tmp/hello.pkg.995hcBSM7"
Jun 10 23:41:12 ibg4 : run preflight script for helloworld
Jun 10 23:41:12 ibg4 : Processing helloworld:
Jun 10 23:41:12 ibg4 : 	Initialize patching
Jun 10 23:41:12 ibg4 : 	Determining files to install
Jun 10 23:41:12 ibg4 : 	Evaluating versions of bundles
Jun 10 23:41:12 ibg4 : 	Evaluating custom file version checking
Jun 10 23:41:12 ibg4 : 	Configuring deferred files
Jun 10 23:41:12 ibg4 : 	Determing obsolete files
Jun 10 23:41:12 ibg4 : 	Assembling temporary receipt
Jun 10 23:41:13 ibg4 : 	Performing pre-extraction actions
Jun 10 23:41:13 ibg4 : ==== It took 0.163776 seconds to check for prebinding
Jun 10 23:41:13 ibg4 : 	run preupgrade script for helloworld
Jun 10 23:41:13 ibg4 : 	Removing obsoleted files
Jun 10 23:41:13 ibg4 : 	Creating destination path
Jun 10 23:41:13 ibg4 : 	Extracting files
Jun 10 23:41:14 ibg4 : 	4 files looked up in 0.00 seconds. 4 files written in 0.07 seconds.
Jun 10 23:41:14 ibg4 : 	0 kilobytes installed.
Jun 10 23:41:14 ibg4 : 	run postupgrade script for helloworld
Jun 10 23:41:14 ibg4 : 	Performing post-extraction actions
Jun 10 23:41:15 ibg4 : 	Assembling receipt
Jun 10 23:41:15 ibg4 : run postflight script for helloworld
Jun 10 23:41:15 ibg4 : Removing temporary directory "/private/tmp/hello.pkg.995hcBSM7"
Jun 10 23:41:16 ibg4 : Finalize disk "tiger"
Jun 10 23:41:16 ibg4 : Notifying system of updated components
Jun 10 23:41:16 ibg4 : TOTAL: Packages report 4 files, 4 actual files written
Jun 10 23:41:17 ibg4 : Private/Total = (6.4MB, 64.9MB),  Heap/Total = (2.3MB, 17.6MB),  Regions(malloc, private) = (26, 29)
Jun 10 23:41:17 ibg4 : It took 5.512232 seconds to successfully install "helloworld" (1 pkg(s))
Jun 10 23:41:17 ibg4 : 	It took 1.027024 seconds to Configuring volume "tiger" (dm prepare*disk)
Jun 10 23:41:17 ibg4 : 	It took 0.452768 seconds to Create temporary directory "/private/tmp/hello.pkg.995hcBSM7"
Jun 10 23:41:17 ibg4 : 	It took 0.218928 seconds to run preflight script for helloworld
Jun 10 23:41:17 ibg4 : 	It took 3.324715 seconds to Install helloworld: 26 elements
Jun 10 23:41:17 ibg4 : 		It took 3.271396 seconds to successfully Install package helloworld
Jun 10 23:41:17 ibg4 : 			It took 0.024007 seconds to Build install plan (& redirected paths)
Jun 10 23:41:17 ibg4 : 			It took 1.050722 seconds to Assembling temporary receipt
Jun 10 23:41:17 ibg4 : 			It took 0.181331 seconds to Collect path info (ATS, Sec Equiv, Kext, Pref Panes)
Jun 10 23:41:17 ibg4 : 			It took 0.238835 seconds to run preupgrade script for helloworld
Jun 10 23:41:17 ibg4 : 			It took 0.807198 seconds to Write files
Jun 10 23:41:17 ibg4 : 			It took 0.292139 seconds to run postupgrade script for helloworld
Jun 10 23:41:17 ibg4 : 			It took 0.110734 seconds to Update SecEqiv db
Jun 10 23:41:17 ibg4 : 			It took 0.552238 seconds to Assembling receipt
Jun 10 23:41:17 ibg4 : 	It took 0.232264 seconds to run postflight script for helloworld
Jun 10 23:41:17 ibg4 : 	It took 0.233428 seconds to Removing temporary directory "/private/tmp/hello.pkg.995hcBSM7"
Jun 10 23:41:17 ibg4 : 	It took 0.021806 seconds to Finalize disk "tiger" (dm finalize*disk)
Jun 10 23:41:17 ibg4 : Jun 10 23:41:17 ibg4 : Summary Information
Jun 10 23:41:17 ibg4 : Type           Elapsed time (sec)
Jun 10 23:41:17 ibg4 :           patch           0.000147
Jun 10 23:41:17 ibg4 :          script           0.982166
Jun 10 23:41:17 ibg4 :            zero           0.699478
Jun 10 23:41:17 ibg4 :         extract           0.807198
Jun 10 23:41:17 ibg4 :          config           0.318086
Jun 10 23:41:17 ibg4 :         receipt           1.602960
Jun 10 23:41:17 ibg4 :            disk           1.048878
Jun 10 23:41:17 ibg4 :         install           3.324715
Jun 10 23:41:17 ibg4 : Jun 10 23:41:17 ibg4 : Starting installation:
Jun 10 23:41:17 ibg4 : Finalizing installation.
Jun 10 23:41:19 ibg4 : Private/Total = (6.5MB, 65.2MB),  Heap/Total = (2.3MB, 17.6MB),  Regions(malloc, private) = (26, 32)
Jun 10 23:41:19 ibg4 : It took 0.241365 seconds to successfully End of Install Jobs
Jun 10 23:41:19 ibg4 : 	It took 0.143508 seconds to Send End Jobs Did End notification "Finishing end-of-install jobs."
Jun 10 23:41:19 ibg4 : 	It took 0.083788 seconds to Send Install Completed notification "Finished install."
Jun 10 23:41:19 ibg4 : Jun 10 23:41:19 ibg4 : Summary Information
Jun 10 23:41:19 ibg4 : Type           Elapsed time (sec)
Jun 10 23:41:19 ibg4 :            zero           0.241365

ファイルもちゃんとできています。
ibg4:~/work/resource kenz$ ls -lat /var/tmp/
total 48
-rw-r--r--    1 root  wheel   29 Jun 10 23:41 postflight
drwxrwxrwt    9 root  wheel  306 Jun 10 23:41 .
-rw-r--r--    1 root  wheel   29 Jun 10 23:41 postupgrade
-rw-r--r--    1 root  wheel   29 Jun 10 23:41 preupgrade
-rw-r--r--    1 root  wheel   29 Jun 10 23:41 preflight
-rw-r--r--    1 root  wheel   29 Jun 10 23:34 postinstall
-rw-r--r--    1 kenz  wheel   29 Jun 10 23:34 preinstall
drwxr-xr-x   24 root  wheel  816 Jun 10 13:05 ..
ibg4:~/work/resource kenz$ 


戻る



(C)1999 - 2006 Kenji Ito All rights reserved.