minecraft.sh 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #!/bin/bash
  2. recover_backup=YES
  3. backup_file="/Cloud/Backup/Minecraft/Minecraft_ubuntu.tar.xz"
  4. function print_centered {
  5. [[ $# == 0 ]] && return 1
  6. declare -i TERM_COLS="$(tput cols)"
  7. declare -i str_len="${#1}"
  8. [[ $str_len -ge $TERM_COLS ]] && {
  9. echo "$1";
  10. return 0;
  11. }
  12. declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
  13. [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
  14. filler=""
  15. for (( i = 0; i < filler_len; i++ )); do
  16. filler="${filler}${ch}"
  17. done
  18. printf "%s%s%s" "$filler" "$1" "$filler"
  19. [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
  20. printf "\n"
  21. return 0
  22. }
  23. function backup_tool {
  24. echo -e "\n$(tput setaf 10)Backup tool:$(tput setaf 7)"
  25. if [ -f /tmp/mcbackup.sh ];then rm /tmp/mcbackup.sh;fi
  26. cat <<'EOF'>> /tmp/mcbackup.sh
  27. #!/bin/bash
  28. ####################################
  29. #
  30. # Backup minecraft world to a
  31. # specified folder.
  32. #
  33. ####################################
  34. set -e
  35. #sudo systemctl stop watchdog >/dev/null
  36. version=3.0
  37. #day_raw=$(date +%A_%d_%m_%y)
  38. #archive_file="minecraft_ubuntu_$day_raw"
  39. archive_file="Minecraft_ubuntu"
  40. output_folder="/Cloud/Backup/Minecraft"
  41. echo -e "\e[95mMinecraft auto-backup version $version\e[0m\n"
  42. function backup_ {
  43. echo "Backup/Compress Files:"
  44. cd ~
  45. if [ -d temp_arc ]
  46. then
  47. rm -r -f temp_arc
  48. fi
  49. mkdir temp_arc
  50. cd temp_arc
  51. cp -r -f ~/Minecraft/world* .
  52. cp -r -f ~/Minecraft/ops.json .
  53. cp -r -f ~/Minecraft/permissions.yml .
  54. cp -r -f ~/Minecraft/server.properties .
  55. cp -r -f ~/Minecraft/usercache.json .
  56. cp -r -f ~/Minecraft/whitelist.json .
  57. tar cf - * --checkpoint=.100 | pixz > $archive_file.tar.xz
  58. echo ""
  59. md5sum $archive_file.tar.xz > $archive_file.md5
  60. cp $archive_file.tar.xz $output_folder
  61. cp $archive_file.md5 $output_folder
  62. }
  63. function Upload_freebox {
  64. echo -e "\n\e[97mUpload on Freebox:\e[0m"
  65. echo "- Mounting Nas -"
  66. sudo mount -t cifs //192.168.1.254/Disque\ dur/ /media/Nas/ -o user=freebox,password=password,uid=1000,gid=1000,rw,vers=1.0
  67. sleep 1
  68. sudo cp -v $archive_file.tar.xz /media/Nas/mc_backup
  69. sudo cp -v $archive_file.md5 /media/Nas/mc_backup
  70. sleep 1
  71. sudo umount /media/Nas
  72. echo "- Unmounting Nas -"
  73. echo ""
  74. }
  75. function Upload_ftp {
  76. echo -e "\e[97mUpload on FTP:\e[0m"
  77. ncftpput -v -u "wareck" -p "zorn692611" ftpperso.free.fr minecraft_bkp/ $archive_file.tar.xz
  78. sleep 1
  79. ncftpput -v -u "wareck" -p "zorn692611" ftpperso.free.fr minecraft_bkp/ $archive_file.md5
  80. sleep 1
  81. }
  82. backup_
  83. Upload_freebox
  84. Upload_ftp
  85. EOF
  86. sudo chmod +x /tmp/mcbackup.sh
  87. sudo cp /tmp/mcbackup.sh /usr/local/bin/
  88. echo "Done"
  89. }
  90. function recovery {
  91. if [ $recover_backup = "YES" ]
  92. then
  93. echo -e "\n$(tput setaf 10)Restore Backup:$(tput sgr0)"
  94. if [ -r /home/wareck/temp_arc ]
  95. then
  96. rm -r /home/wareck/temp_arc
  97. fi
  98. mkdir /home/wareck/temp_arc
  99. cd /home/wareck/temp_arc
  100. cp $backup_file .
  101. pixz -x < $backup_file | tar xf - --checkpoint=.300
  102. echo ""
  103. rm Mine*.tar.xz
  104. cp -r /home/wareck/temp_arc/* /home/wareck/Minecraft/
  105. sudo rm -r /home/wareck/temp_arc
  106. fi
  107. echo -e
  108. }
  109. export TERM=xterm-256color
  110. print_centered "$(tput setaf 10)"
  111. print_centered " ⠀⠀⡰⠉⠉⣷⡄⣀⣎⠉⢹⡎⠉⢉⡞⠉⠉⣧⡎⠉⠉⡞⠉⠉⠉⠉⠉⣿⠉⠉⠉⠉⠉⢹⡏⠋⠉⠉⠉⠙⡏⠉⣉⠉⣉⠉⢿⠉⠉⠉⢉⠉⢱⡏⠉⠉⠉⢉⠉⡄"
  112. print_centered "⠀⢀⠃⠀⠀⠘⠛⠁⠀⠀⣼⠀⠀⣸⠃⠀⠀⠘⠃⠀⢰⡇⠀⠀⠛⠛⠛⣿⠀⠀⢸⣿⣿⣿⡇⠀⠈⠃⠀⣠⣿⠀⠉⣶⣍⠀⢸⡆⠀⠘⠛⠛⠛⣿⣿⡆⠀⠈⡟⠁"
  113. print_centered "⠀⡜⣀⢀⣶⣀⣰⠆⠀⢀⡏⠀⠀⣿⠀⠀⣸⣄⠤⠄⢸⠃⠀⢰⣶⣶⣶⣿⠀⠀⢸⣉⣉⣉⡇⡀⠀⣶⠀⠀⢹⠀⠀⢀⡀⢀⠀⣇⠀⠀⢶⣶⣶⢾⣿⣿⡀⠀⢱⠀"
  114. print_centered "⢰⠀⠀⢸⣿⣦⠈⠀⠀⢼⠁⠀⢰⡇⠀⠀⣿⣿⠀⠀⢼⠀⡄⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⢸⡇⠂⠀⣿⠀⠀⢸⡆⠀⢘⡧⠀⠀⣿⠀⠀⢸⠛⠃⠘⣿⣿⡇⠀⠀⡆"
  115. print_centered "⠀⠑⢤⣀⣙⡿⠉⠱⣄⣠⣷⣄⣀⣹⣄⣀⣘⡏⢆⣀⣘⣧⣀⣀⣀⣀⣀⣿⣀⣀⣀⣀⣀⣸⣇⣀⣰⣏⣀⣠⣿⣀⣀⣾⣁⣀⣴⣋⣀⡠⠃⠀⠀⠀⢿⣋⣀⡤⠋⠀"
  116. print_centered "$(tput sgr0)"
  117. print_centered "Minecraft Ubuntu Server Builder/install v2.2"
  118. print_centered "$(tput sgr0)"
  119. sleep 2
  120. echo -e "$(tput setaf 10)Installation java:$(tput setaf 7)"
  121. if ! [ -x "$(command -v java)" ]
  122. then
  123. sudo apt-get update
  124. sudo apt-get install curl wget git ncftp -y
  125. if ! [ -f openjdk-18_linux-x64_bin.tar.gz ]
  126. then
  127. echo -e
  128. curl -O https://download.java.net/java/GA/jdk18/43f95e8614114aeaa8e8a5fcf20a682d/36/GPL/openjdk-18_linux-x64_bin.tar.gz
  129. fi
  130. cat <<'EOF'>> openjdk-18_linux-x64_bin.tar.gz.md5
  131. f3fc42bd35c3f5e9aff967c9862a153a openjdk-18_linux-x64_bin.tar.gz
  132. EOF
  133. if md5sum -c openjdk-18_linux-x64_bin.tar.gz.md5
  134. then
  135. tar xf openjdk-18_linux-x64_bin.tar.gz --checkpoint=.300
  136. echo -e
  137. rm openjdk-18_linux-x64_bin.tar.gz
  138. rm openjdk-18_linux-x64_bin.tar.gz.md5
  139. else
  140. echo "erreur"
  141. fi
  142. if [ -d /opt/jdk-18 ]
  143. then
  144. sudo rm -r /opt/jdk-18/
  145. fi
  146. sudo mv jdk-18 /opt/
  147. if [ -f /etc/profile.d/jdk18.sh ]
  148. then
  149. sudo rm /etc/profile.d/jdk18.sh
  150. fi
  151. sudo tee /etc/profile.d/jdk18.sh <<EOF
  152. export JAVA_HOME=/opt/jdk-18
  153. export PATH=\$PATH:\$JAVA_HOME/bin
  154. EOF
  155. source /etc/profile.d/jdk18.sh
  156. fi
  157. version=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
  158. if [ $version -ge 18 ]
  159. then
  160. echo -e "$(tput setaf 6)Java version $version =>> OK$(tput sgr0)"
  161. else
  162. echo "erreur ! désinstaller java d'abord !"
  163. exit 1
  164. fi
  165. echo -e "\n$(tput setaf 10)Download/install mcrcon:$(tput sgr0)"
  166. cd /home/wareck/
  167. git clone https://github.com/Tiiffi/mcrcon.git
  168. cd /home/wareck/mcrcon
  169. make
  170. sudo make install
  171. cd ..
  172. rm -r -f /home/wareck/mcrcon
  173. echo -e "$(tput setaf 10)Download Minecraft server structure:$(tput sgr0)"
  174. cd /home/wareck/
  175. wget -c http://folivier.homelinux.org/cube/pack/minecraft.tar.xz
  176. tar xfJ minecraft.tar.xz
  177. rm minecraft.tar.xz
  178. cp -r minecraft Minecraft
  179. rm -r -f minecraft
  180. cd Minecraft
  181. rsync --append --progress --recursive * /home/wareck/Minecraft/
  182. echo -e "\n$(tput setaf 10)Download BuildTools:$(tput sgr0)"
  183. if ! [ -d build ]; then mkdir build ;fi
  184. cd build
  185. wget -c https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
  186. echo -e "\n$(tput setaf 10)Building Spigot:$(tput sgr0)"
  187. java -jar BuildTools.jar
  188. cp spigot* /home/wareck/Minecraft/
  189. echo -e "\n$(tput setaf 10)minecraft.service file build/install:$(tput sgr0)"
  190. if [ -f minecraft.service ];then rm minecraft.service;fi
  191. version=`ls -a /home/wareck/Minecraft/spigot*.jar | sed "s/\/home\/wareck\/Minecraft\///g"`
  192. short_v=`echo $version | sed "s/spigot-//g" | sed "s/.jar//g"`
  193. echo "Version builed : $version"
  194. cat <<'EOF'>> minecraft.service
  195. #!/bin/sh -e
  196. ### BEGIN INIT INFO
  197. # Provides: minecraft
  198. # Required-Start: networking
  199. # Default-Start: 3 4 5
  200. # Default-Stop: 0 6
  201. ### END INIT INFO
  202. cd /home/wareck/Minecraft/
  203. su wareck -c "screen -dmS minecraft /opt/jdk-18/bin/java -jar -Xmx2048M -Xms2048M XXXX nogui"
  204. exit 0
  205. EOF
  206. sed -i "s/XXXX/$version/g" minecraft.service
  207. sed -i "s/XXXX/$version/g" /home/wareck/Minecraft/start.sh
  208. sed -i "s/XXXX/$short_v/g" /home/wareck/Minecraft/server.properties
  209. more minecraft.service
  210. chmod +x minecraft.service
  211. sudo cp minecraft.service /etc/init.d/
  212. sudo sudo update-rc.d minecraft.service defaults
  213. backup_tool
  214. recovery
  215. function server_config {
  216. echo -e "\nDone"
  217. cat <<'EOF'>> /tmp/sp
  218. #Minecraft server properties
  219. #Sat Dec 30 04:15:00 CET 2023
  220. allow-flight=true
  221. allow-nether=true
  222. broadcast-console-to-ops=true
  223. broadcast-rcon-to-ops=true
  224. debug=false
  225. difficulty=easy
  226. enable-command-block=true
  227. enable-jmx-monitoring=false
  228. enable-query=false
  229. enable-rcon=true
  230. enable-status=true
  231. enforce-secure-profile=true
  232. enforce-whitelist=false
  233. entity-broadcast-range-percentage=100
  234. force-gamemode=true
  235. function-permission-level=2
  236. gamemode=creative
  237. generate-structures=true
  238. generator-settings={}
  239. grow-trees=true
  240. hardcore=false
  241. hide-online-players=false
  242. initial-disabled-packs=
  243. initial-enabled-packs=vanilla
  244. level-name=world
  245. level-seed=
  246. level-type=default
  247. log-ips=true
  248. max-build-height=256
  249. max-chained-neighbor-updates=1000000
  250. max-players=20
  251. max-tick-time=120000
  252. max-world-size=29999984
  253. motd=§e§l§m--§6§8§l[§r §A§lTristan's Field §8§l]§e§l§m--§8§l[ §6serveur vZZZZZZZ \!§8§l ]§e§l§m--
  254. network-compression-threshold=512
  255. online-mode=true
  256. op-permission-level=1
  257. player-idle-timeout=0
  258. prevent-proxy-connections=false
  259. previews-chat=false
  260. pvp=true
  261. query.port=25565
  262. rate-limit=0
  263. rcon.password=Paypoo
  264. rcon.port=25575
  265. require-resource-pack=false
  266. resource-pack=
  267. resource-pack-prompt=
  268. resource-pack-sha1=
  269. server-ip=
  270. server-port=25565
  271. simulation-distance=10
  272. snooper-enabled=false
  273. spawn-animals=true
  274. spawn-monsters=true
  275. spawn-npcs=true
  276. spawn-protection=0
  277. sync-chunk-writes=true
  278. text-filtering-config=
  279. use-native-transport=true
  280. view-distance=10
  281. white-list=false
  282. EOF
  283. sed -i "s/ZZZZZZZ/$short_v/g" /tmp/sp
  284. cp /tmp/sp /home/wareck/Minecraft/server.properties
  285. }
  286. server_config
  287. echo "Done"