diff --git a/autopost/common.sh b/autopost/common.sh index d8067eb..46914b3 100644 --- a/autopost/common.sh +++ b/autopost/common.sh @@ -1,5 +1,5 @@ #!/bin/bash -source /home/$USER/autopost/conf.sh +source $HOME/autopost/conf.sh #CONFIG GLOBAL SCREEN_NAME="autopost" diff --git a/autopost/compress.sh b/autopost/compress.sh index c97b820..844d3ab 100644 --- a/autopost/compress.sh +++ b/autopost/compress.sh @@ -1,5 +1,5 @@ #!/bin/bash -source /home/$USER/autopost/common.sh +source $HOME/autopost/common.sh # Recherche récursive des fichiers .nzb dans FINIS find ${DOSSIER_NZB_FINAL} -type f -name "*.nzb" | while IFS= read -r fichier; do # Supprime l'extension .nzb pour conserver le chemin complet diff --git a/autopost/posteur.sh b/autopost/posteur.sh index 4bb13c5..d29b042 100644 --- a/autopost/posteur.sh +++ b/autopost/posteur.sh @@ -1,5 +1,5 @@ #!/bin/bash -source /home/$USER/autopost/common.sh +source $HOME/autopost/common.sh # Vérification et création des dossiers for dossier in "$DOSSIER_NFO" "$DOSSIER_NZB_ATTENTE" "$DOSSIER_NZB_FINAL" "$DOSSIER_LOGS" "tmp" diff --git a/bin/postauto b/bin/postauto index cc7cf43..c1705ed 100644 --- a/bin/postauto +++ b/bin/postauto @@ -1,6 +1,6 @@ #!/bin/bash -source /home/$USER/autopost/common.sh +source $HOME/autopost/common.sh checkdb(){ if [ ! -f "$DB_FILE" ]; then diff --git a/installroot.sh b/installroot.sh new file mode 100644 index 0000000..04c44bb --- /dev/null +++ b/installroot.sh @@ -0,0 +1,356 @@ +#!/bin/bash +set -euo pipefail +# 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' + + +# Initialisation +sudook=false + +if sudo -n true 2>/dev/null; then + # On peut faire sudo sans mot de passe (ticket sudo en cours ou NOPASSWD) + sudook=true +else + # Ni root ni sudo dispo + sudook=false +fi + +# 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 + +#Vérification des prérequis +echo -e "$BLEU""Vérification si les prérequis sont disponibles""$NORMAL" +BIN_DIR="$HOME/bin" +AUTOPOST_DIR="$HOME/autopost" + +LISTE_APPLIS=() +LISTE_APPLIS+=("curl basename php") + +# Vérifier et installer mediainfo si manquant +if command -v mediainfo > /dev/null 2>&1; then + LISTE_APPLIS+=("mediainfo") +else + if $sudook; then + # URLs dans l’ordre souhaité + urls=( + "https://mediaarea.net/download/binary/libzen0/0.4.41/libzen0v5_0.4.41-1_amd64.Debian_12.deb" + "https://mediaarea.net/download/binary/libmediainfo0/25.04/libmediainfo0v5_25.04-1_amd64.Debian_12.deb" + "https://mediaarea.net/download/binary/mediainfo/25.04/mediainfo_25.04-1_amd64.Debian_12.deb" + ) + + # Télécharger + for url in "${urls[@]}"; do + wget -q "$url" + done + + # Extraire les noms de fichiers, dans le même ordre + files=("${urls[@]##*/}") + + # Installer dans l’ordre défini + for pkg in "${files[@]}"; do + sudo dpkg -i "$pkg" + done + + # Nettoyer + rm -f "${files[@]}" + LISTE_APPLIS+=("mediainfo") + echo -e "${VERT}mediainfo installé${NORMAL}" + else + echo -e "${ROUGE}mediainfo est manquant. Installation en cours...${NORMAL}" + curl -L -o "$BIN_DIR/mediainfo" "https://mediaarea.net/download/binary/mediainfo/20.09/mediainfo-20.09.glibc2.3-x86_64.AppImage" + chmod 777 "$BIN_DIR/mediainfo" + LISTE_APPLIS+=("$BIN_DIR/mediainfo") + echo -e "${VERT}mediainfo installé dans $BIN_DIR${NORMAL}" + fi +fi + +# Vérifier et installer sqlite3 si manquant +if command -v sqlite3 > /dev/null 2>&1; then + LISTE_APPLIS+=("sqlite3") +else + echo -e "${ROUGE}sqlite3 est manquant. Installation en cours...${NORMAL}" + if $sudook; then + sudo apt install sqlite3 + LISTE_APPLIS+=("sqlite3") + echo -e "${VERT}sqlite3 installé${NORMAL}" + else + curl -L -o sqlite-tools.zip "https://www.sqlite.org/2024/sqlite-tools-linux-x64-3470000.zip" + unzip sqlite-tools.zip -d "$BIN_DIR" + chmod 777 "$BIN_DIR/sqlite3" + + # Nettoyage des fichiers inutiles + rm -rf sqlite-tools.zip "$BIN_DIR/sqlite-tools-linux-x64-3480000" "$BIN_DIR/sqldiff" "$BIN_DIR/sqlite3_analyzer" "$BIN_DIR/sqlite3_rsync" + + LISTE_APPLIS+=("$BIN_DIR/sqlite3") + echo -e "${VERT}sqlite3 installé dans $BIN_DIR${NORMAL}" + + fi +fi + +# Vérifier et installer jq si manquant +if command -v jq > /dev/null 2>&1; then + LISTE_APPLIS+=("jq") +else + echo -e "${ROUGE}jq est manquant. Installation en cours...${NORMAL}" + curl -L -o "$BIN_DIR/jq" "https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64" + chmod 777 "$BIN_DIR/jq" + LISTE_APPLIS+=("$BIN_DIR/jq") + echo -e "${VERT}jq installé dans $BIN_DIR${NORMAL}" +fi + +# Vérifier et installer 7z si manquant +if command -v 7z > /dev/null 2>&1; then + LISTE_APPLIS+=("7z") +else + echo -e "${ROUGE}7z est manquant. Installation en cours...${NORMAL}" + Z_URL="https://7-zip.org/a/7z2409-linux-x64.tar.xz" + Z_TAR="7z2409-linux-x64.tar.xz" + Z_DIR="7z2409-linux-x64" + Z_EXE="7zzs" + wget -q -O "$Z_TAR" "$Z_URL" + tar -xJf "$Z_TAR" > /dev/null 2>&1 + mv "$Z_EXE" "$BIN_DIR/7z" + rm "$Z_TAR" 7zz + chmod 777 "$BIN_DIR/7z" + LISTE_APPLIS+=("$BIN_DIR/7z") +fi + +# Télécharger et extraire Nyuu +echo -e "$BLEU""Téléchargement et installation de nyuu""$NORMAL" +NYUU_URL="https://github.com/Antidote2151/Nyuu-Obfuscation/releases/download/v0.4.2-Obfuscate1.3/nyuu-v0.4.2-Obfuscate1.3-linux-amd64.tar.xz" +NYUU_TAR="nyuu.tar.xz" +NYUU_EXE="nyuu" + +wget -q -O "$NYUU_TAR" "$NYUU_URL" +tar -xJf "$NYUU_TAR" > /dev/null 2>&1 +mv "$NYUU_EXE" "$BIN_DIR/nyuu" +rm config-sample.json +rm "$NYUU_TAR" +chmod 777 "$BIN_DIR/nyuu" +LISTE_APPLIS+=("$BIN_DIR/nyuu") + +# Télécharger et extraire ParPar +echo -e "$BLEU""Téléchargement et installation de parpar""$NORMAL" +PARPAR_URL="https://github.com/animetosho/ParPar/releases/download/v0.4.5/parpar-v0.4.5-linux-static-amd64.xz" +PARPAR_XZ="parpar-v0.4.5-linux-static-amd64.xz" + +wget -q -O "$PARPAR_XZ" "$PARPAR_URL" +xz -d "$PARPAR_XZ" > /dev/null 2>&1 +chmod 777 "parpar-v0.4.5-linux-static-amd64" +mv "parpar-v0.4.5-linux-static-amd64" "$BIN_DIR/parpar" +LISTE_APPLIS+=("$BIN_DIR/parpar") + +# 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" + +if [ ! -f "$AUTOPOST_DIR/conf.sh" ]; then + wget -q -O "$AUTOPOST_DIR/conf.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/conf.sh" +fi + +# Donner les permissions d'exécution si nécessaire +chmod 777 "$BIN_DIR/postauto" +chmod -R 755 "$AUTOPOST_DIR" + +LISTE_APPLIS+=("$BIN_DIR/postauto") + +source ~/.bashrc + +manquants=() + +for i in $LISTE_APPLIS; do + if ! command -v "$i" > /dev/null 2>&1; then + manquants+=("$i") + fi +done + +if [ ${#manquants[@]} -gt 0 ]; then + echo -e "${ROUGE}Programme(s) manquant(s) : ${manquants[*]}${NORMAL}" + exit 1 +else + echo -e "${VERT}Toutes les dépendances sont disponibles.${NORMAL}" +fi + +# 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 update" + + # 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 + echo "La configuration de complétion pour 'postauto' est déjà présente dans $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 "Vérification de l'environnement pour la page de suivi..." + +# Fonction pour afficher les messages en vert +log() { + echo -e "\033[1;32m$1\033[0m" +} + +# Définition du répertoire AUTOPOST_DIR (ajuster si nécessaire) +AUTOPOST_DIR="$HOME/autopost" + +# Création du dossier si inexistant +mkdir -p "$AUTOPOST_DIR" + +# Définir le répertoire NVM +export NVM_DIR="$HOME/.nvm" + +# Vérifier si nvm est déjà chargé dans la session actuelle +if [ -s "$NVM_DIR/nvm.sh" ]; then + log "nvm est déjà installé. Chargement de nvm..." + \. "$NVM_DIR/nvm.sh" +else + log "nvm non trouvé, installation de nvm..." + # Installer nvm + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash + + # Après l'installation, sourcer nvm pour la session courante + export NVM_DIR="$HOME/.nvm" + if [ -s "$NVM_DIR/nvm.sh" ]; then + \. "$NVM_DIR/nvm.sh" + log "NVM installé et chargé." + else + log "Erreur : nvm n'a pas pu être chargé." + exit 1 + fi +fi + +# Vérification de Node.js +if command -v node &> /dev/null; then + current_version=$(node -v | sed 's/^v//') + major_version=$(echo "$current_version" | cut -d. -f1) + if [ "$major_version" -lt 22 ]; then + log "Node.js version $current_version détectée (inférieure à 22). Mise à jour en cours..." + nvm install 22 + nvm use 22 + else + log "Node.js version $current_version détectée, compatible." + fi +else + log "Node.js non trouvé, installation de Node.js 22..." + nvm install 22 + nvm use 22 + updated="1" +fi + +# Charger nvm après installation +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + +# Vérification des modules npm nécessaires +log "Vérification des modules npm requis..." + +modules=("express" "express-session" "sqlite3" "ansi-to-html" "@tailwindcss/browser" "autoprefixer" "jquery") +missing_modules=() + +for module in "${modules[@]}"; do + if ! npm list "$module" &> /dev/null; then + missing_modules+=("$module") + fi +done + +if [ ${#missing_modules[@]} -gt 0 ]; then + log "Modules manquants détectés : ${missing_modules[*]}" + npm install "${missing_modules[@]}" +else + log "Tous les modules requis sont déjà installés." +fi + +# Vérification et téléchargement des fichiers de configuration +log "Vérification des fichiers de configuration..." + +if [ ! -f "$AUTOPOST_DIR/server.js" ]; then + log "Téléchargement de server.js..." + wget -q -O "$AUTOPOST_DIR/server.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/server.js" + updated="1" +fi + +if [ ! -f "$AUTOPOST_DIR/config.js" ]; then + log "Téléchargement de config.js..." + wget -q -O "$AUTOPOST_DIR/config.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/config.js" + echo -e "${BLEU}Installation terminée. Vous pouvez maintenant configurer $AUTOPOST_DIR/config.js.${NORMAL}" +fi + +echo "Suppression du script après exécution..." +rm -- "$0" + + diff --git a/node_install.sh b/node_install.sh new file mode 100644 index 0000000..afc1ecc --- /dev/null +++ b/node_install.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# Ce script installe Node.js et les modules nécessaires pour faire tourner server.js +# sans nécessiter d'accès root. +# Il vérifie que la version de Node.js est d'au moins 22. + +# Fonction pour afficher les messages en vert +log() { + echo -e "\033[1;32m$1\033[0m" +} + +# 1. Vérifier si nvm est installé, sinon l'installer +if [ -z "$(command -v nvm)" ]; then + log "nvm non trouvé, installation de nvm..." + # Téléchargement et exécution du script d'installation de nvm + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash + + # Charger nvm dans le shell courant + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + + log "Si NVM n'est pas chargé automatiquement dans de nouvelles sessions, ajoutez les lignes suivantes dans votre fichier ~/.bashrc ou équivalent :" + echo 'export NVM_DIR="$HOME/.nvm"' + echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Charge nvm' +else + log "nvm est déjà installé." +fi + +# 2. Vérifier si Node.js est installé et si sa version est >= 22 +if command -v node >/dev/null; then + current_version=$(node -v | sed 's/^v//') + major_version=$(echo "$current_version" | cut -d. -f1) + if [ "$major_version" -lt 22 ]; then + log "Version de Node.js actuelle ($current_version) inférieure à 22. Installation de Node.js version 22..." + nvm install 22 + nvm use 22 + else + log "Version de Node.js suffisante ($current_version)." + fi +else + log "Node.js non trouvé, installation de Node.js version 22..." + nvm install 22 + nvm use 22 +fi + +# 3. Créer package.json s'il n'existe pas déjà +if [ ! -f package.json ]; then + log "Création du fichier package.json..." + npm init -y +fi + +# 4. Installer les dépendances nécessaires pour server.js +log "Installation des modules npm requis..." +npm install express express-session sqlite3 ansi-to-html + +log "Installation terminée. Vous pouvez démarrer votre serveur avec :" +echo "node server.js"