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.

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