mirror of the now-defunct rocklinux.org
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.

312 lines
7.9 KiB

  1. #!/bin/bash
  2. #
  3. # Commands in isofs.txt files:
  4. #
  5. # EVERY from to Put this on every disk
  6. # DISK1 from to Put this on the 1st disk
  7. # SINGLE from to Put it on any disk
  8. # SPLIT from to You may split it up over many disks
  9. #
  10. # BOOT boot-options Add this mkisofs options for 1st disk
  11. #
  12. # If you want to add multiple 'BOOT' lines, use the tag-name 'BOOTx' for
  13. # the 2nd and all further lines.
  14. #
  15. # SCRIPT script-name args Run given script for each image
  16. #
  17. # Intended for image post-processing. The first attached argument is the CD
  18. # number and the second the image file.
  19. #
  20. eval `grep rockver scripts/parse-config`
  21. if [ $# -eq 0 ] ; then
  22. echo
  23. echo "Usage: $0 [ -size <MB> ] [ -source ] [ -mkdebug ] [ -nomd5 ] \\"
  24. echo " ${0//?/ } <ISO-Prefix> <Config> [ <Config> [ .. ] ]"
  25. echo
  26. echo " Create ISO images ready to burn on CD/DVD from one or more target builds."
  27. echo " Targets have to be built using ./scripts/Build-Target before you can create"
  28. echo " ISO images from them."
  29. echo
  30. echo " -size <MB> limit the size of images to <MB> MB; default is 600"
  31. echo " -source include package sources on the images"
  32. echo " -mkdebug create a small debug script for every image"
  33. echo " -nomd5 don't add md5 checksums to images"
  34. echo
  35. echo " <ISO-Prefix> the name of the resulting images"
  36. echo " <Config> the target builds to include; the first has to be a"
  37. echo " bootdisk target for the first image to be bootable"
  38. echo
  39. echo "E.g.: $0 mycdset install generic"
  40. echo
  41. exit 1
  42. fi
  43. # default disk-size is 600 MB
  44. dsize=$(( 600 * 1024 ))
  45. src=0; mkdebug=0; implantisomd5=1
  46. while true ; do
  47. case "$1" in
  48. -size)
  49. dsize=$(( $2 * 1024 )) ; shift ; shift ;;
  50. -source)
  51. src=1 ; shift ;;
  52. -mkdebug)
  53. mkdebug=1 ; shift ;;
  54. -nomd5)
  55. implantisomd5=0 ; shift ;;
  56. -* | '')
  57. $0 ; exit 1 ;;
  58. *)
  59. isoprefix=$1 ; shift ; break ;;
  60. esac
  61. done
  62. spacer=" "
  63. if [ "$implantisomd5" = 1 -a ! -x src/isomd5sum/implantisomd5 ] ; then
  64. echo ; date "+ [%X] Creating ISO-MD5 tools ..."
  65. rm -rf src/isomd5sum; mkdir -p src/isomd5sum
  66. cp misc/isomd5sum/* src/isomd5sum/
  67. make -C src/isomd5sum all
  68. fi
  69. echo ; date "+ [%X] Removing old files with same prefix ..."
  70. rm -rf ${isoprefix}_*
  71. date "+ [%X] Reading configs and creating ISO index ..."
  72. index=`mktemp` ; dat=`mktemp` ; pathspec=`mktemp`
  73. rm -f ${pathspec}*
  74. for cfg ; do
  75. id="`grep '^export ROCKCFG_ID=' config/$cfg/config | cut -f2 -d\'`"
  76. if ! cat build/$id/ROCK/isofs.txt >> $dat
  77. then rm -f $dat $index ${pathspec}_* ; exit 1 ; fi
  78. done
  79. # function to add a given file $1 to the place $2 on the resulting ISO
  80. #
  81. add() {
  82. local from="$1" to="$2" done=0
  83. if [ ! -f "$from" -a ! -d "$from" ] ; then
  84. echo "No such file or directory: $from"
  85. rm -f $dat $index ${pathspec}_* ; exit 1
  86. fi
  87. size="`du -sk $from | cut -f1`"
  88. if [ $size -gt $(( $dsize - $disk_0_size )) ] ; then
  89. echo "Chunk $from is too big!"
  90. rm -f $dat $index ${pathspec}_* ; exit 1
  91. fi
  92. for x in $disks ; do
  93. ds=disk_${x}_size ; dd=disk_${x}_data
  94. if [ $(( ${!ds} + $size )) -le \
  95. $(( $dsize - $disk_0_size )) ] ; then
  96. eval "$ds=$(( ${!ds} + $size ))"
  97. echo "$to=$from" >> ${pathspec}_${disk_nr}
  98. done=1 ; break
  99. fi
  100. done
  101. if [ $done = 0 ] ; then
  102. disk_nr=$(( $disk_nr + 1 ))
  103. ds=disk_${disk_nr}_size ; eval "$ds=$size"
  104. # FIXME: if in a path-list files, mkisofs complains about
  105. # missing isolinux. Should be a mkisofs bug!
  106. if [ "$to" = "isolinux/" -o "$from" = "isolinux/" ] ; then
  107. echo "$to=$from" >> ${pathspec}_iso
  108. else
  109. echo "$to=$from" >> ${pathspec}_${disk_nr}
  110. fi
  111. disks="$disks $disk_nr"
  112. fi
  113. }
  114. bootoptions=""
  115. scripts=""
  116. while read tag data ; do
  117. if [ $tag = BOOT ] ; then
  118. if [ "$bootoptions" ] ; then
  119. echo "Multiple boot options found!"
  120. rm -f $dat $index ${pathspec}_* ; exit 1
  121. else
  122. bootoptions="$data"
  123. fi
  124. elif [ $tag = SCRIPT ] ; then
  125. scripts="$scripts $data"
  126. fi
  127. done < $dat
  128. while read tag data ; do
  129. [ $tag = BOOTx ] && bootoptions="$bootoptions $data"
  130. done < $dat
  131. echo "$spacer parsing for EVERY disk."
  132. disks="0" ; disk_nr=0 ; disk_0_size=0
  133. echo "index.txt=${isoprefix}_index.txt" >> ${pathspec}_0
  134. while read type from to ; do
  135. if [ $type = EVERY ] ; then
  136. add $from $to
  137. if [ $disk_nr -gt 0 ] ; then
  138. echo "Every-disk data is too big!"
  139. rm -f $dat $index ${pathspec}_* ; exit 1
  140. fi
  141. fi
  142. done < $dat
  143. echo "$spacer parsing for DISK1 disk."
  144. disk_nr=0 ; disks=""
  145. while read type from to ; do
  146. if [ $type = DISK1 ] ; then
  147. add $from $to
  148. if [ $disk_nr -gt 1 ] ; then
  149. echo "Disk 1 is too big!"
  150. rm -f $dat $index ${pathspec}_* ; exit 1
  151. fi
  152. fi
  153. done < $dat
  154. echo "$spacer parsing for SINGLE disk."
  155. while read type from to ; do
  156. if [ $type = SINGLE ] ; then
  157. add $from $to
  158. fi
  159. done < $dat
  160. echo "$spacer parsing for SPLIT disk."
  161. while read type from to ; do
  162. if [ $type = SPLIT ] ; then
  163. find $from -type f -printf '%P\n' | sort > $index
  164. while read p ; do
  165. add $from$p $to$p
  166. done < $index
  167. fi
  168. done < $dat
  169. if [ $src = 1 ] ; then
  170. echo "$spacer embedding source."
  171. ./scripts/Create-SrcTar
  172. for x in Documentation/* rock-src-$rockver.tar.bz2 ; do
  173. [ ! -d $x ] && add $x ${x/Documentation\/}
  174. done
  175. while read from ; do
  176. # adaptions of the sed exp need to propagated into Download, too
  177. from="`echo $from | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  178. if [ -e $from ] ; then
  179. add $from $from
  180. else
  181. echo "WARNING: File $from is missing!"
  182. fi
  183. done < <( ./scripts/Download -list )
  184. fi
  185. echo -n > $index
  186. for x in 0 $disks ; do
  187. dd=disk_${x}_data
  188. for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null` ; do
  189. to=${y%=*} ; from=${y#*=}
  190. if [ -e $from ] ; then
  191. find $from -printf "disk$x $to%P\\n" >> $index
  192. else
  193. echo "disk$x $to" >> $index
  194. fi
  195. done
  196. done
  197. disk_0_size=$(( $disk_0_size + $( du -sk $index | cut -f1 ) ))
  198. if [ -z "$bootoptions" ] ; then
  199. echo "WARNING: Disk1 is not bootable - no boot options defined."
  200. fi
  201. xxx() {
  202. if ! mkisofs "$@" &> $dat ; then
  203. echo ; echo "mkisofs $@" ; echo
  204. cat $dat ; rm -f $index $dat; exit 1
  205. fi
  206. }
  207. echo
  208. total=0
  209. for x in 0 $disks ; do
  210. ds=disk_${x}_size
  211. total=$(( $total + ${!ds} ))
  212. if [ $x = 0 ] ; then y="Shared"
  213. else y="`printf 'Disk%2d' $x`" ; fi
  214. z="$( grep "^disk$x " $index | wc -l )"
  215. if [ -z "$bootoptions" -o $x != 1 ] ; then
  216. printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
  217. else
  218. printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
  219. fi
  220. done
  221. printf "%15s Total: %8s kB in %5d files\n" "" $total $( wc -l < $index )
  222. echo
  223. date "+ [%X] Creating ${isoprefix}_index.txt ..."
  224. sort -tk -n -k2 < $index > ${isoprefix}_index.txt
  225. for x in $disks ; do
  226. ds=disk_${x}_size
  227. date "+ [%X] Creating ${isoprefix}_cd$x.iso ..."
  228. echo "This is disk #$x." > $dat
  229. # FIXME: current mkisofs does only accept one -path-list
  230. sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
  231. xxx -q -r -T -J -l -o ${isoprefix}_cd$x.iso -A "ROCK Linux - Disk $x" \
  232. -P 'The ROCK Linux Project - http://www.rocklinux.org' \
  233. -path-list ${pathspec}_current \
  234. $bootoptions -graft-points disk$x.txt=$dat \
  235. `cat ${pathspec}_iso 2>/dev/null`
  236. rm -f ${pathspec}_iso
  237. rm -f ${pathspec}_current
  238. bootoptions=""
  239. if [ "$scripts" ] ; then
  240. echo "$spacer Running post-processing scripts on image ..."
  241. eval $scripts $x ${isoprefix}_cd$x.iso
  242. fi
  243. if [ "$implantisomd5" = 1 -a -x ./misc/isomd5sum/implantisomd5 ] ; then
  244. echo "$spacer Calculating and implanting MD5 checksum ..."
  245. ./src/isomd5sum/implantisomd5 ${isoprefix}_cd$x.iso >/dev/null
  246. fi
  247. if [ "$mkdebug" = 1 ] ; then
  248. cat > ${isoprefix}_loop$x.sh << EOT
  249. #!/bin/sh
  250. if [ "\$1" -a -z "\${1//[0-9]/}" ] ; then
  251. [ "\$2" ] && umount \$2 > /dev/null 2>&1
  252. losetup -d /dev/loop/\$1 > /dev/null 2>&1
  253. losetup /dev/loop/\$1 ${isoprefix}_cd$x.iso
  254. [ "\$2" ] && mount /dev/loop/\$1 \$2
  255. else
  256. echo "Usage: \$0 <loopback-dev-nr> [ <mount-point> ]"
  257. echo " Mount the corresponding ISO image at the given mount point using the given"
  258. echo " loopback device. If no mount point is given, the mount step is skipped."
  259. exit 1
  260. fi
  261. EOT
  262. chmod +x ${isoprefix}_loop$x.sh
  263. fi
  264. done
  265. date "+ [%X] Done. Have fun!"
  266. echo
  267. rm -f $index $dat ${pathspec}_*