minecraft.sh 9.0 KB

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