command_wipe.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # LGSM command_backup.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Wipes server data, useful after updates for some games like Rust
  7. local commandname="WIPE"
  8. local commandaction="data wipe"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. check.sh
  11. fn_print_header
  12. fn_script_log "Entering ${gamename} ${commandaction}"
  13. # Process to server wipe
  14. fn_wipe_server_process(){
  15. check_status.sh
  16. if [ "${status}" != "0" ]; then
  17. exitbypass=1
  18. command_stop.sh
  19. fn_wipe_server_remove_files
  20. exitbypass=1
  21. command_start.sh
  22. else
  23. fn_wipe_server_remove_files
  24. fi
  25. echo "server data wiped"
  26. fn_script_log "server data wiped."
  27. }
  28. # Provides an exit code upon error
  29. fn_wipe_exit_code(){
  30. ((exitcode=$?))
  31. if [ ${exitcode} -ne 0 ]; then
  32. fn_script_log_fatal "${currentaction}"
  33. core_exit.sh
  34. else
  35. fn_print_ok_eol_nl
  36. fi
  37. }
  38. # Removes files to wipe server
  39. fn_wipe_server_remove_files(){
  40. # Rust Wipe
  41. if [ "${gamename}" == "Rust" ]; then
  42. if [ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]; then
  43. currentaction="Removing map ${serveridentitydir}/proceduralmap*.sav"
  44. echo -en "${currentaction}"
  45. fn_script_log "${currentaction}"
  46. rm -f "${serveridentitydir}/proceduralmap*.sav"
  47. fn_wipe_exit_code
  48. fi
  49. if [ -d "${serveridentitydir}/user" ]; then
  50. currentaction="Removing user ${serveridentitydir}/user"
  51. echo -en "${currentaction}"
  52. fn_script_log "${currentaction}"
  53. rm -rf "${serveridentitydir}/user"
  54. fn_wipe_exit_code
  55. fi
  56. if [ -d "${serveridentitydir}/storage" ]; then
  57. currentaction="Removing storage ${serveridentitydir}/storage"
  58. echo -en "${currentaction}"
  59. fn_script_log "${currentaction}"
  60. rm -rf "${serveridentitydir}/storage"
  61. fn_wipe_exit_code
  62. fi
  63. if [ -d "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
  64. currentaction="Removing storage ${serveridentitydir}/Log.*.txt"
  65. echo -en "${currentaction}"
  66. fn_script_log "${currentaction}"
  67. rm -f "${serveridentitydir}/Log.*.txt"
  68. fn_wipe_exit_code
  69. fi
  70. # You can add an "elif" here to add another game or engine
  71. fi
  72. }
  73. # Check if there is something to wipe, prompt the user, and call appropriate functions
  74. # Rust Wipe
  75. if [ "${gamename}" == "Rust" ]; then
  76. if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
  77. fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased."
  78. while true; do
  79. read -e -i "y" -p "Continue? [Y/n]" yn
  80. case $yn in
  81. [Yy]* ) break;;
  82. [Nn]* ) echo Exiting; core_exit.sh;;
  83. * ) echo "Please answer yes or no.";;
  84. esac
  85. done
  86. fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}"
  87. fn_wipe_server_process
  88. else
  89. fn_print_information "No data to wipe was found"
  90. fn_script_log_info "No data to wipe was found."
  91. core_exit.sh
  92. fi
  93. # You can add an "elif" here to add another game or engine
  94. else
  95. # Game not listed
  96. fn_print_information "Wipe is not available for this game"
  97. fn_script_log_info "Wipe is not available for this game."
  98. core_exit.sh
  99. fi