command_wipe.sh 4.4 KB

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