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