This commit is contained in:
Frank Harris 2026-07-02 18:10:41 -05:00
parent 2d16aeb91a
commit 911c63c250
10605 changed files with 2485 additions and 2340 deletions

View file

@ -1,27 +1,27 @@
#!/bin/bash
#
#
# A wrapper script for the OGP agent perl script.
# A wrapper script for the GSP agent perl script.
# Performs auto-restarting of the agent on crash. You can
# extend this to log crashes and more.
#
# The ogp_agent script should be at the top level of the agent tree
# The gsp_agent script should be at the top level of the agent tree
# Make sure we are in that directory since the script assumes this is the case
#####################
# Important VARS #
#####################
AGENTDIR="/OGP"
AGENTDIR="/GSP"
BASH_PREFS_CONF="$AGENTDIR/Cfg/bash_prefs.cfg"
REPONAME=OGP-Agent-Windows
GitHubUsername="OpenGamePanel"
REPONAME=GSP-Agent-Windows
GitHubUsername="GameServerPanel"
#####################
# FUNCTIONS #
#####################
setupOGPAndReadBashPrefs(){
setupGSPAndReadBashPrefs(){
# Find CURL
if [ -z "$CURL" -o -z "$UNZIP" ]; then
@ -29,7 +29,7 @@ setupOGPAndReadBashPrefs(){
fi
chmod -Rf 770 $AGENTDIR
find $AGENTDIR -type f -print | xargs chmod ug=rw
find $AGENTDIR -type f -print | xargs chmod ug=rw
if [ -d "$AGENTDIR/steamcmd" ]; then
find $AGENTDIR/steamcmd -iname \*.dll -exec chmod +x {} \;
find $AGENTDIR/steamcmd -iname \*.exe -exec chmod +x {} \;
@ -37,9 +37,9 @@ setupOGPAndReadBashPrefs(){
if [ -d "$AGENTDIR/screenlogs" ]; then
chmod -Rf ug=rwx $AGENTDIR/screenlogs
fi
chmod +x $AGENTDIR/ogp_agent.pl &> /dev/null
chmod +x $AGENTDIR/gsp_agent.pl &> /dev/null
chmod +x $AGENTDIR/agent_conf.sh &> /dev/null
chmod +x /usr/bin/ogp_agent &> /dev/null
chmod +x /usr/bin/gsp_agent &> /dev/null
# Should we perform an automatic update?
if [ -e $BASH_PREFS_CONF ]
@ -49,35 +49,35 @@ setupOGPAndReadBashPrefs(){
then
AUTO_UPDATE="yes"
fi
if [ "X$run_pureftpd" == "X0" ]
then
RUN_PUREFTPD="no"
else
RUN_PUREFTPD="yes"
fi
if [ "X$ftp_ip" != "X" ]
then
FTP_IP="$ftp_ip"
else
FTP_IP="0.0.0.0"
fi
if [ "X$ftp_port" != "X" ]
then
FTP_PORT="$ftp_port"
else
FTP_PORT="21"
fi
if [ "X$ftp_pasv_range" != "X" ]
then
FTP_PASV_STRING="-p $ftp_pasv_range"
else
FTP_PASV_STRING=""
fi
# Use custom github update address
if [ ! -z "$github_update_username" ]; then
if [ -f "$CURL" -a -x "$CURL" ] && [ -f "$UNZIP" -a -x "$UNZIP" ]; then
@ -87,7 +87,7 @@ setupOGPAndReadBashPrefs(){
fi
fi
fi
else
AUTO_UPDATE="yes"
RUN_PUREFTPD="yes"
@ -100,7 +100,7 @@ setupOGPAndReadBashPrefs(){
echo
echo
echo "************** WARNING ***************"
echo "Running the OGP agent as root "
echo "Running the GSP agent as root "
echo "is highly discouraged. It is generally"
echo "unnecessary to use root privileges to "
echo "execute the agent. "
@ -116,17 +116,17 @@ setupOGPAndReadBashPrefs(){
fi
}
ogpGitCleanup(){
gspGitCleanup(){
echo "Cleaning up..."
rm -Rf ${REPONAME}-* &> /dev/null
if [ -e "ogp_agent_latest.zip" ]; then
rm -f "ogp_agent_latest.zip"
if [ -e "gsp_agent_latest.zip" ]; then
rm -f "gsp_agent_latest.zip"
fi
}
init() {
RESTART="yes"
AGENT="$AGENTDIR/ogp_agent.pl"
AGENT="$AGENTDIR/gsp_agent.pl"
TIMEOUT=10 # time to wait after a crash (in seconds)
PID_FILE=""
while test $# -gt 0; do
@ -135,7 +135,7 @@ init() {
PID_FILE="$2"
PID_FILE_SET=1
echo $$ > $PID_FILE
shift ;;
shift ;;
esac
shift
done
@ -183,20 +183,20 @@ update() {
fi
cd tmp
REVISION=`curl -Lks https://github.com/${GitHubUsername}/${REPONAME}/commits/master.atom | grep -Eo "([a-f0-9]{40})" | head -n 1`
curl -Os https://raw.githubusercontent.com/${GitHubUsername}/${REPONAME}/${REVISION}/bin/ogp_agent
currentOGPAgentRunContent=$(cat "./ogp_agent")
# Check to make sure ogp_agent downloaded successfully from GitHub before we attempt to replace it.
curl -Os https://raw.githubusercontent.com/${GitHubUsername}/${REPONAME}/${REVISION}/bin/gsp_agent
currentGSPAgentRunContent=$(cat "./gsp_agent")
# Check to make sure gsp_agent downloaded successfully from GitHub before we attempt to replace it.
# This should fix random 404 people have been experiencing
if [ -s "./ogp_agent" ] && [ "$(echo "$currentOGPAgentRunContent" | head -n 1)" != "404: Not Found" ] && [ ! -z "$(echo "$currentOGPAgentRunContent" | grep "ogp_agent.pl")" ]; then
diff ./ogp_agent /bin/ogp_agent &>/dev/null
if [ -s "./gsp_agent" ] && [ "$(echo "$currentGSPAgentRunContent" | head -n 1)" != "404: Not Found" ] && [ ! -z "$(echo "$currentGSPAgentRunContent" | grep "gsp_agent.pl")" ]; then
diff ./gsp_agent /bin/gsp_agent &>/dev/null
if test $? -ne 0; then
cp -f ./ogp_agent /bin/ogp_agent &> /dev/null
cp -f ./gsp_agent /bin/gsp_agent &> /dev/null
if test $? -eq 0; then
cd /bin
chmod ugo+x ogp_agent 2>/dev/null
chmod ugo+x gsp_agent 2>/dev/null
echo "`date`: The agent updater has been changed, relaunching..."
rm -Rf tmp
/bin/ogp_agent
/bin/gsp_agent
exit 0
fi
fi
@ -209,35 +209,35 @@ update() {
HEAD=$(curl -L -Os --head -w "%{http_code}" "$URL")
if [ "$HEAD" == "200" ]; then
echo "Updating agent using curl."
curl -L -s "$URL" -o "ogp_agent_latest.zip"
curl -L -s "$URL" -o "gsp_agent_latest.zip"
if test $? -ne 0; then
echo "`date`: curl failed to download the update package."
else
unzip -oq "ogp_agent_latest.zip"
unzip -oq "gsp_agent_latest.zip"
if test $? -ne 0; then
echo "`date`: Unable to unzip the update package."
ogpGitCleanup
gspGitCleanup
else
cd ${REPONAME}-${REVISION}
cp -avf OGP/* $AGENTDIR/. &> /dev/null
cp -avf GSP/* $AGENTDIR/. &> /dev/null
CP_APP_RET=$?
cp -avf bin/* /usr/bin/. &> /dev/null
CP_BIN_RET=$?
if [ $CP_APP_RET -ne 0 -o $CP_BIN_RET -ne 0 ]; then
echo "`date`: The agent files cannot be overwritten."
cd ..
ogpGitCleanup
gspGitCleanup
echo "Agent update failed."
else
if test ! -e "$AGENTDIR/Cfg/Preferences.pm"; then
cp -f Cfg/Preferences.pm $AGENTDIR/Cfg/Preferences.pm &> /dev/null
fi
echo "Fixing permissions..."
chmod +x $AGENTDIR/ogp_agent.pl &> /dev/null
chmod +x $AGENTDIR/gsp_agent.pl &> /dev/null
chmod +x $AGENTDIR/agent_conf.sh &> /dev/null
chmod +x /usr/bin/ogp_agent &> /dev/null
chmod +x /usr/bin/gsp_agent &> /dev/null
cd ..
ogpGitCleanup
gspGitCleanup
sed -i "s/version.*/version => '${REVISION}',/" $AGENTDIR/Cfg/Config.pm
echo "Agent updated successfully."
fi
@ -248,15 +248,15 @@ update() {
echo "Try again later."
fi
fi
else
echo "Update failed."
fi
fi
return 0
}
run() {
# Runs the update and agent
update
@ -267,14 +267,14 @@ run() {
do
# Run
cd $AGENTDIR
./ogp_agent.pl
./gsp_agent.pl
echo "`date`: Agent restart in $TIMEOUT seconds"
# don't thrash the hard disk if the agent dies, wait a little
sleep $TIMEOUT
done # while true
else
cd $AGENTDIR
./ogp_agent.pl
./gsp_agent.pl
fi
}
@ -291,11 +291,11 @@ quit() {
case "$exitcode" in
0)
echo "`date`: OGP Agent Quit" ;;
echo "`date`: GSP Agent Quit" ;;
2)
syntax ;;
*)
echo "`date`: OGP Agent Failed" ;;
echo "`date`: GSP Agent Failed" ;;
esac
# Remove pid file
@ -315,13 +315,13 @@ quit() {
PATH=/usr/local/bin:/usr/bin:${PATH}
# Start PureFTPD if OGP has been configured to manage FTP users
# Start PureFTPD if GSP has been configured to manage FTP users
if [ ! -z "$RUN_PUREFTPD" ] && [ "$RUN_PUREFTPD" == "yes" ]; then
/usr/sbin/pure-ftpd.exe -S ${FTP_IP},${FTP_PORT} ${FTP_PASV_STRING} -lpuredb:/etc/pureftpd.pdb -g /var/run/pure-ftpd.pid &
fi
# Setup OGP and Read Preferences
setupOGPAndReadBashPrefs
# Setup GSP and Read Preferences
setupGSPAndReadBashPrefs
# Initialise
init $*