dnl `uname -m` quoting is a nightmare
dnl <sander> TTimo: You could do:  &#96;uname -a&#96;
changequote([, ])

#!/bin/sh
# post installation script, finalize everything

# The install path is the first argument of the script
install_path="$1"

# Return the appropriate architecture string
function DetectARCH {
	status=1
	case `uname -m` in
		i?86)  echo "x86"
			status=0;;
		*) case `uname -p` in
			powerpc) echo "ppc"
				status=0;;
			*) echo "unknown"
				status=0;;
		esac
	esac
	return $status
}
arch=`DetectARCH`

# Create a wrapper script
cat <<__EOF__ >"$install_path/radiant"
#!/bin/sh
# Needed to make symlinks/shortcuts work.
# Run map editor with some default arguments

cd "$install_path"
radiant="./radiant.$arch"
# gcc 3.x, trying to reduce ABI issues
export LD_LIBRARY_PATH=.:\$LD_LIBRARY_PATH
"\$radiant" \$*
exit \$?
__EOF__

chmod 755 "$install_path/radiant"

# Create a q3map2 wrapper script
cat <<__EOF__ >"$install_path/q3map2"
#!/bin/sh
# Needed to make symlinks/shortcuts work.

cd "$install_path"
q3map2="./q3map2.$arch"
# gcc 3.x, trying to reduce ABI issues
export LD_LIBRARY_PATH=.:\$LD_LIBRARY_PATH
"\$q3map2" \$*
exit \$?
__EOF__

chmod 755 "$install_path/q3map2"

# setup the safe guard
echo "M4_VER_MAJOR" > $install_path/RADIANT_MAJOR
echo "M4_VER_MINOR" > $install_path/RADIANT_MINOR

# why the fuck is openurl.sh not +x by default anyway
chmod 755 "$install_path/openurl.sh"
