1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pihole_ynh.git synced 2024-09-03 20:05:58 +02:00

Few fixes

This commit is contained in:
yalh76 2022-09-18 01:21:15 +02:00
parent a8eb467b66
commit d98ea5d8eb
7 changed files with 89 additions and 91 deletions

View file

@ -23,7 +23,10 @@
setup_private=1
setup_public=0
upgrade=1
# 5.4~ynh1
upgrade=1 from_commit=cfa9c5a3dbcfb765dcca3b2e7d179756afe26def
# 5.11.4~ynh1
upgrade=1 from_commit=3d2f68c4e19f335e63f8ffa259708b38a58c8f67
backup_restore=1
multi_instance=0
port_already_use=1

View file

@ -191,8 +191,7 @@ ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --ta
(
cd scripts
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
ynh_add_config --template="../conf/dnsmasq_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
)
#=================================================
@ -201,7 +200,7 @@ ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --ta
ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2
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"
#=================================================
# RELOAD NGINX

View file

@ -74,7 +74,7 @@ then
ynh_script_progression --message="Restarting Pi-Hole..." --weight=2
# Restart pihole-FTL
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"
fi
# Calculate and store the config file checksum into the app settings

View file

@ -186,10 +186,10 @@ ynh_script_progression --message="Installing a cron job..." --weight=1
install -D -m 644 -T -o root -g root ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.cron /etc/cron.d/pihole
# Randomize gravity update time
sed -i "s/59 1 /$((1 + RANDOM % 58)) $((3 + RANDOM % 2))/" /etc/cron.d/pihole
ynh_replace_string --match_string="59 1 " --replace_string="$((1 + RANDOM % 58)) $((3 + RANDOM % 2)) " --target_file="/etc/cron.d/pihole"
# Randomize update checker time
sed -i "s/59 17/$((1 + RANDOM % 58)) $((12 + RANDOM % 8))/" /etc/cron.d/pihole
ynh_replace_string --match_string="59 17" --replace_string="$((1 + RANDOM % 58)) $((12 + RANDOM % 8))" --target_file="/etc/cron.d/pihole"
# Remove git usage for version. Which fails because we use here a release instead of master.
ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole
@ -210,7 +210,7 @@ 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
@ -313,8 +313,7 @@ echo "$(ynh_app_upstream_version) $pihole_adminlte_version $pihole_flt_version"
#=================================================
ynh_script_progression --message="Setting up conf_regen hook..." --weight=1
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
ynh_add_config --template="../conf/dnsmasq_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
systemctl daemon-reload
ynh_exec_warn_less yunohost tools regen-conf dnsmasq
@ -333,7 +332,7 @@ yunohost service add pihole-FTL --description="PiHole backend service" --log="/v
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --action=restart --service_name=pihole-FTL --log_path="/var/log/pihole-FTL.log"
ynh_systemd_action --service_name=pihole-FTL --action=restart --log_path="/var/log/pihole-FTL.log"
#=================================================
# SETUP SSOWAT

View file

@ -38,7 +38,7 @@ fi
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
ynh_systemd_action --action=stop --service_name=pihole-FTL
ynh_systemd_action --service_name=pihole-FTL --action=stop
# Restore dnsmasq as main DNS resolver
# Move dnsmasq back to its original place
@ -161,7 +161,7 @@ sed -i "/#Added by pihole#/d" /etc/hosts
#=================================================
ynh_script_progression --message="Removing conf_regen hook..." --weight=1
ynh_systemd_action --action=stop --service_name=dnsmasq
ynh_systemd_action --service_name=dnsmasq --action=stop
ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
@ -172,7 +172,7 @@ ynh_exec_warn_less yunohost tools regen-conf dnsmasq
#=================================================
ynh_script_progression --message="Restarting Dnsmasq..." --weight=1
ynh_systemd_action --action=restart --service_name=dnsmasq
ynh_systemd_action --service_name=dnsmasq --action=restart
#=================================================
# GENERIC FINALIZATION

View file

@ -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
#=================================================
@ -115,6 +104,30 @@ ynh_script_progression --message="Restoring the NGINX web server configuration..
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE SPECIFIC FILES
#=================================================
ynh_script_progression --message="Restoring specific files..." --weight=1
ynh_restore_file --origin_path="$PI_HOLE_LOCAL_REPO"
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"
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/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="/etc/sudoers.d/pihole"
#=================================================
# RESTORE THE CRON FILE
#=================================================
@ -123,83 +136,63 @@ ynh_script_progression --message="Restoring the cron file..." --weight=1
ynh_restore_file --origin_path="/etc/cron.d/pihole"
#=================================================
# RECREATE LOG FILES
# DISABLING DNSMASQ
#=================================================
ynh_script_progression --message="Recreate log files..." --weight=1
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
#=================================================
# RESTORE SPECIFIC FILES
#=================================================
ynh_script_progression --message="Restoring specific files..." --weight=1
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"
ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
#=================================================
# REPLACE THE DEFAULT DNSMASQ BY PIHOLE-FTL
#=================================================
ynh_script_progression --message="Replacing the default DNSMASQ by PIHILE-FTL..." --weight=1
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
ynh_script_progression --message="Recreate log files..." --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"
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

View file

@ -63,6 +63,13 @@ ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=pihole-FTL --action="stop" --log_path="/var/log/pihole-FTL.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -240,10 +247,10 @@ ynh_script_progression --message="Updating a cron job..." --weight=1
install -D -m 644 -T -o root -g root ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.cron /etc/cron.d/pihole
# Randomize gravity update time
sed -i "s/59 1 /$((1 + RANDOM % 58)) $((3 + RANDOM % 2))/" /etc/cron.d/pihole
ynh_replace_string --match_string="59 1 " --replace_string="$((1 + RANDOM % 58)) $((3 + RANDOM % 2)) " --target_file="/etc/cron.d/pihole"
# Randomize update checker time
sed -i "s/59 17/$((1 + RANDOM % 58)) $((12 + RANDOM % 8))/" /etc/cron.d/pihole
ynh_replace_string --match_string="59 17" --replace_string="$((1 + RANDOM % 58)) $((12 + RANDOM % 8))" --target_file="/etc/cron.d/pihole"
# Remove git usage for version. Which fails because we use here a release instead of master.
ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole
@ -264,7 +271,7 @@ 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
@ -297,6 +304,7 @@ then
fi
echo "QUERY_LOGGING=$query_logging" >> $setupVars
echo "INSTALL_WEB=true" >> $setupVars
echo "BLOCKING_ENABLED=true" >> $setupVars
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$setupVars"
@ -375,8 +383,7 @@ echo "$(ynh_app_upstream_version) $pihole_adminlte_version $pihole_flt_version"
#=================================================
ynh_script_progression --message="Updating conf_regen hook..." --weight=1
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
ynh_add_config --template="../conf/dnsmasq_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
systemctl daemon-reload
ynh_exec_warn_less yunohost tools regen-conf dnsmasq
@ -395,14 +402,14 @@ yunohost service add pihole-FTL --description="PiHole backend service" --log="/v
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
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"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --action=reload --service_name=nginx
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# DEACTIVE MAINTENANCE MODE