command_wipe.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/bash
  2. # LinuxGSM command_backup.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  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. fn_firstcommand_set
  11. # Provides an exit code upon error.
  12. fn_wipe_exit_code(){
  13. exitcode=$?
  14. if [ "${exitcode}" != 0 ]; then
  15. fn_print_fail_eol_nl
  16. core_exit.sh
  17. else
  18. fn_print_ok_eol_nl
  19. fi
  20. }
  21. # Removes files to wipe server.
  22. fn_wipe_files(){
  23. fn_print_start_nl "${wipetype}"
  24. fn_script_log_info "${wipetype}"
  25. # Remove Map files
  26. if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
  27. if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ]; then
  28. echo -en "removing .map file(s)..."
  29. fn_script_log_info "removing *.map file(s)"
  30. fn_sleep_time
  31. find "${serveridentitydir:?}" -type f -name "*.map" -printf "%f\n" >> "${lgsmlog}"
  32. find "${serveridentitydir:?}" -type f -name "*.map" -delete | tee -a "${lgsmlog}"
  33. fn_wipe_exit_code
  34. else
  35. echo -e "no .map file(s) to remove"
  36. fn_sleep_time
  37. fn_script_log_pass "no .map file(s) to remove"
  38. fi
  39. fi
  40. # Remove Save files.
  41. if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
  42. if [ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]; then
  43. echo -en "removing .sav file(s)..."
  44. fn_script_log_info "removing .sav file(s)"
  45. fn_sleep_time
  46. find "${serveridentitydir:?}" -type f -name "*.sav*" -printf "%f\n" >> "${lgsmlog}"
  47. find "${serveridentitydir:?}" -type f -name "*.sav*" -delete
  48. fn_wipe_exit_code
  49. else
  50. echo -e "no .sav file(s) to remove"
  51. fn_script_log_pass "no .sav file(s) to remove"
  52. fn_sleep_time
  53. fi
  54. fi
  55. # Remove db files for full wipe.
  56. # Excluding player.tokens.db for Rust+.
  57. if [ -n "${serverwipe}" ]; then
  58. if [ -n "$(find "${serveridentitydir}" -type f ! -name 'player.tokens.db' -name "*.db")" ]; then
  59. echo -en "removing .db file(s)..."
  60. fn_script_log_info "removing .db file(s)"
  61. fn_sleep_time
  62. find "${serveridentitydir:?}" -type f ! -name 'player.tokens.db' -name "*.db" -printf "%f\n" >> "${lgsmlog}"
  63. find "${serveridentitydir:?}" -type f ! -name 'player.tokens.db' -name "*.db" -delete
  64. fn_wipe_exit_code
  65. else
  66. echo -e "no .db file(s) to remove"
  67. fn_sleep_time
  68. fn_script_log_pass "no .db file(s) to remove"
  69. fi
  70. fi
  71. }
  72. fn_map_wipe_warning(){
  73. fn_print_warn "Map wipe will reset the map data and keep blueprint data"
  74. fn_script_log_warn "Map wipe will reset the map data and keep blueprint data"
  75. totalseconds=3
  76. for seconds in {3..1}; do
  77. fn_print_warn "Map wipe will reset the map data and keep blueprint data: ${totalseconds}"
  78. totalseconds=$((totalseconds - 1))
  79. sleep 1
  80. if [ "${seconds}" == "0" ]; then
  81. break
  82. fi
  83. done
  84. fn_print_warn_nl "Map wipe will reset the map data and keep blueprint data"
  85. }
  86. fn_full_wipe_warning(){
  87. fn_print_warn "Server wipe will reset the map data and remove blueprint data"
  88. fn_script_log_warn "Server wipe will reset the map data and remove blueprint data"
  89. totalseconds=3
  90. for seconds in {3..1}; do
  91. fn_print_warn "Server wipe will reset the map data and remove blueprint data: ${totalseconds}"
  92. totalseconds=$((totalseconds - 1))
  93. sleep 1
  94. if [ "${seconds}" == "0" ]; then
  95. break
  96. fi
  97. done
  98. fn_print_warn_nl "Server wipe will reset the map data and remove blueprint data"
  99. }
  100. # Will change the seed if the seed is not defined by the user.
  101. fn_wipe_random_seed(){
  102. if [ -f "${datadir}/${selfname}-seed.txt" ]&&[ -n "${randomseed}" ]; then
  103. shuf -i 1-2147483647 -n 1 > "${datadir}/${selfname}-seed.txt"
  104. seed=$(cat "${datadir}/${selfname}-seed.txt")
  105. randomseed=1
  106. echo -en "generating new random seed (${cyan}${seed}${default})..."
  107. fn_script_log_pass "generating new random seed (${cyan}${seed}${default})"
  108. fn_sleep_time
  109. fn_print_ok_eol_nl
  110. fi
  111. }
  112. # A summary of what wipe is going to do.
  113. fn_wipe_details(){
  114. fn_print_information_nl "Wipe does not remove Rust+ data."
  115. echo -en "* Wipe map data: "
  116. if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
  117. fn_print_yes_eol_nl
  118. else
  119. fn_print_no_eol_nl
  120. fi
  121. echo -en "* Wipe blueprint data: "
  122. if [ -n "${serverwipe}" ]; then
  123. fn_print_yes_eol_nl
  124. else
  125. fn_print_no_eol_nl
  126. fi
  127. echo -en "* Change Procedural Map seed: "
  128. if [ -n "${randomseed}" ]; then
  129. fn_print_yes_eol_nl
  130. else
  131. fn_print_no_eol_nl
  132. fi
  133. }
  134. fn_print_dots ""
  135. check.sh
  136. fix_rust.sh
  137. # Check if there is something to wipe.
  138. if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]&&[ -n "$(find "${serveridentitydir}" -type f ! -name 'player.tokens.db' -name "*.db")" ]; then
  139. if [ -n "${serverwipe}" ]; then
  140. wipetype="Full wipe"
  141. fn_full_wipe_warning
  142. fn_wipe_details
  143. elif [ -n "${mapwipe}" ]; then
  144. wipetype="Map wipe"
  145. fn_map_wipe_warning
  146. fn_wipe_details
  147. fi
  148. check_status.sh
  149. if [ "${status}" != "0" ]; then
  150. fn_print_restart_warning
  151. exitbypass=1
  152. command_stop.sh
  153. fn_firstcommand_reset
  154. fn_wipe_files
  155. fn_wipe_random_seed
  156. fn_print_complete_nl "${wipetype}"
  157. fn_script_log_pass "${wipetype}"
  158. exitbypass=1
  159. command_start.sh
  160. fn_firstcommand_reset
  161. else
  162. fn_wipe_files
  163. fn_wipe_random_seed
  164. fn_print_complete_nl "${wipetype}"
  165. fn_script_log_pass "${wipetype}"
  166. fi
  167. else
  168. fn_print_ok_nl "Wipe not required"
  169. fn_script_log_pass "Wipe not required"
  170. fi
  171. core_exit.sh