Răsfoiți Sursa

Fixed Fast download, init script for Debian, improved workshop subroutine.

Fixed Fast Download daemon to force it to use libraries from the agent folder.
Improved init script, tested on latest ubuntu.
Added an alternative way of downloading workshop mods.
DieFeM 8 ani în urmă
părinte
comite
de3ed0a586
3 a modificat fișierele cu 99 adăugiri și 77 ștergeri
  1. 1 0
      FastDownload/ForkedDaemon.pm
  2. 29 41
      includes/ogp_agent.init.dbn
  3. 69 36
      ogp_agent.pl

+ 1 - 0
FastDownload/ForkedDaemon.pm

@@ -1,5 +1,6 @@
 use strict;
 use warnings;
+use lib ".";
 use FastDownload::Settings; # Daemon Settings
 use Cwd;					# Fast way to get the current directory
 use Fcntl ':flock';			# Import LOCK_* constants for file locking

+ 29 - 41
includes/ogp_agent.init.dbn

@@ -12,11 +12,6 @@
 # Description:       Start and stop the OGP Agent
 ### END INIT INFO
 #
-set -e
-set -u
-${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
-
-. /lib/lsb/init-functions
 
 agent_dir=OGP_AGENT_DIR
 agent_user=OGP_USER
@@ -27,17 +22,17 @@ agent_user=OGP_USER
 
 if [ "X`whoami`" != "Xroot" ]
 then
-	log_failure_msg "Permission denied."
 	exit 1
 fi
 
 start() {
 	if [ -e "$agent_dir/ogp_agent_run.pid" ]
 	then
-		if [ "X$(ps -A | grep -o `cat $agent_dir/ogp_agent_run.pid`)" != "X" ]
+		pid=$(cat $agent_dir/ogp_agent_run.pid)
+		out=$(kill -0 $pid > /dev/null 2>&1)
+		if [ $? == 0 ]
 		then
-			log_failure_msg "OGP Agent already running."
-			return 1
+			exit 1
 		fi
 	fi
 
@@ -50,22 +45,22 @@ start() {
 		fi
 		usermod -aG sudo $agent_user >/dev/null 2>&1
 	fi
-
-	# Had to add the "|| true" part to the end of the below command due to chown causing the entire bash script to exit on failure in case of protected files (that have chattr +i applied)
-	# http://unix.stackexchange.com/questions/118217/chmod-silent-mode-how-force-exit-code-0-in-spite-of-error
-	chown -Rf `id -u $agent_user`:`id -g $agent_user` $agent_dir >/dev/null 2>&1 || true
-
+	
+	user_id=$(id -u $agent_user)
+	group_id=$(id -g $agent_user)
+	out=$(chown -Rf $user_id:$group_id $agent_dir >/dev/null 2>&1)
+	
 	# Lets the agent user to attach screens.
-	if [ "$( groups $agent_user | grep "\btty\b" )" == "" ]
+	if [ "$(groups $agent_user|grep -o "\stty\s")" == "" ]
 	then
 		usermod -aG tty $agent_user >/dev/null 2>&1
 	fi
-
-	chmod g+rw /dev/pts/* >/dev/null 2>&1
-	chmod g+rw /dev/tty* >/dev/null 2>&1
+	
+	out=$(chmod g+rw /dev/pts/* >/dev/null 2>&1)
+	out=$(chmod g+rw /dev/tty* >/dev/null 2>&1)
 
 	# Check the FTP status
-	if [ -f "/etc/init.d/pure-ftpd" ] && [ -e "/etc/pure-ftpd/conf" ]
+	if [ -f "/etc/init.d/pure-ftpd" ] && [ -d "/etc/pure-ftpd/conf" ]
 	then
 		echo no > /etc/pure-ftpd/conf/PAMAuthentication
 		echo no > /etc/pure-ftpd/conf/UnixAuthentication
@@ -90,52 +85,45 @@ start() {
 		then
 			ln -s /etc/pure-ftpd/pureftpd.pdb /etc/pureftpd.pdb
 		fi
-		pure-pw mkdb >/dev/null 2>&1
-		service pure-ftpd force-reload >/dev/null 2>&1 &
+		out=$(pure-pw mkdb >/dev/null 2>&1)
+		out=$(service pure-ftpd force-reload >/dev/null 2>&1)
 	fi
 
 	cd $agent_dir
-	su -c "screen -d -m -t ogp_agent -c ogp_screenrc -S ogp_agent ./ogp_agent_run -pidfile ogp_agent_run.pid" $agent_user &> $agent_dir/ogp_agent.svc &
-	log_success_msg "OGP Agent started successfully."
-	echo "Use \"sudo su -c 'screen -S ogp_agent -r' $agent_user\" to attach the agent screen,"
-	echo "and CTRL+A+D to detach it."
-	return 0
+	out=$(su -c "screen -d -m -t ogp_agent -c ogp_screenrc -S ogp_agent ./ogp_agent_run -pidfile ogp_agent_run.pid" $agent_user >/dev/null 2>&1)
+	exit 0
 }
 
 stop() {
 	if [ -e "$agent_dir/ogp_agent_run.pid" ]
 	then
-		if [ "X$(ps -A | grep -o `cat $agent_dir/ogp_agent_run.pid`)" == "X" ]
+		pid=$(cat $agent_dir/ogp_agent_run.pid)
+		kill -0 $pid > /dev/null 2>&1
+		if [ $? == 0 ]
 		then
-			log_failure_msg "OGP Agent not running."
-		else
-			kill `cat $agent_dir/ogp_agent_run.pid` >/dev/null 2>&1
-			log_success_msg "OGP Agent stopped successfully."
+			kill $pid >/dev/null 2>&1
+			exit $?
 		fi
 	else
-		log_failure_msg "PID file not found ($agent_dir/ogp_agent_run.pid)"
+		exit 1
 	fi
-	return 0
+	exit 0
 }
 
 case "${1:-''}" in
-	start)
+	'start')
 	start
-	RETVAL=$?
 	;;
-	stop)
+	'stop')
 	stop
-	RETVAL=$?
 	;;
-	restart)
+	'restart')
 	stop
 	sleep 1
 	start
-	RETVAL=$?
 	;;
  	*)
 	echo "Usage: service ogp_agent start|stop|restart"
-	RETVAL=1
+	exit 1
 	;;
 esac
-exit $RETVAL

+ 69 - 36
ogp_agent.pl

@@ -4059,7 +4059,8 @@ sub steam_workshop_without_decrypt
 		$variable, $place_after, $mod_string, 
 		$string_separator, $config_file_path, 
 		$post_install, $mod_names_list,
-		$anonymous_login, $user, $pass) = @_;
+		$anonymous_login, $user, $pass,
+		$download_method, $url_list, $filename_list) = @_;
 	
 	# Creates mods path if it doesn't exist
 	if ( check_b4_chdir($mods_full_path) != 0)
@@ -4076,33 +4077,64 @@ sub steam_workshop_without_decrypt
 	print FILE	"chmod 771 '$home_path'\n".
 				"rm -f '$sec'";
 	close FILE;
-		
 	
 	my $screen_id = create_screen_id(SCREEN_TYPE_UPDATE, $home_id);
-	my $steam_binary = STEAMCMD_CLIENT_BIN;
-	my $installSteamFile = $screen_id . "_workshop.txt";	
-	my $installtxt = Path::Class::File->new(STEAMCMD_CLIENT_DIR, $installSteamFile);
-	
 	my @workshop_mods = split /,/, $mods_list;
-		
-	open  FILE, '>', $installtxt;
-	print FILE "\@ShutdownOnFailedCommand 1\n";
-	print FILE "\@NoPromptForPassword 1\n";
-	if($anonymous_login eq "0")
-	{
-		print FILE "login $user $pass\n";
-	}
-	else
+	my @installcmds;
+	
+	if($download_method eq 'steamcmd')
 	{
-		print FILE "login anonymous\n";
+		my $steam_binary = STEAMCMD_CLIENT_BIN;
+		my $installSteamFile = $screen_id . "_workshop.txt";	
+		my $installtxt = Path::Class::File->new(STEAMCMD_CLIENT_DIR, $installSteamFile);
+
+		open  FILE, '>', $installtxt;
+		print FILE "\@ShutdownOnFailedCommand 1\n";
+		print FILE "\@NoPromptForPassword 1\n";
+		if($anonymous_login eq "0")
+		{
+			print FILE "login $user $pass\n";
+		}
+		else
+		{
+			print FILE "login anonymous\n";
+		}
+		print FILE "force_install_dir \"$mods_full_path\"\n";
+		foreach my $workshop_mod (@workshop_mods)
+		{
+			print FILE "workshop_download_item $workshop_id $workshop_mod\n";
+		}
+		print FILE "exit\n";
+		close FILE;
+		@installcmds = ("$steam_binary +runscript $installtxt +exit");
 	}
-	print FILE "force_install_dir \"$mods_full_path\"\n";
-	foreach my $workshop_mod (@workshop_mods)
+	
+	if($download_method eq 'steamapi')
 	{
-		print FILE "workshop_download_item $workshop_id $workshop_mod\n";
+		my @urls =  split /,/, $url_list;
+		my @filenames =  split /,/, $filename_list;
+		my $index = 0;
+		foreach my $workshop_mod_id (@workshop_mods)
+		{
+			my $steamcmd_download_path = '/steamapps/workshop/content/'.$workshop_id.'/'.$workshop_mod_id.'/';
+			
+			my $workshop_mod_path = $mods_full_path.$steamcmd_download_path;
+			if(!-d $workshop_mod_path && !mkpath $workshop_mod_path)
+			{
+				logger "Folder $workshop_mod_path could not be created.";
+				$index++;
+				next;
+			}
+			my $url = $urls[$index];
+			my $filename = $filenames[$index];
+			my $download_file_path = Path::Class::File->new($workshop_mod_path, "$filename");
+			$installcmds[$index] = "wget -O \"$download_file_path\" \"$url\"";
+			$index++;
+		}
 	}
-	print FILE "exit\n";
-	close FILE;
+	
+	my $log_file = Path::Class::File->new(SCREEN_LOGS_DIR, "screenlog.$screen_id");
+	backup_home_log($home_id, $log_file);
 		
 	my $precmd = "";
 	my $postcmd = "";
@@ -4113,8 +4145,6 @@ sub steam_workshop_without_decrypt
 											  $string_separator, $config_file_path, 
 											  $post_install, $mod_names_list);
 	
-	my @installcmds = ("$steam_binary +runscript $installtxt +exit");
-	
 	my $bash_scripts_path = MANUAL_TMP_DIR . "/home_id_" . $home_id;
 	
 	if ( check_b4_chdir($bash_scripts_path) != 0)
@@ -4176,7 +4206,19 @@ sub	generate_post_install_scripts
 							 'i=0'."\n".
 							 'for mod_id in "${workshop_mod_id[@]}"'."\n".
 							 'do'."\n".
-							 '	file_content=$(cat $config_file_path)'."\n".
+							 '	first_file="$(ls "${workshop_mod_path[$i]}"| sort -n | head -1)"'."\n";
+	
+	my @post_install_lines = split /[\r\n]+/, $post_install;
+	foreach my $line (@post_install_lines) {
+		if($line ne ""){
+			$line =~ s/\%mods_full_path\%/\$mods_full_path/g;
+			$line =~ s/\%workshop_mod_id\%/\$mod_id/g;
+			$line =~ s/\%first_file\%/\$first_file/g;
+			$post_install_scripts .= "\t".$line."\n";
+		}
+	}
+	
+	$post_install_scripts .= '	file_content=$(cat $config_file_path)'."\n".
 							 '	if [[ $file_content =~ $regex ]]; then'."\n".
 							 '		full_match="${BASH_REMATCH[0]}"'."\n".
 							 '		mods_match="${BASH_REMATCH[$mods_backreference_index]}"'."\n".
@@ -4185,7 +4227,7 @@ sub	generate_post_install_scripts
 							 '		found=0'."\n".
 							 '	fi'."\n".
 							 '	first_file_string="\%first_file%"'."\n".
-							 '	first_file="$(ls "${workshop_mod_path[$i]}"| sort -n | head -1)"'."\n".
+							 
 							 '	if [ -z "${mod_string[$i]##*$first_file_string*}" ];then'."\n".
 							 '		mod_string[$i]="${mod_string[$i]/$first_file_string/$first_file}"'."\n".
 							 '	fi'."\n".
@@ -4213,17 +4255,8 @@ sub	generate_post_install_scripts
 							 '		fi'."\n".
 							 '	fi'."\n".
 							 '	if [ ! -d "${mods_info_path}" ];then mkdir -p "${mods_info_path}";fi'."\n".
-							 '	echo "${mod_name[$i]}" > "${mods_info_path}${mod_string[$i]}.ogpmod"'."\n";
-	my @post_install_lines = split /[\r\n]+/, $post_install;
-	foreach my $line (@post_install_lines) {
-		if($line ne ""){
-			$line =~ s/\%mods_full_path\%/\$mods_full_path/g;
-			$line =~ s/\%workshop_mod_id\%/\$mod_id/g;
-			$line =~ s/\%first_file\%/\$first_file/g;
-			$post_install_scripts .= "\t".$line."\n";
-		}
-	}
-	$post_install_scripts .= '	i=$(expr $i + 1)'."\n".
+							 '	echo "${mod_name[$i]}" > "${mods_info_path}${mod_string[$i]}.ogpmod"'."\n".
+							 '	i=$(expr $i + 1)'."\n".
 							 'done'."\n";
 	return "$post_install_scripts";
 }