From a4e9f22946c84647da0004a94f71458d91f784be Mon Sep 17 00:00:00 2001 From: Grizouille Date: Fri, 28 Nov 2025 15:34:21 +0000 Subject: [PATCH] Ajouter pihole-alpine-install.sh --- pihole-alpine-install.sh | 189 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 pihole-alpine-install.sh diff --git a/pihole-alpine-install.sh b/pihole-alpine-install.sh new file mode 100644 index 0000000..edff86d --- /dev/null +++ b/pihole-alpine-install.sh @@ -0,0 +1,189 @@ +#!/bin/bash +# pihole-alpine-install.sh +# Script d'installation et correction Pi-hole pour Alpine Linux + +set -e + +echo "==========================================" +echo " Installation Pi-hole sur Alpine Linux" +echo "==========================================" + +# Vérifier que c'est Alpine +if [ ! -f /etc/alpine-release ]; then + echo "❌ Ce script est conçu pour Alpine Linux uniquement" + exit 1 +fi + +# Vérifier root +if [ "$EUID" -ne 0 ]; then + echo "❌ Veuillez exécuter en root: sudo bash $0" + exit 1 +fi + +# Couleurs +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +# Fonction de log +log() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Étape 1: Installation des dépendances +log "Étape 1: Installation des dépendances système..." +apk update +apk add sudo bash nano wget curl + +# Étape 2: Téléchargement de l'installateur Pi-hole +log "Étape 2: Téléchargement de l'installateur Pi-hole..." +wget -O basic-install.sh https://install.pi-hole.net + +if [ ! -f basic-install.sh ]; then + error "Échec du téléchargement de l'installateur" + exit 1 +fi + +chmod +x basic-install.sh + +# Étape 3: Installation de Pi-hole +log "Étape 3: Installation de Pi-hole..." +log "⚠️ L'installation peut prendre plusieurs minutes..." +bash basic-install.sh + +# Vérifier si l'installation a réussi +if [ $? -ne 0 ]; then + warn "L'installation a rencontré des erreurs, continuation des corrections..." +fi + +# Étape 4: Correction du service FTL +log "Étape 4: Correction du service Pi-hole FTL..." + +# Vérifier si le service existe +if [ ! -f /etc/init.d/pihole-FTL ]; then + error "Service pihole-FTL non trouvé, l'installation a peut-être échoué" + exit 1 +fi + +# Sauvegarder le service original +cp /etc/init.d/pihole-FTL /etc/init.d/pihole-FTL.backup +log "Sauvegarde créée: /etc/init.d/pihole-FTL.backup" + +# Créer le service corrigé +cat > /tmp/pihole-FTL-fixed << 'EOF' +#!/sbin/openrc-run +# shellcheck shell=sh disable=SC2034 + +: "${PI_HOLE_SCRIPT_DIR:=/opt/pihole}" + +command="/usr/bin/pihole-FTL" +command_user="pihole:pihole" +supervisor=supervise-daemon +command_args_foreground="-f" +command_background=true +pidfile="/run/${RC_SVCNAME}_openrc.pid" +extra_started_commands="reload" + +respawn_max=5 +respawn_period=60 +# NOTE: Capabilities commentées - gérées manuellement +#capabilities="^CAP_NET_BIND_SERVICE,^CAP_NET_RAW,^CAP_NET_ADMIN,^CAP_SYS_NICE,^CAP_IPC_LOCK,^CAP_CHOWN,^CAP_SYS_TIME" + +depend() { + want net + provide dns +} + +checkconfig() { + $command -f test +} + +start_pre() { + # Appliquer manuellement la capacité NET_BIND_SERVICE + setcap cap_net_bind_service=+ep /usr/bin/pihole-FTL 2>/dev/null || true + sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-prestart.sh" +} + +stop_post() { + sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-poststop.sh" +} + +reload() { + checkconfig || return $? + ebegin "Reloading ${RC_SVCNAME}" + start-stop-daemon --signal HUP --pidfile "${pidfile}" + eend $? +} +EOF + +# Appliquer le correctif +mv /tmp/pihole-FTL-fixed /etc/init.d/pihole-FTL +chmod +x /etc/init.d/pihole-FTL + +# Appliquer la capacité manuellement +# log "Application des capacités réseau..." +# setcap cap_net_bind_service=+ep /usr/bin/pihole-FTL 2>/dev/null || true + +# Vérifier la capacité +#if getcap /usr/bin/pihole-FTL | grep -q "cap_net_bind_service"; then +# log "✅ Capacité NET_BIND_SERVICE appliquée avec succès" +#else +# warn "⚠️ Impossible d'appliquer la capacité, vérification manuelle nécessaire" +#fi + +# Étape 5: Démarrer le service +log "Étape 5: Démarrage du service Pi-hole FTL..." +rc-update add pihole-FTL default +service pihole-FTL restart + +# Attendre que le service se stabilise +sleep 5 + +# Étape 6: Vérifications finales +log "Étape 6: Vérifications finales..." + +echo "--- Statut du service ---" +service pihole-FTL status + +echo "--- Processus Pi-hole ---" +ps aux | grep pihole | grep -v grep || warn "Aucun processus Pi-hole trouvé" + +echo "--- Port DNS (53) ---" +netstat -tulpn | grep ':53' || ss -tulpn | grep ':53' || warn "Aucun service sur le port 53" + +echo "--- Test DNS local ---" +if nslookup google.com 127.0.0.1 >/dev/null 2>&1; then + log "✅ Test DNS réussi" +else + warn "⚠️ Test DNS échoué" +fi + +# Étape 7: Instructions finales +log "Installation terminée!" +echo "" +echo "📋 PROCHAINES ÉTAPES:" +echo "1. Configurer vos appareils pour utiliser cette machine comme DNS" +echo "2. Accéder à l'interface web: http://$(hostname -s | awk '{print $1}')/admin/" +echo "3. Le mot de passe admin est affiché ci-dessus ou avec: sudo pihole -a -p" +echo "" +echo "🔄 Redémarrage recommandé pour s'assurer que tout fonctionne correctement:" +echo " reboot" +echo "" +echo "🐛 En cas de problème:" +echo " sudo tail -f /var/log/pihole/FTL.log" +echo " sudo service pihole-FTL status" + +# Nettoyage +rm -f basic-install.sh + +echo "" +log "Script d'installation terminé avec succès! 🎉" \ No newline at end of file