#!/bin/sh

cleanup() {
	# Cleanup
	echo -e "\nCleanup\n"
	rm -rf __MACOSX
	rm -rf q3-server
	rm -rf quake3-latest-pk3s
	rm ioquake3_notarized.zip
	rm quake3-latest-pk3s.zip
}

trap cleanup EXIT

# Create necessary subdirectories
mkdir /Applications/ioquake3
mkdir /Applications/ioquake3/baseq3 /Applications/ioquake3/missionpack

# Getting ioquake3
echo -e "\nGetting ioquake3 binary\n"
curl -o ioquake3_notarized.zip https://files.ioquake3.org/ioquake3_notarized.zip
unzip -q ioquake3_notarized.zip
mv ioquake3.app /Applications/ioquake3/

# Getting pak0.pk3
echo -e "\nGetting pak0.pk3\n"
git clone https://github.com/nrempel/q3-server
mv q3-server/baseq3/pak0.pk3 /Applications/ioquake3/baseq3/

# Getting patch data
echo -e "\nGetting patched pk3s\n"
curl -o quake3-latest-pk3s.zip https://files.ioquake3.org/quake3-latest-pk3s.zip
unzip -q quake3-latest-pk3s.zip
mv quake3-latest-pk3s/missionpack/* /Applications/ioquake3/missionpack/
mv quake3-latest-pk3s/baseq3/* /Applications/ioquake3/baseq3/

cleanup
