added CheckVersion info for dyncall
[t2.git] / scripts / Create-ISO
blob0dd07fc7f7833ebd61855b7443cf5abcf49aafa3
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # T2 SDE: scripts/Create-ISO
4 # Copyright (C) 2004 - 2021 The T2 SDE Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
14 # Commands in isofs.txt files:
16 # EVERY from to Put this on every disk
17 # DISK1 from to Put this on the 1st disk
18 # SINGLE from to Put it on any disk
19 # SPLIT from to You may split it up over many disks
21 # BOOT boot-options Add this mkisofs options for 1st disk
23 # If you want to add multiple 'BOOT' lines, use the tag-name 'BOOTx' for
24 # the 2nd and all further lines.
26 # SCRIPT script-name args Run given script for each image
28 # Intended for image post-processing. The first argument is the CD
29 # number and the second the image file.
32 eval `grep sdever scripts/parse-config`
33 . scripts/functions.in
35 usage()
37 echo
38 echo "Usage: $0 [ -size MB ] [ -source ] [ -mkdebug ] [ -sha len ] ISO-Prefix \\"
39 echo " ${0//?/ } [ Config [ .. ] ]"
40 echo
41 echo "E.g.: $0 mycdset system rescue"
42 echo
43 exit 1
46 # default disk-size
47 dsize=$((1024 * 1024))
48 file_overhead=1
49 src=0; mkdebug=0
50 isoprefix=''
51 shalen=224
53 while [ "$1" ]; do
54 case "$1" in
55 -size)
56 dsize=$(( $2 * 1024 )); shift; shift ;;
57 -source)
58 src=1; shift ;;
59 -mkdebug)
60 mkdebug=1; shift ;;
61 -sha)
62 shalen=$2; shift; shift ;;
63 -* | '')
64 usage ;;
66 break ;;
67 esac
68 done
70 [ $# -eq 0 ] && usage
71 isoprefix="$1"; shift
73 [ $# -eq 0 ] && set -- 'default'
75 spacer=" "
77 errno=0; for cfg; do
78 if [ ! -f config/$cfg/config ]; then
79 echo "Not a valid config: $cfg"
80 errno=1
82 done
83 [ $errno -ne 0 ] && exit 1
85 echo; date "+ [%X] Removing old files with same prefix ..."
86 [ "${isoprefix//\//}" == "${isoprefix}" ] && isoprefix="$isoprefix"
87 rm -rvf ${isoprefix}[_.]* ${isoprefix}.md5
89 date "+ [%X] Reading configs ..."
90 index=`mktemp`; dat=`mktemp`; pathspec=`mktemp`
91 rm -f ${pathspec}*
93 for cfg; do
94 id="`grep '^export SDECFG_ID=' config/$cfg/config |
95 cut -f2 -d\' 2> /dev/null`"
96 if ! cat build/$id/TOOLCHAIN/isofs.txt >> $dat 2> /dev/null
97 then
98 echo "Not a valid build: $cfg"
99 echo "build/$id/TOOLCHAIN/isofs.txt must exist."
100 rm -f $dat $index ${pathspec}_*; exit 1
103 if test -f config/$cfg/license-issue.ask; then
104 if ! grep LICENSE-WARNING $dat &> /dev/null; then
105 echo "EVERY misc/share/LICENSE-WARNING LICENSE-WARNING" >> $dat
108 cp -vf misc/share/LICENSE-WARNING build/$id/TOOLCHAIN/
109 echo "" >> build/$id/TOOLCHAIN/LICENSE-WARNING
110 echo "The following packages may have license restrictions:" >> build/$id/TOOLCHAIN/LICENSE-WARNING
111 cat config/$cfg/license-issue.ask >> build/$id/TOOLCHAIN/LICENSE-WARNING
113 if [ "`grep '^export SDECFG_LICENSE_ISSUE=' config/$cfg/config | cut -f2 -d\'`" = "0" ]; then
114 cat <<EOF
115 You have chosen to compile packages that are restricted
116 in their redistribution. Unless you accept this limitation
117 you cannot burn these packages.
119 Please rerun scripts/Config -cfg $cfg and check
120 'I have read and understood the licensing issues.'
123 #FIXME remove packages that have an issue instead of exiting
124 exit 1
127 done
129 # function to add a given file $1 to the place $2 on the resulting ISO
131 add() {
132 local from="$1" to="$2" done=0
133 if [ ! -f "$from" -a ! -d "$from" ]; then
134 echo "No such file or directory: $from"
135 rm -f $dat $index ${pathspec}_*; exit 1
138 files="`find $from ! -type d | wc -l`"
139 size="`du -s -b $from | cut -f1`"
140 size=$(( size / 1024 + files * file_overhead ))
142 if [ $size -gt $(( $dsize - $disk_0_size )) ]; then
143 echo "Chunk $from is too big!"
144 rm -f $dat $index ${pathspec}_*; exit 1
147 for x in $disks; do
148 ds=disk_${x}_size; dd=disk_${x}_data
149 if [ $(( ${!ds} + $size )) -le \
150 $(( $dsize - $disk_0_size )) ]; then
151 eval "$ds=$(( ${!ds} + $size ))"
152 echo "$to=$from" >> ${pathspec}_${disk_nr}
153 done=1; break
155 done
157 if [ $done = 0 ]; then
158 (( disk_nr++ ))
159 ds=disk_${disk_nr}_size; eval "$ds=$size"
161 # FIXME: if in a path-list files, mkisofs complains about
162 # missing isolinux. Should be a mkisofs bug!
163 if [ "$to" = "isolinux/" -o "$from" = "isolinux/" ]; then
164 echo "$to=$from" >> ${pathspec}_iso
165 else
166 echo "$to=$from" >> ${pathspec}_${disk_nr}
168 disks="$disks${disks:+ }$disk_nr"
172 bootoptions=""
173 scripts=""
174 while read tag data; do
175 # empty lines
176 [ "$tag" ] || continue
177 if [ $tag = BOOT ]; then
178 if [ "$bootoptions" ]; then
179 echo "Multiple boot options found!"
180 rm -f $dat $index ${pathspec}_*; exit 1
181 else
182 bootoptions="$data"
183 [[ $data == *-hfs* ]] && file_overhead=12
185 elif [ $tag = SCRIPT ]; then
186 scripts="$scripts $data"
188 done < $dat
189 while read tag data; do
190 if [ "$tag" = BOOTx ]; then
191 bootoptions="$bootoptions $data"
192 [[ $data == *-hfs* ]] && file_overhead=12
194 done < $dat
196 echo "$spacer parsing for EVERY disk."
198 disks="0"; disk_nr=0; disk_0_size=0
199 echo "index.txt=${isoprefix}_index.txt" >> ${pathspec}_0
200 while read type from to; do
201 if [ "$type" = EVERY ]; then
202 add $from $to
203 if [ $disk_nr -gt 0 ]; then
204 echo "Every-disk data is too big!"
205 rm -f $dat $index ${pathspec}_*; exit 1
208 done < $dat
210 echo "$spacer parsing for DISK1 disk."
212 disk_nr=0; disks=""
213 while read type from to; do
214 if [ "$type" = DISK1 ]; then
215 add $from $to
216 if [ $disk_nr -gt 1 ]; then
217 echo "Disk 1 is too big!"
218 rm -f $dat $index ${pathspec}_*; exit 1
221 done < $dat
223 echo "$spacer parsing for SINGLE disk."
225 while read type from to; do
226 if [ "$type" = SINGLE ]; then
227 add $from $to
229 done < $dat
231 echo "$spacer parsing for SPLIT disk."
233 while read type from to; do
234 if [ "$type" = SPLIT ]; then
235 find $from -type f -printf '%P\n' | sort > $index
236 while read p; do
237 add $from$p $to$p
238 done < $index
240 done < $dat
242 if [ $src = 1 ]; then
243 date "+ [%X] Embedding source ..."
245 while read from; do
246 from="`bz2filename $from`"
247 if [ -e $from ]; then
248 add $from $from
249 else
250 echo "WARNING: File $from is missing!"
252 done < <( scripts/Download -list | sort -u )
255 date "+ [%X] Creating ISO index ..."
256 echo -n > $index
257 for x in 0 $disks; do
258 dd=disk_${x}_data
259 for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null`; do
260 to=${y%=*}; from=${y#*=}
261 if [ -e $from ]; then
262 find $from -printf "disk$x $to%P\\n" >> $index
263 else
264 echo "disk$x $to" >> $index
266 done
267 done
268 disk_0_size=$(( $disk_0_size + $( du -sk $index | cut -f1 ) ))
270 if [ -z "$bootoptions" ]; then
271 echo "WARNING: Disk1 is not bootable - no boot options defined."
274 echo
275 total=0
276 for x in 0 $disks; do
277 ds=disk_${x}_size
278 total=$(( $total + ${!ds} ))
280 if [ $x = 0 ]; then y="Shared"
281 else y="`printf 'Disk%2d' $x`"; fi
283 z="$( grep "^disk$x " $index | wc -l )"
285 if [ -z "$bootoptions" -o $x != 1 ]; then
286 printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
287 else
288 printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
290 done
291 printf "%15s Total: %8s kB in %5d files\n" "" $total $( wc -l < $index )
292 echo
294 date "+ [%X] Creating ${isoprefix}_index.txt ..."
295 sort -tk -n -k2 < $index > ${isoprefix}_index.txt
297 mkisofs=
298 for x in xorrisofs genisoimage mkisofs; do
299 if [ "`type -p $x`" ]; then
300 if [ $x = "xorrisofs" ] && [[ "$bootoptions" = *-hfs* ]]; then
301 echo "$x does not yet support -hfs, ... skipped."
302 else
303 mkisofs="$x"; break
306 done
307 [ ! "$mkisofs" ] && echo 'No "mkisofs" found in path!' && exit 1
309 for x in $disks; do
310 ds=disk_${x}_size
311 isoname=${isoprefix}
312 [ "${disks// /}" != "$disks" ] && isoname=${isoname}_$x
313 date "+ [%X] Creating $isoname ..."
314 echo "This is disc #$x." > $dat
315 # FIXME: current mkisofs does only accept one -path-list
316 sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
317 $mkisofs -r -J -l -A "T2 SDE - Disc $x" \
318 -publisher 'T2 System Develop Environment - https://t2sde.org' \
319 -graft-points -path-list ${pathspec}_current \
320 $bootoptions disk$x.txt=$dat \
321 `cat ${pathspec}_iso 2>/dev/null` | tee $isoname.iso |
322 sha${shalen}sum | sed "s/ -/ `basename ${isoname}.iso`/" >> $isoname.sha${shalen}
323 rm -f ${pathspec}_iso
324 rm -f ${pathspec}_current
326 bootoptions=""
328 if [ "$scripts" ]; then
329 echo "$spacer Running post-processing scripts on image"
330 eval $scripts $x ${isoname}.iso
333 if [ "$mkdebug" = 1 ]; then
334 cat > ${isoprefix}_loop$x.sh << EOT
335 #!/bin/sh
337 if [ "\$1" -a -z "\${1//[0-9]/}" ]; then
338 [ "\$2" ] && umount \$2 > /dev/null 2>&1
339 losetup -d /dev/loop\$1 > /dev/null 2>&1
340 losetup /dev/loop\$1 $isoname.iso
341 [ "\$2" ] && mount /dev/loop\$1 \$2
342 else
343 echo "Usage: \$0 loopback-dev-nr [ mount-point ]"
344 exit 1
347 chmod +x ${isoprefix}_loop$x.sh
349 done
351 date "+ [%X] Done. Have fun!"
352 echo
354 rm -f $index $dat ${pathspec}_*