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