* fix hyprutils to find pixman includes
[t2sde.git] / scripts / Create-ISO
blob71f012a4d8c72a2b05ea1e4283f54ab3cd199b10
1 #!/usr/bin/env bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # T2 SDE: scripts/Create-ISO
4 # Copyright (C) 2004 - 2024 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() {
36 echo
37 echo "Usage: $0 [ -size MB ] [ -source ] [ -mkdebug ] [ -sha len ] ISO-Prefix \\"
38 echo " ${0//?/ } [ Config [ .. ] ]"
39 echo
40 echo "E.g.: $0 mycdset system rescue"
41 echo
42 exit 1
45 # default disk-size
46 dsize=$((2 * 1024 * 1024))
47 file_overhead=1
48 src=0 mkdebug=0
49 isoprefix=''
50 shalen=256
52 while [ "$1" ]; do
53 case "$1" in
54 -size)
55 dsize=$(($2 * 1024)); shift; shift ;;
56 -source)
57 src=1; shift ;;
58 -mkdebug)
59 mkdebug=1; shift ;;
60 -sha)
61 shalen=$2; shift; shift ;;
62 -* | '')
63 usage ;;
65 break ;;
66 esac
67 done
69 [ $# -eq 0 ] && usage
70 isoprefix="$1"; shift
72 [ $# -eq 0 ] && set -- $isoprefix
74 spacer=" "
76 errno=0; for cfg; do
77 if [ ! -f config/$cfg/config ]; then
78 echo "Not a valid config: $cfg"
79 errno=1
81 done
82 [ $errno -ne 0 ] && exit 1
84 echo; date "+ [%X] Removing old files with same prefix ..."
85 [ "${isoprefix//\//}" == "${isoprefix}" ] && isoprefix="$isoprefix"
86 rm -rvf ${isoprefix}[_.]* ${isoprefix}.md5
88 date "+ [%X] Reading configs ..."
89 index=`mktemp` dat=`mktemp` pathspec=`mktemp`
90 rm -f ${pathspec}*
92 for cfg; do
93 id="`grep '^export SDECFG_ID=' config/$cfg/config |
94 cut -f2 -d\' 2> /dev/null`"
95 if ! cat build/$id/TOOLCHAIN/isofs.txt >> $dat 2> /dev/null
96 then
97 echo "Not a valid build: $cfg"
98 echo "build/$id/TOOLCHAIN/isofs.txt must exist."
99 rm -f $dat $index ${pathspec}_*; exit 1
102 if test -f config/$cfg/license-issue.ask; then
103 if ! grep LICENSE-WARNING $dat &> /dev/null; then
104 echo "EVERY misc/share/LICENSE-WARNING LICENSE-WARNING" >> $dat
107 cp -vf misc/share/LICENSE-WARNING build/$id/TOOLCHAIN/
108 echo "" >> build/$id/TOOLCHAIN/LICENSE-WARNING
109 echo "The following packages may have license restrictions:" >> build/$id/TOOLCHAIN/LICENSE-WARNING
110 cat config/$cfg/license-issue.ask >> build/$id/TOOLCHAIN/LICENSE-WARNING
112 if [ "`grep '^export SDECFG_LICENSE_ISSUE=' config/$cfg/config | cut -f2 -d\'`" = "0" ]; then
113 cat <<EOF
114 You have chosen to compile packages that are restricted
115 in their redistribution. Unless you accept this limitation
116 you cannot burn these packages.
118 Please rerun scripts/Config -cfg $cfg and check
119 'I have read and understood the licensing issues.'
122 #FIXME remove packages that have an issue instead of exiting
123 exit 1
126 done
128 # function to add a given file $1 to the place $2 on the resulting ISO
130 add() {
131 local from="$1" to="$2" done=0
132 if [ ! -f "$from" -a ! -d "$from" ]; then
133 echo "No such file or directory: $from"
134 rm -f $dat $index ${pathspec}_*; exit 1
137 files="`find $from ! -type d | wc -l`"
138 size="`du -s -b $from | cut -f1`"
139 size=$((size / 1024 + files * file_overhead))
141 if [ $size -gt $(($dsize - $disk_0_size)) ]; then
142 echo "Chunk $from is too big!"
143 rm -f $dat $index ${pathspec}_*; exit 1
146 for x in $disks; do
147 ds=disk_${x}_size dd=disk_${x}_data
148 if [ $((${!ds} + $size)) -le \
149 $(($dsize - $disk_0_size)) ]; then
150 eval "$ds=$((${!ds} + $size))"
151 echo "$to=$from" >> ${pathspec}_${disk_nr}
152 done=1; break
154 done
156 if [ $done = 0 ]; then
157 ((disk_nr++))
158 ds=disk_${disk_nr}_size; eval "$ds=$size"
160 # FIXME: if in a path-list files, mkisofs complains about
161 # missing isolinux. Should be a mkisofs bug!
162 if [ "$to" = "isolinux/" -o "$from" = "isolinux/" ]; then
163 echo "$to=$from" >> ${pathspec}_iso
164 else
165 echo "$to=$from" >> ${pathspec}_${disk_nr}
167 disks="$disks${disks:+ }$disk_nr"
171 bootoptions=
172 scripts=
173 while read tag data; do
174 # empty lines
175 [ "$tag" ] || continue
176 if [ $tag = BOOT ]; then
177 if [ "$bootoptions" ]; then
178 echo "Multiple boot options found!"
179 rm -f $dat $index ${pathspec}_*; exit 1
180 else
181 bootoptions="$data"
182 [[ $data == *-hfs* ]] && file_overhead=8
184 elif [ $tag = SCRIPT ]; then
185 var_append scripts ' ' "$data"
187 done < $dat
188 while read tag data; do
189 if [ "$tag" = BOOTx ]; then
190 bootoptions="$bootoptions $data"
191 [[ $data == *-hfs* ]] && file_overhead=8
193 done < $dat
195 echo "$spacer parsing for EVERY disk."
197 disks="0" disk_nr=0 disk_0_size=0
198 echo "index.txt=${isoprefix}_index.txt" >> ${pathspec}_0
199 while read type from to; do
200 if [ "$type" = EVERY ]; then
201 add $from $to
202 if [ $disk_nr -gt 0 ]; then
203 echo "Every-disk data is too big!"
204 rm -f $dat $index ${pathspec}_*; exit 1
207 done < $dat
209 echo "$spacer parsing for DISK1 disk."
211 disk_nr=0 disks=""
212 while read type from to; do
213 if [ "$type" = DISK1 ]; then
214 add $from $to
215 if [ $disk_nr -gt 1 ]; then
216 echo "Disk 1 is too big!"
217 rm -f $dat $index ${pathspec}_*; exit 1
220 done < $dat
222 echo "$spacer parsing for SINGLE disk."
224 while read type from to; do
225 if [ "$type" = SINGLE ]; then
226 add $from $to
228 done < $dat
230 echo "$spacer parsing for SPLIT disk."
232 while read type from to; do
233 if [ "$type" = SPLIT ]; then
234 find $from -type f -printf '%P\n' | sort > $index
235 while read p; do
236 add $from$p $to$p
237 done < $index
239 done < $dat
241 if [ $src = 1 ]; then
242 date "+ [%X] Embedding source ..."
244 scripts/Create-SrcTar
246 for x in doc/* t2-src-$sdever.tar.bz2; do
247 [ ! -d $x ] && add $x ${x/doc\/}
248 done
250 while read from; do
251 if [ -e $from ]; then
252 add $from $from
253 else
254 echo "WARNING: File $from is missing!"
256 done < <(scripts/Download -list | sort -u)
259 date "+ [%X] Creating ISO index ..."
260 echo -n > $index
261 for x in 0 $disks; do
262 dd=disk_${x}_data
263 for y in ${!dd} `cat ${pathspec}_${x} 2> /dev/null`; do
264 to=${y%=*} from=${y#*=}
265 if [ -e $from ]; then
266 find $from -printf "disk$x $to%P\\n" >> $index
267 else
268 echo "disk$x $to" >> $index
270 done
271 done
272 disk_0_size=$(($disk_0_size + $(du -sk $index | cut -f1)))
274 if [ -z "$bootoptions" ]; then
275 echo "WARNING: Disk1 is not bootable - no boot options defined."
278 echo
279 total=0
280 for x in 0 $disks; do
281 ds=disk_${x}_size
282 total=$(($total + ${!ds}))
284 if [ $x = 0 ]; then y="Shared"
285 else y="`printf 'Disk%2d' $x`"; fi
287 z="$(grep "^disk$x " $index | wc -l)"
289 if [ -z "$bootoptions" -o $x != 1 ]; then
290 printf "%15s $y: %7s kB in %5d files\n" "" ${!ds} $z
291 else
292 printf "%15s $y: %7s kB in %5d files (boot)\n" "" ${!ds} $z
294 done
295 printf "%15s Total: %8s kB in %5d files\n" "" $total $(wc -l < $index)
296 echo
298 date "+ [%X] Creating ${isoprefix}_index.txt ..."
299 sort -tk -n -k2 < $index > ${isoprefix}_index.txt
301 mkisofs=
302 for x in xorrisofs genisoimage mkisofs; do
303 if [ "`type -p $x`" ]; then
304 if [[ $x = "xorrisofs" && "$bootoptions" = *-hfs* ]]; then
305 echo "Warning: $x does not yet support -hfs, skipped!"
306 else
307 mkisofs="$x"; break
310 done
311 [ ! "$mkisofs" ] && echo 'Error: No suitable "mkisofs" found!' && exit 1
313 for x in $disks; do
314 ds=disk_${x}_size
315 isoname=${isoprefix}
316 [ "${disks// /}" != "$disks" ] && isoname=${isoname}_$x
317 date "+ [%X] Creating $isoname ..."
318 echo "This is disc #$x." > $dat
319 # FIXME: current mkisofs does only accept one -path-list
320 sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
322 # parallel sha? or scripts post-processing?
323 [ "$scripts" ] && psha="echo -n" || psha=sha${shalen}sum
324 $mkisofs -r -J -l -V "T2" -A "T2 SDE - Disc $x" \
325 -publisher 'T2 System Develop Environment - https://t2sde.org' \
326 -graft-points -path-list ${pathspec}_current \
327 $bootoptions disk$x.txt=$dat \
328 `cat ${pathspec}_iso 2>/dev/null` | tee -p $isoname.iso |
329 $psha | sed "s/ -/ `basename $isoname.iso`/" >> $isoname.sha${shalen}
330 rm -f ${pathspec}_iso
331 rm -f ${pathspec}_current
333 bootoptions=""
335 if [ "$scripts" ]; then
336 echo "$spacer Running post-processing scripts on image"
337 eval $scripts $x $isoname.iso
338 sha${shalen}sum < $isoname.iso | sed "s/ -/ `basename $isoname.iso`/" >> $isoname.sha${shalen}
341 if [ "$mkdebug" = 1 ]; then
342 cat > ${isoprefix}_loop$x.sh << EOT
343 #!/bin/sh
345 if [ "\$1" -a -z "\${1//[0-9]/}" ]; then
346 [ "\$2" ] && umount \$2 > /dev/null 2>&1
347 losetup -d /dev/loop\$1 > /dev/null 2>&1
348 losetup /dev/loop\$1 $isoname.iso
349 [ "\$2" ] && mount /dev/loop\$1 \$2
350 else
351 echo "Usage: \$0 loopback-dev-nr [ mount-point ]"
352 exit 1
355 chmod +x ${isoprefix}_loop$x.sh
357 done
359 date "+ [%X] Done. Have fun!"
360 echo
362 rm -f $index $dat ${pathspec}_*