Преглед изворни кода

Agent startup/update script improved.

DieFeM пре 12 година
родитељ
комит
3504908730
1 измењених фајлова са 48 додато и 40 уклоњено
  1. 48 40
      bin/ogp_agent

+ 48 - 40
bin/ogp_agent

@@ -8,7 +8,12 @@
 # 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" 
+BASH_PREFS_CONF="$AGENTDIR/Cfg/bash_prefs.cfg"
+chmod -Rf 770 $AGENTDIR
+find $AGENTDIR -type f -print | xargs chmod ug=rw 
+chmod +x $AGENTDIR/ogp_agent.pl &> /dev/null
+chmod +x /usr/bin/ogp_agent &> /dev/null
+chmod +x /usr/bin/ogp_install &> /dev/null
 
 # Should we perform an automatic update?
 if [ -e $BASH_PREFS_CONF ]
@@ -69,7 +74,7 @@ if test `id -u` -eq 0; then
 	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 "execute the agent.         "
 	echo "**************************************"
 	echo
 	echo
@@ -145,28 +150,44 @@ update() {
 				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."
+					echo "Updating agent 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
+						echo "`date`: curl failed to download the update package."
+					else
+						unzip -q win-agent-${REVISION}.zip
+						if test $? -ne 0; then
+							echo "`date`: Unable to unzip the update package."
+							echo "cleaning up..."
+							rm -f win-agent-* &> /dev/null
+						else				
+							cd win-agent-${REVISION}
+							cp -avf OGP/* $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."
+								echo "Cleaning up..."
+								cd ..
+								rm -Rf win-agent-* &> /dev/null
+								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 /usr/bin/ogp_agent &> /dev/null
+								chmod +x /usr/bin/ogp_install &> /dev/null
+								echo "Cleaning up..."
+								cd ..
+								rm -Rf win-agent-* &> /dev/null
+								sed -i "s/version.*/version => 'v${REVISION}',/" $AGENTDIR/Cfg/Config.pm
+								echo "Agent updated successfully."
+							fi
+						fi
 					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."
@@ -174,12 +195,6 @@ update() {
 			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
@@ -188,28 +203,21 @@ update() {
 }
 	
 run() {
-	# Runs the subversion update and server
+	# Runs the update and agent
+	update
 	if test -n "$RESTART" ; then
-		echo "Server will auto-restart if there is a crash."
-
+		echo "Agent 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
+			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
-		update
 		cd $AGENTDIR
 		./ogp_agent.pl
 	fi
@@ -252,7 +260,7 @@ PATH=/usr/local/bin:/usr/bin:${PATH}
 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 $*