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.

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