#!/bin/bash ScriptLoc=$(readlink -f "$0") recover_backup=YES backup_file="/Cloud/Backup/Minecraft/Minecraft_ubuntu.tar.xz" function print_centered { [[ $# == 0 ]] && return 1 declare -i TERM_COLS="$(tput cols)" declare -i str_len="${#1}" [[ $str_len -ge $TERM_COLS ]] && { echo "$1"; return 0; } declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))" [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" " filler="" for (( i = 0; i < filler_len; i++ )); do filler="${filler}${ch}" done printf "%s%s%s" "$filler" "$1" "$filler" [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}" printf "\n" return 0 } function backup_tool { echo -e "\n$(tput setaf 10)Backup tool:$(tput setaf 7)" if [ -f /tmp/mcbackup.sh ];then rm /tmp/mcbackup.sh;fi cat <<'EOF'>> /tmp/mcbackup.sh #!/bin/bash #################################### # # Backup minecraft world to a # specified folder. # #################################### set -e #sudo systemctl stop watchdog >/dev/null version=3.0 #day_raw=$(date +%A_%d_%m_%y) #archive_file="minecraft_ubuntu_$day_raw" archive_file="Minecraft_ubuntu" output_folder="/Cloud/Backup/Minecraft" echo -e "\e[95mMinecraft auto-backup version $version\e[0m\n" function backup_ { echo "Backup/Compress Files:" cd ~ if [ -d temp_arc ] then rm -r -f temp_arc fi mkdir temp_arc cd temp_arc cp -r -f ~/Minecraft/world* . cp -r -f ~/Minecraft/ops.json . cp -r -f ~/Minecraft/permissions.yml . cp -r -f ~/Minecraft/server.properties . cp -r -f ~/Minecraft/usercache.json . cp -r -f ~/Minecraft/whitelist.json . tar cf - * --checkpoint=.100 | pixz > $archive_file.tar.xz echo "" md5sum $archive_file.tar.xz > $archive_file.md5 cp $archive_file.tar.xz $output_folder cp $archive_file.md5 $output_folder } function Upload_freebox { echo -e "\n\e[97mUpload on Freebox:\e[0m" echo "- Mounting Nas -" 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 sleep 1 sudo cp -v $archive_file.tar.xz /media/Nas/mc_backup sudo cp -v $archive_file.md5 /media/Nas/mc_backup sleep 1 sudo umount /media/Nas echo "- Unmounting Nas -" echo "" } function Upload_ftp { echo -e "\e[97mUpload on FTP:\e[0m" ncftpput -v -u "wareck" -p "zorn692611" ftpperso.free.fr minecraft_bkp/ $archive_file.tar.xz sleep 1 ncftpput -v -u "wareck" -p "zorn692611" ftpperso.free.fr minecraft_bkp/ $archive_file.md5 sleep 1 } backup_ Upload_freebox Upload_ftp EOF sudo chmod +x /tmp/mcbackup.sh sudo cp /tmp/mcbackup.sh /usr/local/bin/ echo "Done" } function recovery { if [ $recover_backup = "YES" ] then echo -e "\n$(tput setaf 10)Restore Backup:$(tput sgr0)" if [ -r /home/wareck/temp_arc ] then rm -r /home/wareck/temp_arc fi mkdir /home/wareck/temp_arc cd /home/wareck/temp_arc cp $backup_file . pixz -x < $backup_file | tar xf - --checkpoint=.300 echo "" rm Mine*.tar.xz cp -r /home/wareck/temp_arc/* /home/wareck/Minecraft/ sudo rm -r /home/wareck/temp_arc fi echo -e } export TERM=xterm-256color if [ ! -f /home/wareck/.mcr ] then print_centered "$(tput setaf 10)" print_centered " ⠀⠀⡰⠉⠉⣷⡄⣀⣎⠉⢹⡎⠉⢉⡞⠉⠉⣧⡎⠉⠉⡞⠉⠉⠉⠉⠉⣿⠉⠉⠉⠉⠉⢹⡏⠋⠉⠉⠉⠙⡏⠉⣉⠉⣉⠉⢿⠉⠉⠉⢉⠉⢱⡏⠉⠉⠉⢉⠉⡄" print_centered "⠀⢀⠃⠀⠀⠘⠛⠁⠀⠀⣼⠀⠀⣸⠃⠀⠀⠘⠃⠀⢰⡇⠀⠀⠛⠛⠛⣿⠀⠀⢸⣿⣿⣿⡇⠀⠈⠃⠀⣠⣿⠀⠉⣶⣍⠀⢸⡆⠀⠘⠛⠛⠛⣿⣿⡆⠀⠈⡟⠁" print_centered "⠀⡜⣀⢀⣶⣀⣰⠆⠀⢀⡏⠀⠀⣿⠀⠀⣸⣄⠤⠄⢸⠃⠀⢰⣶⣶⣶⣿⠀⠀⢸⣉⣉⣉⡇⡀⠀⣶⠀⠀⢹⠀⠀⢀⡀⢀⠀⣇⠀⠀⢶⣶⣶⢾⣿⣿⡀⠀⢱⠀" print_centered "⢰⠀⠀⢸⣿⣦⠈⠀⠀⢼⠁⠀⢰⡇⠀⠀⣿⣿⠀⠀⢼⠀⡄⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⢸⡇⠂⠀⣿⠀⠀⢸⡆⠀⢘⡧⠀⠀⣿⠀⠀⢸⠛⠃⠘⣿⣿⡇⠀⠀⡆" print_centered "⠀⠑⢤⣀⣙⡿⠉⠱⣄⣠⣷⣄⣀⣹⣄⣀⣘⡏⢆⣀⣘⣧⣀⣀⣀⣀⣀⣿⣀⣀⣀⣀⣀⣸⣇⣀⣰⣏⣀⣠⣿⣀⣀⣾⣁⣀⣴⣋⣀⡠⠃⠀⠀⠀⢿⣋⣀⡤⠋⠀" print_centered "$(tput sgr0)" print_centered "Minecraft Ubuntu Server Builder/install v3.0.0" print_centered "$(tput sgr0)" touch /home/wareck/.mcr sleep 2 fi echo -e "$(tput setaf 10)Installation java:$(tput setaf 7)" if ! [ -x "$(command -v java)" ] then sudo apt-get update sudo apt-get install curl wget git ncftp -y if ! [ -f openjdk-18_linux-x64_bin.tar.gz ] then echo -e curl -O https://download.java.net/java/GA/jdk18/43f95e8614114aeaa8e8a5fcf20a682d/36/GPL/openjdk-18_linux-x64_bin.tar.gz fi cat <<'EOF'>> openjdk-18_linux-x64_bin.tar.gz.md5 f3fc42bd35c3f5e9aff967c9862a153a openjdk-18_linux-x64_bin.tar.gz EOF if md5sum -c openjdk-18_linux-x64_bin.tar.gz.md5 then tar xf openjdk-18_linux-x64_bin.tar.gz --checkpoint=.300 echo -e rm openjdk-18_linux-x64_bin.tar.gz rm openjdk-18_linux-x64_bin.tar.gz.md5 else echo "erreur" fi if [ -d /opt/jdk-18 ] then sudo rm -r /opt/jdk-18/ fi sudo mv jdk-18 /opt/ if [ -f /etc/profile.d/jdk18.sh ] then sudo rm /etc/profile.d/jdk18.sh fi sudo tee /etc/profile.d/jdk18.sh <&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1) if [ $version -ge 18 ] then echo -e "$(tput setaf 6)Java version $version =>> OK$(tput sgr0)" else echo "erreur ! désinstaller java d'abord !" sudo apt-get remove openjdk-8-jre-headless -y sudo apt-get remove openjdk-11-jre-headless -y exec "$ScriptLoc" fi echo -e "\n$(tput setaf 10)Download/install mcrcon:$(tput sgr0)" cd /home/wareck/ git clone https://github.com/Tiiffi/mcrcon.git cd /home/wareck/mcrcon make sudo make install cd .. rm -r -f /home/wareck/mcrcon echo -e "$(tput setaf 10)Download Minecraft server structure:$(tput sgr0)" cd /home/wareck/ wget -c http://folivier.homelinux.org/cube/pack/minecraft.tar.xz tar xfJ minecraft.tar.xz rm minecraft.tar.xz cp -r minecraft Minecraft rm -r -f minecraft cd Minecraft rsync --append --progress --recursive * /home/wareck/Minecraft/ echo -e "\n$(tput setaf 10)Download BuildTools:$(tput sgr0)" if ! [ -d build ]; then mkdir build ;fi cd build wget -c https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar echo -e "\n$(tput setaf 10)Building Spigot:$(tput sgr0)" java -jar BuildTools.jar cp spigot* /home/wareck/Minecraft/ echo -e "\n$(tput setaf 10)minecraft.service file build/install:$(tput sgr0)" if [ -f minecraft.service ];then rm minecraft.service;fi version=`ls -a /home/wareck/Minecraft/spigot*.jar | sed "s/\/home\/wareck\/Minecraft\///g"` short_v=`echo $version | sed "s/spigot-//g" | sed "s/.jar//g"` echo "Version builed : $version" cat <<'EOF'>> minecraft.service #!/bin/sh -e ### BEGIN INIT INFO # Provides: minecraft # Required-Start: networking # Default-Start: 3 4 5 # Default-Stop: 0 6 ### END INIT INFO cd /home/wareck/Minecraft/ su wareck -c "screen -dmS minecraft /opt/jdk-18/bin/java -jar -Xmx2048M -Xms2048M XXXX nogui" exit 0 EOF sed -i "s/XXXX/$version/g" minecraft.service sed -i "s/XXXX/$version/g" /home/wareck/Minecraft/start.sh sed -i "s/XXXX/$short_v/g" /home/wareck/Minecraft/server.properties more minecraft.service chmod +x minecraft.service sudo cp minecraft.service /etc/init.d/ sudo sudo update-rc.d minecraft.service defaults backup_tool recovery function server_config { echo -e "\nDone" if [ -f /tmp/sp ]; then rm /tmp/sp ;fi cat <<'EOF'>> /tmp/sp #Minecraft server properties #Sat Dec 30 04:15:00 CET 2023 allow-flight=true allow-nether=true broadcast-console-to-ops=true broadcast-rcon-to-ops=true debug=false difficulty=easy enable-command-block=true enable-jmx-monitoring=false enable-query=false enable-rcon=true enable-status=true enforce-secure-profile=true enforce-whitelist=false entity-broadcast-range-percentage=100 force-gamemode=true function-permission-level=2 gamemode=creative generate-structures=true generator-settings={} grow-trees=true hardcore=false hide-online-players=false initial-disabled-packs= initial-enabled-packs=vanilla level-name=world level-seed= level-type=default log-ips=true max-build-height=256 max-chained-neighbor-updates=1000000 max-players=20 max-tick-time=120000 max-world-size=29999984 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-- network-compression-threshold=512 online-mode=true op-permission-level=1 player-idle-timeout=0 prevent-proxy-connections=false previews-chat=false pvp=true query.port=25565 rate-limit=0 rcon.password=Paypoo rcon.port=25575 require-resource-pack=false resource-pack= resource-pack-prompt= resource-pack-sha1= server-ip= server-port=25565 simulation-distance=10 snooper-enabled=false spawn-animals=true spawn-monsters=true spawn-npcs=true spawn-protection=0 sync-chunk-writes=true text-filtering-config= use-native-transport=true view-distance=10 white-list=false EOF sed -i "s/ZZZZZZZ/$short_v/g" /tmp/sp cp /tmp/sp /home/wareck/Minecraft/server.properties } server_config if [ -f /home/wareck/.mcr ] ; then rm /home/wareck/.mcr;fi echo "Done"