diff --git a/update.sh b/update.sh index 3671dea..4485101 100644 --- a/update.sh +++ b/update.sh @@ -45,12 +45,34 @@ echo -e "$BLEU""Téléchargement de autopost""$NORMAL" mkdir -p "$AUTOPOST_DIR" # Télécharger les fichiers dans autopost -wget -q -O "$AUTOPOST_DIR/analyzer.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.sh" -wget -q -O "$AUTOPOST_DIR/common.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/common.sh" -wget -q -O "$AUTOPOST_DIR/posteur.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/posteur.sh" -# Télécharger le fichier dans bin -wget -q -O "$BIN_DIR/postauto" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/bin/postauto" + +# Liste des fichiers à vérifier et mettre à jour +declare -A FILES +FILES["$HOME/autopost/analyzer.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.sh" +FILES["$HOME/autopost/posteur.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/posteur.sh" +FILES["$HOME/autopost/common.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/common.sh" +FILES["$HOME/bin/postauto"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/bin/postauto" + +# Vérification et mise à jour des fichiers +for LOCAL_FILE in "${!FILES[@]}"; do + URL="${FILES[$LOCAL_FILE]}" + TMP_FILE=$(mktemp) + + # Télécharger le fichier distant + curl -s "$URL" -o "$TMP_FILE" + + # Comparer avec le fichier local et mettre à jour si nécessaire + if ! diff -q "$LOCAL_FILE" "$TMP_FILE" > /dev/null 2>&1; then + #diff -u "$LOCAL_FILE" "$TMP_FILE" || echo "Le fichier local n'existe pas encore." + echo "Mise à jour de $LOCAL_FILE..." + mv "$TMP_FILE" "$LOCAL_FILE" + chmod +x "$LOCAL_FILE" + else + echo "Aucune mise à jour nécessaire pour $LOCAL_FILE." + rm "$TMP_FILE" + fi +done # Définir le chemin du fichier bashrc BASHRC_FILE="$HOME/.bashrc"