mirror of
https://github.com/rxrbln/t2sde.git
synced 2025-05-09 04:31:26 +08:00
358 lines
8.7 KiB
Bash
Executable File
358 lines
8.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# --- T2-COPYRIGHT-BEGIN ---
|
|
# t2/scripts/Create-ISO
|
|
# Copyright (C) 2004 - 2025 The T2 SDE Project
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# --- T2-COPYRIGHT-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 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 ] [ -sha len ] ISO-Prefix \\"
|
|
echo " ${0//?/ } [ Config [ .. ] ]"
|
|
echo
|
|
echo "E.g.: $0 mycdset system rescue"
|
|
echo
|
|
exit 1
|
|
}
|
|
|
|
# default disk-size
|
|
dsize=$((2 * 1024 * 1024))
|
|
file_overhead=1
|
|
src=0 mkdebug=0
|
|
isoprefix=''
|
|
shalen=256
|
|
|
|
while [ "$1" ]; do
|
|
case "$1" in
|
|
-size)
|
|
dsize=$(($2 * 1024)); shift; shift ;;
|
|
-source)
|
|
src=1; shift ;;
|
|
-mkdebug)
|
|
mkdebug=1; shift ;;
|
|
-sha)
|
|
shalen=$2; shift; shift ;;
|
|
-* | '')
|
|
usage ;;
|
|
*)
|
|
break ;;
|
|
esac
|
|
done
|
|
|
|
[ $# -eq 0 ] && usage
|
|
isoprefix="$1"; shift
|
|
|
|
[ $# -eq 0 ] && set -- $isoprefix
|
|
|
|
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
|
|
|
|
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++))
|
|
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${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=8
|
|
fi
|
|
elif [ $tag = SCRIPT ]; then
|
|
var_append scripts ' ' $data
|
|
fi
|
|
done < $dat
|
|
while read tag data; do
|
|
if [ "$tag" = BOOTx ]; then
|
|
bootoptions="$bootoptions $data"
|
|
[[ $data == *-hfs* ]] && file_overhead=8
|
|
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
|
|
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
|
|
|
|
mkisofs=
|
|
for x in xorrisofs genisoimage mkisofs; do
|
|
if [ "`type -p $x`" ]; then
|
|
if [[ $x = "xorrisofs" && "$bootoptions" = *-hfs* ]]; then
|
|
echo "Warning: $x does not yet support -hfs, skipped!"
|
|
else
|
|
mkisofs="$x"; break
|
|
fi
|
|
fi
|
|
done
|
|
[ ! "$mkisofs" ] && echo 'Error: No suitable "mkisofs" found!' && exit 1
|
|
|
|
for x in $disks; do
|
|
ds=disk_${x}_size
|
|
isoname=${isoprefix}
|
|
[ "${disks// /}" != "$disks" ] && isoname=${isoname}_$x
|
|
date "+ [%X] Creating $isoname ..."
|
|
echo "This is disc #$x." > $dat
|
|
# FIXME: current mkisofs does only accept one -path-list
|
|
sort -u ${pathspec}_${x} ${pathspec}_0 > ${pathspec}_current 2> /dev/null
|
|
|
|
# parallel sha? or scripts post-processing?
|
|
[ "$scripts" ] && psha="echo -n" || psha=sha${shalen}sum
|
|
$mkisofs -r -J -l -quiet -V "T2" -A "T2 SDE - Disc $x" \
|
|
-publisher 'T2 System Develop Environment - https://t2sde.org' \
|
|
-graft-points -path-list ${pathspec}_current \
|
|
$bootoptions disk$x.txt=$dat \
|
|
`cat ${pathspec}_iso 2>/dev/null` | tee -p $isoname.iso |
|
|
$psha | sed "s/ -/ `basename $isoname.iso`/" >> $isoname.sha${shalen}
|
|
rm -f ${pathspec}_iso
|
|
rm -f ${pathspec}_current
|
|
|
|
bootoptions=""
|
|
|
|
if [ "$scripts" ]; then
|
|
echo "$spacer Running post-processing scripts on image"
|
|
eval $scripts $x $isoname.iso
|
|
sha${shalen}sum < $isoname.iso | sed "s/ -/ `basename $isoname.iso`/" >> $isoname.sha${shalen}
|
|
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 $isoname.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
|
|
|
|
date "+ [%X] Done. Have fun!"
|
|
echo
|
|
|
|
rm -f $index $dat ${pathspec}_*
|