Browse Source

convert to auto

pull/2971/head
Daniel Gibbs 5 years ago
parent
commit
e4611ae453
  1. 320
      lgsm/functions/command_wipe.sh

320
lgsm/functions/command_wipe.sh

@ -9,26 +9,6 @@ commandname="WIPE"
commandaction="Wiping" commandaction="Wiping"
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
check.sh
fn_print_header
fn_script_log "Entering ${gamename} ${commandaction}"
# Process to server wipe.
fn_wipe_server_process(){
check_status.sh
if [ "${status}" != "0" ]; then
exitbypass=1
command_stop.sh
fn_wipe_server_remove_files
exitbypass=1
command_start.sh
else
fn_wipe_server_remove_files
fi
echo -e "server data wiped"
fn_script_log "server data wiped"
}
# Provides an exit code upon error. # Provides an exit code upon error.
fn_wipe_exit_code(){ fn_wipe_exit_code(){
((exitcode=$?)) ((exitcode=$?))
@ -41,141 +21,139 @@ fn_wipe_exit_code(){
} }
# Removes files to wipe server. # Removes files to wipe server.
fn_wipe_server_remove_files(){ fn_wipe_server_files(){
# Rust Wipe. fn_print_start_nl "Wiping server"
if [ "${shortname}" == "rust" ]; then fn_script_log_info "Wiping server"
# Wipe pocedural map. # Wipe procedural map.
if [ "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.map")" ]; then if [ "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.map")" ]; then
currentaction="Removing map file(s): ${serveridentitydir}/proceduralmap.*.map" currentaction="removing map file(s): ${serveridentitydir}/proceduralmap.*.map"
echo -en "Removing procedural map proceduralmap.*.map file(s)..." echo -en "Removing procedural map proceduralmap.*.map file(s)..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "proceduralmap.*.map" -delete find "${serveridentitydir:?}" -type f -name "proceduralmap.*.map" -delete
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
else else
fn_print_information_nl "No procedural map file to remove" fn_print_information_nl "No procedural map file to remove"
fn_script_log_info "No procedural map file to remove" fn_script_log_info "No procedural map file to remove"
fi fi
# Wipe procedural map save. # Wipe procedural map save.
if [ "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.sav")" ]; then if [ "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.sav")" ]; then
currentaction="Removing procedural map save(s): ${serveridentitydir}/proceduralmap.*.sav" currentaction="Removing procedural map save(s): ${serveridentitydir}/proceduralmap.*.sav"
echo -en "Removing map saves proceduralmap.*.sav file(s)..." echo -en "Removing map saves proceduralmap.*.sav file(s)..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "proceduralmap.*.sav" -delete find "${serveridentitydir:?}" -type f -name "proceduralmap.*.sav" -delete
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
else else
fn_print_information_nl "No procedural map save to remove" fn_print_information_nl "No procedural map save to remove"
fn_script_log_info "No procedural map save to remove" fn_script_log_info "No procedural map save to remove"
fi fi
# Wipe Barren map. # Wipe Barren map.
if [ "$(find "${serveridentitydir}" -type f -name "barren*.map")" ]; then if [ "$(find "${serveridentitydir}" -type f -name "barren*.map")" ]; then
currentaction="Removing map file(s): ${serveridentitydir}/barren*.map" currentaction="Removing map file(s): ${serveridentitydir}/barren*.map"
echo -en "Removing barren map barren*.map file(s)..." echo -en "Removing barren map barren*.map file(s)..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "barren*.map" -delete find "${serveridentitydir:?}" -type f -name "barren*.map" -delete
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
else else
fn_print_information_nl "No barren map file to remove" fn_print_information_nl "No barren map file to remove"
fn_script_log_info "No barren map file to remove" fn_script_log_info "No barren map file to remove"
fi fi
# Wipe barren map save. # Wipe barren map save.
if [ "$(find "${serveridentitydir}" -type f -name "barren*.sav")" ]; then if [ "$(find "${serveridentitydir}" -type f -name "barren*.sav")" ]; then
currentaction="Removing barren map save(s): ${serveridentitydir}/barren*.sav" currentaction="Removing barren map save(s): ${serveridentitydir}/barren*.sav"
echo -en "Removing barren map saves barren*.sav file(s)..." echo -en "Removing barren map saves barren*.sav file(s)..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "barren*.sav" -delete find "${serveridentitydir:?}" -type f -name "barren*.sav" -delete
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
else else
fn_print_information_nl "No barren map save to remove" fn_print_information_nl "No barren map save to remove"
fn_script_log_info "No barren map save to remove." fn_script_log_info "No barren map save to remove."
fi fi
# Wipe user dir, might be a legacy thing, maybe to be removed. # Wipe user dir, might be a legacy thing, maybe to be removed.
if [ -d "${serveridentitydir}/user" ]; then if [ -d "${serveridentitydir}/user" ]; then
currentaction="Removing user directory: ${serveridentitydir}/user" currentaction="Removing user directory: ${serveridentitydir}/user"
echo -en "Removing user directory..." echo -en "Removing user directory..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
rm -rf "${serveridentitydir:?}/user" rm -rf "${serveridentitydir:?}/user"
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
# We do not print additional information if there is nothing to remove since this might be obsolete. # We do not print additional information if there is nothing to remove since this might be obsolete.
fi fi
# Wipe storage dir, might be a legacy thing, maybe to be removed. # Wipe storage dir, might be a legacy thing, maybe to be removed.
if [ -d "${serveridentitydir}/storage" ]; then if [ -d "${serveridentitydir}/storage" ]; then
currentaction="Removing storage directory: ${serveridentitydir}/storage" currentaction="Removing storage directory: ${serveridentitydir}/storage"
echo -en "Removing storage directory..." echo -en "Removing storage directory..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
rm -rf "${serveridentitydir:?}/storage" rm -rf "${serveridentitydir:?}/storage"
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
# We do not print additional information if there is nothing to remove since this might be obsolete. # We do not print additional information if there is nothing to remove since this might be obsolete.
fi fi
# Wipe sv.files. # Wipe sv.files.
if [ "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then if [ "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then
currentaction="Removing server misc files: ${serveridentitydir}/sv.files.*.db" currentaction="Removing server misc files: ${serveridentitydir}/sv.files.*.db"
echo -en "Removing server misc srv.files*.db file(s)..." echo -en "Removing server misc srv.files*.db file(s)..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "sv.files.*.db" -delete find "${serveridentitydir:?}" -type f -name "sv.files.*.db" -delete
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
# No further information if not found because it should I could not get this file showing up. # No further information if not found because it should I could not get this file showing up.
fi fi
# Wipe player death files. # Wipe player death files.
if [ "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]; then if [ "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]; then
currentaction="Removing player death files: ${serveridentitydir}/player.deaths.*.db" currentaction="Removing player death files: ${serveridentitydir}/player.deaths.*.db"
echo -en "Removing player deaths player.deaths.*.db file(s)..." echo -en "Removing player deaths player.deaths.*.db file(s)..."
fn_sleep_time
fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "player.deaths.*.db" -delete
fn_wipe_exit_code
fn_sleep_time
else
fn_print_information_nl "No player death to remove"
fn_script_log_info "No player death to remove"
fi
# Wipe blueprints only if wipeall command was used.
if [ "${wipeall}" == "1" ]; then
if [ "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then
currentaction="Removing blueprint file(s): ${serveridentitydir}/player.blueprints.*.db"
echo -en "Removing blueprints player.blueprints.*.db file(s)..."
fn_sleep_time fn_sleep_time
fn_script_log "${currentaction}" fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "player.deaths.*.db" -delete find "${serveridentitydir:?}" -type f -name "player.blueprints.*.db" -delete
fn_wipe_exit_code fn_wipe_exit_code
fn_sleep_time fn_sleep_time
else else
fn_print_information_nl "No player death to remove" fn_print_information_nl "No blueprint file to remove"
fn_script_log_info "No player death to remove" fn_script_log_info "No blueprint file to remove"
fi fi
# Wipe blueprints only if wipeall command was used. elif [ "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then
if [ "${wipeall}" == "1" ]; then fn_print_information_nl "Keeping blueprints"
if [ "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then fn_script_log_info "Keeping blueprints."
currentaction="Removing blueprint file(s): ${serveridentitydir}/player.blueprints.*.db" else
echo -en "Removing blueprints player.blueprints.*.db file(s)..." fn_print_information_nl "No blueprints found"
fn_sleep_time fn_script_log_info "No blueprints found"
fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "player.blueprints.*.db" -delete
fn_wipe_exit_code
fn_sleep_time
else
fn_print_information_nl "No blueprint file to remove"
fn_script_log_info "No blueprint file to remove"
fi
elif [ "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then
fn_print_information_nl "Keeping blueprints"
fn_script_log_info "Keeping blueprints."
else
fn_print_information_nl "No blueprints found"
fn_script_log_info "No blueprints found"
fn_sleep_time
fi
# Wipe some logs that might be there.
if [ "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
currentaction="Removing log files: ${serveridentitydir}/Log.*.txt"
echo -en "Removing Log files..."
fn_sleep_time
fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "Log.*.txt" -delete
fn_wipe_exit_code
fn_sleep_time fn_sleep_time
# We do not print additional information if there are no logs to remove. fi
fi # Wipe some logs that might be there.
# You can add an "elif" here to add another game or engine. if [ "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
currentaction="Removing log files: ${serveridentitydir}/Log.*.txt"
echo -en "Removing Log files..."
fn_sleep_time
fn_script_log "${currentaction}"
find "${serveridentitydir:?}" -type f -name "Log.*.txt" -delete
fn_wipe_exit_code
fn_sleep_time
# We do not print additional information if there are no logs to remove.
fi fi
} }
@ -194,18 +172,40 @@ fn_stop_warning(){
fn_print_warn_nl "${selfname} will be stopped during wipe" fn_print_warn_nl "${selfname} will be stopped during wipe"
} }
# Check if there is something to wipe, prompt the user, and call appropriate functions. fn_wipe_warning(){
# Rust Wipe. fn_print_warn "${selfname} wipe is about to start"
if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "barren*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then fn_script_log_warn "${selfname} wipe is about to start"
fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased" totalseconds=3
fn_wipe_warning for seconds in {3..1}; do
fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}" fn_print_warn "${selfname} wipe is about to start: ${totalseconds}"
fn_sleep_time totalseconds=$((totalseconds - 1))
fn_wipe_server_process sleep 1
if [ "${seconds}" == "0" ]; then
break
fi
done
fn_print_warn "${selfname} wipe is about to start"
}
fn_print_dots "Wiping server"
check.sh
# Check if there is something to wipe.
if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "barren*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then
fn_wipe_warning
check_status.sh
if [ "${status}" != "0" ]; then
fn_stop_warning
exitbypass=1
command_stop.sh
fn_wipe_server_files
exitbypass=1
command_start.sh
else else
fn_print_information_nl "No data to wipe was found" fn_wipe_server_files
fn_script_log_info "No data to wipe was found"
core_exit.sh
fi fi
else
fn_print_info_nl "No data to wipe was found"
fn_script_log_info "No data to wipe was found"
fi
core_exit.sh core_exit.sh

Loading…
Cancel
Save