Xcode/package
author Sam Lantinga <slouken@libsdl.org>
Sat, 21 Jul 2007 17:09:01 +0000
changeset 2207 d63e9f5944ae
permissions -rwxr-xr-x
Unpacked project archives to get individual file history in subversion
slouken@2207
     1
#! /bin/csh -ef
slouken@2207
     2
slouken@2207
     3
set prog = `/usr/bin/basename $0`
slouken@2207
     4
set usage = "Usage: $prog [-f] root-dir info-file [tiff-file] [-d dest-dir] [-r resource-dir] [-traditional | -gnutar]"
slouken@2207
     5
set noglob
slouken@2207
     6
slouken@2207
     7
if (-x /usr/bin/mkbom) then
slouken@2207
     8
    set mkbom=/usr/bin/mkbom
slouken@2207
     9
    set lsbom=/usr/bin/lsbom
slouken@2207
    10
else
slouken@2207
    11
    set mkbom=/usr/etc/mkbom
slouken@2207
    12
    set lsbom=/usr/etc/lsbom
slouken@2207
    13
endif
slouken@2207
    14
slouken@2207
    15
if (-x /usr/bin/awk) then
slouken@2207
    16
    set awk=/usr/bin/awk
slouken@2207
    17
else
slouken@2207
    18
    set awk=/bin/awk
slouken@2207
    19
endif
slouken@2207
    20
slouken@2207
    21
set gnutar=/usr/bin/gnutar
slouken@2207
    22
set tar=/usr/bin/tar
slouken@2207
    23
set pax=/bin/pax
slouken@2207
    24
slouken@2207
    25
# gather parameters
slouken@2207
    26
if ($#argv == 0) then
slouken@2207
    27
    echo $usage
slouken@2207
    28
    exit(1)
slouken@2207
    29
endif
slouken@2207
    30
slouken@2207
    31
while ( $#argv > 0 )
slouken@2207
    32
    switch ( $argv[1] )
slouken@2207
    33
	case -d:
slouken@2207
    34
	    if ( $?destDir ) then
slouken@2207
    35
		echo ${prog}: dest-dir parameter already set to ${destDir}.
slouken@2207
    36
		echo $usage
slouken@2207
    37
		exit(1)
slouken@2207
    38
	    else if ( $#argv < 2 ) then
slouken@2207
    39
		echo ${prog}: -d option requires destination directory.
slouken@2207
    40
		echo $usage
slouken@2207
    41
		exit(1)
slouken@2207
    42
	    else
slouken@2207
    43
		set destDir = $argv[2]
slouken@2207
    44
		shift; shift
slouken@2207
    45
		breaksw
slouken@2207
    46
	    endif
slouken@2207
    47
	case -f:
slouken@2207
    48
	    if ( $?rootDir ) then
slouken@2207
    49
		echo ${prog}: root-dir parameter already set to ${rootDir}.
slouken@2207
    50
		echo $usage
slouken@2207
    51
		exit(1)
slouken@2207
    52
	    else if ( $#argv < 2 ) then
slouken@2207
    53
		echo ${prog}: -f option requires package root directory.
slouken@2207
    54
		echo $usage
slouken@2207
    55
		exit(1)
slouken@2207
    56
	    else
slouken@2207
    57
		set rootDir = $argv[2]
slouken@2207
    58
		set fflag
slouken@2207
    59
		shift; shift
slouken@2207
    60
		breaksw
slouken@2207
    61
	    endif
slouken@2207
    62
	case -r:
slouken@2207
    63
	    if ( $?resDir ) then
slouken@2207
    64
		echo ${prog}: resource-dir parameter already set to ${resDir}.
slouken@2207
    65
		echo $usage
slouken@2207
    66
		exit(1)
slouken@2207
    67
	    else if ( $#argv < 2 ) then
slouken@2207
    68
		echo ${prog}: -r option requires package resource directory.
slouken@2207
    69
		echo $usage
slouken@2207
    70
		exit(1)
slouken@2207
    71
	    else
slouken@2207
    72
		set resDir = $argv[2]
slouken@2207
    73
		shift; shift
slouken@2207
    74
		breaksw
slouken@2207
    75
	    endif
slouken@2207
    76
	case -traditional:
slouken@2207
    77
	    set usetar
slouken@2207
    78
            unset usegnutar
slouken@2207
    79
	    unset usepax
slouken@2207
    80
	    breaksw
slouken@2207
    81
        case -gnutar:
slouken@2207
    82
	    set usegnutar
slouken@2207
    83
            unset usepax
slouken@2207
    84
	    unset usetar
slouken@2207
    85
	case -B:
slouken@2207
    86
	    # We got long file names, better use bigtar instead
slouken@2207
    87
	    #set archiver = /NextAdmin/Installer.app/Resources/installer_bigtar
slouken@2207
    88
	    echo 2>&1 ${prog}: -B flag is no longer relevant.
slouken@2207
    89
	    shift
slouken@2207
    90
	    breaksw
slouken@2207
    91
	case -*:
slouken@2207
    92
	    echo ${prog}: Unknown option: $argv[1]
slouken@2207
    93
	    echo $usage
slouken@2207
    94
	    exit(1)
slouken@2207
    95
	case *.info:
slouken@2207
    96
	    if ( $?info ) then
slouken@2207
    97
		echo ${prog}: info-file parameter already set to ${info}.
slouken@2207
    98
		echo $usage
slouken@2207
    99
		exit(1)
slouken@2207
   100
	    else
slouken@2207
   101
		set info = "$argv[1]"
slouken@2207
   102
		shift
slouken@2207
   103
		breaksw
slouken@2207
   104
	    endif
slouken@2207
   105
	case *.tiff:
slouken@2207
   106
	    if ( $?tiff ) then
slouken@2207
   107
		echo ${prog}: tiff-file parameter already set to ${tiff}.
slouken@2207
   108
		echo $usage
slouken@2207
   109
		exit(1)
slouken@2207
   110
	    else
slouken@2207
   111
		set tiff = "$argv[1]"
slouken@2207
   112
		shift
slouken@2207
   113
		breaksw
slouken@2207
   114
	    endif
slouken@2207
   115
	default:
slouken@2207
   116
	    if ( $?rootDir ) then
slouken@2207
   117
		echo ${prog}: unrecognized parameter: $argv[1]
slouken@2207
   118
		echo $usage
slouken@2207
   119
		exit(1)
slouken@2207
   120
	    else
slouken@2207
   121
		set rootDir = "$argv[1]"
slouken@2207
   122
		shift
slouken@2207
   123
		breaksw
slouken@2207
   124
	    endif
slouken@2207
   125
    endsw
slouken@2207
   126
end
slouken@2207
   127
slouken@2207
   128
# check for mandatory parameters
slouken@2207
   129
if ( ! $?rootDir ) then
slouken@2207
   130
    echo ${prog}: missing root-dir parameter.
slouken@2207
   131
    echo $usage
slouken@2207
   132
    exit(1)
slouken@2207
   133
else if ( ! $?info) then
slouken@2207
   134
    echo ${prog}: missing info-file parameter.
slouken@2207
   135
    echo $usage
slouken@2207
   136
    exit(1)
slouken@2207
   137
endif
slouken@2207
   138
slouken@2207
   139
# destDir gets default value if unset on command line
slouken@2207
   140
if ( $?destDir ) then
slouken@2207
   141
    /bin/mkdir -p $destDir
slouken@2207
   142
else
slouken@2207
   143
    set destDir = .
slouken@2207
   144
endif
slouken@2207
   145
slouken@2207
   146
# derive the root name for the package from the root name of the info file
slouken@2207
   147
set root = `/usr/bin/basename $info .info`
slouken@2207
   148
slouken@2207
   149
# create package directory
slouken@2207
   150
set pkg = ${destDir}/${root}.pkg
slouken@2207
   151
echo Generating Installer package $pkg ...
slouken@2207
   152
if ( -e $pkg ) /bin/rm -rf $pkg
slouken@2207
   153
/bin/mkdir -p -m 755 $pkg
slouken@2207
   154
slouken@2207
   155
# (gnu)tar/pax and compress root directory to package archive
slouken@2207
   156
echo -n "	creating package archive ... "
slouken@2207
   157
if ( $?fflag ) then
slouken@2207
   158
    set pkgTop = ${rootDir:t}
slouken@2207
   159
    set parent = ${rootDir:h}
slouken@2207
   160
    if ( "$parent" == "$pkgTop" ) set parent = "."
slouken@2207
   161
else
slouken@2207
   162
    set parent = $rootDir
slouken@2207
   163
    set pkgTop = .    
slouken@2207
   164
endif
slouken@2207
   165
if ( $?usetar ) then
slouken@2207
   166
    set pkgArchive = $pkg/$root.tar.Z
slouken@2207
   167
    (cd $parent; $tar -w $pkgTop) | /usr/bin/compress -f -c > $pkgArchive
slouken@2207
   168
else if ( $?usegnutar ) then
slouken@2207
   169
    set pkgArchive = $pkg/$root.tar.gz
slouken@2207
   170
    (cd $parent; $gnutar zcf $pkgArchive $pkgTop)
slouken@2207
   171
else
slouken@2207
   172
    set pkgArchive = $pkg/$root.pax.gz
slouken@2207
   173
    (cd $parent; $pax -w -z -x cpio $pkgTop) > $pkgArchive
slouken@2207
   174
endif
slouken@2207
   175
/bin/chmod 444 $pkgArchive
slouken@2207
   176
echo done.
slouken@2207
   177
slouken@2207
   178
# copy info file to package
slouken@2207
   179
set pkgInfo = $pkg/$root.info
slouken@2207
   180
echo -n "	copying ${info:t} ... "
slouken@2207
   181
/bin/cp $info $pkgInfo
slouken@2207
   182
/bin/chmod 444 $pkgInfo
slouken@2207
   183
echo done.
slouken@2207
   184
slouken@2207
   185
# copy tiff file to package
slouken@2207
   186
if ( $?tiff ) then
slouken@2207
   187
    set pkgTiff = $pkg/$root.tiff
slouken@2207
   188
    echo -n "	copying ${tiff:t} ... "
slouken@2207
   189
    /bin/cp $tiff $pkgTiff
slouken@2207
   190
    /bin/chmod 444 $pkgTiff
slouken@2207
   191
    echo done.
slouken@2207
   192
endif
slouken@2207
   193
slouken@2207
   194
# copy resources to package
slouken@2207
   195
if ( $?resDir ) then
slouken@2207
   196
    echo -n "	copying ${resDir:t} ... "
slouken@2207
   197
slouken@2207
   198
    # don't want to see push/pop output
slouken@2207
   199
    pushd $resDir > /dev/null
slouken@2207
   200
	# get lists of resources. We'll want to change
slouken@2207
   201
	# permissions on just these things later.
slouken@2207
   202
        set directoriesInResDir = `find . -type d`
slouken@2207
   203
        set filesInResDir = `find . -type f`
slouken@2207
   204
    popd > /dev/null
slouken@2207
   205
slouken@2207
   206
    # copy the resource directory contents into the package directory
slouken@2207
   207
    foreach resFile (`ls $resDir`)
slouken@2207
   208
	cp -r $resDir/$resFile $pkg
slouken@2207
   209
    end
slouken@2207
   210
slouken@2207
   211
    pushd $pkg > /dev/null
slouken@2207
   212
	# Change all directories to +r+x, except the package
slouken@2207
   213
	# directory itself
slouken@2207
   214
        foreach resFileItem ($directoriesInResDir)
slouken@2207
   215
            if ( $resFileItem != "." ) then
slouken@2207
   216
                chmod 555 $resFileItem
slouken@2207
   217
            endif
slouken@2207
   218
        end
slouken@2207
   219
	# change all flat files to read only
slouken@2207
   220
        foreach resFileItem ($filesInResDir)
slouken@2207
   221
            chmod 444 $resFileItem
slouken@2207
   222
        end
slouken@2207
   223
    popd > /dev/null
slouken@2207
   224
slouken@2207
   225
    echo done.
slouken@2207
   226
endif
slouken@2207
   227
slouken@2207
   228
# generate bom file
slouken@2207
   229
set pkgBom = $pkg/$root.bom
slouken@2207
   230
echo -n "	generating bom file ... "
slouken@2207
   231
/bin/rm -f $pkgBom
slouken@2207
   232
if ( $?fflag ) then
slouken@2207
   233
    $mkbom $parent $pkgBom >& /dev/null
slouken@2207
   234
else
slouken@2207
   235
    $mkbom $rootDir $pkgBom >& /dev/null
slouken@2207
   236
endif
slouken@2207
   237
/bin/chmod 444 $pkgArchive
slouken@2207
   238
echo done.
slouken@2207
   239
	
slouken@2207
   240
# generate sizes file
slouken@2207
   241
set pkgSizes = $pkg/$root.sizes
slouken@2207
   242
echo -n "	generating sizes file ... "
slouken@2207
   243
slouken@2207
   244
# compute number of files in package
slouken@2207
   245
set numFiles = `$lsbom -s $pkgBom | /usr/bin/wc -l`
slouken@2207
   246
slouken@2207
   247
# compute package size when compressed
slouken@2207
   248
@ compressedSize = `/usr/bin/du -k -s $pkg | $awk '{print $1}'`
slouken@2207
   249
@ compressedSize += 3		# add 1KB each for sizes, location, status files
slouken@2207
   250
slouken@2207
   251
@ infoSize = `/bin/ls -s $pkgInfo | $awk '{print $1}'`
slouken@2207
   252
@ bomSize = `/bin/ls -s $pkgBom | $awk '{print $1}'`
slouken@2207
   253
if ( $?tiff ) then
slouken@2207
   254
    @ tiffSize = `/bin/ls -s $pkgTiff | $awk '{print $1}'`
slouken@2207
   255
else
slouken@2207
   256
    @ tiffSize = 0
slouken@2207
   257
endif 
slouken@2207
   258
slouken@2207
   259
@ installedSize = `/usr/bin/du -k -s $rootDir | $awk '{print $1}'`
slouken@2207
   260
@ installedSize += $infoSize + $bomSize + $tiffSize + 3
slouken@2207
   261
slouken@2207
   262
# echo size parameters to sizes file
slouken@2207
   263
echo NumFiles $numFiles             >  $pkgSizes
slouken@2207
   264
echo InstalledSize $installedSize   >> $pkgSizes
slouken@2207
   265
echo CompressedSize $compressedSize >> $pkgSizes
slouken@2207
   266
echo done.
slouken@2207
   267
echo " ... finished generating $pkg."
slouken@2207
   268
slouken@2207
   269
exit(0)
slouken@2207
   270
slouken@2207
   271
# end package
slouken@2207
   272