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.

322 lines
8.3 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. if ! make -C src/isomd5sum all ; then
  68. implantisomd5=0
  69. date "+ [%X] Could not create ISO-MD5 tools"
  70. date "+ [%X] Not implanting md5sum into isos"
  71. fi
  72. fi
  73. echo ; date "+ [%X] Removing old files with same prefix ..."
  74. rm -rf ${isoprefix}_*
  75. date "+ [%X] Reading configs and creating ISO index ..."
  76. index=`mktemp` ; dat=`mktemp` ; pathspec=`mktemp`
  77. rm -f ${pathspec}*
  78. for cfg ; do
  79. id="`grep '^export ROCKCFG_ID=' config/$cfg/config | cut -f2 -d\'`"
  80. if ! cat build/$id/ROCK/isofs.txt >> $dat
  81. then rm -f $dat $index ${pathspec}_* ; exit 1 ; fi
  82. done
  83. # function to add a given file $1 to the place $2 on the resulting ISO
  84. #
  85. add() {
  86. local from="$1" to="$2" done=0
  87. if [ ! -f "$from" -a ! -d "$from" ] ; then
  88. echo "No such file or directory: $from"
  89. rm -f $dat $index ${pathspec}_* ; exit 1
  90. fi
  91. size="`du -sk $from | cut -f1`"
  92. if [ $size -gt $(( $dsize - $disk_0_size )) ] ; then
  93. echo "Chunk $from is too big!"
  94. rm -f $dat $index ${pathspec}_* ; exit 1
  95. fi
  96. for x in $disks ; do
  97. ds=disk_${x}_size ; dd=disk_${x}_data
  98. if [ $(( ${!ds} + $size )) -le \
  99. $(( $dsize - $disk_0_size )) ] ; then
  100. eval "$ds=$(( ${!ds} + $size ))"
  101. echo "$to=$from" >> ${pathspec}_${disk_nr}
  102. done=1 ; break
  103. fi
  104. done
  105. if [ $done = 0 ] ; then
  106. disk_nr=$(( $disk_nr + 1 ))
  107. ds=disk_${disk_nr}_size ; eval "$ds=$size"
  108. # FIXME: if in a path-list files, mkisofs complains about
  109. # missing isolinux. Should be a mkisofs bug!
  110. if [ "$to" = "isolinux/" -o "$from" = "isolinux/" ] ; then
  111. echo "$to=$from" >> ${pathspec}_iso
  112. else
  113. echo "$to=$from" >> ${pathspec}_${disk_nr}
  114. fi
  115. disks="$disks $disk_nr"
  116. fi
  117. }
  118. bootoptions=""
  119. scripts=""
  120. while read tag data ; do
  121. if [ $tag = BOOT ] ; then
  122. if [ "$bootoptions" ] ; then
  123. echo "Multiple boot options found!"
  124. rm -f $dat $index ${pathspec}_* ; exit 1
  125. else
  126. bootoptions="$data"
  127. fi
  128. elif [ $tag = SCRIPT ] ; then
  129. scripts="$scripts $data"
  130. fi
  131. done < $dat
  132. while read tag data ; do
  133. [ $tag = BOOTx ] && bootoptions="$bootoptions $data"
  134. done < $dat
  135. echo "$spacer parsing for EVERY disk."
  136. disks="0" ; disk_nr=0 ; disk_0_size=0
  137. echo "index.txt=${isoprefix}_index.txt" >> ${pathspec}_0
  138. while read type from to ; do
  139. if [ $type = EVERY ] ; then
  140. add $from $to
  141. if [ $disk_nr -gt 0 ] ; then
  142. echo "Every-disk data is too big!"
  143. rm -f $dat $index ${pathspec}_* ; exit 1
  144. fi
  145. fi
  146. done < $dat
  147. echo "$spacer parsing for DISK1 disk."
  148. disk_nr=0 ; disks=""
  149. while read type from to ; do
  150. if [ $type = DISK1 ] ; then
  151. add $from $to
  152. if [ $disk_nr -gt 1 ] ; then
  153. echo "Disk 1 is too big!"
  154. rm -f $dat $index ${pathspec}_* ; exit 1
  155. fi
  156. fi
  157. done < $dat
  158. echo "$spacer parsing for SINGLE disk."
  159. while read type from to ; do
  160. if [ $type = SINGLE ] ; then
  161. add $from $to
  162. fi
  163. done < $dat
  164. echo "$spacer parsing for SPLIT disk."
  165. while read type from to ; do
  166. if [ $type = SPLIT ] ; then
  167. find $from -type f -printf '%P\n' | sort > $index
  168. grep ':dev' $index > ${index}_dev
  169. grep ':doc' $index > ${index}_doc
  170. grep -v ':dev' $index | grep -v ':doc' >${index}_new
  171. cat ${index}_new ${index}_doc ${index}_dev >$index
  172. rm ${index}_{dev,doc,new}
  173. while read p ; do
  174. add $from$p $to$p
  175. done < $index
  176. fi
  177. done < $dat
  178. if [ $src = 1 ] ; then
  179. echo "$spacer embedding source."
  180. ./scripts/Create-SrcTar
  181. for x in Documentation/* rock-src-$rockver.tar.bz2 ; do
  182. [ ! -d $x ] && add $x ${x/Documentation\/}
  183. done
  184. while read from ; do
  185. # adaptions of the sed exp need to propagated into Download, too
  186. from="`echo $from | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  187. if [ -e $from ] ; then
  188. add $from $from
  189. else
  190. echo "WARNING: File $from is missing!"
  191. fi
  192. done < <( ./scripts/Download -list )
  193. fi
  194. echo -n > $index
  195. for x in 0 $disks ; do
  196. dd=disk_${x}_data
  197. for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null` ; do
  198. to=${y%=*} ; from=${y#*=}
  199. if [ -e $from ] ; then
  200. find $from -printf "disk$x $to%P\\n" >> $index
  201. else
  202. echo "disk$x $to" >> $index
  203. fi
  204. done
  205. done
  206. disk_0_size=$(( $disk_0_size + $( du -sk $index | cut -f1 ) ))
  207. if [ -z "$bootoptions" ] ; then
  208. echo "WARNING: Disk1 is not bootable - no boot options defined."
  209. fi
  210. xxx() {
  211. if ! mkisofs "$@" &> $dat ; then
  212. echo ; echo "mkisofs $@" ; echo
  213. cat $dat ; rm -f $index $dat; exit 1
  214. fi
  215. }
  216. echo
  217. total=0
  218. for x in 0 $disks ; do
  219. ds=disk_${x}_size
  220. total=$(( $total + ${!ds} ))
  221. if [ $x = 0 ] ; then y="Shared"
  222. else y="`printf 'Disk%2d' $x`" ; fi
  223. z="$( grep "^disk$x " $index | wc -l )"
  224. if [ -z "$bootoptions" -o $x != 1 ] ; then
  225. printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
  226. else
  227. printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
  228. fi
  229. done
  230. printf "%15s Total: %8s kB in %5d files\n" "" $total $( wc -l < $index )
  231. echo
  232. date "+ [%X] Creating ${isoprefix}_index.txt ..."
  233. sort -tk -n -k2 < $index > ${isoprefix}_index.txt
  234. for x in $disks ; do
  235. ds=disk_${x}_size
  236. date "+ [%X] Creating ${isoprefix}_cd$x.iso ..."
  237. echo "This is disk #$x." > $dat
  238. # FIXME: current mkisofs does only accept one -path-list
  239. sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
  240. xxx -q -r -T -J -l -o ${isoprefix}_cd$x.iso -A "ROCK Linux - Disk $x" \
  241. -P 'The ROCK Linux Project - http://www.rocklinux.org' \
  242. -V "ROCK Linux - Disk $x" \
  243. -path-list ${pathspec}_current \
  244. $bootoptions -graft-points disk$x.txt=$dat \
  245. `cat ${pathspec}_iso 2>/dev/null`
  246. rm -f ${pathspec}_iso
  247. rm -f ${pathspec}_current
  248. bootoptions=""
  249. if [ "$scripts" ] ; then
  250. date "+ [%X] Running post-processing scripts on image ..."
  251. eval $scripts $x ${isoprefix}_cd$x.iso
  252. fi
  253. if [ "$implantisomd5" = 1 -a -x ./src/isomd5sum/implantisomd5 ] ; then
  254. date "+ [%X] Calculating and implanting MD5 checksum ..."
  255. ./src/isomd5sum/implantisomd5 ${isoprefix}_cd$x.iso >/dev/null
  256. fi
  257. if [ "$mkdebug" = 1 ] ; then
  258. cat > ${isoprefix}_loop$x.sh << EOT
  259. #!/bin/sh
  260. if [ "\$1" -a -z "\${1//[0-9]/}" ] ; then
  261. [ "\$2" ] && umount \$2 > /dev/null 2>&1
  262. losetup -d /dev/loop/\$1 > /dev/null 2>&1
  263. losetup /dev/loop/\$1 ${isoprefix}_cd$x.iso
  264. [ "\$2" ] && mount /dev/loop/\$1 \$2
  265. else
  266. echo "Usage: \$0 <loopback-dev-nr> [ <mount-point> ]"
  267. echo " Mount the corresponding ISO image at the given mount point using the given"
  268. echo " loopback device. If no mount point is given, the mount step is skipped."
  269. exit 1
  270. fi
  271. EOT
  272. chmod +x ${isoprefix}_loop$x.sh
  273. fi
  274. done
  275. date "+ [%X] Done. Have fun!"
  276. echo
  277. rm -f $index $dat ${pathspec}_*