command_wipe.sh 7.3 KB

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