Xcode/package
changeset 2207 d63e9f5944ae
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Xcode/package	Sat Jul 21 17:09:01 2007 +0000
     1.3 @@ -0,0 +1,272 @@
     1.4 +#! /bin/csh -ef
     1.5 +
     1.6 +set prog = `/usr/bin/basename $0`
     1.7 +set usage = "Usage: $prog [-f] root-dir info-file [tiff-file] [-d dest-dir] [-r resource-dir] [-traditional | -gnutar]"
     1.8 +set noglob
     1.9 +
    1.10 +if (-x /usr/bin/mkbom) then
    1.11 +    set mkbom=/usr/bin/mkbom
    1.12 +    set lsbom=/usr/bin/lsbom
    1.13 +else
    1.14 +    set mkbom=/usr/etc/mkbom
    1.15 +    set lsbom=/usr/etc/lsbom
    1.16 +endif
    1.17 +
    1.18 +if (-x /usr/bin/awk) then
    1.19 +    set awk=/usr/bin/awk
    1.20 +else
    1.21 +    set awk=/bin/awk
    1.22 +endif
    1.23 +
    1.24 +set gnutar=/usr/bin/gnutar
    1.25 +set tar=/usr/bin/tar
    1.26 +set pax=/bin/pax
    1.27 +
    1.28 +# gather parameters
    1.29 +if ($#argv == 0) then
    1.30 +    echo $usage
    1.31 +    exit(1)
    1.32 +endif
    1.33 +
    1.34 +while ( $#argv > 0 )
    1.35 +    switch ( $argv[1] )
    1.36 +	case -d:
    1.37 +	    if ( $?destDir ) then
    1.38 +		echo ${prog}: dest-dir parameter already set to ${destDir}.
    1.39 +		echo $usage
    1.40 +		exit(1)
    1.41 +	    else if ( $#argv < 2 ) then
    1.42 +		echo ${prog}: -d option requires destination directory.
    1.43 +		echo $usage
    1.44 +		exit(1)
    1.45 +	    else
    1.46 +		set destDir = $argv[2]
    1.47 +		shift; shift
    1.48 +		breaksw
    1.49 +	    endif
    1.50 +	case -f:
    1.51 +	    if ( $?rootDir ) then
    1.52 +		echo ${prog}: root-dir parameter already set to ${rootDir}.
    1.53 +		echo $usage
    1.54 +		exit(1)
    1.55 +	    else if ( $#argv < 2 ) then
    1.56 +		echo ${prog}: -f option requires package root directory.
    1.57 +		echo $usage
    1.58 +		exit(1)
    1.59 +	    else
    1.60 +		set rootDir = $argv[2]
    1.61 +		set fflag
    1.62 +		shift; shift
    1.63 +		breaksw
    1.64 +	    endif
    1.65 +	case -r:
    1.66 +	    if ( $?resDir ) then
    1.67 +		echo ${prog}: resource-dir parameter already set to ${resDir}.
    1.68 +		echo $usage
    1.69 +		exit(1)
    1.70 +	    else if ( $#argv < 2 ) then
    1.71 +		echo ${prog}: -r option requires package resource directory.
    1.72 +		echo $usage
    1.73 +		exit(1)
    1.74 +	    else
    1.75 +		set resDir = $argv[2]
    1.76 +		shift; shift
    1.77 +		breaksw
    1.78 +	    endif
    1.79 +	case -traditional:
    1.80 +	    set usetar
    1.81 +            unset usegnutar
    1.82 +	    unset usepax
    1.83 +	    breaksw
    1.84 +        case -gnutar:
    1.85 +	    set usegnutar
    1.86 +            unset usepax
    1.87 +	    unset usetar
    1.88 +	case -B:
    1.89 +	    # We got long file names, better use bigtar instead
    1.90 +	    #set archiver = /NextAdmin/Installer.app/Resources/installer_bigtar
    1.91 +	    echo 2>&1 ${prog}: -B flag is no longer relevant.
    1.92 +	    shift
    1.93 +	    breaksw
    1.94 +	case -*:
    1.95 +	    echo ${prog}: Unknown option: $argv[1]
    1.96 +	    echo $usage
    1.97 +	    exit(1)
    1.98 +	case *.info:
    1.99 +	    if ( $?info ) then
   1.100 +		echo ${prog}: info-file parameter already set to ${info}.
   1.101 +		echo $usage
   1.102 +		exit(1)
   1.103 +	    else
   1.104 +		set info = "$argv[1]"
   1.105 +		shift
   1.106 +		breaksw
   1.107 +	    endif
   1.108 +	case *.tiff:
   1.109 +	    if ( $?tiff ) then
   1.110 +		echo ${prog}: tiff-file parameter already set to ${tiff}.
   1.111 +		echo $usage
   1.112 +		exit(1)
   1.113 +	    else
   1.114 +		set tiff = "$argv[1]"
   1.115 +		shift
   1.116 +		breaksw
   1.117 +	    endif
   1.118 +	default:
   1.119 +	    if ( $?rootDir ) then
   1.120 +		echo ${prog}: unrecognized parameter: $argv[1]
   1.121 +		echo $usage
   1.122 +		exit(1)
   1.123 +	    else
   1.124 +		set rootDir = "$argv[1]"
   1.125 +		shift
   1.126 +		breaksw
   1.127 +	    endif
   1.128 +    endsw
   1.129 +end
   1.130 +
   1.131 +# check for mandatory parameters
   1.132 +if ( ! $?rootDir ) then
   1.133 +    echo ${prog}: missing root-dir parameter.
   1.134 +    echo $usage
   1.135 +    exit(1)
   1.136 +else if ( ! $?info) then
   1.137 +    echo ${prog}: missing info-file parameter.
   1.138 +    echo $usage
   1.139 +    exit(1)
   1.140 +endif
   1.141 +
   1.142 +# destDir gets default value if unset on command line
   1.143 +if ( $?destDir ) then
   1.144 +    /bin/mkdir -p $destDir
   1.145 +else
   1.146 +    set destDir = .
   1.147 +endif
   1.148 +
   1.149 +# derive the root name for the package from the root name of the info file
   1.150 +set root = `/usr/bin/basename $info .info`
   1.151 +
   1.152 +# create package directory
   1.153 +set pkg = ${destDir}/${root}.pkg
   1.154 +echo Generating Installer package $pkg ...
   1.155 +if ( -e $pkg ) /bin/rm -rf $pkg
   1.156 +/bin/mkdir -p -m 755 $pkg
   1.157 +
   1.158 +# (gnu)tar/pax and compress root directory to package archive
   1.159 +echo -n "	creating package archive ... "
   1.160 +if ( $?fflag ) then
   1.161 +    set pkgTop = ${rootDir:t}
   1.162 +    set parent = ${rootDir:h}
   1.163 +    if ( "$parent" == "$pkgTop" ) set parent = "."
   1.164 +else
   1.165 +    set parent = $rootDir
   1.166 +    set pkgTop = .    
   1.167 +endif
   1.168 +if ( $?usetar ) then
   1.169 +    set pkgArchive = $pkg/$root.tar.Z
   1.170 +    (cd $parent; $tar -w $pkgTop) | /usr/bin/compress -f -c > $pkgArchive
   1.171 +else if ( $?usegnutar ) then
   1.172 +    set pkgArchive = $pkg/$root.tar.gz
   1.173 +    (cd $parent; $gnutar zcf $pkgArchive $pkgTop)
   1.174 +else
   1.175 +    set pkgArchive = $pkg/$root.pax.gz
   1.176 +    (cd $parent; $pax -w -z -x cpio $pkgTop) > $pkgArchive
   1.177 +endif
   1.178 +/bin/chmod 444 $pkgArchive
   1.179 +echo done.
   1.180 +
   1.181 +# copy info file to package
   1.182 +set pkgInfo = $pkg/$root.info
   1.183 +echo -n "	copying ${info:t} ... "
   1.184 +/bin/cp $info $pkgInfo
   1.185 +/bin/chmod 444 $pkgInfo
   1.186 +echo done.
   1.187 +
   1.188 +# copy tiff file to package
   1.189 +if ( $?tiff ) then
   1.190 +    set pkgTiff = $pkg/$root.tiff
   1.191 +    echo -n "	copying ${tiff:t} ... "
   1.192 +    /bin/cp $tiff $pkgTiff
   1.193 +    /bin/chmod 444 $pkgTiff
   1.194 +    echo done.
   1.195 +endif
   1.196 +
   1.197 +# copy resources to package
   1.198 +if ( $?resDir ) then
   1.199 +    echo -n "	copying ${resDir:t} ... "
   1.200 +
   1.201 +    # don't want to see push/pop output
   1.202 +    pushd $resDir > /dev/null
   1.203 +	# get lists of resources. We'll want to change
   1.204 +	# permissions on just these things later.
   1.205 +        set directoriesInResDir = `find . -type d`
   1.206 +        set filesInResDir = `find . -type f`
   1.207 +    popd > /dev/null
   1.208 +
   1.209 +    # copy the resource directory contents into the package directory
   1.210 +    foreach resFile (`ls $resDir`)
   1.211 +	cp -r $resDir/$resFile $pkg
   1.212 +    end
   1.213 +
   1.214 +    pushd $pkg > /dev/null
   1.215 +	# Change all directories to +r+x, except the package
   1.216 +	# directory itself
   1.217 +        foreach resFileItem ($directoriesInResDir)
   1.218 +            if ( $resFileItem != "." ) then
   1.219 +                chmod 555 $resFileItem
   1.220 +            endif
   1.221 +        end
   1.222 +	# change all flat files to read only
   1.223 +        foreach resFileItem ($filesInResDir)
   1.224 +            chmod 444 $resFileItem
   1.225 +        end
   1.226 +    popd > /dev/null
   1.227 +
   1.228 +    echo done.
   1.229 +endif
   1.230 +
   1.231 +# generate bom file
   1.232 +set pkgBom = $pkg/$root.bom
   1.233 +echo -n "	generating bom file ... "
   1.234 +/bin/rm -f $pkgBom
   1.235 +if ( $?fflag ) then
   1.236 +    $mkbom $parent $pkgBom >& /dev/null
   1.237 +else
   1.238 +    $mkbom $rootDir $pkgBom >& /dev/null
   1.239 +endif
   1.240 +/bin/chmod 444 $pkgArchive
   1.241 +echo done.
   1.242 +	
   1.243 +# generate sizes file
   1.244 +set pkgSizes = $pkg/$root.sizes
   1.245 +echo -n "	generating sizes file ... "
   1.246 +
   1.247 +# compute number of files in package
   1.248 +set numFiles = `$lsbom -s $pkgBom | /usr/bin/wc -l`
   1.249 +
   1.250 +# compute package size when compressed
   1.251 +@ compressedSize = `/usr/bin/du -k -s $pkg | $awk '{print $1}'`
   1.252 +@ compressedSize += 3		# add 1KB each for sizes, location, status files
   1.253 +
   1.254 +@ infoSize = `/bin/ls -s $pkgInfo | $awk '{print $1}'`
   1.255 +@ bomSize = `/bin/ls -s $pkgBom | $awk '{print $1}'`
   1.256 +if ( $?tiff ) then
   1.257 +    @ tiffSize = `/bin/ls -s $pkgTiff | $awk '{print $1}'`
   1.258 +else
   1.259 +    @ tiffSize = 0
   1.260 +endif 
   1.261 +
   1.262 +@ installedSize = `/usr/bin/du -k -s $rootDir | $awk '{print $1}'`
   1.263 +@ installedSize += $infoSize + $bomSize + $tiffSize + 3
   1.264 +
   1.265 +# echo size parameters to sizes file
   1.266 +echo NumFiles $numFiles             >  $pkgSizes
   1.267 +echo InstalledSize $installedSize   >> $pkgSizes
   1.268 +echo CompressedSize $compressedSize >> $pkgSizes
   1.269 +echo done.
   1.270 +echo " ... finished generating $pkg."
   1.271 +
   1.272 +exit(0)
   1.273 +
   1.274 +# end package
   1.275 +