Browse Source

Fix and cleanup restore

Félix Piédallu 2 years ago
parent
commit
483704f611
1 changed files with 25 additions and 41 deletions
  1. 25 41
      scripts/restore

+ 25 - 41
scripts/restore

@@ -71,69 +71,52 @@ setupVars="$PI_HOLE_CONFIG_DIR/setupVars.conf"
 
 
 # Get the default network interface
 # Get the default network interface
 main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
 main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
-echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
-ynh_replace_string --match_string="^PIHOLE_INTERFACE=.*" --replace_string="PIHOLE_INTERFACE=$main_iface" --target_file=$setupVars
-ynh_replace_string --match_string="^IPV4_ADDRESS=.*" --replace_string="IPV4_ADDRESS=127.0.0.1" --target_file=$setupVars
+echo "PIHOLE_INTERFACE=$main_iface" > "$setupVars"
+ynh_replace_string --target_file="$setupVars" --match_string="^PIHOLE_INTERFACE=.*" --replace_string="PIHOLE_INTERFACE=$main_iface"
+ynh_replace_string --target_file="$setupVars" --match_string="^IPV4_ADDRESS=.*" --replace_string="IPV4_ADDRESS=127.0.0.1"
 
 
 # Calculate and store the config file checksum into the app settings
 # Calculate and store the config file checksum into the app settings
 ynh_store_file_checksum --file="$setupVars"
 ynh_store_file_checksum --file="$setupVars"
 
 
 #=================================================
 #=================================================
-# DISABLING DNSMASQ
+# CONFIGURE DNS FOR THE LOCAL DOMAINS
 #=================================================
 #=================================================
-ynh_script_progression --message="Disabling DNSMASQ..." --weight=1
+ynh_script_progression --message="Configuring DNS for the local domains..." --weight=2
 
 
-# Last version available
-# Stopped dnsmasq to replace it by pihole-FTL
-ynh_systemd_action --service_name=dnsmasq --action=stop
+# Find the IP associated to the network interface
+localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
 
 
-# Disable the real dnsmasq service
-#ynh_exec_warn_less systemctl disable dnsmasq --quiet
+# List all YunoHost domains
+while read -r perdomain; do
+    # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution.
+    ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts
+
+    # And add a resolution on the local IP instead
+    grep -q "^$localipv4.*$perdomain" /etc/hosts || \
+        echo "$localipv4	$perdomain #Added by pihole#" >> /etc/hosts
+done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
 
 
 #=================================================
 #=================================================
-# ENABLING FTL
+# DISABLING DNSMASQ
 #=================================================
 #=================================================
-ynh_script_progression --message="Enable FTL..." --weight=1
+ynh_script_progression --message="Disabling Dnsmasq in system and yunohost..." --weight=1
 
 
-ynh_exec_warn_less systemctl enable pihole-FTL --quiet
+# Stopped dnsmasq to replace it by pihole-FTL
+ynh_systemd_action --service_name=dnsmasq --action=stop
 
 
 # Replace the service dnsmasq by pihole-FTL
 # Replace the service dnsmasq by pihole-FTL
 # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
 # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
 #ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
 #ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
 systemctl mask dnsmasq.service
 systemctl mask dnsmasq.service
 
 
+# Disable the real dnsmasq service
+#ynh_exec_warn_less systemctl disable dnsmasq --quiet
+
 # Reload systemd config
 # Reload systemd config
 systemctl daemon-reload
 systemctl daemon-reload
 
 
-#=================================================
-# CONFIGURE DNS FOR THE LOCAL DOMAINS
-#=================================================
-ynh_script_progression --message="Configuring DNS for the local domains..." --weight=2
-
-# Find the IP associated to the network interface
-localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
-
-# List all YunoHost domains
-while read perdomain
-do
-	# Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution.
-	ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts
-
-	# And add a resolution on the local IP instead
-	grep -q "^$localipv4.*$perdomain" /etc/hosts || \
-		echo "$localipv4	$perdomain #Added by pihole#" >> /etc/hosts
-done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
-
-#=================================================
-# SET UP CONF_REGEN HOOK
-#=================================================
-ynh_script_progression --message="Setting up conf_regen hook..." --weight=1
-
 test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" && ynh_restore_file --origin_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
 test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" && ynh_restore_file --origin_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
-
 ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
 ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
-
-
 ynh_exec_warn_less yunohost tools regen-conf dnsmasq
 ynh_exec_warn_less yunohost tools regen-conf dnsmasq
 
 
 #=================================================
 #=================================================
@@ -152,8 +135,9 @@ ynh_restore_file --origin_path="/etc/cron.d/pihole"
 ynh_restore_file --origin_path="/etc/sudoers.d/pihole"
 ynh_restore_file --origin_path="/etc/sudoers.d/pihole"
 
 
 ynh_restore_file --origin_path="/etc/init.d/pihole-FTL"
 ynh_restore_file --origin_path="/etc/init.d/pihole-FTL"
-systemctl daemon-reload
 # install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL"
 # install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL"
+systemctl daemon-reload
+ynh_exec_warn_less systemctl enable pihole-FTL --quiet
 yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log" --needs_exposed_ports 53 67
 yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log" --needs_exposed_ports 53 67
 
 
 #=================================================
 #=================================================