Przeglądaj źródła

First test agent updating from GitHub

DieFeM 9 lat temu
rodzic
commit
3688ee2bad
1 zmienionych plików z 27 dodań i 22 usunięć
  1. 27 22
      ogp_agent_run

+ 27 - 22
ogp_agent_run

@@ -9,18 +9,17 @@
 # Make sure we are in that directory since the script assumes this is the case
 # Make sure we are in that directory since the script assumes this is the case
 AGENTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 AGENTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 BASH_PREFS_CONF="$AGENTDIR/Cfg/bash_prefs.cfg" 
 BASH_PREFS_CONF="$AGENTDIR/Cfg/bash_prefs.cfg" 
-chmod -Rf 770 $AGENTDIR
-find $AGENTDIR -type f -print | xargs chmod ug=rw 
+chmod -Rf ug+rw $AGENTDIR 2>/dev/null
 if [ -d "$AGENTDIR/steamcmd" ]; then
 if [ -d "$AGENTDIR/steamcmd" ]; then
-	chmod +x $AGENTDIR/steamcmd/linux32/*
-	chmod +x $AGENTDIR/steamcmd/*.sh
+	chmod ug+x $AGENTDIR/steamcmd/linux32/* 2>/dev/null
+	chmod ug+x $AGENTDIR/steamcmd/*.sh 2>/dev/null
 fi
 fi
 if [ -d "$AGENTDIR/screenlogs" ]; then
 if [ -d "$AGENTDIR/screenlogs" ]; then
 	chmod -Rf ug=rwx $AGENTDIR/screenlogs
 	chmod -Rf ug=rwx $AGENTDIR/screenlogs
 fi
 fi
-chmod +x $AGENTDIR/ogp_agent.pl
-chmod +x $AGENTDIR/ogp_agent_run
-chmod +x $AGENTDIR/agent_conf.sh
+chmod ug+x $AGENTDIR/ogp_agent.pl 2>/dev/null
+chmod ug+x $AGENTDIR/ogp_agent_run 2>/dev/null
+chmod ug+x $AGENTDIR/agent_conf.sh 2>/dev/null
 
 
 if test `id -u` -eq 0; then
 if test `id -u` -eq 0; then
 	echo
 	echo
@@ -94,7 +93,6 @@ init() {
 
 
 syntax () {
 syntax () {
 	# Prints script syntax
 	# Prints script syntax
-
 	echo "Syntax:"
 	echo "Syntax:"
 	echo "$0"
 	echo "$0"
 }
 }
@@ -112,26 +110,35 @@ checkDepends() {
 	else
 	else
 		echo "INFO: Located unzip: $UNZIP"
 		echo "INFO: Located unzip: $UNZIP"
 	fi
 	fi
+	GIT=`which git 2>/dev/null`
+	if test "$?" -gt 0; then
+		echo "WARNING: Failed to locate git binary."
+	else
+		echo "INFO: Located git: $GIT"
+	fi
 }
 }
 
 
 update() {
 update() {
 	# Run the update
 	# Run the update
-	expires=$(LC_ALL=en_US.utf8 date --date='TZ="GMT" @'`expr $(date +"%s") + 31536000000`'' +"%a, %d-%b-%Y %H:%M:%S GMT")
 	if test -n "$AUTO_UPDATE"; then
 	if test -n "$AUTO_UPDATE"; then
 		if [ -z "$CURL" -o -z "$UNZIP" ]; then
 		if [ -z "$CURL" -o -z "$UNZIP" ]; then
 			checkDepends
 			checkDepends
 		fi
 		fi
 		if [ -f "$CURL" -a -x "$CURL" ] && [ -f "$UNZIP" -a -x "$UNZIP" ]; then
 		if [ -f "$CURL" -a -x "$CURL" ] && [ -f "$UNZIP" -a -x "$UNZIP" ]; then
 			cd $AGENTDIR
 			cd $AGENTDIR
-			mkdir tmp
+			if [ ! -d tmp ]; then
+				mkdir tmp
+			fi
 			cd tmp
 			cd tmp
-			curl -b "FreedomCookie=true;path=/;expires=$expires" -Os http://svn.code.sf.net/p/hldstart/svn/trunk/agent/ogp_agent_run
+			REPONAME=OGP-Agent-Windows
+			REVISION=`git ls-remote --heads https://github.com/OpenGamePanel/${REPONAME}.git | grep -owE "^[^?\s]+"`
+			curl -Os https://raw.githubusercontent.com/OpenGamePanel/${REPONAME}/${REVISION}/OGP/ogp_agent_run
 			diff ./ogp_agent_run $AGENTDIR/ogp_agent_run &>/dev/null
 			diff ./ogp_agent_run $AGENTDIR/ogp_agent_run &>/dev/null
 			if test $? -ne 0; then
 			if test $? -ne 0; then
 				cp -f ./ogp_agent_run $AGENTDIR/ogp_agent_run &> /dev/null
 				cp -f ./ogp_agent_run $AGENTDIR/ogp_agent_run &> /dev/null
 				if test $? -eq 0; then
 				if test $? -eq 0; then
 					cd $AGENTDIR
 					cd $AGENTDIR
-					chmod +x ogp_agent_run
+					chmod ug+x ogp_agent_run 2>/dev/null
 					echo "`date`: The agent updater has been changed, relaunching..."
 					echo "`date`: The agent updater has been changed, relaunching..."
 					rm -Rf tmp
 					rm -Rf tmp
 					./ogp_agent_run
 					./ogp_agent_run
@@ -139,33 +146,31 @@ update() {
 				fi
 				fi
 			fi
 			fi
 			cd $AGENTDIR
 			cd $AGENTDIR
-			rm -Rf tmp
 			CURRENT=$(cat $AGENTDIR/Cfg/Config.pm | grep version | grep -Eo '[0-9]{1,6}')
 			CURRENT=$(cat $AGENTDIR/Cfg/Config.pm | grep version | grep -Eo '[0-9]{1,6}')
-			REVISION=$(curl -L -b "FreedomCookie=true;path=/;expires=$expires" -s https://sourceforge.net/projects/ogpextras/rss?path=/Alternative-Snapshot\&limit=3 | grep -m 1 "title.*hldstart-code-" | grep -o -P '(?<=hldstart-code-).*(?=.zip)')
 			if [ "$CURRENT" == "$REVISION" ]; then
 			if [ "$CURRENT" == "$REVISION" ]; then
 				echo "The agent is up to date."
 				echo "The agent is up to date."
 			else
 			else
-				URL=https://${MIRROR}.dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/linux-agent-${REVISION}.zip
-				HEAD=$(curl -L --insecure -b "FreedomCookie=true;path=/;expires=$expires" -Os --head -w "%{http_code}" "$URL")
+				URL=https://github.com/OpenGamePanel/${REPONAME}/archive/${REVISION}.zip
+				HEAD=$(curl -L -Os --head -w "%{http_code}" "$URL")
 				if [ "$HEAD" == "200" ]; then
 				if [ "$HEAD" == "200" ]; then
 					echo "Updating agent using curl."
 					echo "Updating agent using curl."
-					curl -L --insecure -b "FreedomCookie=true;path=/;expires=$expires" -Os $URL
+					curl -L -Os $URL
 					if test $? -ne 0; then
 					if test $? -ne 0; then
 						echo "`date`: curl failed to download the update package."
 						echo "`date`: curl failed to download the update package."
 					else
 					else
-						unzip -oq linux-agent-${REVISION}.zip
+						unzip -oq "${REVISION}.zip"
 						if test $? -ne 0; then
 						if test $? -ne 0; then
 							echo "`date`: Unable to unzip the update package."
 							echo "`date`: Unable to unzip the update package."
 							echo "cleaning up..."
 							echo "cleaning up..."
-							rm -Rf linux-agent-* &> /dev/null
+							rm -Rf ${REPONAME}-* &> /dev/null
 						else
 						else
-							cd linux-agent-${REVISION}
+							cd ${REPONAME}-${REVISION}
 							cp -avf Schedule Time FastDownload php-query ogp_agent.pl ogp_screenrc ogp_agent_run agent_conf.sh $AGENTDIR &> /dev/null
 							cp -avf Schedule Time FastDownload php-query ogp_agent.pl ogp_screenrc ogp_agent_run agent_conf.sh $AGENTDIR &> /dev/null
 							if test $? -ne 0; then
 							if test $? -ne 0; then
 								echo "`date`: The agent files cannot be overwritten."
 								echo "`date`: The agent files cannot be overwritten."
 								echo "Cleaning up..."
 								echo "Cleaning up..."
 								cd ..
 								cd ..
-								rm -Rf linux-agent-* &> /dev/null
+								rm -Rf ${REPONAME}-* &> /dev/null
 								echo "Agent update failed."
 								echo "Agent update failed."
 							else
 							else
 								if test ! -d "$AGENTDIR/IspConfig"; then
 								if test ! -d "$AGENTDIR/IspConfig"; then
@@ -183,7 +188,7 @@ update() {
 								chmod ug+x $AGENTDIR/agent_conf.sh &> /dev/null
 								chmod ug+x $AGENTDIR/agent_conf.sh &> /dev/null
 								echo "Cleaning up..."
 								echo "Cleaning up..."
 								cd ..
 								cd ..
-								rm -Rf linux-agent-* &> /dev/null
+								rm -Rf ${REPONAME}-* &> /dev/null
 								sed -i "s/version.*/version => 'v${REVISION}',/" $AGENTDIR/Cfg/Config.pm
 								sed -i "s/version.*/version => 'v${REVISION}',/" $AGENTDIR/Cfg/Config.pm
 								echo "Agent updated successfully."
 								echo "Agent updated successfully."
 							fi
 							fi