|
|
@@ -75,17 +75,6 @@ chmod 750 "$final_path"
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
|
-ynh_restore_file --origin_path="$PI_HOLE_LOCAL_REPO"
|
|
|
-
|
|
|
-ynh_restore_file --origin_path="$PI_HOLE_CONFIG_DIR"
|
|
|
-
|
|
|
-ynh_restore_file --origin_path="$PI_HOLE_INSTALL_DIR"
|
|
|
-
|
|
|
-# Restore permissions on app files
|
|
|
-chown $app: -R "$PI_HOLE_CONFIG_DIR"
|
|
|
-# $PI_HOLE_CONFIG_DIR/logrotate have to belong to root, otherwise logrotate will failed silently...
|
|
|
-chown root: -R "$PI_HOLE_CONFIG_DIR/logrotate"
|
|
|
-
|
|
|
#=================================================
|
|
|
# SPECIFIC RESTORATION
|
|
|
#=================================================
|
|
|
@@ -116,90 +105,94 @@ ynh_script_progression --message="Restoring the NGINX web server configuration..
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
#=================================================
|
|
|
-# RESTORE THE CRON FILE
|
|
|
+# RESTORE SPECIFIC FILES
|
|
|
#=================================================
|
|
|
-ynh_script_progression --message="Restoring the cron file..." --weight=1
|
|
|
-
|
|
|
-ynh_restore_file --origin_path="/etc/cron.d/pihole"
|
|
|
+ynh_script_progression --message="Restoring specific files..." --weight=1
|
|
|
|
|
|
-#=================================================
|
|
|
-# RECREATE LOG FILES
|
|
|
-#=================================================
|
|
|
-ynh_script_progression --message="Recreate log files..." --weight=1
|
|
|
+ynh_restore_file --origin_path="$PI_HOLE_LOCAL_REPO"
|
|
|
|
|
|
-touch /var/log/pihole.log
|
|
|
-chmod 644 /var/log/pihole.log
|
|
|
-dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
|
|
|
-chown $dnsmasq_user:root /var/log/pihole.log
|
|
|
+ynh_restore_file --origin_path="$PI_HOLE_CONFIG_DIR"
|
|
|
+# Restore permissions on app files
|
|
|
+chown $app: -R "$PI_HOLE_CONFIG_DIR"
|
|
|
+# $PI_HOLE_CONFIG_DIR/logrotate have to belong to root, otherwise logrotate will failed silently...
|
|
|
+chown root: -R "$PI_HOLE_CONFIG_DIR/logrotate"
|
|
|
|
|
|
-#=================================================
|
|
|
-# RESTORE SPECIFIC FILES
|
|
|
-#=================================================
|
|
|
-ynh_script_progression --message="Restoring specific files..." --weight=1
|
|
|
+ynh_restore_file --origin_path="$PI_HOLE_INSTALL_DIR"
|
|
|
|
|
|
ynh_restore_file --origin_path="$PI_HOLE_BIN_DIR/pihole"
|
|
|
ynh_restore_file --origin_path="/etc/bash_completion.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="/usr/bin/pihole-FTL"
|
|
|
+install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL"
|
|
|
|
|
|
-ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
|
|
|
+ynh_restore_file --origin_path="/etc/sudoers.d/pihole"
|
|
|
|
|
|
#=================================================
|
|
|
-# REPLACE THE DEFAULT DNSMASQ BY PIHOLE-FTL
|
|
|
+# RESTORE THE CRON FILE
|
|
|
#=================================================
|
|
|
-ynh_script_progression --message="Replacing the default DNSMASQ by PIHILE-FTL..." --weight=1
|
|
|
+ynh_script_progression --message="Restoring the cron file..." --weight=1
|
|
|
+
|
|
|
+ynh_restore_file --origin_path="/etc/cron.d/pihole"
|
|
|
+
|
|
|
+#=================================================
|
|
|
+# DISABLING DNSMASQ
|
|
|
+#=================================================
|
|
|
+ynh_script_progression --message="Disabling DNSMASQ..." --weight=1
|
|
|
|
|
|
# Last version available
|
|
|
# Stopped dnsmasq to replace it by pihole-FTL
|
|
|
-ynh_systemd_action --action=stop --service_name=dnsmasq
|
|
|
+ynh_systemd_action --service_name=dnsmasq --action=stop
|
|
|
|
|
|
# Disable the real dnsmasq service
|
|
|
#ynh_exec_warn_less systemctl disable dnsmasq --quiet
|
|
|
|
|
|
-# And move the files that make the service available in systemd to really disable it
|
|
|
-#mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service.backup_by_pihole
|
|
|
-#mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq.backup_by_pihole
|
|
|
+#=================================================
|
|
|
+# FINAL EXPORTS
|
|
|
+#=================================================
|
|
|
+ynh_script_progression --message="Final exports..." --weight=1
|
|
|
|
|
|
-# Move dnsmasq to preserve the current binary
|
|
|
-#mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.backup_by_pihole
|
|
|
-# Replace dnsmasq by pihole-FTL
|
|
|
-# NOTE: pihole-FTL is actually a modified version of dnsmasq
|
|
|
-# https://github.com/pi-hole/FTL/tree/master/dnsmasq
|
|
|
-#ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq
|
|
|
+setupVars="$PI_HOLE_CONFIG_DIR/setupVars.conf"
|
|
|
+
|
|
|
+# Get the default network interface
|
|
|
+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
|
|
|
+
|
|
|
+# Calculate and store the config file checksum into the app settings
|
|
|
+ynh_store_file_checksum --file="$setupVars"
|
|
|
+
|
|
|
+#=================================================
|
|
|
+# ENABLING FTL
|
|
|
+#=================================================
|
|
|
+ynh_script_progression --message="Enable FTL..." --weight=1
|
|
|
|
|
|
-cp -a $PI_HOLE_LOCAL_REPO/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-FTL
|
|
|
-chmod +x /etc/init.d/pihole-FTL
|
|
|
ynh_exec_warn_less systemctl enable pihole-FTL --quiet
|
|
|
|
|
|
# Replace the service dnsmasq by pihole-FTL
|
|
|
# That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
|
|
|
-#ln -s /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
|
|
|
|
|
|
# Reload systemd config
|
|
|
systemctl daemon-reload
|
|
|
|
|
|
#=================================================
|
|
|
-# RESTORE DNSMASQ CONFIG
|
|
|
+# RECREATE LOG FILES
|
|
|
#=================================================
|
|
|
-ynh_script_progression --message="Restoring Dnsmasq config..." --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"
|
|
|
+ynh_script_progression --message="Recreate log files..." --weight=1
|
|
|
|
|
|
-systemctl daemon-reload
|
|
|
-ynh_exec_warn_less yunohost tools regen-conf dnsmasq
|
|
|
+touch /var/log/{pihole,pihole-FTL}.log
|
|
|
+chmod 644 /var/log/{pihole,pihole-FTL}.log
|
|
|
+dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
|
|
|
+chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log
|
|
|
|
|
|
#=================================================
|
|
|
# CONFIGURE DNS FOR THE LOCAL DOMAINS
|
|
|
#=================================================
|
|
|
-ynh_script_progression --message="Configuring dns for the local domains..." --weight=2
|
|
|
+ynh_script_progression --message="Configuring DNS for the local domains..." --weight=2
|
|
|
|
|
|
-# Get the default network interface
|
|
|
-main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
|
|
|
# Find the IP associated to the network interface
|
|
|
localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
|
|
|
|
|
|
@@ -215,18 +208,16 @@ do
|
|
|
done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
|
|
|
|
|
|
#=================================================
|
|
|
-# UPDATE VARIABLES FILE
|
|
|
+# SET UP CONF_REGEN HOOK
|
|
|
#=================================================
|
|
|
-ynh_script_progression --message="Updating variables files..." --weight=1
|
|
|
+ynh_script_progression --message="Setting up conf_regen hook..." --weight=1
|
|
|
|
|
|
-setupVars="$PI_HOLE_CONFIG_DIR/setupVars.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"
|
|
|
|
|
|
-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
|
|
|
+ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
|
|
|
|
|
|
-# Recalculate and store the checksum of the file for the next upgrade.
|
|
|
-ynh_store_file_checksum --file="$setupVars"
|
|
|
+systemctl daemon-reload
|
|
|
+ynh_exec_warn_less yunohost tools regen-conf dnsmasq
|
|
|
|
|
|
#=================================================
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
@@ -240,8 +231,7 @@ yunohost service add pihole-FTL --description="PiHole backend service" --log="/v
|
|
|
#=================================================
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
|
|
|
|
|
-ynh_exec_warn_less systemctl enable pihole-FTL --quiet
|
|
|
-ynh_systemd_action --action=restart --service_name=pihole-FTL
|
|
|
+ynh_systemd_action --service_name=pihole-FTL --action=restart --log_path="/var/log/pihole-FTL.log"
|
|
|
|
|
|
#=================================================
|
|
|
# GENERIC FINALIZATION
|