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.

360 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 - 2008 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=$(( 700 * 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 | cut -f2 -d"'" 2> /dev/null)"
  90. if ! cat build/$id/TOOLCHAIN/isofs.txt >> $dat 2> /dev/null
  91. then
  92. echo "Not a valid build: $cfg"
  93. echo "build/$id/TOOLCHAIN/isofs.txt might be created."
  94. rm -f $dat $index ${pathspec}_* ; exit 1
  95. fi
  96. if test -f config/$cfg/license-issue.ask; then
  97. if ! grep LICENSE-WARNING $dat &> /dev/null; then
  98. echo "EVERY doc/files/LICENSE-WARNING LICENSE-WARNING" >> $dat
  99. fi
  100. cp -vf doc/files/LICENSE-WARNING build/$id/TOOLCHAIN/
  101. echo "" >> build/$id/TOOLCHAIN/LICENSE-WARNING
  102. echo "The following packages may have license restrictions:" >> build/$id/TOOLCHAIN/LICENSE-WARNING
  103. cat config/$cfg/license-issue.ask >> build/$id/TOOLCHAIN/LICENSE-WARNING
  104. if [ "$( grep '^export SDECFG_LICENSE_ISSUE=' config/$cfg/config | cut -f2 -d"'")" = "0" ]; then
  105. cat <<EOF
  106. You have chosen to compile packages that are restricted
  107. in their redistribution. Unless you accept this limitation
  108. you cannot burn these packages.
  109. Please rerun ./scripts/Config -cfg $cfg and check
  110. 'I have read and understood the licensing issues.'
  111. EOF
  112. #FIXME remove packages that have an issue instead of exiting
  113. exit 1
  114. fi
  115. fi
  116. done
  117. # function to add a given file $1 to the place $2 on the resulting ISO
  118. #
  119. add() {
  120. local from="$1" to="$2" done=0
  121. if [ ! -f "$from" -a ! -d "$from" ] ; then
  122. echo "No such file or directory: $from"
  123. rm -f $dat $index ${pathspec}_* ; exit 1
  124. fi
  125. files="`find $from ! -type d | wc -l`"
  126. size="`du -s -b $from | cut -f1`"
  127. size=$(( size / 1024 + files * file_overhead ))
  128. if [ $size -gt $(( $dsize - $disk_0_size )) ] ; then
  129. echo "Chunk $from is too big!"
  130. rm -f $dat $index ${pathspec}_* ; exit 1
  131. fi
  132. for x in $disks ; do
  133. ds=disk_${x}_size ; dd=disk_${x}_data
  134. if [ $(( ${!ds} + $size )) -le \
  135. $(( $dsize - $disk_0_size )) ] ; then
  136. eval "$ds=$(( ${!ds} + $size ))"
  137. echo "$to=$from" >> ${pathspec}_${disk_nr}
  138. done=1 ; break
  139. fi
  140. done
  141. if [ $done = 0 ] ; then
  142. disk_nr=$(( $disk_nr + 1 ))
  143. ds=disk_${disk_nr}_size ; eval "$ds=$size"
  144. # FIXME: if in a path-list files, mkisofs complains about
  145. # missing isolinux. Should be a mkisofs bug!
  146. if [ "$to" = "isolinux/" -o "$from" = "isolinux/" ] ; then
  147. echo "$to=$from" >> ${pathspec}_iso
  148. else
  149. echo "$to=$from" >> ${pathspec}_${disk_nr}
  150. fi
  151. disks="$disks $disk_nr"
  152. fi
  153. }
  154. bootoptions=
  155. scripts=
  156. while read tag data ; do
  157. # empty lines
  158. [ "$tag" ] || continue
  159. if [ $tag = BOOT ]; then
  160. if [ "$bootoptions" ]; then
  161. echo "Multiple boot options found!"
  162. rm -f $dat $index ${pathspec}_* ; exit 1
  163. else
  164. bootoptions="$data"
  165. [[ $data == *-hfs* ]] && file_overhead=12
  166. fi
  167. elif [ $tag = SCRIPT ]; then
  168. scripts="$scripts $data"
  169. fi
  170. done < $dat
  171. while read tag data ; do
  172. if [ "$tag" = BOOTx ]; then
  173. bootoptions="$bootoptions $data"
  174. [[ $data == *-hfs* ]] && file_overhead=12
  175. fi
  176. done < $dat
  177. echo "$spacer parsing for EVERY disk."
  178. disks="0" ; disk_nr=0 ; disk_0_size=0
  179. echo "index.txt=${isoprefix}_index.txt" >> ${pathspec}_0
  180. while read type from to ; do
  181. if [ "$type" = EVERY ]; then
  182. add $from $to
  183. if [ $disk_nr -gt 0 ] ; then
  184. echo "Every-disk data is too big!"
  185. rm -f $dat $index ${pathspec}_* ; exit 1
  186. fi
  187. fi
  188. done < $dat
  189. echo "$spacer parsing for DISK1 disk."
  190. disk_nr=0 ; disks=
  191. while read type from to ; do
  192. if [ "$type" = DISK1 ] ; then
  193. add $from $to
  194. if [ $disk_nr -gt 1 ] ; then
  195. echo "Disk 1 is too big!"
  196. rm -f $dat $index ${pathspec}_* ; exit 1
  197. fi
  198. fi
  199. done < $dat
  200. echo "$spacer parsing for SINGLE disk."
  201. while read type from to ; do
  202. if [ "$type" = SINGLE ] ; then
  203. add $from $to
  204. fi
  205. done < $dat
  206. echo "$spacer parsing for SPLIT disk."
  207. while read type from to ; do
  208. if [ "$type" = SPLIT ] ; then
  209. find $from -type f -printf '%P\n' | sort > $index
  210. while read p ; do
  211. add $from$p $to$p
  212. done < $index
  213. fi
  214. done < $dat
  215. if [ $src = 1 ] ; then
  216. date "+ [%X] Embedding source ..."
  217. ./scripts/Create-SrcTar
  218. for x in doc/* opensde-src-$sdever.tar.bz2 ; do
  219. [ ! -d $x ] && add $x ${x/doc\/}
  220. done
  221. while read from ; do
  222. from="`bz2filename $from`"
  223. if [ -e $from ] ; then
  224. add $from $from
  225. else
  226. echo "WARNING: File $from is missing!"
  227. fi
  228. done < <( ./bin/sde-download -list | sort -u )
  229. fi
  230. date "+ [%X] Creating ISO index ..."
  231. echo -n > $index
  232. for x in 0 $disks ; do
  233. dd=disk_${x}_data
  234. for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null` ; do
  235. to=${y%=*} ; from=${y#*=}
  236. if [ -e $from ] ; then
  237. find $from -printf "disk$x $to%P\\n" >> $index
  238. else
  239. echo "disk$x $to" >> $index
  240. fi
  241. done
  242. done
  243. disk_0_size=$(( $disk_0_size + $( du -sk $index | cut -f1 ) ))
  244. if [ -z "$bootoptions" ] ; then
  245. echo "WARNING: Disk1 is not bootable - no boot options defined."
  246. fi
  247. echo
  248. total=0
  249. for x in 0 $disks ; do
  250. ds=disk_${x}_size
  251. total=$(( $total + ${!ds} ))
  252. if [ $x = 0 ] ; then y="Shared"
  253. else y="`printf 'Disk%2d' $x`" ; fi
  254. z="$( grep "^disk$x " $index | wc -l )"
  255. if [ -z "$bootoptions" -o $x != 1 ] ; then
  256. printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
  257. else
  258. printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
  259. fi
  260. done
  261. printf "%15s Total: %8s kB in %5d files\n" "" $total $( wc -l < $index )
  262. echo
  263. date "+ [%X] Creating ${isoprefix}_index.txt ..."
  264. sort -tk -n -k2 < $index | tee ${isoprefix}_index.txt | md5sum |
  265. sed "s/ -/ ${isoprefix##*/}_index.txt/" >> ${isoprefix}.md5
  266. for x in $disks ; do
  267. ds=disk_${x}_size
  268. date "+ [%X] Creating ${isoprefix}_cd$x.iso ..."
  269. echo "This is disk #$x." > $dat
  270. # FIXME: current mkisofs does only accept one -path-list
  271. sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
  272. mkisofs -quiet -r -T -J -l -A "OpenSDE - Disk $x" \
  273. -publisher 'OpenSDE System Develop Environment - http://www.opensde.org' \
  274. -path-list ${pathspec}_current \
  275. $bootoptions -graft-points disk$x.txt=$dat \
  276. `cat ${pathspec}_iso 2>/dev/null` | tee ${isoprefix}_cd$x.iso |
  277. md5sum | sed "s/ -/ ${isoprefix##*/}_cd$x.iso/" \
  278. >> ${isoprefix}.md5
  279. rm -f ${pathspec}_iso
  280. rm -f ${pathspec}_current
  281. bootoptions=
  282. if [ "$scripts" ] ; then
  283. echo "$spacer Running post-processing scripts on image ..."
  284. eval $scripts $x ${isoprefix}_cd$x.iso
  285. fi
  286. if [ "$implantisomd5" = 1 -a -x ./src/isomd5sum/implantisomd5 ] ; then
  287. echo "$spacer Calculating and implanting MD5 checksum ..."
  288. ./tmp/isomd5sum/implantisomd5 ${isoprefix}_cd$x.iso >/dev/null
  289. fi
  290. if [ "$mkdebug" = 1 ] ; then
  291. cat > ${isoprefix}_loop$x.sh << EOT
  292. #!/bin/sh
  293. if [ "\$1" -a -z "\${1//[0-9]/}" ] ; then
  294. [ "\$2" ] && umount \$2 > /dev/null 2>&1
  295. losetup -d /dev/loop/\$1 > /dev/null 2>&1
  296. losetup /dev/loop/\$1 ${isoprefix##*/}_cd$x.iso
  297. [ "\$2" ] && mount /dev/loop/\$1 \$2
  298. else
  299. echo "Usage: \$0 loopback-dev-nr [ mount-point ]"
  300. exit 1
  301. fi
  302. EOT
  303. chmod +x ${isoprefix}_loop$x.sh
  304. fi
  305. done
  306. date "+ [%X] Done. Have fun!"
  307. echo
  308. rm -f $index $dat ${pathspec}_*