| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #!/bin/bash
- # LinuxGSM command_backup.sh module
- # Author: Daniel Gibbs
- # Contributors: http://linuxgsm.com/contrib
- # Website: https://linuxgsm.com
- # Description: Wipes server data, useful after updates for some games like Rust.
- commandname="WIPE"
- commandaction="Wiping"
- functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
- fn_firstcommand_set
- # Provides an exit code upon error.
- fn_wipe_exit_code(){
- exitcode=$?
- if [ "${exitcode}" != 0 ]; then
- fn_print_fail_eol_nl
- core_exit.sh
- else
- fn_print_ok_eol_nl
- fi
- }
- # Removes files to wipe server.
- fn_wipe_files(){
- fn_print_start_nl "${wipetype}"
- fn_script_log_info "${wipetype}"
- # Remove Map files
- if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
- if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ]; then
- echo -en "removing .map file(s)..."
- fn_script_log_info "removing *.map file(s)"
- fn_sleep_time
- find "${serveridentitydir:?}" -type f -name "*.map" -printf "%f\n" >> "${lgsmlog}"
- find "${serveridentitydir:?}" -type f -name "*.map" -delete | tee -a "${lgsmlog}"
- fn_wipe_exit_code
- else
- echo -e "no .map file(s) to remove"
- fn_sleep_time
- fn_script_log_pass "no .map file(s) to remove"
- fi
- fi
- # Remove Save files.
- if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
- if [ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]; then
- echo -en "removing .sav file(s)..."
- fn_script_log_info "removing .sav file(s)"
- fn_sleep_time
- find "${serveridentitydir:?}" -type f -name "*.sav*" -printf "%f\n" >> "${lgsmlog}"
- find "${serveridentitydir:?}" -type f -name "*.sav*" -delete
- fn_wipe_exit_code
- else
- echo -e "no .sav file(s) to remove"
- fn_script_log_pass "no .sav file(s) to remove"
- fn_sleep_time
- fi
- fi
- # Remove db files for full wipe.
- # Excluding player.tokens.db for Rust+.
- if [ -n "${serverwipe}" ]; then
- if [ -n "$(find "${serveridentitydir}" -type f ! -name 'player.tokens.db' -name "*.db")" ]; then
- echo -en "removing .db file(s)..."
- fn_script_log_info "removing .db file(s)"
- fn_sleep_time
- find "${serveridentitydir:?}" -type f ! -name 'player.tokens.db' -name "*.db" -printf "%f\n" >> "${lgsmlog}"
- find "${serveridentitydir:?}" -type f ! -name 'player.tokens.db' -name "*.db" -delete
- fn_wipe_exit_code
- else
- echo -e "no .db file(s) to remove"
- fn_sleep_time
- fn_script_log_pass "no .db file(s) to remove"
- fi
- fi
- }
- fn_map_wipe_warning(){
- fn_print_warn "Map wipe will reset the map data and keep blueprint data"
- fn_script_log_warn "Map wipe will reset the map data and keep blueprint data"
- totalseconds=3
- for seconds in {3..1}; do
- fn_print_warn "Map wipe will reset the map data and keep blueprint data: ${totalseconds}"
- totalseconds=$((totalseconds - 1))
- sleep 1
- if [ "${seconds}" == "0" ]; then
- break
- fi
- done
- fn_print_warn_nl "Map wipe will reset the map data and keep blueprint data"
- }
- fn_full_wipe_warning(){
- fn_print_warn "Server wipe will reset the map data and remove blueprint data"
- fn_script_log_warn "Server wipe will reset the map data and remove blueprint data"
- totalseconds=3
- for seconds in {3..1}; do
- fn_print_warn "Server wipe will reset the map data and remove blueprint data: ${totalseconds}"
- totalseconds=$((totalseconds - 1))
- sleep 1
- if [ "${seconds}" == "0" ]; then
- break
- fi
- done
- fn_print_warn_nl "Server wipe will reset the map data and remove blueprint data"
- }
- # Will change the seed if the seed is not defined by the user.
- fn_wipe_random_seed(){
- if [ -f "${datadir}/${selfname}-seed.txt" ]&&[ -n "${randomseed}" ]; then
- shuf -i 1-2147483647 -n 1 > "${datadir}/${selfname}-seed.txt"
- seed=$(cat "${datadir}/${selfname}-seed.txt")
- randomseed=1
- echo -en "generating new random seed (${cyan}${seed}${default})..."
- fn_script_log_pass "generating new random seed (${cyan}${seed}${default})"
- fn_sleep_time
- fn_print_ok_eol_nl
- fi
- }
- # A summary of what wipe is going to do.
- fn_wipe_details(){
- fn_print_information_nl "Wipe does not remove Rust+ data."
- echo -en "* Wipe map data: "
- if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
- fn_print_yes_eol_nl
- else
- fn_print_no_eol_nl
- fi
- echo -en "* Wipe blueprint data: "
- if [ -n "${serverwipe}" ]; then
- fn_print_yes_eol_nl
- else
- fn_print_no_eol_nl
- fi
- echo -en "* Change Procedural Map seed: "
- if [ -n "${randomseed}" ]; then
- fn_print_yes_eol_nl
- else
- fn_print_no_eol_nl
- fi
- }
- fn_print_dots ""
- check.sh
- fix_rust.sh
- # Check if there is something to wipe.
- if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]&&[ -n "$(find "${serveridentitydir}" -type f ! -name 'player.tokens.db' -name "*.db")" ]; then
- if [ -n "${serverwipe}" ]; then
- wipetype="Full wipe"
- fn_full_wipe_warning
- fn_wipe_details
- elif [ -n "${mapwipe}" ]; then
- wipetype="Map wipe"
- fn_map_wipe_warning
- fn_wipe_details
- fi
- check_status.sh
- if [ "${status}" != "0" ]; then
- fn_print_restart_warning
- exitbypass=1
- command_stop.sh
- fn_firstcommand_reset
- fn_wipe_files
- fn_wipe_random_seed
- fn_print_complete_nl "${wipetype}"
- fn_script_log_pass "${wipetype}"
- exitbypass=1
- command_start.sh
- fn_firstcommand_reset
- else
- fn_wipe_files
- fn_wipe_random_seed
- fn_print_complete_nl "${wipetype}"
- fn_script_log_pass "${wipetype}"
- fi
- else
- fn_print_ok_nl "Wipe not required"
- fn_script_log_pass "Wipe not required"
- fi
- core_exit.sh
|