Files
llamamod/deb-build/build.sh
T

102 lines
4.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Baut ein .deb für "Ein Königreich für ein Lama" aus einer intakten CD-ISO.
# ./build.sh /pfad/zur/GROOVE.iso
# Benötigt: 7z, ffmpeg (mit argo_asf/libmp3lame), wrestool, icotool, convert,
# fakeroot, dpkg-deb
set -euo pipefail
umask 022
ISO=$(realpath "${1:?Aufruf: $0 /pfad/zur/cd.iso}")
HERE=$(cd "$(dirname "$0")" && pwd)
PKG=ein-koenigreich-fuer-ein-lama
VER=1.0-1
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
ROOT="$WORK/root"
OPT="$ROOT/opt/$PKG"
echo ">> ISO entpacken"
mkdir -p "$WORK/iso"
7z x -y -o"$WORK/iso" "$ISO" >/dev/null
SRC="$WORK/iso/Setup/Eng"
[ -f "$SRC/Hd/groove.exe" ] || { echo "groove.exe nicht gefunden – falsche ISO?" >&2; exit 1; }
echo ">> Integrität prüfen"
python3 -I - "$SRC" <<'EOF'
import sys, struct, os
src = sys.argv[1]
bad = []
fe = open(os.path.join(src, 'Cd/wads/FESOUND.WAD'), 'rb').read()
if struct.unpack('<I', fe[:4])[0] != len(fe) - 4: bad.append('FESOUND.WAD')
for f in os.listdir(os.path.join(src, 'Cd/wads')):
if f.lower().endswith('.wad') and f.upper() != 'FESOUND.WAD':
d = open(os.path.join(src, 'Cd/wads', f), 'rb').read(8)
if d[4:8] != b'OFNI': bad.append(f)
cvs = open(os.path.join(src, 'Hd/music/english.cvs'), 'rb').read()
if cvs[-4 * 1024 * 1024:].count(0) == 4 * 1024 * 1024: bad.append('english.cvs (Nullbereich am Ende)')
if bad:
sys.exit('Beschädigte Dateien: ' + ', '.join(bad))
print(' ok')
EOF
echo ">> Spieldaten"
mkdir -p "$OPT"
cp -r "$SRC/Cd" "$OPT/cd"
cp -r "$SRC/Hd" "$OPT/hd"
cp "$WORK/iso/GROOVE.HLP" "$OPT/" 2>/dev/null || true
find "$OPT" -type d -exec chmod 755 {} +
find "$OPT" -type f -exec chmod 644 {} +
echo ">> Startskript, Menüeintrag, Icon"
install -Dm755 "$HERE/files/$PKG" "$ROOT/usr/games/$PKG"
ln -s "$PKG" "$ROOT/usr/games/lama"
install -Dm644 "$HERE/files/$PKG.desktop" "$ROOT/usr/share/applications/$PKG.desktop"
wrestool -x -t 14 "$SRC/Hd/groove.exe" -o "$WORK/icon.ico"
icotool -x -o "$WORK/icon.png" "$WORK/icon.ico" 2>/dev/null
for s in 32 64 128; do
mkdir -p "$ROOT/usr/share/icons/hicolor/${s}x${s}/apps"
convert "$WORK/icon.png" -filter point -resize "${s}x${s}" \
"$ROOT/usr/share/icons/hicolor/${s}x${s}/apps/$PKG.png"
done
echo ">> Soundtrack nach MP3"
OST="$ROOT/usr/share/$PKG/soundtrack"
mkdir -p "$OST"
# Nicht FFmpegs adpcm_argo verwenden: der klemmt den Prädiktor auf 16 Bit,
# das Original lässt ihn überlaufen -> sonst massiver DC-Offset / Drift.
# asf2wav.py dekodiert wie asfcodec.adl; Hochpass 10 Hz entfernt den Rest-DC
# (steckt auch im Original), Pegel so, dass das MP3 nicht übersteuert.
mkdir -p "$WORK/wav"
ls "$SRC/Cd/music/"*.asf | xargs -P "$(nproc)" -I{} \
sh -c 'python3 -I "$0" "$1" "$2/$(basename "$1" .asf).wav"' "$HERE/asf2wav.py" {} "$WORK/wav"
peak() {
ffmpeg -nostdin -v error -i "$1" -c:a pcm_f32le -f f32le - | python3 -I -c \
'import sys,array; a=array.array("f",sys.stdin.buffer.read()); print(max(max(a),-min(a)))'
}
n=0
while IFS= read -r f; do
n=$((n + 1)); b=$(basename "$f" .wav); out="$OST/$(printf %02d "$n") - $b.mp3"
for gain in -2 -4 -6; do
ffmpeg -nostdin -hide_banner -loglevel error -y -i "$f" \
-af "highpass=f=10:poles=2,volume=${gain}dB" -c:a libmp3lame -q:a 2 \
-metadata title="$b" -metadata album="Ein Königreich für ein Lama (PC-Spiel)" \
-metadata artist="Disney Interactive / Argonaut Games" -metadata date=2000 \
-metadata track="$n" "$out"
python3 -I -c 'import sys; sys.exit(float(sys.argv[1]) > 0.99)' "$(peak "$out")" && break
done
done < <(ls "$WORK/wav/"*.wav | sort -f)
chmod 644 "$OST"/*.mp3
echo ">> Doku"
DOC="$ROOT/usr/share/doc/$PKG"
install -Dm644 "$HERE/files/README.Debian" "$DOC/README.Debian"
install -Dm644 "$HERE/files/copyright" "$DOC/copyright"
echo ">> Paket bauen"
find "$ROOT" -type d -exec chmod 755 {} +
mkdir -p "$ROOT/DEBIAN"
SIZE=$(du -sk --exclude=DEBIAN "$ROOT" | cut -f1)
sed -e "s/@VERSION@/$VER/" -e "s/@SIZE@/$SIZE/" "$HERE/files/control" > "$ROOT/DEBIAN/control"
fakeroot dpkg-deb -Zxz -z3 --build "$ROOT" "$HERE/${PKG}_${VER}_all.deb"
echo ">> Fertig: $HERE/${PKG}_${VER}_all.deb"