command_wipe.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. # LinuxGSM command_backup.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.com
  6. # Description: Wipes server data, useful after updates for some games like Rust
  7. local commandname="WIPE"
  8. local commandaction="data wipe"
  9. 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. #WipeProceduralSave
  42. if [ "${gamename}" == "Rust" ]; then
  43. if [ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.sav")" ]; then
  44. currentaction="Removing procedural map save(s): ${serveridentitydir}/proceduralmap.*.sav"
  45. echo -en "Removing map saves proceduralmap.*.sav file(s)..."
  46. sleep 0.5
  47. fn_script_log "${currentaction}"
  48. find "${serveridentitydir:?}" -type f -name "proceduralmap.*.sav" -delete
  49. fn_wipe_exit_code
  50. sleep 0.5
  51. else
  52. fn_print_information_nl "No procedural map save to remove"
  53. fn_script_log_info "No procedural map save to remove."
  54. sleep 0.5
  55. fi
  56. #WipeBarrenSave
  57. if [ -n "$(find "${serveridentitydir}" -type f -name "barren*.sav")" ]; then
  58. currentaction="Removing barren map save(s): ${serveridentitydir}/barren*.sav"
  59. echo -en "Removing barren map saves barren*.sav file(s)..."
  60. sleep 0.5
  61. fn_script_log "${currentaction}"
  62. find "${serveridentitydir:?}" -type f -name "barren*.sav" -delete
  63. fn_wipe_exit_code
  64. sleep 0.5
  65. else
  66. fn_print_information_nl "No barren map save to remove"
  67. fn_script_log_info "No barren map save to remove."
  68. sleep 0.5
  69. fi
  70. #WipeProceduralMap
  71. if [ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.map")" ]; then
  72. currentaction="Removing map file(s): ${serveridentitydir}/proceduralmap.*.map"
  73. echo -en "Removing procedural map proceduralmap.*.map file(s)..."
  74. sleep 0.5
  75. fn_script_log "${currentaction}"
  76. find "${serveridentitydir:?}" -type f -name "proceduralmap.*.map" -delete
  77. fn_wipe_exit_code
  78. sleep 0.5
  79. else
  80. fn_print_information_nl "No procedural map file to remove"
  81. fn_script_log_info "No procedural map file to remove."
  82. sleep 0.5
  83. fi
  84. #WipeBarrenMap
  85. if [ -n "$(find "${serveridentitydir}" -type f -name "barren*.map")" ]; then
  86. currentaction="Removing map file(s): ${serveridentitydir}/barren*.map"
  87. echo -en "Removing barren map barren*.map file(s)..."
  88. sleep 0.5
  89. fn_script_log "${currentaction}"
  90. find "${serveridentitydir:?}" -type f -name "barren*.map" -delete
  91. fn_wipe_exit_code
  92. sleep 0.5
  93. else
  94. fn_print_information_nl "No barren map file to remove"
  95. fn_script_log_info "No barren map file to remove."
  96. sleep 0.5
  97. fi
  98. if [ -d "${serveridentitydir}/user" ]; then
  99. currentaction="Removing user directory: ${serveridentitydir}/user"
  100. echo -en "Removing user directory..."
  101. sleep 0.5
  102. fn_script_log "${currentaction}"
  103. rm -rf "${serveridentitydir:?}/user"
  104. fn_wipe_exit_code
  105. sleep 0.5
  106. else
  107. fn_print_information_nl "No user directory to remove"
  108. fn_script_log_info "No user directory to remove."
  109. sleep 0.5
  110. fi
  111. if [ -d "${serveridentitydir}/storage" ]; then
  112. currentaction="Removing storage directory: ${serveridentitydir}/storage"
  113. echo -en "Removing storage directory..."
  114. sleep 0.5
  115. fn_script_log "${currentaction}"
  116. rm -rf "${serveridentitydir:?}/storage"
  117. fn_wipe_exit_code
  118. sleep 0.5
  119. else
  120. fn_print_information_nl "No storage directory to remove"
  121. fn_script_log_info "No storage directory to remove."
  122. sleep 0.5
  123. fi
  124. if [ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
  125. currentaction="Removing log files: ${serveridentitydir}/Log.*.txt"
  126. echo -en "Removing Log files..."
  127. sleep 0.5
  128. fn_script_log "${currentaction}"
  129. find "${serveridentitydir:?}" -type f -name "Log.*.txt" -delete
  130. fn_wipe_exit_code
  131. sleep 0.5
  132. else
  133. fn_print_information_nl "No log files to remove"
  134. fn_script_log_info "No log files to remove."
  135. sleep 0.5
  136. fi
  137. # You can add an "elif" here to add another game or engine
  138. fi
  139. }
  140. # Check if there is something to wipe, prompt the user, and call appropriate functions
  141. # Rust Wipe
  142. if [ "${gamename}" == "Rust" ]; then
  143. 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")" ]; then
  144. fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased."
  145. if ! fn_prompt_yn "Continue?" Y; then
  146. echo Exiting; core_exit.sh
  147. fi
  148. fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}"
  149. sleep 0.5
  150. fn_wipe_server_process
  151. else
  152. fn_print_information_nl "No data to wipe was found"
  153. fn_script_log_info "No data to wipe was found."
  154. sleep 0.5
  155. core_exit.sh
  156. fi
  157. # You can add an "elif" here to add another game or engine
  158. else
  159. # Game not listed
  160. fn_print_information_nl "Wipe is not available for this game"
  161. fn_script_log_info "Wipe is not available for this game."
  162. sleep 0.5
  163. core_exit.sh
  164. fi
  165. core_exit.sh