2023-05-06 13:37:28 -07:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# builds a pak0.pak file for a respective gamedir
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
usage ()
|
|
|
|
{
|
|
|
|
echo Usage: `basename $0` gamedir >&2
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]
|
|
|
|
then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
FILES_OUTDIR="$(pwd)/_build/halflife/$1"
|
|
|
|
FILES_MISSING="$(pwd)/_build/missing-$1-loose.txt"
|
|
|
|
|
|
|
|
find_file ()
|
|
|
|
{
|
|
|
|
SEARCHNAME=$(basename "${1}")
|
|
|
|
|
|
|
|
#echo "Looking for $SEARCHNAME"
|
|
|
|
|
|
|
|
find "./_tmp" -type f -name "${SEARCHNAME}" | while read FOUND
|
|
|
|
do
|
2023-05-07 09:39:13 -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
|
2023-05-06 13:37:28 -07:00
|
|
|
|
|
|
|
if [ "${CHECK}" = "$2" ]
|
|
|
|
then
|
|
|
|
mkdir -p "${FILES_OUTDIR}/$(dirname $1)"
|
|
|
|
cp -v "${FOUND}" "${FILES_OUTDIR}/$1"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ! -f "${FILES_OUTDIR}/$1" ]
|
|
|
|
then
|
|
|
|
echo "${1}" >> "$FILES_MISSING"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
find_file_whatever ()
|
|
|
|
{
|
|
|
|
echo "Looking for $1"
|
|
|
|
|
|
|
|
find "./_tmp" -type f -path "*/${2}/${1}*" | while read FOUND
|
|
|
|
do
|
|
|
|
mkdir -p "${FILES_OUTDIR}/$(dirname $1)"
|
|
|
|
cp -v "${FOUND}" "${FILES_OUTDIR}/$1"
|
|
|
|
exit 0
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! -d "$FILES_OUTDIR" ]
|
|
|
|
then
|
|
|
|
echo "Please generate a pak0.pak first."
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$FILES_MISSING" ]
|
|
|
|
then
|
|
|
|
rm -v "$FILES_MISSING"
|
|
|
|
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.sha256"
|
|
|
|
|
|
|
|
# since we don't need to pass purity checks for these
|
|
|
|
# we'll find the next best equivalent
|
|
|
|
while read LINE
|
|
|
|
do
|
|
|
|
FILE=$(echo ${LINE} | cut -d ' ' -f 2)
|
|
|
|
find_file_whatever ${FILE} $1
|
|
|
|
done < "$FILES_MISSING"
|