3 # original script by Chris Roberts (The OS X Package Manager)
4 # slightly modified by Frank Vercruesse (mainly fixed quoting issues)
6 set prog
= `/usr/bin/basename $0`
7 set usage
= "Usage: $prog [-f] root-dir info-file [tiff-file] [-d dest-dir] [-r resource-dir] [-traditional | -gnutar]"
10 if (-x /usr
/bin
/mkbom
) then
11 set mkbom
=/usr
/bin
/mkbom
12 set lsbom
=/usr
/bin
/lsbom
14 set mkbom
=/usr
/etc
/mkbom
15 set lsbom
=/usr
/etc
/lsbom
18 if (-x /usr
/bin
/awk) then
24 set gnutar
=/usr
/bin
/gnutar
38 echo ${prog}: dest
-dir parameter already
set to
${destDir}.
41 else if ( $#argv < 2 ) then
42 echo ${prog}: -d option requires destination directory.
46 set destDir
= "$argv[2]"
52 echo ${prog}: root
-dir parameter already
set to
${rootDir}.
55 else if ( $#argv < 2 ) then
56 echo ${prog}: -f option requires package root directory.
60 set rootDir
= "$argv[2]"
67 echo ${prog}: resource
-dir parameter already
set to
${resDir}.
70 else if ( $#argv < 2 ) then
71 echo ${prog}: -r option requires package resource directory.
75 set resDir
= "$argv[2]"
92 # We got long file names, better use bigtar instead
93 #set archiver = /NextAdmin/Installer.app/Resources/installer_bigtar
94 #echo 2>&1 ${prog}: -B flag is longer relevant.
98 echo ${prog}: Unknown option
: $argv[1]
103 echo ${prog}: info
-file parameter already
set to
${info}.
107 set info
= "$argv[1]"
113 echo ${prog}: tiff
-file parameter already
set to
${tiff}.
117 set tiff
= "$argv[1]"
122 if ( $?rootDir
) then
123 echo ${prog}: unrecognized parameter
: $argv[1]
127 set rootDir
= "$argv[1]"
134 # check for mandatory parameters
135 if ( ! $?rootDir
) then
136 echo ${prog}: missing root
-dir parameter.
139 else if ( ! $?info
) then
140 echo ${prog}: missing info
-file parameter.
145 # destDir gets default value if unset on command line
146 if ( $?destDir
) then
147 /bin
/mkdir -p "$destDir"
152 # derive the root name for the package from the root name of the info file
153 set root
= `/usr/bin/basename $info .info`
155 # create package directory
156 set pkg
= "${destDir}/${root}.pkg"
157 echo Generating Installer package
$pkg ...
158 if ( -e "$pkg" ) /bin
/rm -rf "$pkg"
159 /bin
/mkdir -p -m 755 "$pkg"
160 /bin
/mkdir -p -m 755 "$pkg/Contents"
161 /bin
/mkdir -p -m 755 "$pkg/Contents/Resources"
162 /bin
/mkdir -p -m 755 "$pkg/Contents/Resources/English.lproj/"
163 echo -n "pmkrpkg1" >"$pkg/Contents/PkgInfo"
164 chmod 755 "$pkg/Contents/PkgInfo"
165 # (gnu)tar/pax and compress root directory to package archive
166 echo -n " creating package archive ... "
168 set pkgTop
= "${rootDir:t}"
169 set parent
= "${rootDir:h}"
170 if ( "$parent" == "$pkgTop" ) set parent
= "."
172 set parent
= "$rootDir"
176 set pkgArchive
= "$pkg/Contents/Resources/$root.tar.Z"
177 (cd "$parent"; $tar -w "$pkgTop") | /usr
/bin
/tar -f -c > "$pkgArchive"
178 else if ( $?usegnutar
) then
179 set pkgArchive
= "$pkg/Contents/Resources/$root.tar.gz"
180 (cd "$parent"; $gnutar zcf
"$pkgArchive" "$pkgTop")
182 set pkgArchive
= "$pkg/Contents/Resources/$root.pax.gz"
183 (cd "$parent"; $pax -w -z -x cpio "$pkgTop") > "$pkgArchive"
185 /bin
/chmod 755 "$pkgArchive"
188 # copy info file to package
189 set pkgInfo
= "$pkg/Contents/Resources/English.lproj/$root.info"
190 echo -n " copying ${info:t} ... "
191 /bin
/cp $info "$pkgInfo"
192 /bin
/chmod 755 "$pkgInfo"
195 # copy tiff file to package
197 set pkgTiff
= "$pkg/$root.tiff"
198 echo -n " copying ${tiff:t} ... "
199 /bin
/cp $tiff "$pkgTiff"
200 /bin
/chmod 444 "$pkgTiff"
204 # copy resources to package
206 echo -n " copying ${resDir:t} ... "
208 # don't want to see push/pop output
209 pushd "$resDir" > /dev
/null
210 # get lists of resources. We'll want to change
211 # permissions on just these things later.
212 set directoriesInResDir
= `find . -type d`
213 set filesInResDir
= `find . -type f`
216 # copy the resource directory contents into the package directory
217 foreach resFile
(`ls "$resDir"`)
218 cp -r "$resDir/$resFile" "$pkg/Contents/Resources"
221 pushd "$pkg/Contents/Resources" > /dev
/null
222 # Change all directories to +r+x, except the package
224 foreach resFileItem
($directoriesInResDir)
225 if ( "$resFileItem" != "." ) then
226 chmod 755 $resFileItem
229 # change all flat files to read only
230 foreach resFileItem
($filesInResDir)
231 if ( "$resFileItem" != "./.DS_Store" ) then
232 chmod 755 $resFileItem
241 set pkgBom
= "$pkg/Contents/Resources/$root.bom"
242 echo -n " generating bom file ... "
245 $mkbom "$parent" "$pkgBom" >& /dev
/null
247 $mkbom "$rootDir" "$pkgBom" >& /dev
/null
249 /bin
/chmod 444 "$pkgArchive"
252 # generate sizes file
253 set pkgSizes
= "$pkg/Contents/Resources/$root.sizes"
254 echo -n " generating sizes file ... "
256 # compute number of files in package
257 set numFiles
= `$lsbom -s "$pkgBom" | /usr/bin/wc -l`
259 # compute package size when compressed
260 @ compressedSize
= `/usr/bin/du -k -s "$pkg" | $awk '{print $1}'`
261 @ compressedSize
+= 3 # add 1KB each for sizes, location, status files
263 @ infoSize
= `/bin/ls -s "$pkgInfo" | $awk '{print $1}'`
264 @ bomSize
= `/bin/ls -s "$pkgBom" | $awk '{print $1}'`
266 @ tiffSize
= `/bin/ls -s "$pkgTiff" | $awk '{print $1}'`
271 @ installedSize
= `/usr/bin/du -k -s "$rootDir" | $awk '{print $1}'`
272 @ installedSize
+= $infoSize + $bomSize + $tiffSize + 3
274 # echo size parameters to sizes file
275 echo NumFiles
$numFiles > "$pkgSizes"
276 echo InstalledSize
$installedSize >> "$pkgSizes"
277 echo CompressedSize
$compressedSize >> "$pkgSizes"
279 echo " ... finished generating $pkg."