1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| #!/bin/bash
backup_source="/home/feneck91/docker/$1/$2"
backup_dest_up="/mnt/ntfs1/Backups/Minecraft/Worlds/$2"
backup_dest="$backup_dest_up/$(date '+%Y-%m-%d_%H:%M:%S')"
current_date="$(date '+%Y-%m-%d - %H:%M:%S')"
playerlogged=""
if [ -d "$backup_source/logs" ]
then
playerlogged=$(cat "$backup_source/logs/latest.log" | grep "joined the game")
fi
# Stop docker
docker stop "$3"
# Ne copier que si un joueur s'est connecté sinon rien n'a changé
if [ -n "$playerlogged" ]
then
if [ ! -d "$backup_dest_up" ]
then
mkdir -m 755 -p "$backup_dest_up"
fi
cp -Rfp "$backup_source" "$backup_dest"
fi
# A réactiver si problème de mise à jour
# Pour le moment, tant que pas de version stable, plus de mise à jour des plugins
# docker start watchtower-once "$3"
# exit 0
#=================================================================
#
# Mettre à jour les plugins
#
#=================================================================
# Update floodgate-spigot.jar
if [ -e "${backup_source}/plugins/floodgate-spigot.jar" ]
then
wget -N "https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot" -O "${backup_source}/plugins/floodgate-spigot.jar"
fi
# Update Geyser-Spigot.jar
if [ -e "${backup_source}/plugins/Geyser-Spigot.jar" ]
then
wget -N "https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot" -O "${backup_source}/plugins/Geyser-Spigot.jar"
fi
# Update worldedit-bukkit-xxx.jar
# 1 - Récupérer le fichier worldedit-bukkit-xxx sur le disque, fichier à mettre à jour
wordeditfileold=$(find "$backup_source/plugins/" -maxdepth 1 -regextype posix-extended -regex '.*/worldedit-bukkit-[0-9\.]+\.jar$' | sed -n 's/.*\(worldedit-bukkit-.*\.jar\)/\1/p')
if [ -n "$wordeditfileold" ]
then
# Le fichier wordedit existe, donc ce répertoire contient ce plugin, voir s'il faut le mettre à jour
# 2 - récupérer le nom du fichier worldedit-bukkit-xxx dernière version pour voir s'il faut le mettre à jour
worldedit_url=$(curl -s "https://api.modrinth.com/v2/project/worldedit/version" | grep -oP '"url":"\K[^"]+' | grep -m1 "bukkit")
# 3 - Vérifier que l'url de la version a bien été trouvée
if [ -n "$worldedit_url" ]
then
# 4 - Vérifier que le nom de fichier a été trouvé dans l'url
wordeditfilenew=$(basename "$worldedit_url")
if [ -n "$wordeditfilenew" ]
then
# 5 - Vérifier qu'il y a réellement une nouvelle version
if [ "$wordeditfileold" != "$wordeditfilenew" ]
then
# 6 - Mise à jour du nouveau fichier
echo "$current_date - Téléchargement du fichier : $wordeditfilenew à partir de l'url = $worldedit_url" >> "$backup_source/plugins/update_info.txt"
wget -q "$worldedit_url" -O "$backup_source/plugins/$wordeditfilenew"
# 7 Tester que le type de fichier est correct
if file "$backup_source/plugins/$wordeditfilenew" | grep -q "Zip archive data"
then
echo "$current_date - Mise à jour du fichier : $wordeditfilenew" >> "$backup_source/plugins/update_info.txt"
# 8 Suppression de l'ancien fichier
echo "$current_date - Suppression du fichier : $wordeditfileold" >> "$backup_source/plugins/update_info.txt"
rm "$backup_source/plugins/$wordeditfileold"
else
echo "$current_date - Erreur lors du téléchargement de WorldEdit (fichier $wordeditfilenew invalide)" >> "$backup_source/plugins/update_info.txt"
rm -f "$backup_source/plugins/$wordeditfilenew"
fi
else
echo "$current_date - Fichier WorldEdit déjà à jour : $wordeditfilenew" >> "$backup_source/plugins/update_info.txt"
fi
else
echo "$current_date - Impossible de récupérer le nom de la dernière version de WorldEdit dans l'url $worldedit_url" >> "$backup_source/plugins/update_info.txt"
fi
else
echo "$current_date - Impossible de récupérer les informations de dernière version de WorldEdit" >> "$backup_source/plugins/update_info.txt"
fi
fi
# Update worldguard-bukkit-xxx-dist.jar
# 1 - Récupérer le fichier worldguard-bukkit-xxx-dist.jar sur le disque, fichier à mettre à jour
wordguardfileold=$(find "$backup_source/plugins/" -maxdepth 1 -regextype posix-extended -regex '.*/worldguard-bukkit-[0-9\.]+-dist\.jar$' | sed -n 's/.*\(worldguard-bukkit-.*\.jar\)/\1/p')
if [ -n "$wordguardfileold" ]
then
# Le fichier wordguard existe, donc ce répertoire contient ce plugin, voir s'il faut le mettre à jour
# 2 - récupérer le nom du fichier worldguard-bukkit-xxx-dist.jar dernière version pour voir s'il faut le mettre à jour
wordguardfilenew=$(wget -SqO /dev/null "https://dev.bukkit.org/projects/worldguard/files/latest" 2>&1 | grep -m1 -Po '^\s*Location.*/\K.*\.jar')
wordguardfilenewurl=$(wget -SqO /dev/null "https://dev.bukkit.org/projects/worldguard/files/latest" 2>&1 | grep -m1 -Po '^\s*Location: *\K.*\.jar')
if [ "$wordguardfileold" != "$wordguardfilenew" ];
then
# Mise à jour du nouveau fichier
echo "$current_date - Téléchargement du fichier : $wordguardfilenew" >> "$backup_source/plugins/update_info.txt"
wget -N "$wordguardfilenewurl" -O "${backup_source}/plugins/$wordguardfilenew"
if [ -e "$backup_source/plugins/$wordguardfilenew" ]
then
echo "$current_date - Mise à jour du fichier : $wordguardfilenew" >> "$backup_source/plugins/update_info.txt"
# Suppression de l'ancien fichier
echo "$current_date - Suppression du fichier : $wordguardfileold" >> "$backup_source/plugins/update_info.txt"
rm "$backup_source/plugins/$wordguardfileold"
else
echo "$current_date - Echec lors de la mise à jour du fichier : $wordguardfilenew" >> "$backup_source/plugins/update_info.txt"
fi
fi
fi
docker start watchtower-once "$3" |
Partager