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