hl-pak0-gen/build_pak0.sh

136 lines
2.6 KiB
Bash
Raw Normal View History

#!/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"
2023-05-07 09:37:23 -07:00
FINAL_TEST=$(cat "sums/$1_pak0.sha512" | awk '{ print $1 }')
find_file ()
{
SEARCHNAME=$(basename "${1}")
if [ ! -z "$HL_STEAM_INSTALL" ]
then
find "$HL_STEAM_INSTALL" -type f -name "${SEARCHNAME}" | while read FOUND
do
2023-05-07 09:37:23 -07:00
# GNU vs non GNU
if [ -x "$(command -v sha512sum)" ]
then
CHECK=$(sha256sum "$FOUND" | awk '{ print $1 }')
elif [ -x "$(command -v sha512)" ]
then
CHECK=$(sha256 -q "$FOUND")
else
echo "No tool to validate sha256 sums with!"
exit 2
fi
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
return
fi
fi
find "./_tmp" -type f -name "${SEARCHNAME}" | while read FOUND
do
2023-05-07 09:37:23 -07:00
# GNU vs non GNU
if [ -x "$(command -v sha512sum)" ]
then
CHECK=$(sha256sum "$FOUND" | awk '{ print $1 }')
elif [ -x "$(command -v sha512)" ]
then
CHECK=$(sha256 -q "$FOUND")
else
echo "No tool to validate sha256 sums with!"
exit 2
fi
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
2023-05-07 09:37:23 -07:00
FILE=$(echo ${LINE} | awk '{ print $2 }')
SUM=$(echo ${LINE} | awk '{ print $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
2023-05-07 09:37:23 -07:00
# GNU vs non GNU
if [ -x "$(command -v sha512sum)" ]
then
FINAL_CHECK=$(sha512sum "$PAK0_OUTDIR/pak0.pak" | awk '{ print $1 }')
elif [ -x "$(command -v sha512)" ]
then
FINAL_CHECK=$(sha512 -q "$PAK0_OUTDIR/pak0.pak")
else
echo "No tool to validate sha512 sums with!"
exit 2
fi
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"