command_wipe.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. commandname="WIPE"
  8. commandaction="Wiping"
  9. functionselfname="$(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 -e "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 [ "${shortname}" == "rust" ]; then
  42. # Wipe pocedural map.
  43. if [ "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.map")" ]; then
  44. currentaction="Removing map file(s): ${serveridentitydir}/proceduralmap.*.map"
  45. echo -en "Removing procedural map proceduralmap.*.map file(s)..."
  46. fn_sleep_time
  47. fn_script_log "${currentaction}"
  48. find "${serveridentitydir:?}" -type f -name "proceduralmap.*.map" -delete
  49. fn_wipe_exit_code
  50. fn_sleep_time
  51. else
  52. fn_print_information_nl "No procedural map file to remove"
  53. fn_script_log_info "No procedural map file to remove."
  54. fi
  55. # Wipe procedural map save.
  56. if [ "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.sav")" ]; then
  57. currentaction="Removing procedural map save(s): ${serveridentitydir}/proceduralmap.*.sav"
  58. echo -en "Removing map saves proceduralmap.*.sav file(s)..."
  59. fn_sleep_time
  60. fn_script_log "${currentaction}"
  61. find "${serveridentitydir:?}" -type f -name "proceduralmap.*.sav" -delete
  62. fn_wipe_exit_code
  63. fn_sleep_time
  64. else
  65. fn_print_information_nl "No procedural map save to remove"
  66. fn_script_log_info "No procedural map save to remove."
  67. fi
  68. # Wipe Barren map.
  69. if [ "$(find "${serveridentitydir}" -type f -name "barren*.map")" ]; then
  70. currentaction="Removing map file(s): ${serveridentitydir}/barren*.map"
  71. echo -en "Removing barren map barren*.map file(s)..."
  72. fn_sleep_time
  73. fn_script_log "${currentaction}"
  74. find "${serveridentitydir:?}" -type f -name "barren*.map" -delete
  75. fn_wipe_exit_code
  76. fn_sleep_time
  77. else
  78. fn_print_information_nl "No barren map file to remove"
  79. fn_script_log_info "No barren map file to remove."
  80. fi
  81. # Wipe barren map save.
  82. if [ "$(find "${serveridentitydir}" -type f -name "barren*.sav")" ]; then
  83. currentaction="Removing barren map save(s): ${serveridentitydir}/barren*.sav"
  84. echo -en "Removing barren map saves barren*.sav file(s)..."
  85. fn_sleep_time
  86. fn_script_log "${currentaction}"
  87. find "${serveridentitydir:?}" -type f -name "barren*.sav" -delete
  88. fn_wipe_exit_code
  89. fn_sleep_time
  90. else
  91. fn_print_information_nl "No barren map save to remove"
  92. fn_script_log_info "No barren map save to remove."
  93. fi
  94. # Wipe user dir, might be a legacy thing, maybe to be removed.
  95. if [ -d "${serveridentitydir}/user" ]; then
  96. currentaction="Removing user directory: ${serveridentitydir}/user"
  97. echo -en "Removing user directory..."
  98. fn_sleep_time
  99. fn_script_log "${currentaction}"
  100. rm -rf "${serveridentitydir:?}/user"
  101. fn_wipe_exit_code
  102. fn_sleep_time
  103. # We do not print additional information if there is nothing to remove since this might be obsolete.
  104. fi
  105. # Wipe storage dir, might be a legacy thing, maybe to be removed.
  106. if [ -d "${serveridentitydir}/storage" ]; then
  107. currentaction="Removing storage directory: ${serveridentitydir}/storage"
  108. echo -en "Removing storage directory..."
  109. fn_sleep_time
  110. fn_script_log "${currentaction}"
  111. rm -rf "${serveridentitydir:?}/storage"
  112. fn_wipe_exit_code
  113. fn_sleep_time
  114. # We do not print additional information if there is nothing to remove since this might be obsolete.
  115. fi
  116. # Wipe sv.files.
  117. if [ "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then
  118. currentaction="Removing server misc files: ${serveridentitydir}/sv.files.*.db"
  119. echo -en "Removing server misc srv.files*.db file(s)..."
  120. fn_sleep_time
  121. fn_script_log "${currentaction}"
  122. find "${serveridentitydir:?}" -type f -name "sv.files.*.db" -delete
  123. fn_wipe_exit_code
  124. fn_sleep_time
  125. # No further information if not found because it should I could not get this file showing up.
  126. fi
  127. # Wipe player death files.
  128. if [ "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]; then
  129. currentaction="Removing player death files: ${serveridentitydir}/player.deaths.*.db"
  130. echo -en "Removing player deaths player.deaths.*.db file(s)..."
  131. fn_sleep_time
  132. fn_script_log "${currentaction}"
  133. find "${serveridentitydir:?}" -type f -name "player.deaths.*.db" -delete
  134. fn_wipe_exit_code
  135. fn_sleep_time
  136. else
  137. fn_print_information_nl "No player death to remove"
  138. fn_script_log_info "No player death to remove."
  139. fi
  140. # Wipe blueprints only if wipeall command was used.
  141. if [ "${wipeall}" == "1" ]; then
  142. if [ "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then
  143. currentaction="Removing blueprint file(s): ${serveridentitydir}/player.blueprints.*.db"
  144. echo -en "Removing blueprints player.blueprints.*.db file(s)..."
  145. fn_sleep_time
  146. fn_script_log "${currentaction}"
  147. find "${serveridentitydir:?}" -type f -name "player.blueprints.*.db" -delete
  148. fn_wipe_exit_code
  149. fn_sleep_time
  150. else
  151. fn_print_information_nl "No blueprint file to remove"
  152. fn_script_log_info "No blueprint file to remove."
  153. fi
  154. elif [ "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then
  155. fn_print_information_nl "Keeping blueprints"
  156. fn_script_log_info "Keeping blueprints."
  157. else
  158. fn_print_information_nl "No blueprints found"
  159. fn_script_log_info "No blueprints found."
  160. fn_sleep_time
  161. fi
  162. # Wipe some logs that might be there.
  163. if [ "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
  164. currentaction="Removing log files: ${serveridentitydir}/Log.*.txt"
  165. echo -en "Removing Log files..."
  166. fn_sleep_time
  167. fn_script_log "${currentaction}"
  168. find "${serveridentitydir:?}" -type f -name "Log.*.txt" -delete
  169. fn_wipe_exit_code
  170. fn_sleep_time
  171. # We do not print additional information if there are no logs to remove.
  172. fi
  173. # You can add an "elif" here to add another game or engine.
  174. fi
  175. }
  176. # Check if there is something to wipe, prompt the user, and call appropriate functions.
  177. # Rust Wipe.
  178. if [ "${shortname}" == "rust" ]; then
  179. 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")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then
  180. fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased."
  181. if ! fn_prompt_yn "Continue?" Y; then
  182. core_exit.sh
  183. fi
  184. fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}"
  185. fn_sleep_time
  186. fn_wipe_server_process
  187. else
  188. fn_print_information_nl "No data to wipe was found"
  189. fn_script_log_info "No data to wipe was found."
  190. core_exit.sh
  191. fi
  192. # You can add an "elif" here to add another game or engine.
  193. else
  194. # Game not listed.
  195. fn_print_information_nl "Wipe is not available for this game"
  196. fn_script_log_info "Wipe is not available for this game."
  197. core_exit.sh
  198. fi
  199. core_exit.sh