hl-pak0-gen/build_pak0.sh

89 lines
No EOL
1.6 KiB
Bash
Executable file

#!/bin/sh
# builds a pak0.pak file for a respective gamedir
export PATH=$(pwd)/_bin:$PATH;
set -e
usage ()
{
echo Usage: `basename $0` gamedir >&2
exit 2
}
if [ $# -lt 1 ]
then
usage
fi
PAK0_OUTDIR="$(pwd)/_build/halflife/$1-pak0"
FINAL_TEST=$(cat "sums/$1_pak0.sha512" | cut -d ' ' -f 1)
find_file ()
{
SEARCHNAME=$(basename "${1}")
#echo "Looking for $SEARCHNAME"
find "./_tmp" -type f -name "${SEARCHNAME}" | while read FOUND
do
CHECK=$(sha256sum "${FOUND}" | cut -d ' ' -f 1)
#echo "$CHECK == $2"
if [ "${CHECK}" = "$2" ]
then
mkdir -p "${PAK0_OUTDIR}/$(dirname $1)"
cp -v "${FOUND}" "${PAK0_OUTDIR}/$1"
exit 0
fi
done
if [ ! -f "${PAK0_OUTDIR}/$1" ]
then
echo "${1}" >> "./_build/missing-$3-pak0.txt"
fi
}
# clean up
if [ -d "$PAK0_OUTDIR" ]
then
rm -rf "$PAK0_OUTDIR"
fi
mkdir -p "$PAK0_OUTDIR"
if [ -f "./_build/missing-$1-pak0.txt" ]
then
rm "./_build/missing-$1-pak0.txt"
fi
while read LINE
do
FILE=$(echo ${LINE} | cut -d ' ' -f 2)
SUM=$(echo ${LINE} | cut -d ' ' -f 1)
find_file ${FILE} $SUM $1
done < "games/$1-pak0.sha256"
# move the qfiles script over
mkdir -p "$PAK0_OUTDIR/src/"
cp -v "games/$1.dat" "$PAK0_OUTDIR/src/files.dat"
cd "$PAK0_OUTDIR/src/"
qfiles -pak 0
FINAL_CHECK=$(sha512sum "$PAK0_OUTDIR/pak0.pak" | cut -d ' ' -f 1)
echo "Desired SHA512: ${FINAL_TEST}"
echo "Generated SHA512: ${FINAL_CHECK}"
if [ "${FINAL_CHECK}" = "${FINAL_TEST}" ]
then
echo "$1's pak0.pak has been built and verified!"
else
echo "$1's pak0.pak FAILED the check. Will not pass purity test."
fi
cd "$PAK0_OUTDIR/../"
mkdir -p "./$1"
mv "$PAK0_OUTDIR/pak0.pak" "./$1/pak0.pak"
rm -rf "$PAK0_OUTDIR"