2 # this file was orignally distributed by Apple in the Developer Tools package
3 #it is distributed under the Apple Open Source License
5 set prog = `/usr/bin/basename $0`
6 set usage = "Usage: $prog [-f] root-dir info-file [tiff-file] [-d dest-dir] [-r resource-dir] [-traditional | -gnutar] [-bzip]"
9 if (-x /usr/bin/mkbom) then
10 set mkbom=/usr/bin/mkbom
11 set lsbom=/usr/bin/lsbom
13 set mkbom=/usr/etc/mkbom
14 set lsbom=/usr/etc/lsbom
17 if (-x /usr/bin/awk) then
22 set bzip2=`which bzip2`
23 set gnutar=/usr/bin/gnutar
37 echo ${prog}: dest-dir parameter already set to ${destDir}.
40 else if ( $#argv < 2 ) then
41 echo ${prog}: -d option requires destination directory.
45 set destDir = $argv[2]
51 echo ${prog}: root-dir parameter already set to ${rootDir}.
54 else if ( $#argv < 2 ) then
55 echo ${prog}: -f option requires package root directory.
59 set rootDir = $argv[2]
66 echo ${prog}: resource-dir parameter already set to ${resDir}.
69 else if ( $#argv < 2 ) then
70 echo ${prog}: -r option requires package resource directory.
79 echo useing standard tar
93 echo using bzip compression
95 echo COMPRESSION ERROR: You can not use BZIP2 you do not have it installed
101 echo ${prog}: Unknown option: $argv[1]
106 echo ${prog}: info-file parameter already set to ${info}.
110 set info = "$argv[1]"
116 echo ${prog}: tiff-file parameter already set to ${tiff}.
120 set tiff = "$argv[1]"
125 if ( $?rootDir ) then
126 echo ${prog}: unrecognized parameter: $argv[1]
130 set rootDir = "$argv[1]"
137 # check for mandatory parameters
138 if ( ! $?rootDir ) then
139 echo ${prog}: missing root-dir parameter.
142 else if ( ! $?info) then
143 echo ${prog}: missing info-file parameter.
148 # destDir gets default value if unset on command line
149 if ( $?destDir ) then
150 /bin/mkdir -p $destDir
155 # derive the root name for the package from the root name of the info file
156 set root = `/usr/bin/basename $info .info`
158 # create package directory
159 set pkg = ${destDir}/${root}.pkg
160 echo Generating Installer package $pkg ...
161 if ( -e $pkg ) /bin/rm -rf $pkg
162 /bin/mkdir -p -m 755 $pkg
163 /bin/mkdir -p -m 755 $pkg/Contents
164 /bin/mkdir -p -m 755 $pkg/Contents/Resources
165 /bin/mkdir -p -m 755 $pkg/Contents/Resources/English.lproj/
166 echo "gxpmpkg2" >$pkg/Contents/PkgInfo
167 chmod 755 $pkg/Contents/PkgInfo
168 # (gnu)tar/pax and compress root directory to package archive
169 echo -n " creating package archive ... "
171 set pkgTop = ${rootDir:t}
172 set parent = ${rootDir:h}
173 if ( "$parent" == "$pkgTop" ) set parent = "."
175 set parent = $rootDir
179 set pkgArchive = $pkg/Contents/Resources/$root.tar.Z
180 (cd $parent; $tar -w $pkgTop) | /usr/bin/tar -f -c > $pkgArchive
181 else if ( $?usegnutar ) then
182 if ( $?usebzip ) then
183 set pkgArchive = $pkg/Contents/Resources/$root.tar.bz2
184 (cd $parent; $gnutar c $pkgTop) | $bzip2 -f -c > $pkgArchive
186 set pkgArchive = $pkg/Contents/Resources/$root.tar.gz
187 (cd $parent; $gnutar zcf $pkgArchive $pkgTop)
190 set pkgArchive = $pkg/Contents/Resources/$root.pax.gz
191 (cd $parent; $pax -w -z -x cpio $pkgTop) > $pkgArchive
193 /bin/chmod 755 $pkgArchive
196 # copy info file to package
197 set pkgInfo = $pkg/Contents/Resources/English.lproj/$root.info
198 echo -n " copying ${info:t} ... "
199 /bin/cp $info $pkgInfo
200 /bin/chmod 755 $pkgInfo
203 # copy tiff file to package
205 set pkgTiff = $pkg/$root.tiff
206 echo -n " copying ${tiff:t} ... "
207 /bin/cp $tiff $pkgTiff
208 /bin/chmod 444 $pkgTiff
212 # copy resources to package
214 echo -n " copying ${resDir:t} ... "
216 # don't want to see push/pop output
217 pushd $resDir > /dev/null
218 # get lists of resources. We'll want to change
219 # permissions on just these things later.
220 set directoriesInResDir = `find . -type d | grep -v svn`
221 set filesInResDir = `find . -type f | grep -v svn`
224 # copy the resource directory contents into the package directory
225 foreach resFile (`ls $resDir | grep -v svn`)
226 cp -r "$resDir/$resFile" "$pkg/Contents/Resources"
229 pushd $pkg/Contents/Resources > /dev/null
230 # Change all directories to +r+x, except the package
232 foreach resFileItem ($directoriesInResDir)
233 if ( $resFileItem != "." ) then
234 chmod 755 "$resFileItem"
237 # change all flat files to read only
238 foreach resFileItem ($filesInResDir)
239 if ( $resFileItem != "./.DS_Store" ) then
240 chmod 755 "$resFileItem"
249 set pkgBom = $pkg/Contents/Resources/$root.bom
250 echo -n " generating bom file ... "
253 $mkbom $parent $pkgBom >& /dev/null
255 $mkbom $rootDir $pkgBom >& /dev/null
257 /bin/chmod 444 $pkgArchive
260 # generate sizes file
261 set pkgSizes = $pkg/Contents/Resources/$root.sizes
262 echo -n " generating sizes file ... "
264 # compute number of files in package
265 set numFiles = `$lsbom -s $pkgBom | /usr/bin/wc -l`
267 # compute package size when compressed
268 @ compressedSize = `/usr/bin/du -k -s $pkg | $awk '{print $1}'`
269 @ compressedSize += 3 # add 1KB each for sizes, location, status files
271 @ infoSize = `/bin/ls -s $pkgInfo | $awk '{print $1}'`
272 @ bomSize = `/bin/ls -s $pkgBom | $awk '{print $1}'`
274 @ tiffSize = `/bin/ls -s $pkgTiff | $awk '{print $1}'`
279 @ installedSize = `/usr/bin/du -k -s $rootDir | $awk '{print $1}'`
280 @ installedSize += $infoSize + $bomSize + $tiffSize + 3
282 # echo size parameters to sizes file
283 echo NumFiles $numFiles > $pkgSizes
284 echo InstalledSize $installedSize >> $pkgSizes
285 echo CompressedSize $compressedSize >> $pkgSizes
287 echo " ... finished generating $pkg."