Przeglądaj źródła

Merged feature/prompt into develop

Daniel Gibbs 9 lat temu
rodzic
commit
19b9dfa1b1

+ 6 - 15
lgsm/functions/command_console.sh

@@ -13,13 +13,9 @@ fn_print_header
 fn_print_information_nl "Press \"CTRL+b\" then \"d\" to exit console."
 fn_print_warning_nl "Do NOT press CTRL+c to exit."
 echo ""
-while true; do
-	read -e -i "y" -p "Continue? [Y/n]" yn
-	case $yn in
-	[Yy]* ) break;;
-	[Nn]* ) echo Exiting; return;;
-	* ) echo "Please answer yes or no.";;
-esac
+if ! fn_prompt_yn "Continue?" Y; then
+	echo Exiting; return
+fi
 done
 fn_print_dots "Accessing console"
 sleep 1
@@ -35,14 +31,9 @@ else
 	fn_print_error_nl "Server not running"
 	fn_script_log_error "Failed to access: Server not running"
 	sleep 1
-	while true; do
-		read -e -i "y" -p  "Do you want to start the server? [Y/n]" yn
-		case $yn in
-		[Yy]* ) exitbypass=1; command_start.sh; break;;
-		[Nn]* ) break;;
-		* ) echo "Please answer yes or no.";;
-	esac
-	done
+	if fn_prompt_yn "Do you want to start the server?" Y; then
+		exitbypass=1; command_start.sh
+	fi
 fi
 
 core_exit.sh

+ 3 - 8
lgsm/functions/command_debug.sh

@@ -68,14 +68,9 @@ echo -e "Use for identifying server issues only!"
 echo -e "Press CTRL+c to drop out of debug mode."
 fn_print_warning_nl "If ${servicename} is already running it will be stopped."
 echo ""
-while true; do
-	read -e -i "y" -p "Continue? [Y/n]" yn
-	case $yn in
-	[Yy]* ) break;;
-	[Nn]* ) echo Exiting; return;;
-	* ) echo "Please answer yes or no.";;
-esac
-done
+if ! fn_prompt_yn "Continue?" Y; then
+	echo Exiting; return
+fi
 
 fn_print_info_nl "Stopping any running servers"
 fn_script_log_info "Stopping any running servers"

+ 18 - 32
lgsm/functions/command_fastdl.sh

@@ -42,14 +42,9 @@ fn_fastdl_init(){
 	sleep 1
 	echo -en "\n"
 	fn_script_log "Started FastDL creation"
-	while true; do
-		read -e -i "y" -p "Continue? [Y/n]" yn
-		case $yn in
-		[Yy]* ) break;;
-		[Nn]* ) exit;;
-		* ) echo "Please answer yes or no.";;
-		esac
-	done
+	if ! fn_prompt_yn "Continue?" Y; then
+		exit
+	fi
 	fn_script_log "Initiating FastDL creation"
 
 	# Check and create directories
@@ -91,27 +86,21 @@ fn_fastdl_config(){
 	# Prompt for clearing old files if directory was already here
 	if [ -n "${newfastdl}" ] && [ "${newfastdl}" == "0" ]; then
 		fn_print_dots
-		while true; do
-			read -e -i "y" -p "Clear old FastDL files? [Y/n]" yn
-			case $yn in
-			[Yy]* ) clearoldfastdl="on"; fn_script_log "clearoldfastdl enabled"; fn_print_ok "Clearing Enabled"; break;;
-			[Nn]* ) clearoldfastdl="off"; fn_script_log "clearoldfastdl disabled"; fn_print_ok "Clearing Disabled"; break;;
-			* ) echo "Please answer yes or no.";;
-			esac
-		done
+		if fn_prompt_yn "Clear old FastDL files?" Y; then
+			clearoldfastdl="on"; fn_script_log "clearoldfastdl enabled"; fn_print_ok "Clearing Enabled"
+		else
+			clearoldfastdl="off"; fn_script_log "clearoldfastdl disabled"; fn_print_ok "Clearing Disabled"
+		fi
 		echo -en "\n"
 	fi
 	# Prompt for using bzip2 if it's installed
 	if [ ${bzip2installed} == 1 ]; then
 		fn_print_dots
-		while true; do
-			read -e -i "y" -p "Enable file compression using bzip2? [Y/n]" yn
-			case $yn in
-			[Yy]* ) bzip2enable="on"; fn_script_log "bzip2 enabled"; fn_print_ok "bzip2 Enabled"; break;;
-			[Nn]* ) bzip2enable="off"; fn_script_log "bzip2 disabled"; fn_print_ok "bzip2 Disabled"; break;;
-			* ) echo "Please answer yes or no.";;
-			esac
-		done
+		if fn_prompt_yn "Enable file compression using bzip2?" Y; then
+			bzip2enable="on"; fn_script_log "bzip2 enabled"; fn_print_ok "bzip2 Enabled"
+		else
+			bzip2enable="off"; fn_script_log "bzip2 disabled"; fn_print_ok "bzip2 Disabled"
+		fi
 		echo -en "\n"
 	fi
 }
@@ -119,14 +108,11 @@ fn_fastdl_config(){
 fn_fastdl_gmod_config(){
 	# Prompt for download enforcer, that is using a .lua addfile resource generator
 	fn_print_dots
-	while true; do
-		read -e -i "y" -p "Use client download enforcer? [Y/n]" yn
-		case $yn in
-		[Yy]* ) luaressource="on"; fn_script_log "DL enforcer Enabled"; fn_print_ok "Enforcer Enabled"; break;;
-		[Nn]* ) luaressource="off"; fn_script_log "DL enforcer Disabled"; fn_print_ok "Enforcer Disabled"; break;;
-		* ) echo "Please answer yes or no.";;
-		esac
-	done
+	if fn_prompt_yn "Use client download enforcer?" Y; then
+		luaressource="on"; fn_script_log "DL enforcer Enabled"; fn_print_ok "Enforcer Enabled"
+	else
+		luaressource="off"; fn_script_log "DL enforcer Disabled"; fn_print_ok "Enforcer Disabled"
+	fi
 	echo -en "\n"
 }
 

+ 3 - 8
lgsm/functions/command_install_resources_mta.sh

@@ -21,11 +21,6 @@ fn_install_resources(){
 fn_print_header
 
 fn_print_warning_nl "Installing the default resources with existing resources may cause issues."
-while true; do
-	read -e -i "y" -p "Do you want to install MTA default resources? [Y/n]" yn
-	case $yn in
-	[Yy]* ) fn_install_resources && break;;
-	[Nn]* ) break;;
-	* ) echo "Please answer yes or no.";;
-	esac
-done
+if fn_prompt_yn "Do you want to install MTA default resources?" Y; then
+	fn_install_resources
+fi

+ 3 - 8
lgsm/functions/command_mods_install.sh

@@ -87,14 +87,9 @@ if [ -f "${modsinstalledlistfullpath}" ]; then
 		fn_script_log_warn "${modprettyname} is already installed"
 		sleep 1
 		echo " * Any configs may be overwritten."
-		while true; do
-			read -e -i "y" -p "Continue? [Y/n]" yn
-			case $yn in
-			[Yy]* ) break;;
-			[Nn]* ) echo Exiting; core_exit.sh;;
-			* ) echo "Please answer yes or no.";;
-			esac
-		done
+		if ! fn_prompt_yn "Continue?" Y; then
+			echo Exiting; core_exit.sh
+		fi
 		fn_script_log_info "User selected to continue"
 	fi
 fi

+ 3 - 8
lgsm/functions/command_mods_remove.sh

@@ -45,14 +45,9 @@ done
 
 fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
 echo " * Any custom files/configuration will be removed."
-while true; do
-	read -e -i "y" -p "Continue? [Y/n]" yn
-	case $yn in
-	[Yy]* ) break;;
-	[Nn]* ) echo Exiting; exit;;
-	* ) echo "Please answer yes or no.";;
-esac
-done
+if ! fn_prompt_yn "Continue?" Y; then
+	echo Exiting; exit
+fi
 
 currentmod="${usermodselect}"
 fn_mod_get_info

+ 3 - 8
lgsm/functions/command_ts3_server_pass.sh

@@ -19,14 +19,9 @@ fn_serveradmin_password_prompt(){
 	fn_print_information_nl "You are about to change the ${gamename} ServerAdmin password."
 	fn_print_warning_nl "${gamename} will restart during this process."
 	echo ""
-	while true; do
-		read -e -i "y" -p "Continue? [Y/n]" yn
-		case $yn in
-		[Yy]* ) break;;
-		[Nn]* ) echo Exiting; exit;;
-		* ) echo "Please answer yes or no.";;
-	esac
-	done
+	if ! fn_prompt_yn "Continue?" Y; then
+		echo Exiting; exit
+	fi
 	fn_script_log_info "Initiating ${gamename} ServerAdmin password change"
 	read -p "Enter new password : " newpassword
 }

+ 3 - 8
lgsm/functions/command_wipe.sh

@@ -105,14 +105,9 @@ fn_wipe_server_remove_files(){
 if [ "${gamename}" == "Rust" ]; then
 	if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
 		fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased."
-		while true; do
-			read -e -i "y" -p "Continue? [Y/n]" yn
-			case $yn in
-			[Yy]* ) break;;
-			[Nn]* ) echo Exiting; core_exit.sh;;
-			* ) echo "Please answer yes or no.";;
-			esac
-		done
+		if ! fn_prompt_yn "Continue?" Y; then
+				echo Exiting; core_exit.sh
+		fi
 		fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}"
 		sleep 1
 		fn_wipe_server_process

+ 4 - 9
lgsm/functions/compress_unreal2_maps.sh

@@ -19,14 +19,9 @@ echo "Compressed maps saved to:"
 echo ""
 echo "${compressedmapsdir}"
 echo ""
-while true; do
-	read -e -i "y" -p "Start compression [Y/n]" yn
-	case $yn in
-	[Yy]* ) break;;
-	[Nn]* ) echo Exiting; return;;
-	* ) echo "Please answer yes or no.";;
-	esac
-done
+if ! fn_prompt_yn "Start compression?" Y; then
+	echo Exiting; return
+fi
 mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
 rm -rfv "${filesdir}/Maps/"*.ut2.uz2
 cd "${systemdir}"
@@ -34,4 +29,4 @@ for map in "${filesdir}/Maps/"*; do
 	./ucc-bin compress "${map}" --nohomedir
 done
 mv -fv "${filesdir}/Maps/"*.ut2.uz2 "${compressedmapsdir}"
-core_exit.sh
+core_exit.sh

+ 4 - 9
lgsm/functions/compress_ut99_maps.sh

@@ -19,14 +19,9 @@ echo "Compressed maps saved to:"
 echo ""
 echo "${compressedmapsdir}"
 echo ""
-while true; do
-	read -e -i "y" -p "Start compression [Y/n]" yn
-	case $yn in
-	[Yy]* ) break;;
-	[Nn]* ) echo Exiting; return;;
-	* ) echo "Please answer yes or no.";;
-	esac
-done
+if ! fn_prompt_yn "Start compression?" Y; then
+	echo Exiting; return
+fi
 mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
 rm -rfv "${filesdir}/Maps/"*.unr.uz
 cd "${systemdir}"
@@ -34,4 +29,4 @@ for map in "${filesdir}/Maps/"*; do
 	./ucc-bin compress "${map}" --nohomedir
 done
 mv -fv "${filesdir}/Maps/"*.unr.uz "${compressedmapsdir}"
-core_exit.sh
+core_exit.sh

+ 24 - 0
lgsm/functions/core_messages.sh

@@ -1,6 +1,7 @@
 #!/bin/bash
 # LinuxGSM core_messages.sh function
 # Author: Daniel Gibbs
+# Contributor: s-eam
 # Website: https://gameservermanagers.com
 # Description: Defines on-screen messages such as [  OK  ] and how script logs look.
 
@@ -268,6 +269,29 @@ fn_print_information_nl(){
 	echo -e "${cyan}Information!${default} $@"
 }
 
+# Y/N Prompt
+fn_prompt_yn(){
+	local prompt="$1"
+	local initial="$2"
+
+	if [ "${initial}" == "Y" ]; then
+		prompt+=" [Y/n] "
+	elif [ "${initial}" == "N" ]; then
+		prompt+=" [y/N] "
+	else
+		prompt+=" [y/n] "
+	fi
+
+	while true; do
+		read -e -i "${initial}" -p  "${prompt}" -r yn
+		case "${yn}" in
+			[Yy]|[Yy][Ee][Ss]) return 0 ;;
+			[Nn]|[Nn][Oo]) return 1 ;;
+		*) echo "Please answer yes or no." ;;
+		esac
+	done
+}
+
 # On-Screen End of Line
 ##################################
 

+ 5 - 8
lgsm/functions/install_dst_token.sh

@@ -21,14 +21,11 @@ if [ -z "${autoinstall}" ]; then
 	if [ -s "${clustercfgdir}/cluster_token.txt" ]; then
 		echo "The cluster token is already set. Do you want to overwrite it?"
 		fn_script_log_info "Don't Starve Together cluster token is already set"
-		while true; do
-			read -e -i "n" -p "Continue? [Y/n]" yn
-			case $yn in
-			[Yy]* ) overwritetoken="true"; break;;
-			[Nn]* ) overwritetoken="false"; break;;
-			* ) echo "Please answer yes or no.";;
-			esac
-		done
+		if fn_prompt_yn "Continue?" N; then
+			overwritetoken="true"
+		else
+			overwritetoken="false"
+		fi
 	fi
 	if [ "${overwritetoken}" == "true" ]; then
 		echo "Once you have the cluster token, enter it below"

+ 4 - 9
lgsm/functions/install_minecraft_eula.sh

@@ -16,18 +16,13 @@ echo "eula=false" > "${filesdir}/eula.txt"
 if [ -z "${autoinstall}" ]; then
 echo "By continuing you are indicating your agreement to the EULA."
 echo ""
-	while true; do
-		read -e -i "y" -p "Continue [Y/n]" yn
-		case $yn in
-		[Yy]* ) break;;
-		[Nn]* ) core_exit.sh;;
-		* ) echo "Please answer yes or no.";;
-		esac
-	done
+	if ! fn_prompt_yn "Continue?" Y; then
+		core_exit.sh
+	fi
 else
 echo "By using auto-install you are indicating your agreement to the EULA."
 echo ""
 	sleep 5
 fi
 
-sed -i "s/eula=false/eula=true/g" "${filesdir}/eula.txt"
+sed -i "s/eula=false/eula=true/g" "${filesdir}/eula.txt"

+ 5 - 8
lgsm/functions/install_retry.sh

@@ -8,11 +8,8 @@ local commandname="INSTALL"
 local commandaction="Install"
 local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
 
-while true; do
-	read -e -i "y" -p "Retry install? [Y/n]" yn
-	case $yn in
-	[Yy]* ) command_install.sh; exit;;
-	[Nn]* ) echo Exiting; exit;;
-	* ) echo "Please answer yes or no.";;
-	esac
-done
+if fn_prompt_yn "Retry install?" Y; then
+	command_install.sh; exit
+else
+	echo Exiting; exit
+fi

+ 4 - 9
lgsm/functions/install_server_dir.sh

@@ -19,16 +19,11 @@ if [ -d "${filesdir}" ]; then
 	fn_print_warning_nl "A server is already installed here."
 fi
 if [ -z "${autoinstall}" ]; then
-	while true; do
-		read -e -i "y" -p "Continue [Y/n]" yn
-		case $yn in
-		[Yy]* ) break;;
-		[Nn]* ) exit;;
-		* ) echo "Please answer yes or no.";;
-		esac
-	done
+	if ! fn_prompt_yn "Continue?" Y; then
+		exit
+	fi
 fi
 if [ ! -d "${filesdir}" ]; then
 	mkdir -v "${filesdir}"
 fi
-sleep 1
+sleep 1

+ 3 - 8
lgsm/functions/install_server_files.sh

@@ -144,12 +144,7 @@ fi
 if [ -z "${autoinstall}" ]; then
 	echo ""
 	echo "================================="
-	while true; do
-	read -e -i "y" -p "Was the install successful? [Y/n]" yn
-		case $yn in
-			[Yy]* ) break;;
-			[Nn]* ) install_retry.sh;;
-			* ) echo "Please answer yes or no.";;
-		esac
-	done
+	if ! fn_prompt_yn "Was the install successful?" Y; then
+		install_retry.sh
+	fi
 fi

+ 3 - 8
lgsm/functions/install_ts3db.sh

@@ -48,14 +48,9 @@ fn_install_ts3db_mariadb(){
 
 if [ -z "${autoinstall}" ]; then
 	echo ""
-	while true; do
-		read -e -i "n" -p "Do you want to use MariaDB/MySQL instead of sqlite (Database Server including user and database already has to be set up!)? [y/N]" yn
-		case $yn in
-		[Yy]* ) fn_install_ts3db_mariadb && break;;
-		[Nn]* ) break;;
-		* ) echo "Please answer yes or no.";;
-		esac
-	done
+	if ! fn_prompt_yn "Do you want to use MariaDB/MySQL instead of sqlite (Database Server including user and database already has to be set up!)?" N; then
+		fn_install_ts3db_mariadb
+	fi
 else
 fn_print_warning_nl "./${selfname} auto-install is uses sqlite. For MariaDB/MySQL use ./${selfname} install"
 fi

+ 4 - 9
lgsm/functions/install_unreal_tournament_eula.sh

@@ -16,18 +16,13 @@ echo "eula=false" > "${filesdir}/eula.txt"
 if [ -z "${autoinstall}" ]; then
 echo "By continuing you are indicating your agreement to the EULA."
 echo ""
-	while true; do
-		read -e -i "y" -p "Continue [Y/n]" yn
-		case $yn in
-		[Yy]* ) break;;
-		[Nn]* ) core_exit.sh;;
-		* ) echo "Please answer yes or no.";;
-		esac
-	done
+	if ! fn_prompt_yn "Continue?" Y; then
+		core_exit.sh
+	fi
 else
 echo "By using auto-install you are indicating your agreement to the EULA."
 echo ""
 	sleep 5
 fi
 
-sed -i "s/eula=false/eula=true/g" "${filesdir}/eula.txt"
+sed -i "s/eula=false/eula=true/g" "${filesdir}/eula.txt"