OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
9.2 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: scripts/Create-ISO
  6. # Copyright (C) 2006 - 2007 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. #
  17. # Commands in isofs.txt files:
  18. #
  19. # EVERY from to Put this on every disk
  20. # DISK1 from to Put this on the 1st disk
  21. # SINGLE from to Put it on any disk
  22. # SPLIT from to You may split it up over many disks
  23. #
  24. # BOOT boot-options Add this mkisofs options for 1st disk
  25. #
  26. # If you want to add multiple 'BOOT' lines, use the tag-name 'BOOTx' for
  27. # the 2nd and all further lines.
  28. #
  29. # SCRIPT script-name args Run given script for each image
  30. #
  31. # Intended for image post-processing. The first attached argument is the CD
  32. # number and the second the image file.
  33. #
  34. eval `grep sdever lib/parse-config`
  35. . lib/functions.in
  36. usage()
  37. {
  38. echo
  39. echo "Usage: $0 [ -size MB ] [ -source ] [ -mkdebug ] [ -nomd5 ] ISO-Prefix \\"
  40. echo " ${0//?/ } Config [ Config [ .. ] ]"
  41. echo
  42. echo "E.g.: $0 mycdset install generic"
  43. echo
  44. exit 1
  45. }
  46. # default disk-size
  47. dsize=$(( 650 * 1024 ))
  48. file_overhead=1
  49. src=0; mkdebug=0; implantisomd5=1
  50. while [ "$1" ] ; do
  51. case "$1" in
  52. -size)
  53. dsize=$(( $2 * 1024 )) ; shift ; shift ;;
  54. -source)
  55. src=1 ; shift ;;
  56. -mkdebug)
  57. mkdebug=1 ; shift ;;
  58. -nomd5)
  59. implantisomd5=0 ; shift ;;
  60. -* | '')
  61. $0 ; exit 1 ;;
  62. *)
  63. isoprefix=$1 ; shift ; break ;;
  64. esac
  65. done
  66. [ $# -eq 0 ] && usage
  67. spacer=" "
  68. errno=0; for cfg ; do
  69. if [ ! -f config/$cfg/config ]; then
  70. echo "Not a valid config: $cfg"
  71. errno=1
  72. fi
  73. done
  74. [ $errno -ne 0 ] && exit 1
  75. if [ "$implantisomd5" = 1 -a ! -x tmp/isomd5sum/implantisomd5 ] ; then
  76. echo ; date "+ [%X] Creating ISO-MD5 tools ..."
  77. rm -rf tmp/isomd5sum; mkdir -p tmp/isomd5sum
  78. cp src/isomd5sum/* tmp/isomd5sum/
  79. make -C tmp/isomd5sum all
  80. fi
  81. echo ; date "+ [%X] Removing old files with same prefix ..."
  82. [ "${isoprefix//\//}" == "${isoprefix}" ] && isoprefix="iso/$isoprefix"
  83. mkdir -vp ${isoprefix%/*}
  84. rm -rvf ${isoprefix}_* ${isoprefix}.md5
  85. date "+ [%X] Reading configs ..."
  86. index=`mktemp` ; dat=`mktemp` ; pathspec=`mktemp`
  87. rm -f ${pathspec}*
  88. for cfg ; do
  89. id="`grep '^export SDECFG_ID=' config/$cfg/config |
  90. cut -f2 -d\' 2> /dev/null`"
  91. if ! cat build/$id/TOOLCHAIN/isofs.txt >> $dat 2> /dev/null
  92. then
  93. echo "Not a valid build: $cfg"
  94. echo "build/$id/TOOLCHAIN/isofs.txt might be created."
  95. rm -f $dat $index ${pathspec}_* ; exit 1
  96. fi
  97. if test -f config/$cfg/license-issue.ask; then
  98. if ! grep LICENSE-WARNING $dat &> /dev/null; then
  99. echo "EVERY doc/files/LICENSE-WARNING LICENSE-WARNING" >> $dat
  100. fi
  101. cp -vf doc/files/LICENSE-WARNING build/$id/TOOLCHAIN/
  102. echo "" >> build/$id/TOOLCHAIN/LICENSE-WARNING
  103. echo "The following packages may have license restrictions:" >> build/$id/TOOLCHAIN/LICENSE-WARNING
  104. cat config/$cfg/license-issue.ask >> build/$id/TOOLCHAIN/LICENSE-WARNING
  105. if [ "`grep '^export SDECFG_LICENSE_ISSUE=' config/$cfg/config | cut -f2 -d\'`" = "0" ]; then
  106. cat <<EOF
  107. You have chosen to compile packages that are restricted
  108. in their redistribution. Unless you accept this limitation
  109. you cannot burn these packages.
  110. Please rerun ./scripts/Config -cfg $cfg and check
  111. 'I have read and understood the licensing issues.'
  112. EOF
  113. #FIXME remove packages that have an issue instead of exiting
  114. exit 1
  115. fi
  116. fi
  117. done
  118. # function to add a given file $1 to the place $2 on the resulting ISO
  119. #
  120. add() {
  121. local from="$1" to="$2" done=0
  122. if [ ! -f "$from" -a ! -d "$from" ] ; then
  123. echo "No such file or directory: $from"
  124. rm -f $dat $index ${pathspec}_* ; exit 1
  125. fi
  126. files="`find $from ! -type d | wc -l`"
  127. size="`du -s -b $from | cut -f1`"
  128. size=$(( size / 1024 + files * file_overhead ))
  129. if [ $size -gt $(( $dsize - $disk_0_size )) ] ; then
  130. echo "Chunk $from is too big!"
  131. rm -f $dat $index ${pathspec}_* ; exit 1
  132. fi
  133. for x in $disks ; do
  134. ds=disk_${x}_size ; dd=disk_${x}_data
  135. if [ $(( ${!ds} + $size )) -le \
  136. $(( $dsize - $disk_0_size )) ] ; then
  137. eval "$ds=$(( ${!ds} + $size ))"
  138. echo "$to=$from" >> ${pathspec}_${disk_nr}
  139. done=1 ; break
  140. fi
  141. done
  142. if [ $done = 0 ] ; then
  143. disk_nr=$(( $disk_nr + 1 ))
  144. ds=disk_${disk_nr}_size ; eval "$ds=$size"
  145. # FIXME: if in a path-list files, mkisofs complains about
  146. # missing isolinux. Should be a mkisofs bug!
  147. if [ "$to" = "isolinux/" -o "$from" = "isolinux/" ] ; then
  148. echo "$to=$from" >> ${pathspec}_iso
  149. else
  150. echo "$to=$from" >> ${pathspec}_${disk_nr}
  151. fi
  152. disks="$disks $disk_nr"
  153. fi
  154. }
  155. bootoptions=""
  156. scripts=""
  157. while read tag data ; do
  158. # empty lines
  159. [ "$tag" ] || continue
  160. if [ $tag = BOOT ]; then
  161. if [ "$bootoptions" ]; then
  162. echo "Multiple boot options found!"
  163. rm -f $dat $index ${pathspec}_* ; exit 1
  164. else
  165. bootoptions="$data"
  166. [[ $data == *-hfs* ]] && file_overhead=12
  167. fi
  168. elif [ $tag = SCRIPT ]; then
  169. scripts="$scripts $data"
  170. fi
  171. done < $dat
  172. while read tag data ; do
  173. if [ "$tag" = BOOTx ]; then
  174. bootoptions="$bootoptions $data"
  175. [[ $data == *-hfs* ]] && file_overhead=12
  176. fi
  177. done < $dat
  178. echo "$spacer parsing for EVERY disk."
  179. disks="0" ; disk_nr=0 ; disk_0_size=0
  180. echo "index.txt=${isoprefix}_index.txt" >> ${pathspec}_0
  181. while read type from to ; do
  182. if [ "$type" = EVERY ]; then
  183. add $from $to
  184. if [ $disk_nr -gt 0 ] ; then
  185. echo "Every-disk data is too big!"
  186. rm -f $dat $index ${pathspec}_* ; exit 1
  187. fi
  188. fi
  189. done < $dat
  190. echo "$spacer parsing for DISK1 disk."
  191. disk_nr=0 ; disks=""
  192. while read type from to ; do
  193. if [ "$type" = DISK1 ] ; then
  194. add $from $to
  195. if [ $disk_nr -gt 1 ] ; then
  196. echo "Disk 1 is too big!"
  197. rm -f $dat $index ${pathspec}_* ; exit 1
  198. fi
  199. fi
  200. done < $dat
  201. echo "$spacer parsing for SINGLE disk."
  202. while read type from to ; do
  203. if [ "$type" = SINGLE ] ; then
  204. add $from $to
  205. fi
  206. done < $dat
  207. echo "$spacer parsing for SPLIT disk."
  208. while read type from to ; do
  209. if [ "$type" = SPLIT ] ; then
  210. find $from -type f -printf '%P\n' | sort > $index
  211. while read p ; do
  212. add $from$p $to$p
  213. done < $index
  214. fi
  215. done < $dat
  216. if [ $src = 1 ] ; then
  217. date "+ [%X] Embedding source ..."
  218. ./scripts/Create-SrcTar
  219. for x in doc/* opensde-src-$sdever.tar.bz2 ; do
  220. [ ! -d $x ] && add $x ${x/doc\/}
  221. done
  222. while read from ; do
  223. from="`bz2filename $from`"
  224. if [ -e $from ] ; then
  225. add $from $from
  226. else
  227. echo "WARNING: File $from is missing!"
  228. fi
  229. done < <( ./bin/sde-download -list | sort -u )
  230. fi
  231. date "+ [%X] Creating ISO index ..."
  232. echo -n > $index
  233. for x in 0 $disks ; do
  234. dd=disk_${x}_data
  235. for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null` ; do
  236. to=${y%=*} ; from=${y#*=}
  237. if [ -e $from ] ; then
  238. find $from -printf "disk$x $to%P\\n" >> $index
  239. else
  240. echo "disk$x $to" >> $index
  241. fi
  242. done
  243. done
  244. disk_0_size=$(( $disk_0_size + $( du -sk $index | cut -f1 ) ))
  245. if [ -z "$bootoptions" ] ; then
  246. echo "WARNING: Disk1 is not bootable - no boot options defined."
  247. fi
  248. echo
  249. total=0
  250. for x in 0 $disks ; do
  251. ds=disk_${x}_size
  252. total=$(( $total + ${!ds} ))
  253. if [ $x = 0 ] ; then y="Shared"
  254. else y="`printf 'Disk%2d' $x`" ; fi
  255. z="$( grep "^disk$x " $index | wc -l )"
  256. if [ -z "$bootoptions" -o $x != 1 ] ; then
  257. printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
  258. else
  259. printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
  260. fi
  261. done
  262. printf "%15s Total: %8s kB in %5d files\n" "" $total $( wc -l < $index )
  263. echo
  264. date "+ [%X] Creating ${isoprefix}_index.txt ..."
  265. sort -tk -n -k2 < $index | tee ${isoprefix}_index.txt | md5sum |
  266. sed "s/ -/ ${isoprefix##*/}_index.txt/" >> ${isoprefix}.md5
  267. for x in $disks ; do
  268. ds=disk_${x}_size
  269. date "+ [%X] Creating ${isoprefix}_cd$x.iso ..."
  270. echo "This is disk #$x." > $dat
  271. # FIXME: current mkisofs does only accept one -path-list
  272. sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
  273. mkisofs -q -r -T -J -l -A "OpenSDE - Disk $x" \
  274. -publisher 'OpenSDE System Develop Environment - http://www.opensde.org' \
  275. -path-list ${pathspec}_current \
  276. $bootoptions -graft-points disk$x.txt=$dat \
  277. `cat ${pathspec}_iso 2>/dev/null` | tee ${isoprefix}_cd$x.iso |
  278. md5sum | sed "s/ -/ ${isoprefix##*/}_cd$x.iso/" \
  279. >> ${isoprefix}.md5
  280. rm -f ${pathspec}_iso
  281. rm -f ${pathspec}_current
  282. bootoptions=""
  283. if [ "$scripts" ] ; then
  284. echo "$spacer Running post-processing scripts on image ..."
  285. eval $scripts $x ${isoprefix}_cd$x.iso
  286. fi
  287. if [ "$implantisomd5" = 1 -a -x ./src/isomd5sum/implantisomd5 ] ; then
  288. echo "$spacer Calculating and implanting MD5 checksum ..."
  289. ./tmp/isomd5sum/implantisomd5 ${isoprefix}_cd$x.iso >/dev/null
  290. fi
  291. if [ "$mkdebug" = 1 ] ; then
  292. cat > ${isoprefix}_loop$x.sh << EOT
  293. #!/bin/sh
  294. if [ "\$1" -a -z "\${1//[0-9]/}" ] ; then
  295. [ "\$2" ] && umount \$2 > /dev/null 2>&1
  296. losetup -d /dev/loop/\$1 > /dev/null 2>&1
  297. losetup /dev/loop/\$1 ${isoprefix##*/}_cd$x.iso
  298. [ "\$2" ] && mount /dev/loop/\$1 \$2
  299. else
  300. echo "Usage: \$0 loopback-dev-nr [ mount-point ]"
  301. exit 1
  302. fi
  303. EOT
  304. chmod +x ${isoprefix}_loop$x.sh
  305. fi
  306. done
  307. date "+ [%X] Done. Have fun!"
  308. echo
  309. rm -f $index $dat ${pathspec}_*