command_wipe.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 file(s): ${serveridentitydir}/proceduralmap.*.sav"
  44. echo -en "Removing map proceduralmap.*.sav file(s)..."
  45. sleep 1
  46. fn_script_log "${currentaction}"
  47. rm -f "${serveridentitydir}/proceduralmap.*.sav"
  48. fn_wipe_exit_code
  49. sleep 0.5
  50. else
  51. fn_print_information "No map file to remove"
  52. fn_script_log_info "No map file to remove."
  53. fi
  54. if [ -d "${serveridentitydir}/user" ]; then
  55. currentaction="Removing user directory: ${serveridentitydir}/user"
  56. echo -en "Removing user directory..."
  57. sleep 1
  58. fn_script_log "${currentaction}"
  59. rm -rf "${serveridentitydir}/user"
  60. fn_wipe_exit_code
  61. sleep 0.5
  62. else
  63. fn_print_information "No user directory to remove"
  64. fn_script_log_info "No user directory to remove."
  65. fi
  66. if [ -d "${serveridentitydir}/storage" ]; then
  67. currentaction="Removing storage directory: ${serveridentitydir}/storage"
  68. echo -en "Removing storage directory..."
  69. sleep 1
  70. fn_script_log "${currentaction}"
  71. rm -rf "${serveridentitydir}/storage"
  72. fn_wipe_exit_code
  73. sleep 0.5
  74. else
  75. fn_print_information "No storage directory to remove"
  76. fn_script_log_info "No storage directory to remove."
  77. fi
  78. if [ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
  79. currentaction="Removing log files: ${serveridentitydir}/Log.*.txt"
  80. echo -en "Removing Log files..."
  81. sleep 1
  82. fn_script_log "${currentaction}"
  83. rm -f "${serveridentitydir}/Log.*.txt"
  84. fn_wipe_exit_code
  85. sleep 0.5
  86. else
  87. fn_print_information "No log files to remove"
  88. fn_script_log_info "No log files to remove."
  89. fi
  90. # You can add an "elif" here to add another game or engine
  91. fi
  92. }
  93. # Check if there is something to wipe, prompt the user, and call appropriate functions
  94. # Rust Wipe
  95. if [ "${gamename}" == "Rust" ]; then
  96. if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
  97. fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased."
  98. while true; do
  99. read -e -i "y" -p "Continue? [Y/n]" yn
  100. case $yn in
  101. [Yy]* ) break;;
  102. [Nn]* ) echo Exiting; core_exit.sh;;
  103. * ) echo "Please answer yes or no.";;
  104. esac
  105. done
  106. fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}"
  107. sleep 1
  108. fn_wipe_server_process
  109. else
  110. fn_print_information "No data to wipe was found"
  111. fn_script_log_info "No data to wipe was found."
  112. sleep 1
  113. core_exit.sh
  114. fi
  115. # You can add an "elif" here to add another game or engine
  116. else
  117. # Game not listed
  118. fn_print_information "Wipe is not available for this game"
  119. fn_script_log_info "Wipe is not available for this game."
  120. sleep 1
  121. core_exit.sh
  122. fi