This app has been put under maintenance by your administrator at $(date)
100 |Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.
101 | 102 | 103 | " > "/var/www/html/maintenance.$app.html" 104 | 105 | # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. 106 | echo "# All request to the app will be redirected to ${path}_maintenance and fall on the maintenance notice 107 | rewrite ^${path}/(.*)$ ${path}_maintenance/? redirect; 108 | # Use another location, to not be in conflict with the original config file 109 | location ${path}_maintenance/ { 110 | alias /var/www/html/ ; 111 | 112 | try_files maintenance.$app.html =503; 113 | 114 | # Include SSOWAT user panel. 115 | include conf.d/yunohost_panel.conf.inc; 116 | }" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" 117 | 118 | # The current config file will redirect all requests to the root of the app. 119 | # To keep the full path, we can use the following rewrite rule: 120 | # rewrite ^${path}/(.*)$ ${path}_maintenance/\$1? redirect; 121 | # The difference will be in the $1 at the end, which keep the following queries. 122 | # But, if it works perfectly for a html request, there's an issue with any php files. 123 | # This files are treated as simple files, and will be downloaded by the browser. 124 | # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. 125 | 126 | systemctl reload nginx 127 | } 128 | 129 | ynh_maintenance_mode_OFF () { 130 | # Rewrite the nginx config file to redirect from ${path}_maintenance to the real url of the app. 131 | echo "rewrite ^${path}_maintenance/(.*)$ ${path}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" 132 | systemctl reload nginx 133 | 134 | # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. 135 | sleep 4 136 | 137 | # Then remove the temporary files used for the maintenance. 138 | rm "/var/www/html/maintenance.$app.html" 139 | rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" 140 | 141 | systemctl reload nginx 142 | } 143 | 144 | #================================================= 145 | # FUTURE OFFICIAL HELPERS 146 | #================================================= 147 | -------------------------------------------------------------------------------- /scripts/backup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # IMPORT GENERIC HELPERS 5 | #================================================= 6 | 7 | # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts 8 | source ../settings/scripts/_common.sh 9 | source /usr/share/yunohost/helpers 10 | 11 | #================================================= 12 | # DECLARE DATA AND CONF FILES TO BACKUP 13 | #================================================= 14 | ynh_print_info --message="Declaring files to be backed up..." 15 | 16 | #================================================= 17 | # BACKUP THE APP MAIN DIR 18 | #================================================= 19 | 20 | ynh_backup --src_path="$install_dir" 21 | 22 | #================================================= 23 | # BACKUP THE SYSTEM CONFIGURATION 24 | #================================================= 25 | 26 | ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" 27 | 28 | ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" 29 | 30 | ynh_backup --src_path="/etc/cron.d/pihole" 31 | 32 | ynh_backup --src_path="/etc/sudoers.d/pihole" 33 | 34 | ynh_backup --src_path="/etc/init.d/pihole-FTL" 35 | 36 | ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" 37 | 38 | if test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf"; then 39 | ynh_backup --src_path="/etc/dnsmasq.d/03-pihole-wildcard.conf" 40 | fi 41 | 42 | #================================================= 43 | # BACKUP VARIOUS FILES 44 | #================================================= 45 | 46 | ynh_backup --src_path="$PI_HOLE_LOCAL_REPO" 47 | ynh_backup --src_path="$PI_HOLE_CONFIG_DIR" 48 | ynh_backup --src_path="$PI_HOLE_INSTALL_DIR" 49 | 50 | ynh_backup --src_path="$PI_HOLE_BIN_DIR/pihole" 51 | ynh_backup --src_path="/etc/bash_completion.d/pihole" 52 | 53 | ynh_backup --src_path="/usr/bin/pihole-FTL" 54 | 55 | #================================================= 56 | # END OF SCRIPT 57 | #================================================= 58 | 59 | ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." 60 | -------------------------------------------------------------------------------- /scripts/change_url: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # IMPORT GENERIC HELPERS 5 | #================================================= 6 | 7 | source _common.sh 8 | source /usr/share/yunohost/helpers 9 | 10 | #================================================= 11 | # ACTIVATE MAINTENANCE MODE 12 | #================================================= 13 | ynh_script_progression --message="Activating maintenance mode..." --weight=1 14 | 15 | ynh_maintenance_mode_ON 16 | 17 | #================================================= 18 | # MODIFY URL IN NGINX CONF 19 | #================================================= 20 | ynh_script_progression --message="Updating NGINX web server configuration..." --weight=4 21 | 22 | ynh_change_url_nginx_config 23 | 24 | #================================================= 25 | # DEACTIVE MAINTENANCE MODE 26 | #================================================= 27 | ynh_script_progression --message="Disabling maintenance mode..." --weight=5 28 | 29 | ynh_maintenance_mode_OFF 30 | 31 | #================================================= 32 | # END OF SCRIPT 33 | #================================================= 34 | 35 | ynh_script_progression --message="Change of URL completed for $app" --last 36 | -------------------------------------------------------------------------------- /scripts/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # IMPORT GENERIC HELPERS 5 | #================================================= 6 | 7 | source _common.sh 8 | source /usr/share/yunohost/helpers 9 | 10 | #================================================= 11 | # INITIALIZE AND STORE SETTINGS 12 | #================================================= 13 | 14 | ynh_app_setting_set --app="$app" --key="overwrite_setupvars" --value=1 15 | ynh_app_setting_set --app="$app" --key="overwrite_ftl" --value=1 16 | 17 | #================================================= 18 | # CHECK AVAILABLE PORT 19 | #================================================= 20 | 21 | _configure_ports 22 | 23 | #================================================= 24 | # DOWNLOAD, CHECK AND UNPACK SOURCE 25 | #================================================= 26 | ynh_script_progression --message="Setting up source files..." --weight=4 27 | 28 | # Download, check integrity, uncompress and patch the source from app.src 29 | ynh_setup_source --dest_dir="$PI_HOLE_LOCAL_REPO" 30 | ynh_setup_source --source_id="pi-hole_web" --dest_dir="$install_dir/web" 31 | ynh_setup_source --source_id="pi-hole_ftl" --dest_dir="$install_dir/ftl" 32 | 33 | chmod -R o-rwx "$install_dir" 34 | chown -R "$app:www-data" "$install_dir" 35 | 36 | touch /var/log/{pihole,pihole-FTL}.log 37 | chmod 644 /var/log/{pihole,pihole-FTL}.log 38 | chown "$dnsmasq_user:root" /var/log/{pihole,pihole-FTL}.log 39 | 40 | #================================================= 41 | # INSTALLATION OF PIHOLE-FTL 42 | #================================================= 43 | ynh_script_progression --message="Building PiHole-FTL..." --weight=30 44 | 45 | # Instead of downloading a binary file, we're going to compile it 46 | pushd "$install_dir/ftl" 47 | ynh_exec_warn_less cmake . 48 | ynh_exec_warn_less make 49 | ynh_exec_warn_less make install 50 | popd 51 | ynh_secure_remove --file="$install_dir/ftl" 52 | 53 | #================================================= 54 | # INSTALL THE SCRIPTS 55 | #================================================= 56 | ynh_script_progression --message="Installing Pihole..." --weight=1 57 | 58 | install -o "$app" -Dm755 -d "$PI_HOLE_INSTALL_DIR" 59 | install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/gravity.sh" 60 | install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/advanced/Scripts"/*.sh 61 | install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/advanced/Scripts/COL_TABLE" 62 | install -Dm644 -t /etc/bash_completion.d/ "$PI_HOLE_LOCAL_REPO/advanced/bash-completion/pihole" 63 | 64 | install -o "$app" -Dm755 -t "$PI_HOLE_BIN_DIR" "$PI_HOLE_LOCAL_REPO/pihole" 65 | 66 | #================================================= 67 | # INSTALL THE CONFIGS 68 | #================================================= 69 | ynh_script_progression --message="Installing $app's configuration files..." --weight=1 70 | 71 | install -d -m 0755 "$PI_HOLE_CONFIG_DIR" 72 | ynh_add_config --template="dns-servers.conf" --destination="$PI_HOLE_CONFIG_DIR/dns-servers.conf" 73 | ynh_add_config --template="pihole-FTL.conf" --destination="$PI_HOLE_CONFIG_DIR/pihole-FTL.conf" 74 | ynh_add_config --template="setupVars.conf" --destination="$PI_HOLE_CONFIG_DIR/setupVars.conf" 75 | 76 | chmod 644 "${PI_HOLE_CONFIG_DIR}/dns-servers.conf" 77 | 78 | #================================================= 79 | # SET VERSIONS FOR THE FOOTER OF THE WEB INTERFACE 80 | #================================================= 81 | ynh_script_progression --message="Setting versions for the footer of the web interface..." --weight=1 82 | 83 | echo "master master master" > "$PI_HOLE_CONFIG_DIR/localbranches" 84 | echo "$(ynh_app_upstream_version) $pihole_adminlte_version $pihole_flt_version" \ 85 | | tee "$PI_HOLE_CONFIG_DIR/"{GitHubVersions,localversions} > /dev/null 86 | 87 | #================================================= 88 | # BUILD THE LISTS WITH GRAVITY 89 | #================================================= 90 | ynh_script_progression --message="Building the lists with Gravity..." --weight=7 91 | 92 | ynh_add_config --template="adlists.default" --destination="$PI_HOLE_CONFIG_DIR/adlists.list" 93 | ynh_exec_warn_less "$PI_HOLE_INSTALL_DIR/gravity.sh" --force 94 | 95 | #================================================= 96 | # CONFIGURE DNS FOR THE LOCAL DOMAINS 97 | #================================================= 98 | ynh_script_progression --message="Configuring DNS for the local domains..." --weight=7 99 | 100 | # List all YunoHost domains 101 | while read -r perdomain; do 102 | # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution. 103 | ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts 104 | 105 | # And add a resolution on the local IP instead 106 | grep -q "^$localipv4.*$perdomain" /etc/hosts || \ 107 | echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts 108 | done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" 109 | 110 | #================================================= 111 | # DISABLING DNSMASQ 112 | #================================================= 113 | ynh_script_progression --message="Disabling Dnsmasq in system and yunohost..." --weight=1 114 | 115 | # Stop dnsmasq to replace it by pihole-FTL 116 | ynh_systemd_action --service_name=dnsmasq --action=stop 117 | 118 | # Replace the service dnsmasq by pihole-FTL 119 | # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL 120 | #ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service 121 | systemctl mask dnsmasq.service 122 | 123 | # Reload systemd config 124 | systemctl daemon-reload 125 | 126 | # Workaround for strings to not be replaced 127 | a_range="__A_RANGE__" 128 | b_range="__B_RANGE__" 129 | gateway="__GATEWAY__" 130 | ynh_add_config --template="dnsmasq_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" 131 | ynh_exec_warn_less yunohost tools regen-conf dnsmasq 132 | 133 | #================================================= 134 | # SYSTEM CONFIGURATION 135 | #================================================= 136 | ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 137 | 138 | # Create a dedicated PHP-FPM config 139 | ynh_add_fpm_config 140 | 141 | # Create a dedicated NGINX config 142 | ynh_add_nginx_config 143 | 144 | # Create sudoers config 145 | _add_sudoers_config 146 | 147 | _add_cron_jobs 148 | 149 | _add_logrotate_config 150 | 151 | install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL" 152 | install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-prestart.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-prestart.sh" 153 | install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-poststop.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-poststop.sh" 154 | 155 | ynh_exec_warn_less systemctl enable pihole-FTL --quiet 156 | yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log" --needs_exposed_ports 53 67 157 | 158 | #================================================= 159 | # START SYSTEMD SERVICE 160 | #================================================= 161 | ynh_script_progression --message="Starting $app's systemd service..." --weight=2 162 | 163 | ynh_systemd_action --service_name="pihole-FTL" --action=restart --log_path="/var/log/pihole-FTL.log" 164 | 165 | #================================================= 166 | # END OF SCRIPT 167 | #================================================= 168 | 169 | ynh_script_progression --message="Installation of $app completed" --last 170 | -------------------------------------------------------------------------------- /scripts/remove: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # IMPORT GENERIC HELPERS 5 | #================================================= 6 | 7 | source _common.sh 8 | source /usr/share/yunohost/helpers 9 | 10 | #================================================= 11 | # REMOVE SYSTEM CONFIGURATIONS 12 | #================================================= 13 | ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 14 | 15 | # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) 16 | if ynh_exec_warn_less yunohost service status "pihole-FTL" >/dev/null; then 17 | yunohost service remove "pihole-FTL" 18 | fi 19 | 20 | ynh_systemd_action --service_name="pihole-FTL" --action="stop" 21 | 22 | # Restore dnsmasq as main DNS resolver 23 | # Move dnsmasq back to its original place 24 | #if [ -e "/usr/sbin/dnsmasq.backup_by_pihole" ] 25 | #then # Remove dnsmasq only if we have its backup 26 | # ynh_secure_remove --file="/usr/sbin/dnsmasq" 27 | # mv /usr/sbin/dnsmasq.backup_by_pihole /usr/sbin/dnsmasq 28 | #fi 29 | 30 | # Move back the service configuration for dnsmasq 31 | #ynh_secure_remove --file="/etc/systemd/system/dnsmasq.service" 32 | #mv /lib/systemd/system/.dnsmasq.service.backup_by_pihole /lib/systemd/system/dnsmasq.service 33 | #mv /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq 34 | systemctl unmask dnsmasq.service 35 | 36 | #ynh_exec_warn_less systemctl enable dnsmasq --quiet 37 | # Reload systemd config 38 | systemctl daemon-reload 39 | 40 | ynh_secure_remove --file="/etc/init.d/pihole-FTL" 41 | ynh_secure_remove --file="/usr/bin/pihole-FTL" 42 | ynh_secure_remove --file="/var/run/pihole-FTL.pid" 43 | ynh_secure_remove --file="/var/run/pihole-FTL.port" 44 | 45 | # Remove the dedicated NGINX config 46 | ynh_remove_nginx_config 47 | 48 | # Remove the dedicated PHP-FPM config 49 | ynh_remove_fpm_config 50 | 51 | #================================================= 52 | # CLOSE A PORT 53 | #================================================= 54 | 55 | if yunohost firewall list | grep -q "\- $port$"; then 56 | ynh_script_progression --message="Closing port $port..." --weight=1 57 | ynh_exec_warn_less yunohost firewall disallow TCP "$port" 58 | fi 59 | 60 | if yunohost firewall list | grep -q "\- 67$"; then 61 | ynh_script_progression --message="Closing port 67..." --weight=1 62 | ynh_exec_warn_less yunohost firewall disallow UDP 67 63 | fi 64 | 65 | #================================================= 66 | # REMOVE VARIOUS FILES 67 | #================================================= 68 | ynh_script_progression --message="Removing various files..." --weight=1 69 | 70 | # Remove a cron file 71 | ynh_secure_remove --file="/etc/cron.d/$app" 72 | 73 | # Remove main script 74 | ynh_secure_remove --file="$PI_HOLE_BIN_DIR/pihole" 75 | ynh_secure_remove --file="/etc/bash_completion.d/pihole" 76 | 77 | # Remove sudoer file 78 | ynh_secure_remove --file="/etc/sudoers.d/pihole" 79 | 80 | # Remove storage directory 81 | ynh_secure_remove --file="$PI_HOLE_CONFIG_DIR" 82 | # Remove app directory 83 | ynh_secure_remove --file="$PI_HOLE_INSTALL_DIR" 84 | # Remove local clone of the repository 85 | ynh_secure_remove --file="$PI_HOLE_LOCAL_REPO" 86 | 87 | #================================================= 88 | # REMOVE DNSMASQ CONFIG 89 | #================================================= 90 | ynh_script_progression --message="Removing Dnsmasq config..." --weight=2 91 | 92 | ynh_secure_remove --file="/etc/dnsmasq.d/03-pihole-wildcard.conf" 93 | 94 | #================================================= 95 | # CLEAN /etc/hosts 96 | #================================================= 97 | ynh_script_progression --message="Clean /etc/hosts" --weight=1 98 | 99 | # Uncomment lines in /etc/hosts 100 | ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" --target_file=/etc/hosts 101 | 102 | # And remove extra lines, added by PiHole 103 | sed -i "/#Added by pihole#/d" /etc/hosts 104 | 105 | #================================================= 106 | # REMOVE CONF_REGEN HOOK 107 | #================================================= 108 | ynh_script_progression --message="Removing conf_regen hook..." --weight=1 109 | 110 | ynh_systemd_action --service_name=dnsmasq --action=stop 111 | 112 | ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" 113 | 114 | ynh_exec_warn_less yunohost tools regen-conf dnsmasq 115 | 116 | #================================================= 117 | # RESTART DNSMASQ 118 | #================================================= 119 | ynh_script_progression --message="Restarting Dnsmasq..." --weight=1 120 | 121 | ynh_systemd_action --service_name=dnsmasq --action=restart 122 | 123 | #================================================= 124 | # REMOVE DEDICATED USER 125 | #================================================= 126 | 127 | # Dirty hack to remove correctly the user 128 | killall -u "$app" 129 | 130 | #================================================= 131 | # END OF SCRIPT 132 | #================================================= 133 | 134 | ynh_script_progression --message="Removal of $app completed" --last 135 | -------------------------------------------------------------------------------- /scripts/restore: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # IMPORT GENERIC HELPERS 5 | #================================================= 6 | 7 | # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts 8 | source ../settings/scripts/_common.sh 9 | source /usr/share/yunohost/helpers 10 | 11 | #================================================= 12 | # INITIALIZE AND STORE SETTINGS 13 | #================================================= 14 | 15 | dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2) 16 | 17 | #================================================= 18 | # CHECK AVAILABLE PORT 19 | #================================================= 20 | 21 | _configure_ports 22 | 23 | #================================================= 24 | # ACTIVATE MAINTENANCE MODE 25 | #================================================= 26 | ynh_script_progression --message="Activating maintenance mode..." --weight=2 27 | 28 | ynh_maintenance_mode_ON 29 | 30 | #================================================= 31 | # RESTORE THE APP MAIN DIR 32 | #================================================= 33 | ynh_script_progression --message="Restoring the app main directory..." --weight=1 34 | 35 | ynh_restore_file --origin_path="$install_dir" 36 | 37 | chmod -R o-rwx "$install_dir" 38 | chown -R "$app:www-data" "$install_dir" 39 | 40 | touch /var/log/{pihole,pihole-FTL}.log 41 | chmod 644 /var/log/{pihole,pihole-FTL}.log 42 | chown "$dnsmasq_user:root" /var/log/{pihole,pihole-FTL}.log 43 | 44 | #================================================= 45 | # RESTORE SPECIFIC FILES 46 | #================================================= 47 | ynh_script_progression --message="Restoring specific files..." --weight=1 48 | 49 | ynh_restore_file --origin_path="$PI_HOLE_LOCAL_REPO" 50 | 51 | ynh_restore_file --origin_path="$PI_HOLE_CONFIG_DIR" 52 | chown "$app:" -R "$PI_HOLE_CONFIG_DIR" 53 | 54 | # $PI_HOLE_CONFIG_DIR/logrotate have to belong to root, otherwise logrotate will failed silently... 55 | chown root: -R "$PI_HOLE_CONFIG_DIR/logrotate" 56 | 57 | ynh_restore_file --origin_path="$PI_HOLE_INSTALL_DIR" 58 | 59 | ynh_restore_file --origin_path="$PI_HOLE_BIN_DIR/pihole" 60 | 61 | ynh_restore_file --origin_path="/etc/bash_completion.d/pihole" 62 | 63 | ynh_restore_file --origin_path="/usr/bin/pihole-FTL" 64 | 65 | #================================================= 66 | # FINAL EXPORTS 67 | #================================================= 68 | ynh_script_progression --message="Final exports..." --weight=1 69 | 70 | setupVars="$PI_HOLE_CONFIG_DIR/setupVars.conf" 71 | 72 | # Get the default network interface 73 | main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}') 74 | echo "PIHOLE_INTERFACE=$main_iface" > "$setupVars" 75 | ynh_replace_string --target_file="$setupVars" --match_string="^PIHOLE_INTERFACE=.*" --replace_string="PIHOLE_INTERFACE=$main_iface" 76 | ynh_replace_string --target_file="$setupVars" --match_string="^IPV4_ADDRESS=.*" --replace_string="IPV4_ADDRESS=127.0.0.1" 77 | 78 | # Calculate and store the config file checksum into the app settings 79 | ynh_store_file_checksum --file="$setupVars" 80 | 81 | #================================================= 82 | # CONFIGURE DNS FOR THE LOCAL DOMAINS 83 | #================================================= 84 | ynh_script_progression --message="Configuring DNS for the local domains..." --weight=2 85 | 86 | # Find the IP associated to the network interface 87 | localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1) 88 | 89 | # List all YunoHost domains 90 | while read -r perdomain; do 91 | # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution. 92 | ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts 93 | 94 | # And add a resolution on the local IP instead 95 | grep -q "^$localipv4.*$perdomain" /etc/hosts || \ 96 | echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts 97 | done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" 98 | 99 | #================================================= 100 | # DISABLING DNSMASQ 101 | #================================================= 102 | ynh_script_progression --message="Disabling Dnsmasq in system and yunohost..." --weight=1 103 | 104 | # Stopped dnsmasq to replace it by pihole-FTL 105 | ynh_systemd_action --service_name=dnsmasq --action=stop 106 | 107 | # Replace the service dnsmasq by pihole-FTL 108 | # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL 109 | #ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service 110 | systemctl mask dnsmasq.service 111 | 112 | # Disable the real dnsmasq service 113 | #ynh_exec_warn_less systemctl disable dnsmasq --quiet 114 | 115 | # Reload systemd config 116 | systemctl daemon-reload 117 | 118 | 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" 119 | ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" 120 | ynh_exec_warn_less yunohost tools regen-conf dnsmasq 121 | 122 | #================================================= 123 | # RESTORE SYSTEM CONFIGURATIONS 124 | #================================================= 125 | ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 126 | 127 | ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" 128 | 129 | # Restore the file first, so it can have a backup if different 130 | ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" 131 | ynh_add_fpm_config 132 | 133 | ynh_restore_file --origin_path="/etc/cron.d/pihole" 134 | 135 | ynh_restore_file --origin_path="/etc/sudoers.d/pihole" 136 | 137 | ynh_restore_file --origin_path="/etc/init.d/pihole-FTL" 138 | # install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL" 139 | systemctl daemon-reload 140 | ynh_exec_warn_less systemctl enable pihole-FTL --quiet 141 | yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log" --needs_exposed_ports 53 67 142 | 143 | #================================================= 144 | # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE 145 | #================================================= 146 | ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 147 | 148 | ynh_systemd_action --service_name="pihole-FTL" --action="restart" --log_path="/var/log/pihole-FTL.log" 149 | 150 | ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload 151 | 152 | ynh_systemd_action --service_name="nginx" --action=reload 153 | 154 | #================================================= 155 | # DEACTIVE MAINTENANCE MODE 156 | #================================================= 157 | ynh_script_progression --message="Disabling maintenance mode..." --weight=4 158 | 159 | ynh_maintenance_mode_OFF 160 | 161 | #================================================= 162 | # END OF SCRIPT 163 | #================================================= 164 | 165 | ynh_script_progression --message="Restoration completed for $app" --last 166 | -------------------------------------------------------------------------------- /scripts/upgrade: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #================================================= 4 | # IMPORT GENERIC HELPERS 5 | #================================================= 6 | 7 | source _common.sh 8 | source /usr/share/yunohost/helpers 9 | 10 | #================================================= 11 | # ACTIVATE MAINTENANCE MODE 12 | #================================================= 13 | ynh_script_progression --message="Activating maintenance mode..." --weight=1 14 | 15 | ynh_maintenance_mode_ON 16 | 17 | #================================================= 18 | # STOP SYSTEMD SERVICE 19 | #================================================= 20 | ynh_script_progression --message="Stopping a systemd service..." --weight=1 21 | 22 | ynh_systemd_action --service_name=pihole-FTL --action="stop" --log_path="/var/log/pihole-FTL.log" 23 | 24 | #================================================= 25 | # ENSURE DOWNWARD COMPATIBILITY 26 | #================================================= 27 | ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 28 | 29 | # If overwrite_setupvars doesn't exist, create it 30 | if [ -z "${overwrite_setupvars:-}" ]; then 31 | overwrite_setupvars=1 32 | ynh_app_setting_set --app="$app" --key="overwrite_setupvars" --value="$overwrite_setupvars" 33 | fi 34 | 35 | # If overwrite_ftl doesn't exist, create it 36 | if [ -z "${overwrite_ftl:-}" ]; then 37 | overwrite_ftl=1 38 | ynh_app_setting_set --app="$app" --key="overwrite_ftl" --value="$overwrite_ftl" 39 | fi 40 | 41 | # If pihole_version doesn't exist, create it 42 | if [ -z "${pihole_version:-}" ]; then 43 | pihole_version="Last 3.X" 44 | ynh_app_setting_set --app="$app" --key="pihole_version" --value=""$pihole_version"" 45 | fi 46 | 47 | #================================================= 48 | # DOWNLOAD, CHECK AND UNPACK SOURCE 49 | #================================================= 50 | ynh_script_progression --message="Upgrading source files..." --weight=4 51 | 52 | # Download, check integrity, uncompress and patch the source from app.src 53 | ynh_setup_source --dest_dir="$PI_HOLE_LOCAL_REPO" 54 | ynh_setup_source --source_id="pi-hole_web" --dest_dir="$install_dir/web" 55 | ynh_setup_source --source_id="pi-hole_ftl" --dest_dir="$install_dir/ftl" 56 | 57 | chmod -R o-rwx "$install_dir" 58 | chown -R "$app:www-data" "$install_dir" 59 | 60 | touch /var/log/{pihole,pihole-FTL}.log 61 | chmod 644 /var/log/{pihole,pihole-FTL}.log 62 | chown "$dnsmasq_user:root" /var/log/{pihole,pihole-FTL}.log 63 | 64 | #================================================= 65 | # UPGRADE OF PIHOLE-FTL 66 | #================================================= 67 | ynh_script_progression --message="Rebuilding PiHole-FTL..." --weight=30 68 | 69 | # Instead of downloading a binary file, we're going to compile it 70 | pushd "$install_dir/ftl" 71 | ynh_exec_warn_less cmake . 72 | ynh_exec_warn_less make 73 | ynh_exec_warn_less make install 74 | popd 75 | ynh_secure_remove --file="$install_dir/ftl" 76 | 77 | #================================================= 78 | # UPDATE THE SCRIPTS 79 | #================================================= 80 | ynh_script_progression --message="Upgrading Pihole..." --weight=1 81 | 82 | install -o "$app" -Dm755 -d "$PI_HOLE_INSTALL_DIR" 83 | install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/gravity.sh" 84 | install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/advanced/Scripts"/*.sh 85 | install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/advanced/Scripts/COL_TABLE" 86 | install -Dm644 -t /etc/bash_completion.d/ "$PI_HOLE_LOCAL_REPO/advanced/bash-completion/pihole" 87 | 88 | install -o "$app" -Dm755 -t "$PI_HOLE_BIN_DIR" "$PI_HOLE_LOCAL_REPO/pihole" 89 | 90 | #================================================= 91 | # UPDATE THE CONFIGS 92 | #================================================= 93 | ynh_script_progression --message="Updating $app's configuration files..." --weight=1 94 | 95 | install -d -m 0755 "$PI_HOLE_CONFIG_DIR" 96 | ynh_add_config --template="dns-servers.conf" --destination="$PI_HOLE_CONFIG_DIR/dns-servers.conf" 97 | # Overwrite pihole-FTL config file only if it's allowed 98 | if [ "$overwrite_ftl" -eq 1 ]; then 99 | ynh_add_config --template="pihole-FTL.conf" --destination="$PI_HOLE_CONFIG_DIR/pihole-FTL.conf" 100 | fi 101 | # Overwrite the setupVars config file only if it's allowed 102 | if [ "$overwrite_setupvars" -eq 1 ]; then 103 | ynh_add_config --template="setupVars.conf" --destination="$PI_HOLE_CONFIG_DIR/setupVars.conf" 104 | fi 105 | 106 | chmod 644 "${PI_HOLE_CONFIG_DIR}/dns-servers.conf" 107 | 108 | #================================================= 109 | # SET VERSIONS FOR THE FOOTER OF THE WEB INTERFACE 110 | #================================================= 111 | ynh_script_progression --message="Setting versions for the footer of the web interface..." --weight=1 112 | 113 | echo "master master master" > "$PI_HOLE_CONFIG_DIR/localbranches" 114 | echo "$(ynh_app_upstream_version) $pihole_adminlte_version $pihole_flt_version" \ 115 | | tee "$PI_HOLE_CONFIG_DIR/"{GitHubVersions,localversions} > /dev/null 116 | 117 | #================================================= 118 | # BUILD THE LISTS WITH GRAVITY 119 | #================================================= 120 | ynh_script_progression --message="Building the lists with Gravity..." --weight=7 121 | 122 | ynh_add_config --template="adlists.default" --destination="$PI_HOLE_CONFIG_DIR/adlists.list" 123 | ynh_exec_warn_less "$PI_HOLE_INSTALL_DIR/gravity.sh" --force 124 | 125 | #================================================= 126 | # CONFIGURE DNS FOR THE LOCAL DOMAINS 127 | #================================================= 128 | ynh_script_progression --message="Configuring DNS for the local domains..." --weight=7 129 | 130 | # List all YunoHost domains 131 | while read -r perdomain; do 132 | # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution. 133 | ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts 134 | 135 | # And add a resolution on the local IP instead 136 | grep -q "^$localipv4.*$perdomain" /etc/hosts || \ 137 | echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts 138 | done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" 139 | 140 | #================================================= 141 | # DISABLING DNSMASQ 142 | #================================================= 143 | ynh_script_progression --message="Disabling Dnsmasq in system and yunohost..." --weight=1 144 | 145 | # Stop dnsmasq to replace it by pihole-FTL 146 | ynh_systemd_action --service_name=dnsmasq --action=stop 147 | 148 | # Disable the real dnsmasq service 149 | #ynh_exec_warn_less systemctl disable dnsmasq --quiet 150 | 151 | # Replace the service dnsmasq by pihole-FTL 152 | # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL 153 | #ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service 154 | systemctl mask dnsmasq.service 155 | 156 | # Reload systemd config 157 | systemctl daemon-reload 158 | 159 | # Workaround for strings to not be replaced 160 | a_range="__A_RANGE__" 161 | b_range="__B_RANGE__" 162 | gateway="__GATEWAY__" 163 | ynh_add_config --template="dnsmasq_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" 164 | ynh_exec_warn_less yunohost tools regen-conf dnsmasq 165 | 166 | #================================================= 167 | # REAPPLY SYSTEM CONFIGURATIONS 168 | #================================================= 169 | ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 170 | 171 | # Create a dedicated PHP-FPM config 172 | ynh_add_fpm_config 173 | 174 | # Create a dedicated NGINX config 175 | ynh_add_nginx_config 176 | 177 | _add_sudoers_config 178 | 179 | _add_cron_jobs 180 | 181 | _add_logrotate_config 182 | 183 | install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL" 184 | install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-prestart.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-prestart.sh" 185 | install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-poststop.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-poststop.sh" 186 | ynh_exec_warn_less systemctl enable pihole-FTL --quiet 187 | yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log" --needs_exposed_ports 53 67 188 | 189 | #================================================= 190 | # START SYSTEMD SERVICE 191 | #================================================= 192 | ynh_script_progression --message="Starting $app's systemd service..." --weight=2 193 | 194 | ynh_systemd_action --service_name=pihole-FTL --action=restart --log_path="/var/log/pihole-FTL.log" 195 | 196 | #================================================= 197 | # DEACTIVE MAINTENANCE MODE 198 | #================================================= 199 | ynh_script_progression --message="Disabling maintenance mode..." --weight=5 200 | 201 | ynh_maintenance_mode_OFF 202 | 203 | #================================================= 204 | # END OF SCRIPT 205 | #================================================= 206 | 207 | ynh_script_progression --message="Upgrade of $app completed" --last 208 | -------------------------------------------------------------------------------- /tests.toml: -------------------------------------------------------------------------------- 1 | #:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json 2 | 3 | test_format = 1.0 4 | 5 | [default] 6 | 7 | args.query_logging = 1 8 | args.enable_dhcp = 0 9 | 10 | # ------------ 11 | # Tests to run 12 | # ------------ 13 | 14 | [default.test_upgrade_from.5cc0fe9d7586001602bbaf87084c0ddbbaa041a6] 15 | name = "Last packagingv1 version" 16 | args.admin = "package_checker" 17 | args.domain = "domain.tld" 18 | args.path = "/" 19 | 20 | # ; Config_panel 21 | # main.overwrite_files.overwrite_setupvars=0|1 22 | # main.overwrite_files.overwrite_ftl=0|1 23 | # main.overwrite_files.overwrite_nginx=0|1 24 | # main.overwrite_files.overwrite_phpfpm=0|1 25 | # main.global_config.email_type=0|1 26 | # main.php_fpm_config.footprint=low|medium|high 27 | # main.php_fpm_config.free_footprint=20 28 | # main.php_fpm_config.usage=low|medium|high 29 | # main.php_fpm_config.force_max_children=20|0 30 | 31 | # actions=0 32 | # config_panel=0 33 | --------------------------------------------------------------------------------