#!/bin/bash

cd "/opt/bin32-enemy-territory/pb/"
./pbweb.x86 $*
# Change permissions on files in dll folder to suppress PunkBuster errors
chmod 775 dll/*
# Move updated PunkBuster files
if [ -e "/opt/bin32-enemy-territory/pb/pbclnew.so" ]; then
    mv -f /opt/bin32-enemy-territory/pb/pbcl.so /opt/bin32-enemy-territory/pb/pbclold.so
    mv -f /opt/bin32-enemy-territory/pb/pbclnew.so /opt/bin32-enemy-territory/pb/pbcl.so
fi

if [ -e "/opt/bin32-enemy-territory/pb/pbclsnew.so" ]; then
    mv -f /opt/bin32-enemy-territory/pb/pbcls.so /opt/bin32-enemy-territory/pb/pbclsold.so
    mv -f /opt/bin32-enemy-territory/pb/pbclsnew.so /opt/bin32-enemy-territory/pb/pbcls.so
fi

if [ -e "/opt/bin32-enemy-territory/pb/pbsvnew.so" ]; then
    mv -f /opt/bin32-enemy-territory/pb/pbsv.so /opt/bin32-enemy-territory/pb/pbsvold.so
    mv -f /opt/bin32-enemy-territory/pb/pbsvnew.so /opt/bin32-enemy-territory/pb/pbsv.so
fi

exit $?

