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.

318 lines
8.2 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 680"
  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 680 MB
  44. dsize=$(( 680 * 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. grep ':dev' $index > ${index}_dev
  165. grep ':doc' $index > ${index}_doc
  166. grep -v ':dev' $index | grep -v ':doc' >${index}_new
  167. cat ${index}_new ${index}_doc ${index}_dev >$index
  168. rm ${index}_{dev,doc,new}
  169. while read p ; do
  170. add $from$p $to$p
  171. done < $index
  172. fi
  173. done < $dat
  174. if [ $src = 1 ] ; then
  175. echo "$spacer embedding source."
  176. ./scripts/Create-SrcTar
  177. for x in Documentation/* rock-src-$rockver.tar.bz2 ; do
  178. [ ! -d $x ] && add $x ${x/Documentation\/}
  179. done
  180. while read from ; do
  181. # adaptions of the sed exp need to propagated into Download, too
  182. from="`echo $from | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  183. if [ -e $from ] ; then
  184. add $from $from
  185. else
  186. echo "WARNING: File $from is missing!"
  187. fi
  188. done < <( ./scripts/Download -list )
  189. fi
  190. echo -n > $index
  191. for x in 0 $disks ; do
  192. dd=disk_${x}_data
  193. for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null` ; do
  194. to=${y%=*} ; from=${y#*=}
  195. if [ -e $from ] ; then
  196. find $from -printf "disk$x $to%P\\n" >> $index
  197. else
  198. echo "disk$x $to" >> $index
  199. fi
  200. done
  201. done
  202. disk_0_size=$(( $disk_0_size + $( du -sk $index | cut -f1 ) ))
  203. if [ -z "$bootoptions" ] ; then
  204. echo "WARNING: Disk1 is not bootable - no boot options defined."
  205. fi
  206. xxx() {
  207. if ! mkisofs "$@" &> $dat ; then
  208. echo ; echo "mkisofs $@" ; echo
  209. cat $dat ; rm -f $index $dat; exit 1
  210. fi
  211. }
  212. echo
  213. total=0
  214. for x in 0 $disks ; do
  215. ds=disk_${x}_size
  216. total=$(( $total + ${!ds} ))
  217. if [ $x = 0 ] ; then y="Shared"
  218. else y="`printf 'Disk%2d' $x`" ; fi
  219. z="$( grep "^disk$x " $index | wc -l )"
  220. if [ -z "$bootoptions" -o $x != 1 ] ; then
  221. printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
  222. else
  223. printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
  224. fi
  225. done
  226. printf "%15s Total: %8s kB in %5d files\n" "" $total $( wc -l < $index )
  227. echo
  228. date "+ [%X] Creating ${isoprefix}_index.txt ..."
  229. sort -tk -n -k2 < $index > ${isoprefix}_index.txt
  230. for x in $disks ; do
  231. ds=disk_${x}_size
  232. date "+ [%X] Creating ${isoprefix}_cd$x.iso ..."
  233. echo "This is disk #$x." > $dat
  234. # FIXME: current mkisofs does only accept one -path-list
  235. sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
  236. xxx -q -r -T -J -l -o ${isoprefix}_cd$x.iso -A "ROCK Linux - Disk $x" \
  237. -P 'The ROCK Linux Project - http://www.rocklinux.org' \
  238. -V "ROCK Linux - Disk $x" \
  239. -path-list ${pathspec}_current \
  240. $bootoptions -graft-points disk$x.txt=$dat \
  241. `cat ${pathspec}_iso 2>/dev/null`
  242. rm -f ${pathspec}_iso
  243. rm -f ${pathspec}_current
  244. bootoptions=""
  245. if [ "$scripts" ] ; then
  246. date "+ [%X] Running post-processing scripts on image ..."
  247. eval $scripts $x ${isoprefix}_cd$x.iso
  248. fi
  249. if [ "$implantisomd5" = 1 -a -x ./src/isomd5sum/implantisomd5 ] ; then
  250. date "+ [%X] Calculating and implanting MD5 checksum ..."
  251. ./src/isomd5sum/implantisomd5 ${isoprefix}_cd$x.iso >/dev/null
  252. fi
  253. if [ "$mkdebug" = 1 ] ; then
  254. cat > ${isoprefix}_loop$x.sh << EOT
  255. #!/bin/sh
  256. if [ "\$1" -a -z "\${1//[0-9]/}" ] ; then
  257. [ "\$2" ] && umount \$2 > /dev/null 2>&1
  258. losetup -d /dev/loop/\$1 > /dev/null 2>&1
  259. losetup /dev/loop/\$1 ${isoprefix}_cd$x.iso
  260. [ "\$2" ] && mount /dev/loop/\$1 \$2
  261. else
  262. echo "Usage: \$0 <loopback-dev-nr> [ <mount-point> ]"
  263. echo " Mount the corresponding ISO image at the given mount point using the given"
  264. echo " loopback device. If no mount point is given, the mount step is skipped."
  265. exit 1
  266. fi
  267. EOT
  268. chmod +x ${isoprefix}_loop$x.sh
  269. fi
  270. done
  271. date "+ [%X] Done. Have fun!"
  272. echo
  273. rm -f $index $dat ${pathspec}_*