Advertisement
slyfox1186

minecraft-server-launcher.sh

Nov 21st, 2022 (edited)
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.67 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. pushd "${PWD}" || exit 1
  4. #
  5. clear
  6. #
  7. ### Important script information below
  8. #
  9. ### IP = server WAN on LAN address that hosts the Minecraft server
  10. #
  11. ### PW = rcon password (set in server.properties)
  12. #
  13. ### PORT = server default rcon port (change if needed and is set in server.properties)
  14. #
  15. ### SCRIPT = the default server start script that comes with the server files you download
  16. ###          from the Curseforge Desktop App (or you can google "Curseforge + the mod pack name")
  17. #
  18. ### Download server files via Curseforge Desktop App
  19. #     1) Use the Curseforge app to install the mod of your choosing (requires overwolf.exe)
  20. #     2) Click the 3 dots in the mod's main menu and use the drop-down menu to select
  21. #        "Download Server Files"
  22. #     3) Transport the server files to the Linux (Debian) pc you want to run the server on
  23. #     4) Set the below variables as needed for this script to work successfully
  24. #
  25. IP=192.168.1.40
  26. PW=47j8a8&
  27. PORT=25575
  28. SCRIPT=start.sh
  29. #
  30. ### Install the mcrcon package if not found
  31. ### Use Git to download the repository and then install with the make command
  32. #
  33. if [ ! -f '/usr/local/bin/mcrcon' ]; then
  34.     git clone 'https://github.com/Tiiffi/mcrcon.git'
  35.     cd mcrcon || exit 1
  36.     make "-j$(nproc)"
  37.     sudo make install
  38. fi
  39. #
  40. ### Install HTOP Process Monitor
  41. #
  42. if [ ! -f '/usr/bin/htop' ]; then sudo apt -y install htop; fi
  43. #
  44. ### Install Screen package if not found
  45. #
  46. if [ ! -f '/usr/bin/screen' ]; then sudo apt -y install screen; fi
  47. #
  48. ### Set color vars
  49. #
  50. BLUE="\033[34m"
  51. CYAN="\033[36m"
  52. GREEN="\033[32m"
  53. MAGENTA="\033[35m"
  54. RED="\033[31m"
  55. RESET="\033[0m"
  56. YELLOW="\033[33m"
  57. #
  58. ### Set color functions
  59. #
  60. greenprint() { printf "${GREEN}%s${RESET}\n" "$1"; }
  61. blueprint() { printf "${BLUE}%s${RESET}\n" "$1"; }
  62. redprint() { printf "${RED}%s${RESET}\n" "$1"; }
  63. yellowprint() { printf "${YELLOW}%s${RESET}\n" "$1"; }
  64. magentaprint() { printf "${MAGENTA}%s${RESET}\n" "$1"; }
  65. cyanprint() { printf "${CYAN}%s${RESET}\n" "$1"; }
  66. #
  67. ### Set misc functions
  68. #
  69. fn_remindUser() { clear; echo 'Please input one of the available choices.'; }
  70. fn_exit() { clear; exit 0; }
  71. fn_fail() { clear; echo -e "\\n[i] Invalid input: Please try a different choice.\\n"; exit 1; }
  72. clear
  73. #
  74. ### Fast stop server
  75. #
  76. fn_faststop_server()
  77. {
  78.     echo -e "Server shutdown command executed... please wait.\\n"
  79.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 10 "say Server stopping!" save-all stop && \
  80.     sudo killall java && \
  81.     echo -e "[i] The server has stopped.\\n"
  82.     echo
  83.     sleep 3
  84.     htop
  85. }
  86. #
  87. ### Restart server
  88. #
  89. fn_restart_server()
  90. {
  91.     echo -e "[i] Server restarting in 30 seconds...\\n    - Warning users to save their work within 30 seconds..."
  92.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 2 "say The server is restarting in 30 seconds!"
  93.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 13 "say Please save all work!"
  94.     echo -e "[i] Server restarting in 15 seconds...\\n    - Warning users to save their work within 15 seconds..."
  95.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 2 "say The server is restarting in 15 seconds!"
  96.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 8 "say Please save all work NOW!"
  97.     echo -e "[i] Server restarting in  5 seconds...\\n    - Warning users to save their work within 5 seconds..."
  98.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 1 "say The server is restarting in 5 seconds!"
  99.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 4 "say Please save all work NOW!"
  100.     echo -e "[i] Server restarting...\\n"
  101.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 10 "say Server restarting!" save-all stop && \
  102.     sudo killall java && \
  103.     echo -e "[i] Executing command: screen -dmS mc ./"${SCRIPT}"\\n    - Please wait for the server to completely load before reconnecting.\\n"
  104.     screen -dmS mc ./"${SCRIPT}"
  105.     echo
  106.     sleep 3
  107.     htop
  108. }
  109. #
  110. ### Stop server
  111. #
  112. fn_stop_server()
  113. {
  114.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 2 "say The server is stopping in 30 seconds!"
  115.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 13 "say Please save all work!"
  116.     echo -e "[i] Server stopping in 30 seconds...\\n    - Warning users to save their work within 30 seconds..." && \
  117.     echo -e "[i] Warning users to save their work within 30 seconds..."
  118.     echo -e "[i] Server stopping in 15 seconds...\\n    - Warning users to save their work within 15 seconds..."
  119.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 2 "say The server is stopping in 15 seconds!"
  120.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 8 "say Please save all work NOW!"
  121.     echo -e "[i] Server stopping in  5 seconds...\\n    - Warning users to save their work within 5 seconds..."
  122.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 1 "say The server is stopping in 5 seconds!"
  123.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 4 "say Please save all work NOW!"
  124.     echo -e "[i] Server stopping..."
  125.     mcrcon -H ${IP} -P ${PORT} -p ${PW} -w 10 "say Server stopping!" save-all stop && \
  126.     sudo killall java && \
  127.     echo -e "[i] The server has stopped.\\n"
  128.     echo
  129.     sleep 3
  130.     htop
  131. }
  132. #
  133. ### Start server
  134. #
  135. fn_start_server()
  136. {
  137.     local SCRIPT
  138.     echo -e "[i] Executing command: screen -dmS mc ./${SCRIPT}\\n    - Please wait for the server to completely load before reconnecting.\\n"
  139.     screen -dmS mc ./"${SCRIPT}"
  140.     echo
  141.     sleep 2
  142.     htop
  143. }
  144. #
  145. ### Start subemenu section
  146. #
  147. ### submenu4
  148. #
  149. submenu4()
  150. {
  151.     local i
  152.     echo -e "$(cyanprint 'Fast Stop the server?')"
  153. echo -ne "
  154. $(greenprint '1)') Yes
  155. $(magentaprint '2)') No
  156. $(redprint '3)') Exit
  157. Make a choice: "
  158.     read -r i
  159.     case ${i} in
  160.     1)
  161.         clear
  162.         fn_faststop_server
  163.         fn_exit
  164.         ;;
  165.     2)
  166.         clear
  167.         mainmenu
  168.         ;;
  169.     3)
  170.         fn_exit
  171.         ;;
  172.     *)
  173.         fn_fail
  174.         ;;
  175.     esac
  176. }
  177. #
  178. ### submenu3
  179. #
  180. submenu3()
  181. {
  182.     local i
  183.     echo -e "$(cyanprint 'Restart the server?')"
  184.     echo -ne "
  185. $(greenprint '1)') Yes
  186. $(magentaprint '2)') No
  187. $(redprint '3)') Exit
  188. Make a choice: "
  189.     read -r i
  190.     case ${i} in
  191.     1)
  192.         clear
  193.         fn_restart_server
  194.         fn_exit
  195.         ;;
  196.     2)
  197.         clear
  198.         mainmenu
  199.         ;;
  200.     3)
  201.         fn_exit
  202.         ;;
  203.     *)
  204.         fn_fail
  205.         ;;
  206.     esac
  207. }
  208. #
  209. ### submenu2
  210. #
  211. submenu2()
  212. {
  213.     local i
  214.     echo -e "$(cyanprint 'Stop the server?')"
  215.     echo -ne "
  216. $(greenprint '1)') Yes
  217. $(magentaprint '2)') No
  218. $(redprint '3)') Exit
  219. Make a choice: "
  220.     read -r i
  221.     case ${i} in
  222.     1)
  223.         clear
  224.         fn_stop_server
  225.         fn_exit
  226.         ;;
  227.     2)
  228.         clear
  229.         mainmenu
  230.         ;;
  231.     3)
  232.         fn_exit
  233.         ;;
  234.     *)
  235.         fn_fail
  236.         ;;
  237.     esac
  238. }
  239. #
  240. ### submenu1
  241. #
  242. submenu1()
  243. {
  244.     local i
  245.     echo -e "$(cyanprint 'Start the server?')"
  246.     echo -ne "
  247. $(greenprint '1)') Yes
  248. $(magentaprint '2)') No
  249. $(redprint '3)') Exit
  250. Make a choice: "
  251.     read -r i
  252.     case ${i} in
  253.     1)
  254.         clear
  255.         fn_start_server
  256.         fn_exit
  257.         ;;
  258.     2)
  259.         clear
  260.         mainmenu
  261.         ;;
  262.     3)
  263.         fn_exit
  264.         ;;
  265.     *)
  266.         fn_fail
  267.         ;;
  268.     esac
  269. }
  270. #
  271. ### Main Menu
  272. #
  273. mainmenu()
  274. {
  275.     local i
  276.     echo -e "$(magentaprint '[i] Minecraft Server Launcher')"
  277.     echo -ne "
  278. $(greenprint '1)') Start Server
  279. $(redprint '2)') Stop Server
  280. $(yellowprint '3)') Restart Server
  281. $(cyanprint '4)') Fast Stop Server
  282. $(magentaprint '5)') Exit
  283. Make a choice: "
  284.     read -r i
  285.     case ${i} in
  286.     1)
  287.         clear
  288.         submenu1
  289.         ;;
  290.     2)
  291.         clear
  292.         submenu2
  293.         ;;
  294.     3)
  295.         clear
  296.         submenu3
  297.         ;;
  298.     4)
  299.         clear
  300.         submenu4
  301.         ;;
  302.     5)
  303.         fn_exit
  304.         ;;
  305.     *)
  306.         fn_fail
  307.         ;;
  308.     esac
  309. }
  310. #
  311. mainmenu
  312.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement