Procházet zdrojové kódy

Añadido archivos de instalación y configuración

DieFeM před 12 roky
rodič
revize
d2b6f7dac7
2 změnil soubory, kde provedl 441 přidání a 0 odebrání
  1. 263 0
      bin/ogp_agent
  2. 178 0
      bin/ogp_install

+ 263 - 0
bin/ogp_agent

@@ -0,0 +1,263 @@
+#!/bin/bash
+#
+#
+#	A wrapper script for the OGP agent perl script.
+#	Performs auto-restarting of the agent on crash. You can
+#	extend this to log crashes and more.
+#
+# The ogp_agent_run 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
+AGENTDIR="/OGP"
+BASH_PREFS_CONF="$AGENTDIR/Cfg/bash_prefs.cfg" 
+
+# Should we perform an automatic update?
+if [ -e $BASH_PREFS_CONF ]
+then
+	source "$BASH_PREFS_CONF"
+	if [ "$agent_auto_update" -eq "1" ]
+	then
+		AUTO_UPDATE="yes"
+	fi
+	
+	if [ "$ogp_manages_ftp" -eq "0" ]
+	then
+		OGP_MAN_FTP="no"
+	else
+		OGP_MAN_FTP="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
+	
+	if [ -z "$sf_update_mirror" ]
+	then
+		MIRROR="master"
+	else
+		MIRROR=$sf_update_mirror
+	fi
+else
+	AUTO_UPDATE="yes"
+	MIRROR="master"
+	OGP_MAN_FTP="yes"
+	FTP_IP="0.0.0.0"
+	FTP_PORT="21"
+	FTP_PASV_STING=""
+fi
+
+if test `id -u` -eq 0; then
+	echo
+	echo
+	echo "************** WARNING ***************"
+	echo "Running the OGP agent as root  "
+	echo "is highly discouraged. It is generally"
+	echo "unnecessary to use root privileges to "
+	echo "execute a dedicated server.         "
+	echo "**************************************"
+	echo
+	echo
+	timeout=10
+	while test $timeout -gt 0; do
+		echo -n "The agent will continue to launch in $timeout seconds\r"
+		timeout=`expr $timeout - 1`
+		sleep 1
+	done
+fi
+
+init() {
+	RESTART="yes"
+	AGENT="$AGENTDIR/ogp_agent.pl"
+	TIMEOUT=10 # time to wait after a crash (in seconds)
+	PID_FILE=""
+	while test $# -gt 0; do
+		case "$1" in
+		"-pidfile")
+			PID_FILE="$2"
+			PID_FILE_SET=1
+			echo $$ > $PID_FILE
+			shift ;;			
+		esac
+		shift
+	done
+
+	if test ! -f "$AGENT"; then
+		echo "ERROR: '$AGENT' not found, exiting"
+		quit 1
+	elif test ! -x "$AGENT"; then
+		# Could try chmod but dont know what we will be
+		# chmoding so just fail.
+		echo "ERROR: '$AGENT' not executable, exiting"
+		quit 1
+	fi
+}
+
+syntax () {
+	# Prints script syntax
+
+	echo "Syntax:"
+	echo "$0"
+}
+
+checkDepends() {
+	CURL=`which curl 2>/dev/null`
+	if test "$?" -gt 0; then
+		echo "WARNING: Failed to locate curl binary."
+	else
+		echo "INFO: Located curl: $CURL"
+	fi
+	UNZIP=`which unzip 2>/dev/null`
+	if test "$?" -gt 0; then
+		echo "WARNING: Failed to locate unzip binary."
+	else
+		echo "INFO: Located unzip: $UNZIP"
+	fi
+}
+
+update() {
+	# Run the subversion update
+	if test -n "$AUTO_UPDATE"; then
+		if [ -z "$CURL" -o -z "$UNZIP" ]; then
+			checkDepends
+		fi
+		if [ -f "$CURL" -a -x "$CURL" ] && [ -f "$UNZIP" -a -x "$UNZIP" ]; then
+			CURRENT=$(cat $AGENTDIR/Cfg/Config.pm | grep version | grep -oh [0-9]*)
+			REVISION=$(curl -s http://svn.code.sf.net/p/hldstart/code/trunk/ | grep "<h2>" | awk '{print $4}' | tr -d [:punct:])
+			if [ "$CURRENT" == "$REVISION" ]; then
+				echo "The agent is up to date."
+			else
+				URL=http://${MIRROR}.dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/win-agent-${REVISION}.zip
+				HEAD=$(curl -Os --head -w "%{http_code}" "$URL")
+				if [ "$HEAD" == "200" ]; then
+					echo "Updating server using curl."
+					curl -Os $URL
+					unzip -q win-agent-${REVISION}.zip
+					sed -i "s/version.*/version => 'v${REVISION}',/" $AGENTDIR/Cfg/Config.pm
+					if test $? -ne 0; then
+						echo "`date`: subversion Update failed, ignoring."
+						return 0
+					fi
+					cd win-agent-${REVISION}
+					cp -avf OGP/* $AGENTDIR/. &> /dev/null
+					chmod +x $AGENTDIR/ogp_agent.pl &> /dev/null
+					chmod +x $AGENTDIR/ogp_agent_run &> /dev/null
+					cp -avf bin/* /usr/bin/. &> /dev/null
+					chmod +x /usr/bin/ogp_agent &> /dev/null
+					chmod +x /usr/bin/ogp_install &> /dev/null
+					if test ! -e "$AGENTDIR/Cfg/Preferences.pm"; then
+						cd Cfg
+						cp -avf Preferences.pm $AGENTDIR/Cfg &> /dev/null
+						cd ..
+					fi
+					cd ..
+					rm -Rf win-agent-${REVISION} &> /dev/null
+				else
+					echo "There is a update available (${REVISION}) but the download source is not ready.";
+					echo "Try again later."
+				fi
+			fi
+			
+		else
+			if [ !-f "$CURL" ]; then
+				echo "WARNING: Could not locate curl binary: ${CURL}."
+			fi
+			if [ !-f "$UNZIP" ]; then
+				echo "WARNING: Could not locate unzip binary: ${UNZIP}."
+			fi
+			echo "Update failed."
+		fi
+	fi
+	
+	return 0
+}
+	
+run() {
+	# Runs the subversion update and server
+	if test -n "$RESTART" ; then
+		echo "Server will auto-restart if there is a crash."
+
+		#loop forever
+		while true
+		do
+			# Update
+			update
+			# Run
+			cd $AGENTDIR
+			./ogp_agent.pl
+			retval=$?
+			if test $retval -eq 0 && test -z "$AUTO_UPDATE"; then
+				break; # if 0 is returned then just quit
+			fi
+			echo "`date`: Server restart in $TIMEOUT seconds"
+			# don't thrash the hard disk if the server dies, wait a little
+			sleep $TIMEOUT
+		done # while true
+	else
+		update
+		cd $AGENTDIR
+		./ogp_agent.pl
+	fi
+}
+
+quit() {
+	# Exits with the give error code, 1
+	# if none specified.
+	# exit code 2 also prints syntax
+	exitcode="$1"
+
+	# default to failure
+	if test -z "$exitcode"; then
+		exitcode=1
+	fi
+
+	case "$exitcode" in
+	0)
+		echo "`date`: OGP Agent Quit" ;;
+	2)
+		syntax ;;
+	*)
+		echo "`date`: OGP Agent Failed" ;;
+	esac
+
+	# Remove pid file
+	if test -n "$PID_FILE" && test -f "$PID_FILE" ; then
+		# The specified pid file
+		rm -f $PID_FILE
+	fi
+
+	# reset SIGINT and then kill ourselves properly
+	trap - 2
+	kill -2 $$
+}
+
+PATH=/usr/local/bin:/usr/bin:${PATH}
+
+# Start PureFTPD if OGP has been configured to manage FTP users
+if [ ! -z "$OGP_MAN_FTP" ] && [ "$OGP_MAN_FTP" == "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
+chown -Rf `whoami` $AGENTDIR
+# Initialise
+init $*
+
+# Run
+run
+
+# Quit normally
+quit 0

+ 178 - 0
bin/ogp_install

@@ -0,0 +1,178 @@
+#!/bin/bash
+
+#
+# OGP - Open Game Panel
+# Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
+#
+# http://www.opengamepanel.org/
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+agent_home="/OGP"
+
+checkDepends() {
+	CURL=`which curl 2>/dev/null`
+	if test "$?" -gt 0; then
+		echo "FAILURE: Failed to locate curl binary."
+		exit 1
+	else
+		echo "INFO: Located curl: $CURL"
+	fi
+	UNZIP=`which unzip 2>/dev/null`
+	if test "$?" -gt 0; then
+		echo "FAILURE: Failed to locate unzip binary."
+		exit 1
+	else
+		echo "INFO: Located unzip: $UNZIP"
+	fi
+}
+
+checkDepends
+
+REVISION=$(curl -s http://svn.code.sf.net/p/hldstart/code/trunk/ | grep "<h2>" | awk '{print $4}' | tr -d [:punct:])
+
+URLLIN=http://master.dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/linux-agent-${REVISION}.zip
+URLWIN=http://master.dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/win-agent-${REVISION}.zip
+
+HEADLIN=$(curl -Os --head -w "%{http_code}" "$URLLIN")
+HEADWIN=$(curl -Os --head -w "%{http_code}" "$URLWIN")
+
+if [ "$HEADLIN" == "200" -a "$HEADWIN" == "200" ]; then
+
+	if [ ! -d ${agent_home} ]; then
+		mkdir ${agent_home}
+	fi
+	
+	echo "Downloading and installing OGP agent files."
+	
+	curl -Os $URLLIN
+	unzip -q linux-agent-${REVISION}.zip
+	cd linux-agent-${REVISION}
+	cp -Rf * ${agent_home}/. &> /dev/null
+	rm -f ${agent_home}/ogp_agent.pl ${agent_home}/ogp_agent_run &> /dev/null
+	cd ..
+	
+	curl -Os $URLWIN
+	unzip -q win-agent-${REVISION}.zip
+	cd win-agent-${REVISION}
+	cp -f OGP/* ${agent_home}/. &> /dev/null
+	chmod +x ${agent_home}/ogp_agent.pl &> /dev/null
+	chmod +x ${agent_home}/ogp_agent_run &> /dev/null
+	cp -f bin/* /usr/bin/. &> /dev/null
+	chmod +x /usr/bin/ogp_agent &> /dev/null
+	chmod +x /usr/bin/ogp_install &> /dev/null
+	cd ..
+	
+	echo "Removing temporary files."
+	
+	rm -Rf win-agent-${REVISION}* linux-agent-${REVISION}* &> /dev/null
+else
+	echo "Unable to download agent files."
+	echo "Try again later by running the command ogp_install."
+	exit 1
+fi
+
+AE=`perldoc -l Archive::Extract &>/dev/null`
+if test "$?" -gt 0; then
+	cpan -i Archive::Extract
+fi
+
+if [ ! -d ${agent_home}/tmp ]; then
+	mkdir ${agent_home}/tmp
+fi
+
+# Run the configuration script
+chmod +x ${agent_home}/agent_conf.sh
+bash ${agent_home}/agent_conf.sh
+
+bashprefsfile=${agent_home}/Cfg/bash_prefs.cfg
+
+readonly DEFAULT_IP=0.0.0.0
+readonly DEFAULT_FTP_PORT=21
+readonly DEFAULT_FTP_PASV_RANGE=40000:50000
+
+echo;
+echo -n "Should Open Game Panel create and manage FTP accounts for panel users (FTP users, permissions, etc)? [yes|no]: "
+read manage_ftp
+if [ "${manage_ftp}" != "yes" ] && [ "${manage_ftp}" != "no" ]; then
+	ogpManagesFTP=1
+else
+	if [ "${manage_ftp}" == "no" ]; then
+		ogpManagesFTP=0
+	else
+		ogpManagesFTP=1
+	fi
+fi
+
+echo;
+if [ "$ogpManagesFTP" == "1" ]
+then
+	echo
+	echo "Set the listen port for the FTP server. The default should be fine for everyone."
+	echo "However, if you want to change it that can be done here, otherwise just press Enter."
+	echo -n "Set listen port [Default ${DEFAULT_FTP_PORT}]: "
+	read port
+
+	if [ -z "${ftp_port}" ]
+	then 
+		ftp_port=$DEFAULT_FTP_PORT
+	fi
+
+	echo 
+	echo "Set the listen IP for the FTP server."
+	echo "Default is (${DEFAULT_IP}) to bind on all interfaces."
+	echo -n "Set FTP server IP [Default ${DEFAULT_IP}]: "
+	read ip
+
+	if [ -z "${ip}" ]  
+	then 
+		ftp_ip=$DEFAULT_IP
+	fi
+	
+	echo
+	echo "Passive-mode downloads."
+	echo "This is especially useful if the server is behind a firewall."
+	echo -n "Use only ports in the range?(yes|no)[Default no]: "
+	read passive_ftp
+
+	if [ -z "${passive_ftp}" -o "${passive_ftp}" != "yes" ]
+	then 
+		ftp_pasv_range=""
+	else
+		echo "Enter passive ports range separated by colon (<first port>:<last port>)."
+		echo -n "[Default ${DEFAULT_FTP_PASV_RANGE}]: "
+		read ftp_pasv_range
+		if [ -z "${ftp_pasv_range}" ]
+		then 
+			ftp_pasv_range=$DEFAULT_FTP_PASV_RANGE
+		fi
+	fi
+else
+	ftp_port=$DEFAULT_FTP_PORT
+	ftp_ip=$DEFAULT_IP
+	ftp_pasv_range=""
+fi
+
+echo -e "\nogp_manages_ftp=${ogpManagesFTP}\nftp_port=${ftp_port}\nftp_ip=${ftp_ip}\nftp_pasv_range=${ftp_pasv_range}" >> $bashprefsfile
+
+if [ $? != 0 ]
+then
+	failed "Failed to write MISC configuration file used by bash scripts."
+fi
+
+sed -i "s/version.*/version => 'v${REVISION}',/" ${agent_home}/Cfg/Config.pm
+
+ogp_agent