Browse Source

Attempt for better logging and outputs

pull/1275/head
UltimateByte 8 years ago
committed by GitHub
parent
commit
2da83d47a7
  1. 112
      lgsm/functions/command_wipe.sh

112
lgsm/functions/command_wipe.sh

@ -6,70 +6,100 @@
# Description: Wipes server data, useful after updates for some games like Rust # Description: Wipes server data, useful after updates for some games like Rust
local commandname="WIPE" local commandname="WIPE"
local commandaction="wipe data" local commandaction="data wipe"
local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
check.sh check.sh
fn_print_header fn_print_header
fn_scripg_log "Entering ${gamename} ${commandaction}"
# Checks if there is something to wipe # Process to server wipe
fn_wipe_server(){ fn_wipe_server_process(){
# Rust Wipe check_status.sh
if [ "${gamename}" == "Rust" ]; then if [ "${status}" != "0" ]; then
if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]; then exitbypass=1
echo " * Any user, storage, and map data will be erased." command_stop.sh
while true; do fn_wipe_server_remove_files
read -e -i "y" -p "Continue? [Y/n]" yn exitbypass=1
case $yn in command_start.sh
[Yy]* ) break;;
[Nn]* ) echo Exiting; core_exit.sh;;
* ) echo "Please answer yes or no.";;
esac
done
fn_script_log_info "User selected to continue"
fn_wipe_server_process
else
echo "Nothing to wipe"
core_exit.sh
fi
else else
echo "Wipe is not available" fn_wipe_server_remove_files
fi
echo "server data wiped"
fn_script_log "server data wiped."
}
# Provides an exit code upon error
fn_wipe_exit_code(){
((exitcode=$?))
if [ ${exitcode} -ne 0 ]; then
fn_script_log_fatal "${currentaction}"
core_exit.sh core_exit.sh
else
fn_print_ok_eol_nl
fi fi
} }
# Removes files to wipe server # Removes files to wipe server
fn_wipe_server_remove_files(){ fn_wipe_server_remove_files(){
# Rust Wipe
if [ "${gamename}" == "Rust" ]; then if [ "${gamename}" == "Rust" ]; then
if [ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]; then if [ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]; then
echo "Removing map" currentaction="Removing map ${serveridentitydir}/proceduralmap*.sav"
echo -en "${currentaction}"
fn_script_log "${currentaction}"
rm -f "${serveridentitydir}/proceduralmap*.sav" rm -f "${serveridentitydir}/proceduralmap*.sav"
fn_wipe_exit_code
fi fi
if [ -d "${serveridentitydir}/user" ]; then if [ -d "${serveridentitydir}/user" ]; then
echo "Removing users data" currentaction="Removing user ${serveridentitydir}/user"
echo -en "${currentaction}"
fn_script_log "${currentaction}"
rm -rf "${serveridentitydir}/user" rm -rf "${serveridentitydir}/user"
fn_wipe_exit_code
fi fi
if [ -d "${serveridentitydir}/storage" ]; then if [ -d "${serveridentitydir}/storage" ]; then
echo "Removing storage data" currentaction="Removing storage ${serveridentitydir}/storage"
echo -en "${currentaction}"
fn_script_log "${currentaction}"
rm -rf "${serveridentitydir}/storage" rm -rf "${serveridentitydir}/storage"
fn_wipe_exit_code
fi
if [ -d "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
currentaction="Removing storage ${serveridentitydir}/Log.*.txt"
echo -en "${currentaction}"
fn_script_log "${currentaction}"
rm -f "${serveridentitydir}/Log.*.txt"
fn_wipe_exit_code
fi fi
# You can add an "elif" here to add another game or engine
fi fi
} }
# Process to server wipe # Check if there is something to wipe, prompt the user, and call appropriate functions
fn_wipe_server_process(){ # Rust Wipe
check_status.sh if [ "${gamename}" == "Rust" ]; then
if [ "${status}" != "0" ]; 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
exitbypass=1 fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased."
command_stop.sh while true; do
fn_wipe_server_remove_files read -e -i "y" -p "Continue? [Y/n]" yn
exitbypass=1 case $yn in
command_start.sh [Yy]* ) break;;
else [Nn]* ) echo Exiting; core_exit.sh;;
fn_wipe_server_remove_files * ) echo "Please answer yes or no.";;
esac
done
fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}"
fn_wipe_server_process
else
fn_print_information "No data to wipe was found"
fn_script_log_info "No data to wipe was found."
core_exit.sh
fi fi
echo "Server Wiped" # You can add an "elif" here to add another game or engine
} else
# Game not listed
fn_wipe_server fn_print_information "Wipe is not available for this game"
fn_script_log_info "Wipe is not available for this game."
core_exit.sh
fi

Loading…
Cancel
Save