From f8b2e304869a8951387a004642745e1197e84668 Mon Sep 17 00:00:00 2001 From: unfr Date: Fri, 21 Feb 2025 11:16:24 +0100 Subject: [PATCH] Ajout d'une option de chech et d'un script d'update --- bin/postauto | 30 +++++++++++++- install.sh | 2 +- update.sh | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 update.sh diff --git a/bin/postauto b/bin/postauto index b82b11a..f931ebd 100644 --- a/bin/postauto +++ b/bin/postauto @@ -76,7 +76,6 @@ do_add() { mediainfo --output=JSON --full "${DOSSIER_GLOBAL}${release_name}" > "${DOSSIER_NFO}${release_without_ext}.json" echo -e "$CYAN""AJOUT DE LA RELEASE ${release_name} DANS LA DATABASE""$NORMAL" - #sqlite3 "$DB_FILE" "INSERT INTO release (nom, status) VALUES ('${release_name}', 0);" sqlite3 "$DB_FILE" "BEGIN IMMEDIATE; INSERT INTO release (nom, status) VALUES ('${release_name}', 0); COMMIT;" else echo "il ne s'agit pas d'un fichier mkv ou mp4" @@ -85,6 +84,28 @@ do_add() { fi } +do_check() { + release_path="$2" + release_name=$(basename "$release_path") + release_without_ext="${release_name%.*}" + + # Récupération de la réponse JSON complète + response=$(curl -s "${URL_API}${APIKEY}&check=${release_without_ext}") + + # Extraction du champ "code" avec jq + code=$(echo "$response" | jq -r '.code') + + # Extraction du champ "explain" avec jq + explain=$(echo "$response" | jq -r '.Explain') + + # Arrêt du script si "code" vaut 1, en affichant le message "explain" + if [ "$code" = "1" ]; then + echo -e "${release_name}" "$ROUGE""$explain""$NORMAL" + else + echo -e "${release_name}" "$BLEU""$explain""$NORMAL" + fi +} + do_status() { checkdb @@ -174,6 +195,13 @@ case "$1" in status) do_status ;; + check) + if [ -z "$2" ]; then + echo "Usage: $0 add " + exit 1 + fi + do_check "$@" + ;; createdb) do_createdb ;; diff --git a/install.sh b/install.sh index 969fb43..3b00a60 100644 --- a/install.sh +++ b/install.sh @@ -164,7 +164,7 @@ _autopost_completion() { prev="${COMP_WORDS[COMP_CWORD-1]}" # Liste des commandes disponibles - opts="start stop restart show status createdb add log" + opts="start stop restart show status createdb add log check" # Si l'utilisateur est en train de taper le premier argument, proposer les commandes if [ $COMP_CWORD -eq 1 ]; then diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..3671dea --- /dev/null +++ b/update.sh @@ -0,0 +1,110 @@ +#!/bin/bash +# Couleurs de texte +NOIR='\e[30m' +ROUGE='\e[31m' +VERT='\e[32m' +JAUNE='\e[33m' +BLEU='\e[34m' +ROSE='\e[35m' +CYAN='\e[36m' +BLANC='\e[37m' + +# Couleurs de fond +FOND_NOIR='\e[40m' +FOND_ROUGE='\e[41m' +FOND_VERT='\e[42m' +FOND_JAUNE='\e[43m' +FOND_BLEU='\e[44m' +FOND_ROSE='\e[45m' +FOND_CYAN='\e[46m' +FOND_BLANC='\e[47m' + +# Effets +GRAS='\e[1m' +SOULIGNE='\e[4m' +CLIGNOTANT='\e[5m' +INVERSE='\e[7m' +NORMAL='\e[0m' + +#Vérification des prérequis +echo -e "$BLEU""Vérification si les prérequis sont disponibles""$NORMAL" +LISTE_APPLIS="curl basename php" +BIN_DIR="$HOME/bin" +AUTOPOST_DIR="$HOME/autopost" + +# Vérifier si le dossier bin existe, sinon le créer +echo -e "$BLEU""Vérification de la présence du dossier bin""$NORMAL" +if [ ! -d "$BIN_DIR" ]; then + mkdir -p "$BIN_DIR" +fi + +# Téléchargement et installation du script de post +echo -e "$BLEU""Téléchargement de autopost""$NORMAL" + +# Création des répertoires si inexistants +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" + +# Définir le chemin du fichier bashrc +BASHRC_FILE="$HOME/.bashrc" + +# Marqueurs pour identifier la section ajoutée +DEBUT_MARKER="# DEBUT COMPLETION POSTAUTO" +FIN_MARKER="# FIN COMPLETION POSTAUTO" + +# Le code de complétion à ajouter, encadré par les marqueurs +read -r -d '' COMPLETION_CODE << 'EOF' +# DEBUT COMPLETION POSTAUTO +# Fonction de complétion pour ton script +_autopost_completion() { + local cur prev opts + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + # Liste des commandes disponibles + opts="start stop restart show status createdb add log check" + + # Si l'utilisateur est en train de taper le premier argument, proposer les commandes + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + + # (Optionnel) Pour la sous-commande "add", proposer des fichiers en complétion + if [ $COMP_CWORD -eq 2 ] && [ "${COMP_WORDS[1]}" = "add" ]; then + COMPREPLY=( $(compgen -f -- "${cur}") ) + return 0 + fi +} + +# Associer la fonction de complétion à ton script (ici, 'postauto' est le nom de la commande) +complete -F _autopost_completion postauto +# FIN COMPLETION POSTAUTO +EOF + +# Vérifier si le code est déjà présent dans le fichier bashrc +if grep -q "$DEBUT_MARKER" "$BASHRC_FILE"; then + # Faire une sauvegarde de sécurité du fichier .bashrc + cp "$BASHRC_FILE" "${BASHRC_FILE}.bak" + echo "Sauvegarde réalisée dans ${BASHRC_FILE}.bak" + + # Supprimer le bloc de code entre les marqueurs (inclusifs) + sed -i "/$DEBUT_MARKER/,/$FIN_MARKER/d" "$BASHRC_FILE" +else + echo "Ajout de la configuration de complétion dans $BASHRC_FILE..." + # Ajouter une ligne vide pour séparer (optionnel) + echo "" >> "$BASHRC_FILE" + # Ajouter le code de complétion + echo "$COMPLETION_CODE" >> "$BASHRC_FILE" + echo "Mise à jour effectuée." +fi + +echo "Suppression du script après exécution..." +rm -- "$0 \ No newline at end of file