* updated kldap (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / scripts / Create-ISO
blob76f67cf94e0777639478cf46388bb550db4da931
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by scripts/Create-CopyPatch.
4 #
5 # T2 SDE: scripts/Create-ISO
6 # Copyright (C) 2004 - 2021 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
17 # Commands in isofs.txt files:
19 # EVERY from to Put this on every disk
20 # DISK1 from to Put this on the 1st disk
21 # SINGLE from to Put it on any disk
22 # SPLIT from to You may split it up over many disks
24 # BOOT boot-options Add this mkisofs options for 1st disk
26 # If you want to add multiple 'BOOT' lines, use the tag-name 'BOOTx' for
27 # the 2nd and all further lines.
29 # SCRIPT script-name args Run given script for each image
31 # Intended for image post-processing. The first argument is the CD
32 # number and the second the image file.
35 eval `grep sdever scripts/parse-config`
36 . scripts/functions.in
38 usage()
40 echo
41 echo "Usage: $0 [ -size MB ] [ -source ] [ -mkdebug ] [ -sha len ] ISO-Prefix \\"
42 echo " ${0//?/ } [ Config [ .. ] ]"
43 echo
44 echo "E.g.: $0 mycdset system rescue"
45 echo
46 exit 1
49 # default disk-size
50 dsize=$((1024 * 1024))
51 file_overhead=1
52 src=0; mkdebug=0
53 isoprefix=''
54 shalen=224
56 while [ "$1" ]; do
57 case "$1" in
58 -size)
59 dsize=$(( $2 * 1024 )); shift; shift ;;
60 -source)
61 src=1; shift ;;
62 -mkdebug)
63 mkdebug=1; shift ;;
64 -sha)
65 shalen=$2; shift; shift ;;
66 -* | '')
67 usage ;;
69 break ;;
70 esac
71 done
73 [ $# -eq 0 ] && usage
74 isoprefix="$1"; shift
76 [ $# -eq 0 ] && set -- 'default'
78 spacer=" "
80 errno=0; for cfg; do
81 if [ ! -f config/$cfg/config ]; then
82 echo "Not a valid config: $cfg"
83 errno=1
85 done
86 [ $errno -ne 0 ] && exit 1
88 echo; date "+ [%X] Removing old files with same prefix ..."
89 [ "${isoprefix//\//}" == "${isoprefix}" ] && isoprefix="$isoprefix"
90 rm -rvf ${isoprefix}[_.]* ${isoprefix}.md5
92 date "+ [%X] Reading configs ..."
93 index=`mktemp`; dat=`mktemp`; pathspec=`mktemp`
94 rm -f ${pathspec}*
96 for cfg; do
97 id="`grep '^export SDECFG_ID=' config/$cfg/config |
98 cut -f2 -d\' 2> /dev/null`"
99 if ! cat build/$id/TOOLCHAIN/isofs.txt >> $dat 2> /dev/null
100 then
101 echo "Not a valid build: $cfg"
102 echo "build/$id/TOOLCHAIN/isofs.txt must exist."
103 rm -f $dat $index ${pathspec}_*; exit 1
106 if test -f config/$cfg/license-issue.ask; then
107 if ! grep LICENSE-WARNING $dat &> /dev/null; then
108 echo "EVERY misc/share/LICENSE-WARNING LICENSE-WARNING" >> $dat
111 cp -vf misc/share/LICENSE-WARNING build/$id/TOOLCHAIN/
112 echo "" >> build/$id/TOOLCHAIN/LICENSE-WARNING
113 echo "The following packages may have license restrictions:" >> build/$id/TOOLCHAIN/LICENSE-WARNING
114 cat config/$cfg/license-issue.ask >> build/$id/TOOLCHAIN/LICENSE-WARNING
116 if [ "`grep '^export SDECFG_LICENSE_ISSUE=' config/$cfg/config | cut -f2 -d\'`" = "0" ]; then
117 cat <<EOF
118 You have chosen to compile packages that are restricted
119 in their redistribution. Unless you accept this limitation
120 you cannot burn these packages.
122 Please rerun scripts/Config -cfg $cfg and check
123 'I have read and understood the licensing issues.'
126 #FIXME remove packages that have an issue instead of exiting
127 exit 1
130 done
132 # function to add a given file $1 to the place $2 on the resulting ISO
134 add() {
135 local from="$1" to="$2" done=0
136 if [ ! -f "$from" -a ! -d "$from" ]; then
137 echo "No such file or directory: $from"
138 rm -f $dat $index ${pathspec}_*; exit 1
141 files="`find $from ! -type d | wc -l`"
142 size="`du -s -b $from | cut -f1`"
143 size=$(( size / 1024 + files * file_overhead ))
145 if [ $size -gt $(( $dsize - $disk_0_size )) ]; then
146 echo "Chunk $from is too big!"
147 rm -f $dat $index ${pathspec}_*; exit 1
150 for x in $disks; do
151 ds=disk_${x}_size; dd=disk_${x}_data
152 if [ $(( ${!ds} + $size )) -le \
153 $(( $dsize - $disk_0_size )) ]; then
154 eval "$ds=$(( ${!ds} + $size ))"
155 echo "$to=$from" >> ${pathspec}_${disk_nr}
156 done=1; break
158 done
160 if [ $done = 0 ]; then
161 (( disk_nr++ ))
162 ds=disk_${disk_nr}_size; eval "$ds=$size"
164 # FIXME: if in a path-list files, mkisofs complains about
165 # missing isolinux. Should be a mkisofs bug!
166 if [ "$to" = "isolinux/" -o "$from" = "isolinux/" ]; then
167 echo "$to=$from" >> ${pathspec}_iso
168 else
169 echo "$to=$from" >> ${pathspec}_${disk_nr}
171 disks="$disks${disks:+ }$disk_nr"
175 bootoptions=""
176 scripts=""
177 while read tag data; do
178 # empty lines
179 [ "$tag" ] || continue
180 if [ $tag = BOOT ]; then
181 if [ "$bootoptions" ]; then
182 echo "Multiple boot options found!"
183 rm -f $dat $index ${pathspec}_*; exit 1
184 else
185 bootoptions="$data"
186 [[ $data == *-hfs* ]] && file_overhead=12
188 elif [ $tag = SCRIPT ]; then
189 scripts="$scripts $data"
191 done < $dat
192 while read tag data; do
193 if [ "$tag" = BOOTx ]; then
194 bootoptions="$bootoptions $data"
195 [[ $data == *-hfs* ]] && file_overhead=12
197 done < $dat
199 echo "$spacer parsing for EVERY disk."
201 disks="0"; disk_nr=0; disk_0_size=0
202 echo "index.txt=${isoprefix}_index.txt" >> ${pathspec}_0
203 while read type from to; do
204 if [ "$type" = EVERY ]; then
205 add $from $to
206 if [ $disk_nr -gt 0 ]; then
207 echo "Every-disk data is too big!"
208 rm -f $dat $index ${pathspec}_*; exit 1
211 done < $dat
213 echo "$spacer parsing for DISK1 disk."
215 disk_nr=0; disks=""
216 while read type from to; do
217 if [ "$type" = DISK1 ]; then
218 add $from $to
219 if [ $disk_nr -gt 1 ]; then
220 echo "Disk 1 is too big!"
221 rm -f $dat $index ${pathspec}_*; exit 1
224 done < $dat
226 echo "$spacer parsing for SINGLE disk."
228 while read type from to; do
229 if [ "$type" = SINGLE ]; then
230 add $from $to
232 done < $dat
234 echo "$spacer parsing for SPLIT disk."
236 while read type from to; do
237 if [ "$type" = SPLIT ]; then
238 find $from -type f -printf '%P\n' | sort > $index
239 while read p; do
240 add $from$p $to$p
241 done < $index
243 done < $dat
245 if [ $src = 1 ]; then
246 date "+ [%X] Embedding source ..."
248 scripts/Create-SrcTar
250 for x in doc/* t2-src-$sdever.tar.bz2; do
251 [ ! -d $x ] && add $x ${x/doc\/}
252 done
254 while read from; do
255 from="`bz2filename $from`"
256 if [ -e $from ]; then
257 add $from $from
258 else
259 echo "WARNING: File $from is missing!"
261 done < <( scripts/Download -list | sort -u )
264 date "+ [%X] Creating ISO index ..."
265 echo -n > $index
266 for x in 0 $disks; do
267 dd=disk_${x}_data
268 for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null`; do
269 to=${y%=*}; from=${y#*=}
270 if [ -e $from ]; then
271 find $from -printf "disk$x $to%P\\n" >> $index
272 else
273 echo "disk$x $to" >> $index
275 done
276 done
277 disk_0_size=$(( $disk_0_size + $( du -sk $index | cut -f1 ) ))
279 if [ -z "$bootoptions" ]; then
280 echo "WARNING: Disk1 is not bootable - no boot options defined."
283 echo
284 total=0
285 for x in 0 $disks; do
286 ds=disk_${x}_size
287 total=$(( $total + ${!ds} ))
289 if [ $x = 0 ]; then y="Shared"
290 else y="`printf 'Disk%2d' $x`"; fi
292 z="$( grep "^disk$x " $index | wc -l )"
294 if [ -z "$bootoptions" -o $x != 1 ]; then
295 printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
296 else
297 printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
299 done
300 printf "%15s Total: %8s kB in %5d files\n" "" $total $( wc -l < $index )
301 echo
303 date "+ [%X] Creating ${isoprefix}_index.txt ..."
304 sort -tk -n -k2 < $index > ${isoprefix}_index.txt
306 mkisofs=
307 for x in xorrisofs genisoimage mkisofs; do
308 if [ "`type -p $x`" ]; then
309 if [ $x = "xorrisofs" ] && [[ "$bootoptions" = *-hfs* ]]; then
310 echo "$x does not yet support -hfs, ... skipped."
311 else
312 mkisofs="$x"; break
315 done
316 [ ! "$mkisofs" ] && echo 'No "mkisofs" found in path!' && exit 1
318 for x in $disks; do
319 ds=disk_${x}_size
320 isoname=${isoprefix}
321 [ "${disks// /}" != "$disks" ] && isoname=${isoname}_$x
322 date "+ [%X] Creating $isoname ..."
323 echo "This is disc #$x." > $dat
324 # FIXME: current mkisofs does only accept one -path-list
325 sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
326 $mkisofs -r -J -l -V "T2SDE" -A "T2 SDE - Disc $x" \
327 -publisher 'T2 System Develop Environment - https://t2sde.org' \
328 -graft-points -path-list ${pathspec}_current \
329 $bootoptions disk$x.txt=$dat \
330 `cat ${pathspec}_iso 2>/dev/null` | tee $isoname.iso |
331 sha${shalen}sum | sed "s/ -/ `basename ${isoname}.iso`/" >> $isoname.sha${shalen}
332 rm -f ${pathspec}_iso
333 rm -f ${pathspec}_current
335 bootoptions=""
337 if [ "$scripts" ]; then
338 echo "$spacer Running post-processing scripts on image"
339 eval $scripts $x ${isoname}.iso
342 if [ "$mkdebug" = 1 ]; then
343 cat > ${isoprefix}_loop$x.sh << EOT
344 #!/bin/sh
346 if [ "\$1" -a -z "\${1//[0-9]/}" ]; then
347 [ "\$2" ] && umount \$2 > /dev/null 2>&1
348 losetup -d /dev/loop\$1 > /dev/null 2>&1
349 losetup /dev/loop\$1 $isoname.iso
350 [ "\$2" ] && mount /dev/loop\$1 \$2
351 else
352 echo "Usage: \$0 loopback-dev-nr [ mount-point ]"
353 exit 1
356 chmod +x ${isoprefix}_loop$x.sh
358 done
360 date "+ [%X] Done. Have fun!"
361 echo
363 rm -f $index $dat ${pathspec}_*