package 6.3 KB

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