Explorar o código

Merge pull request #73 from YunoHost-Apps/5.7

5.9
Éric Gaspar %!s(int64=4) %!d(string=hai) anos
pai
achega
c9b5ffd9c1

+ 1 - 3
README.md

@@ -18,7 +18,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
 Network-wide ad blocking via your own DNS server
 
 
-**Shipped version:** 5.6~ynh1
+**Shipped version:** 5.9~ynh1
 
 
 
@@ -35,8 +35,6 @@ Use the admin panel of your Pi-hole to configure this app. You may also need to
 ## Limitations
 
 * Activate DHCP with Pi-hole needs manual configuration of your router.
-* Pi-Hole can't be updated beyond version 3.3.1, because higher versions use an integrated version of dnsmasq. This would require disabling the version of dnsmasq used by YunoHost.
-
 
 ## Using Pi-hole as your DHCP server
 

+ 1 - 3
README_fr.md

@@ -14,7 +14,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
 Network-wide ad blocking via your own DNS server
 
 
-**Version incluse :** 5.6~ynh1
+**Version incluse :** 5.9~ynh1
 
 
 
@@ -31,8 +31,6 @@ Utiliser le panneau d'administration de votre Pi-hole pour configurer cette appl
 ## Limitations
 
 * Activer DHCP avec Pi-hole nécessite une configuration manuelle de votre routeur.
-* Pi-Hole ne peut pas être mis à jour au-delà de la version 3.3.1, car les versions supérieures utilisent une version intégrée de dnsmasq. Ce qui oblige a désactiver la version de dnsmasq utilisée par YunoHost.
-
 
 ## Faire de Pi-hole votre serveur DHCP
 

+ 45 - 0
actions.toml

@@ -0,0 +1,45 @@
+[reset_default_setupvars]
+name = "Reset the config file and restore a default one."
+command = "/bin/bash scripts/actions/reset_default_config \"setupVars.conf\""
+# user = "root"  # optional
+# cwd = "/" # optional
+# accepted_return_codes = [0, 1, 2, 3]  # optional
+accepted_return_codes = [0]
+description = "Reset the config file setupVars.conf."
+
+[reset_default_ftl]
+name = "Reset the config file and restore a default one."
+command = "/bin/bash scripts/actions/reset_default_config \"pihole-FTL.conf\""
+# user = "root"  # optional
+# cwd = "/" # optional
+# accepted_return_codes = [0, 1, 2, 3]  # optional
+accepted_return_codes = [0]
+description = "Reset the config file pihole-FTL.conf."
+
+[reset_default_nginx]
+name = "Reset the nginx config for this app."
+command = "/bin/bash scripts/actions/reset_default_system nginx"
+# user = "root"  # optional
+# cwd = "/" # optional
+# accepted_return_codes = [0, 1, 2, 3]  # optional
+accepted_return_codes = [0]
+description = "Reset the nginx config for this app."
+
+[reset_default_phpfpm]
+name = "Reset the php-fpm config for this app."
+command = "/bin/bash scripts/actions/reset_default_system phpfpm"
+# user = "root"  # optional
+# cwd = "/" # optional
+# accepted_return_codes = [0, 1, 2, 3]  # optional
+accepted_return_codes = [0]
+description = "Reset the php-fpm config for this app."
+
+
+[reset_default_app]
+name = "Reset the app with a default configuration."
+command = "/bin/bash scripts/actions/reset_default_app"
+# user = "root"  # optional
+# cwd = "/" # optional
+# accepted_return_codes = [0, 1, 2, 3]  # optional
+accepted_return_codes = [0]
+description = "Reset the app to its default configuration to try to fix potential issues.<br>This action won't remove any data added to the app.<br>However, if you have modified any configuration, it will be overwritten."

+ 14 - 23
check_process

@@ -5,7 +5,16 @@
         admin="john"
         query_logging=1
         enable_dhcp=0
-        pihole_version="Last available"
+    ; Config_panel
+        main.overwrite_files.overwrite_setupvars=0|1
+        main.overwrite_files.overwrite_ftl=0|1
+        main.overwrite_files.overwrite_nginx=0|1
+        main.overwrite_files.overwrite_phpfpm=0|1
+        main.global_config.email_type=0|1
+        main.php_fpm_config.footprint=low|medium|high
+        main.php_fpm_config.free_footprint=20
+        main.php_fpm_config.usage=low|medium|high
+        main.php_fpm_config.force_max_children=20|0
     ; Checks
         pkg_linter=1
         setup_sub_dir=1
@@ -14,34 +23,16 @@
         setup_private=1
         setup_public=0
         upgrade=1
+        upgrade=1   from_commit=cfa9c5a3dbcfb765dcca3b2e7d179756afe26def
         backup_restore=1
         multi_instance=0
         port_already_use=1
         change_url=1
         actions=0
         config_panel=0
-;; Test version 3
-    ; Manifest
-        domain="domain.tld"
-        path="/path"
-        admin="john"
-        query_logging=1
-        enable_dhcp=0
-        pihole_version="Last 3.X"
-    ; Checks
-        setup_sub_dir=1
-        setup_root=1
-        upgrade=1
-        # 3.3.1~ynh1
-        upgrade=1   from_commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
-        # 5.4~ynh1
-        upgrade=1   from_commit=cfa9c5a3dbcfb765dcca3b2e7d179756afe26def
-        backup_restore=1
-        actions=1
 ;;; Options
 Email=
-Notification=change
+Notification=none
 ;;; Upgrade options
-    ; commit=d79ec131b3038ff4695c3317b5d3ee4eda9c8932
-        name= Stretch fix
-        manifest_arg=domain=DOMAIN&path=PATH&admin=USER&query_logging=1&
+    ; commit=cfa9c5a3dbcfb765dcca3b2e7d179756afe26def
+        name=Merge pull request #66

+ 5 - 0
conf/FTL.src

@@ -0,0 +1,5 @@
+SOURCE_URL=https://github.com/pi-hole/FTL/archive/v5.12.tar.gz
+SOURCE_SUM=cc0864cdf7c10b82f04049e97dafef2eacb2b8155e7cb11e0383482f5dc0f1d6
+SOURCE_SUM_PRG=sha256sum
+SOURCE_FORMAT=tar.gz
+SOURCE_IN_SUBDIR=true

+ 0 - 5
conf/FTL_3.src

@@ -1,5 +0,0 @@
-SOURCE_URL=https://github.com/pi-hole/FTL/archive/v3.0.tar.gz
-SOURCE_SUM=8c3d55eb3054698172e59ae81b8562ce235d73da461389840da62d90b32f0057
-SOURCE_SUM_PRG=sha256sum
-SOURCE_FORMAT=tar.gz
-SOURCE_IN_SUBDIR=true

+ 0 - 6
conf/FTL_last.src

@@ -1,6 +0,0 @@
-SOURCE_URL=https://github.com/pi-hole/FTL/archive/v5.11.tar.gz
-SOURCE_SUM=e7f1ec8b12629ae4b1b5453f18f5247cb7c68037094c6cf7f8e046e18ce2c283
-SOURCE_SUM_PRG=sha256sum
-SOURCE_FORMAT=tar.gz
-SOURCE_IN_SUBDIR=true
-SOURCE_FILENAME=

+ 5 - 0
conf/admin_dashboard.src

@@ -0,0 +1,5 @@
+SOURCE_URL=https://github.com/pi-hole/AdminLTE/archive/v5.11.tar.gz
+SOURCE_SUM=589ef049135a90d622fc68299140e4dc16451ce541b804b35ffa5d25201afeb4
+SOURCE_SUM_PRG=sha256sum
+SOURCE_FORMAT=tar.gz
+SOURCE_IN_SUBDIR=true

+ 0 - 5
conf/admin_dashboard_3.src

@@ -1,5 +0,0 @@
-SOURCE_URL=https://github.com/pi-hole/AdminLTE/archive/v3.3.tar.gz
-SOURCE_SUM=caba2129fe8753b0c7aaf611b7c7b2146ff1ac56d5ac58987053b1553d09c49f
-SOURCE_SUM_PRG=sha256sum
-SOURCE_FORMAT=tar.gz
-SOURCE_IN_SUBDIR=true

+ 0 - 5
conf/admin_dashboard_last.src

@@ -1,5 +0,0 @@
-SOURCE_URL=https://github.com/pi-hole/AdminLTE/archive/v5.8.tar.gz
-SOURCE_SUM=b594374bd3d6361ad5fa35958b17a08965fcc77d3ef4c4a7938410116b0cf5be
-SOURCE_SUM_PRG=sha256sum
-SOURCE_FORMAT=tar.gz
-SOURCE_IN_SUBDIR=true

+ 5 - 0
conf/app.src

@@ -0,0 +1,5 @@
+SOURCE_URL=https://github.com/pi-hole/pi-hole/archive/v5.9.tar.gz
+SOURCE_SUM=13e7c3d7cdf19c9b9b8a449fea86d55ef68fce9b67ee3ad0429104c0ff509dde
+SOURCE_SUM_PRG=sha256sum
+SOURCE_FORMAT=tar.gz
+SOURCE_IN_SUBDIR=true

+ 0 - 6
conf/app_3.src

@@ -1,6 +0,0 @@
-SOURCE_URL=https://github.com/pi-hole/pi-hole/archive/v3.3.1.tar.gz
-SOURCE_SUM=6a80e4b6b38fc65df83459fe52f3a61623763709a077645f25ac9e29247e6d6d
-SOURCE_SUM_PRG=sha256sum
-SOURCE_FORMAT=tar.gz
-SOURCE_IN_SUBDIR=true
-SOURCE_FILENAME=

+ 0 - 5
conf/app_last.src

@@ -1,5 +0,0 @@
-SOURCE_URL=https://github.com/pi-hole/pi-hole/archive/v5.6.tar.gz
-SOURCE_SUM=c65f31418bdbfbf9ed482e5380f0b7f8370e69817dd1db70bea98f337198bf47
-SOURCE_SUM_PRG=sha256sum
-SOURCE_FORMAT=tar.gz
-SOURCE_IN_SUBDIR=true

+ 3 - 2
conf/dnsmasq_regenconf_hook

@@ -37,9 +37,10 @@ fi
 #
 
 ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf"
-ynh_replace_string --match_string="^listen-address=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf"
+ynh_replace_string --match_string="^listen-address=" --replace_string="#pihole# listen-address=" --target_file="${pending_conf}/etc/dnsmasq.conf"
 
-echo "conf-dir=/etc/dnsmasq.d/" >> "${pending_conf}/etc/dnsmasq.conf"
+echo "
+conf-dir=/etc/dnsmasq.d/" >> "${pending_conf}/etc/dnsmasq.conf"
 
 #
 # Regen /etc/dnsmasq.d/02-pihole-dhcp.conf

+ 10 - 11
conf/nginx.conf

@@ -6,17 +6,16 @@ location __PATH__/ {
 
   index index.html index.php;
 
-  try_files $uri $uri/ index.php;
-  location ~ [^/]\.php(/|$) {
-    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
-    fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
-
-    fastcgi_index index.php;
-    include fastcgi_params;
-    fastcgi_param REMOTE_USER $remote_user;
-    fastcgi_param PATH_INFO $fastcgi_path_info;
-    fastcgi_param SCRIPT_FILENAME $request_filename;
-  }
+    try_files $uri $uri/ index.php;
+    location ~ [^/]\.php(/|$) {
+        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
+        fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param REMOTE_USER $remote_user;
+        fastcgi_param PATH_INFO $fastcgi_path_info;
+        fastcgi_param SCRIPT_FILENAME $request_filename;
+    }
 
   # Include SSOWAT user panel.
   include conf.d/yunohost_panel.conf.inc;

+ 70 - 0
config_panel.toml.example

@@ -0,0 +1,70 @@
+version = "0.1"
+name = "PiHole configuration panel"
+
+[main]
+name = "PiHole configuration"
+
+    [main.overwrite_files]
+    name = "Overwriting config files"
+
+        [main.overwrite_files.overwrite_setupvars]
+        ask = "Overwrite the config file setupVars.conf?"
+        type = "boolean"
+        default = true
+        help = "If the file is overwritten, a backup will be created."
+
+        [main.overwrite_files.overwrite_ftl]
+        ask = "Overwrite the config file pihole-FTL.conf?"
+        type = "boolean"
+        default = true
+        help = "If the file is overwritten, a backup will be created."
+
+        [main.overwrite_files.overwrite_nginx]
+        ask = "Overwrite the nginx config file?"
+        type = "boolean"
+        default = true
+        help = "If the file is overwritten, a backup will be created."
+
+        [main.overwrite_files.overwrite_phpfpm]
+        ask = "Overwrite the php-fpm config file?"
+        type = "boolean"
+        default = true
+        help = "If the file is overwritten, a backup will be created."
+
+
+    [main.global_config]
+    name = "Global configuration"
+
+        [main.global_config.email_type]
+        ask = "Send HTML email to admin?"
+        type = "boolean"
+        default = true
+        help = "Allow app scripts to send HTML mails instead of plain text."
+
+
+    [main.php_fpm_config]
+    name = "PHP-FPM configuration"
+
+        [main.php_fpm_config.footprint]
+        ask = "Memory footprint of the service?"
+        choices = ["low", "medium", "high", "specific"]
+        default = "low"
+        help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.<br>Use specific to set a value with the following option."
+
+        [main.php_fpm_config.free_footprint]
+        ask = "Memory footprint of the service?"
+        type = "number"
+        default = "0"
+        help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values."
+
+        [main.php_fpm_config.usage]
+        ask = "Expected usage of the service?"
+        choices = ["low", "medium", "high"]
+        default = "low"
+        help = "low: Personal usage, behind the sso. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
+
+        [main.php_fpm_config.force_max_children]
+        ask = "Force the value of pm.max_children?"
+        type = "number"
+        default = "0"
+        help = "Do not change this value unless you're sure about what you're doing !<br>pm.max_children is automatically defined by this formula: $max_ram / 2 / $footprint<br>You can force that value, and ignore the formula by changing the value here.<br>To reset to the default value, set to 0."

+ 0 - 2
doc/DISCLAIMER.md

@@ -5,8 +5,6 @@ Use the admin panel of your Pi-hole to configure this app. You may also need to
 ## Limitations
 
 * Activate DHCP with Pi-hole needs manual configuration of your router.
-* Pi-Hole can't be updated beyond version 3.3.1, because higher versions use an integrated version of dnsmasq. This would require disabling the version of dnsmasq used by YunoHost.
-
 
 ## Using Pi-hole as your DHCP server
 

+ 0 - 2
doc/DISCLAIMER_fr.md

@@ -5,8 +5,6 @@ Utiliser le panneau d'administration de votre Pi-hole pour configurer cette appl
 ## Limitations
 
 * Activer DHCP avec Pi-hole nécessite une configuration manuelle de votre routeur.
-* Pi-Hole ne peut pas être mis à jour au-delà de la version 3.3.1, car les versions supérieures utilisent une version intégrée de dnsmasq. Ce qui oblige a désactiver la version de dnsmasq utilisée par YunoHost.
-
 
 ## Faire de Pi-hole votre serveur DHCP
 

+ 1 - 15
manifest.json

@@ -6,7 +6,7 @@
         "en": "Network-wide ad blocking via your own DNS server",
         "fr": "Filtrage publicitaire via votre propre serveur DNS"
     },
-    "version": "5.6~ynh1",
+    "version": "5.9~ynh1",
     "url": "https://pi-hole.net/",
     "upstream": {
         "license": "EUPL-1.2",
@@ -72,20 +72,6 @@
                     "fr": "Si vous voulez faire ça, <a href=https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md target=_blank>vous devez vraiment lire cela avant</a> !"
                 },
                 "default": false
-            },
-            {
-                "name": "pihole_version",
-                "type": "string",
-                "ask": {
-                    "en": "Which version of Pi-Hole do you want to install?",
-                    "fr": "Quelle version de Pi-Hole voulez-vous installer ?"
-                },
-                "help": {
-                    "en": "The last 3.X version is the last version available with the Debian version of dnsmasq. The last available version will replace the Debian version of dnsmasq by FTLDNS.<br>See the readme for more information.",
-                    "fr": "La dernière version 3.X est la dernière version disponible avec la version Debian de dnsmasq. La dernière version disponible remplacera la version Debian de dnsmasq par FTLDNS.<br>Voir le readme pour plus d'informations."
-                },
-                "choices": ["Last 3.X","Last available"],
-                "default": "Last 3.X"
             }
         ]
     }

+ 9 - 3
scripts/_common.sh

@@ -4,11 +4,17 @@
 # COMMON VARIABLES
 #=================================================
 
-# dependencies used by the app
-pkg_dependencies="sqlite3 idn2 php7.3-sqlite3 nettle-dev libcap2-bin build-essential libgmp-dev m4 cmake libidn11-dev libreadline-dev xxd"
+YNH_PHP_VERSION="7.3"
+
+# Dependencies
+pkg_dependencies="sqlite3 idn2 php${YNH_PHP_VERSION}-sqlite3 nettle-dev libcap2-bin build-essential libgmp-dev m4 cmake libidn11-dev libreadline-dev xxd"
+
+pihole_core_version=5.9
+dashboard_version=5.11
+FTL_version=5.14
 
 #=================================================
-# PERSONAL HELPERS
+# FUTUR OFFICIAL HELPERS
 #=================================================
 
 #=================================================

+ 6 - 10
scripts/_variables

@@ -1,12 +1,8 @@
 #!/bin/bash
 
-if [ "$YNH_APP_ARG_PIHOLE_VERSION" == "Last 3.X" ]
-then
-    pihole_core_version=3.3.1
-    dashboard_version=3.3
-    FTL_version=3.0
-else
-    pihole_core_version=5.6
-    dashboard_version=5.8
-    FTL_version=5.11
-fi
+# Dependencies
+app_depencencies="sqlite3 idn2 php7.3-sqlite3 nettle-dev libcap2-bin build-essential libgmp-dev m4 cmake libidn11-dev libreadline-dev xxd"
+
+pihole_core_version=5.6
+dashboard_version=5.8
+FTL_version=5.11

+ 20 - 57
scripts/actions/reset_default_app

@@ -7,8 +7,6 @@
 #=================================================
 
 # Load common variables for all scripts.
-source scripts/_variables
-
 source scripts/_common.sh
 source /usr/share/yunohost/helpers
 
@@ -32,7 +30,6 @@ app=$YNH_APP_INSTANCE_NAME
 path_url=$(ynh_app_setting_get --app=$app --key=path)
 domain=$(ynh_app_setting_get --app=$app --key=domain)
 final_path=$(ynh_app_setting_get --app=$app --key=final_path)
-pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
 
 #=================================================
 # SPECIFIC ACTION
@@ -58,21 +55,14 @@ ynh_script_progression --message="Resetting source files..." --weight=1
 
 # Download, check integrity, uncompress and patch the source from app.src
 pihole_local_repo="/etc/.pihole"
-(cd scripts
-if [ "$pihole_version" == "Last 3.X" ]
-then
-    # Overwrite the version 3.3.1
-    YNH_CWD=$PWD ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_3
-    # Overwrite admin dashboard
-    YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_3
-else
+(
+    cd scripts
     # Overwrite the last version available
-    YNH_CWD=$PWD ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_last
+    YNH_CWD=$PWD ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app
     # Overwrite admin dashboard
-    YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_last
-fi
+    YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard
 
-chown $app:www-data "$final_path"
+    chown $app:www-data "$final_path"
 
 )
 
@@ -133,12 +123,7 @@ chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log
 #=================================================
 
 # This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
-if [ "$pihole_version" == "Last 3.X" ]
-then
-    cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
-else
-    cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
-fi
+cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
 echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
 # echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin" >> /etc/sudoers.d/pihole
 chmod 0440 /etc/sudoers.d/pihole
@@ -147,12 +132,7 @@ chmod 0440 /etc/sudoers.d/pihole
 # REINSTALL LOGROTATE SCRIPT FOR PI-HOLE
 #=================================================
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-    cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
-else
-    cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
-fi
+cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
 sed -i "/# su #/d;" "$pihole_storage/logrotate"
 
 #=================================================
@@ -162,19 +142,15 @@ ynh_script_progression --message="Reinstalling PiHole-FTL..." --weight=30
 
 # Get the source of Pi-Hole-FTL
 FTL_temp_path=$(mktemp -d)
-if [ "$pihole_version" == "Last 3.X" ]
-then
-    # Install the version 3.3.1
-    ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_3
-else
-    # Install the last version available
-    ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_last
-fi
+# Install the last version available
+ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL
 
 # Instead of downloading a binary file, we're going to compile it
-( cd "$FTL_temp_path"
-ynh_exec_warn_less make
-ynh_exec_warn_less make install )
+( 
+    cd "$FTL_temp_path"
+    ynh_exec_warn_less make
+    ynh_exec_warn_less make install
+)
 ynh_secure_remove --file="$FTL_temp_path"
 
 cp "../conf/dns-servers.conf" "$pihole_storage"
@@ -182,20 +158,12 @@ cp "../conf/dns-servers.conf" "$pihole_storage"
 # Restore the default pihole-FTL.conf
 yunohost app action run $app reset_default_ftl
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-    # Version 3.3.1
-    cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
-    chmod +x /etc/init.d/pihole-FTL
-    ynh_exec_warn_less systemctl enable pihole-FTL
-else
-    cp -a $pihole_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
+cp -a $pihole_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
 
-    # Reload systemd config
-    systemctl daemon-reload
-fi
+# Reload systemd config
+systemctl daemon-reload
 
 #=================================================
 # RESET THE VARIABLES FILE
@@ -215,12 +183,7 @@ yunohost app action run $app reset_default_dnsmasq
 # REINSTALL CRON JOB
 #=================================================
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-    cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
-else
-    cp $pihole_local_repo/advanced/Templates/pihole.cron /etc/cron.d/pihole
-fi
+cp $pihole_local_repo/advanced/Templates/pihole.cron /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

+ 174 - 0
scripts/config

@@ -0,0 +1,174 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC STARTING
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source _common.sh
+source /usr/share/yunohost/helpers
+
+#=================================================
+# RETRIEVE ARGUMENTS
+#=================================================
+
+app=$YNH_APP_INSTANCE_NAME
+
+fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
+final_path=$(ynh_app_setting_get --app=$app --key=final_path)
+
+#=================================================
+# SPECIFIC CODE
+#=================================================
+# LOAD VALUES
+#=================================================
+
+# Load the real value from the app config or elsewhere.
+# Then get the value from the form.
+# If the form has a value for a variable, take the value from the form,
+# Otherwise, keep the value from the app config.
+
+# Overwrite setupVars.conf file
+old_overwrite_setupvars="$(ynh_app_setting_get --app=$app --key=overwrite_setupvars)"
+overwrite_setupvars="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS:-$old_overwrite_setupvars}"
+
+# Overwrite pihole-FTL.conf file
+old_overwrite_ftl="$(ynh_app_setting_get --app=$app --key=overwrite_ftl)"
+overwrite_ftl="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL:-$old_overwrite_ftl}"
+
+# Overwrite nginx configuration
+old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
+overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
+
+# Overwrite php-fpm configuration
+old_overwrite_phpfpm="$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)"
+overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
+
+
+# Type of admin mail configuration
+old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)"
+admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
+
+
+# Footprint for php-fpm
+old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)"
+fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}"
+
+# Free footprint value for php-fpm
+# Check if fpm_footprint is an integer
+if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null
+then
+    # If fpm_footprint is an integer, that's a numeric value for the footprint
+    old_free_footprint=$fpm_footprint
+    fpm_footprint=specific
+else
+    old_free_footprint=0
+fi
+free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}"
+
+# Usage for php-fpm
+old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)"
+fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}"
+
+# php_forced_max_children for php-fpm
+old_php_forced_max_children="$(ynh_app_setting_get --app=$app --key=php_forced_max_children)"
+# If php_forced_max_children isn't into settings.yml, get the current value from the fpm config
+if [ -z "$old_php_forced_max_children" ]; then
+    old_php_forced_max_children="$(grep "^pm.max_children" "$fpm_config_dir/pool.d/$app.conf" | awk '{print $3}')"
+fi
+php_forced_max_children="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN:-$old_php_forced_max_children}"
+
+#=================================================
+# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
+#=================================================
+
+show_config() {
+    # here you are supposed to read some config file/database/other then print the values
+    # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
+
+    ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
+    ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
+    ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
+    ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
+
+    ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
+
+    ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint"
+    ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint"
+    ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage"
+    ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN=$php_forced_max_children"
+}
+
+#=================================================
+# MODIFY THE CONFIGURATION
+#=================================================
+
+apply_config() {
+
+    #=================================================
+    # MODIFY OVERWRITTING SETTINGS
+    #=================================================
+
+    # Set overwrite_setupvars
+    ynh_app_setting_set --app=$app --key=overwrite_setupvars --value="$overwrite_setupvars"
+    # Set overwrite_ftl
+    ynh_app_setting_set --app=$app --key=overwrite_ftl --value="$overwrite_ftl"
+    # Set overwrite_nginx
+    ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
+    # Set overwrite_phpfpm
+    ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="$overwrite_phpfpm"
+
+    #=================================================
+    # MODIFY EMAIL SETTING
+    #=================================================
+
+    # Set admin_mail_html
+    ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
+
+    #=================================================
+    # RECONFIGURE PHP-FPM
+    #=================================================
+
+    if [ "$fpm_usage" != "$old_fpm_usage" ] || \
+        [ "$fpm_footprint" != "$old_fpm_footprint" ] || \
+        [ "$free_footprint" != "$old_free_footprint" ] || \
+        [ "$php_forced_max_children" != "$old_php_forced_max_children" ]
+    then
+        # If fpm_footprint is set to 'specific', use $free_footprint value.
+        if [ "$fpm_footprint" = "specific" ]
+        then
+            fpm_footprint=$free_footprint
+        fi
+
+        if [ "$php_forced_max_children" != "$old_php_forced_max_children" ]
+        then
+            # Set php_forced_max_children
+            if [ $php_forced_max_children -ne 0 ]
+            then
+                ynh_app_setting_set --app=$app --key=php_forced_max_children --value="$php_forced_max_children"
+            else
+                # If the value is set to 0, remove the setting
+                ynh_app_setting_delete --app=$app --key=php_forced_max_children
+            fi
+        fi
+
+        if [ "$fpm_footprint" != "0" ]
+        then
+            ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --dedicated_service
+        else
+            ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
+        fi
+    fi
+}
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
+#=================================================
+
+case $1 in
+    show) show_config;;
+    apply) apply_config;;
+esac

+ 49 - 104
scripts/install

@@ -7,7 +7,6 @@
 #=================================================
 
 # Load common variables for all scripts.
-source _variables
 source _common.sh
 source /usr/share/yunohost/helpers
 
@@ -27,7 +26,6 @@ path_url=$YNH_APP_ARG_PATH
 admin=$YNH_APP_ARG_ADMIN
 query_logging=$YNH_APP_ARG_QUERY_LOGGING
 enable_dhcp=$YNH_APP_ARG_ENABLE_DHCP
-pihole_version="$YNH_APP_ARG_PIHOLE_VERSION"
 
 app=$YNH_APP_INSTANCE_NAME
 
@@ -52,7 +50,6 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url
 ynh_app_setting_set --app=$app --key=admin --value=$admin
 ynh_app_setting_set --app=$app --key=query_logging --value=$query_logging
 ynh_app_setting_set --app=$app --key=enable_dhcp --value=$enable_dhcp
-ynh_app_setting_set --app=$app --key=pihole_version --value="$pihole_version"
 
 ynh_app_setting_set --app=$app --key=overwrite_setupvars --value=1
 ynh_app_setting_set --app=$app --key=overwrite_ftl --value=1
@@ -102,18 +99,11 @@ ynh_script_progression --message="Setting up source files..." --weight=4
 ynh_app_setting_set --app=$app --key=final_path --value=$final_path
 # Make a copy of local pihole repository (for Gravity)
 pihole_local_repo="/etc/.pihole"
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	# Install the version 3.3.1
-	ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_3
-	# Install admin dashboard
-	ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_3
-else
-	# Install the last version available
-	ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_last
-	# Install admin dashboard
-	ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_last
-fi
+
+# Install the last version available
+ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app
+# Install admin dashboard
+ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard
 
 chown $app:www-data "$final_path"
 
@@ -176,12 +166,8 @@ chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log
 #=================================================
 
 # This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
-else
-	cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
-fi
+cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
+
 echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
 # echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin" >> /etc/sudoers.d/pihole
 chmod 0440 /etc/sudoers.d/pihole
@@ -190,12 +176,8 @@ chmod 0440 /etc/sudoers.d/pihole
 # INSTALL LOGROTATE SCRIPT FOR PI-HOLE
 #=================================================
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
-else
-	cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
-fi
+cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
+
 sed -i "/# su #/d;" "$pihole_storage/logrotate"
 
 #=================================================
@@ -205,65 +187,52 @@ ynh_script_progression --message="Installing PiHole-FTL..." --weight=30
 
 # Get the source of Pi-Hole-FTL
 FTL_temp_path=$(mktemp -d)
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	# Install the version 3.3.1
-	ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_3
-else
-	# Install the last version available
-	ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_last
-fi
+# Install the last version available
+ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL
 
 # Instead of downloading a binary file, we're going to compile it
-( cd "$FTL_temp_path"
-if [ "$pihole_version" == "Last available" ]
-then
-	ynh_exec_warn_less cmake .
-fi
-ynh_exec_warn_less make
-ynh_exec_warn_less make install )
+( 
+    cd "$FTL_temp_path"
+    ynh_exec_warn_less cmake .
+    ynh_exec_warn_less make
+    ynh_exec_warn_less make install 
+)
+
 ynh_secure_remove --file="$FTL_temp_path"
 
 cp "../conf/dns-servers.conf" "$pihole_storage"
 
 ynh_add_config --template="../conf/pihole-FTL.conf" --destination="$pihole_storage/pihole-FTL.conf"
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	# Version 3.3.1
-	cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
-	chmod +x /etc/init.d/pihole-FTL
-	ynh_exec_warn_less systemctl enable pihole-FTL --quiet
-else
-	# Last version available
-	# Stopped dnsmasq to replace it by pihole-FTL
-	ynh_systemd_action --action=stop --service_name=dnsmasq
-
-	# 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
-
-	# 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
-
-	cp -a $pihole_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
-
-	# Reload systemd config
-	systemctl daemon-reload
-fi
+# Last version available
+# Stopped dnsmasq to replace it by pihole-FTL
+ynh_systemd_action --action=stop --service_name=dnsmasq
+
+# 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
+
+# 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
+
+cp -a $pihole_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
+systemctl mask dnsmasq.service
+
+# Reload systemd config
+systemctl daemon-reload
 
 #=================================================
 # BUILD VARIABLES FILE
@@ -326,41 +295,17 @@ echo "$pihole_core_version $dashboard_version $FTL_version" | tee $pihole_storag
 # INSTALL CRON JOB
 #=================================================
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
-else
-	cp $pihole_local_repo/advanced/Templates/pihole.cron /etc/cron.d/pihole
-fi
+cp $pihole_local_repo/advanced/Templates/pihole.cron /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
 
-#=================================================
-# RESTART DNSMASQ
-#=================================================
-
-# Restart dnsmasq only for the version 3.X, otherwise we're going to restart it twice.
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	ynh_script_progression --message="Restarting Dnsmasq..." --weight=2
-
-	ynh_systemd_action --action=restart --service_name=dnsmasq
-
-	ynh_systemd_action --action=restart --service_name=pihole-FTL
-fi
-
 #=================================================
 # BUILD THE LISTS WITH GRAVITY
 #=================================================
 ynh_script_progression --message="Building the lists with Gravity..." --weight=7
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	cp "$pihole_local_repo/adlists.default" "$pihole_storage/adlists.default"
-else
-	cp "../conf/adlists.default" "$pihole_storage/adlists.list"
-fi
+cp "../conf/adlists.default" "$pihole_storage/adlists.list"
 ynh_exec_warn_less /opt/pihole/gravity.sh
 
 #=================================================

+ 22 - 30
scripts/remove

@@ -18,7 +18,6 @@ app=$YNH_APP_INSTANCE_NAME
 
 domain=$(ynh_app_setting_get --app=$app --key=domain)
 port=$(ynh_app_setting_get --app=$app --key=port)
-pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
 
 #=================================================
 # STANDARD REMOVE
@@ -38,30 +37,25 @@ fi
 #=================================================
 ynh_script_progression --message="Stop and remove the service"
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	ynh_systemd_action --action=stop --service_name=pihole-FTL
-	ynh_exec_warn_less systemctl disable pihole-FTL --quiet
-else
-	ynh_systemd_action --action=stop --service_name=pihole-FTL
-
-	# Restore dnsmasq as main DNS resolver
-	# Move dnsmasq back to its original place
-	if [ -e "/usr/sbin/dnsmasq.backup_by_pihole" ]
-	then	# Remove dnsmasq only if we have its backup
-		ynh_secure_remove --file="/usr/sbin/dnsmasq"
-		mv /usr/sbin/dnsmasq.backup_by_pihole /usr/sbin/dnsmasq
-	fi
-
-	# Move back the service configuration for dnsmasq
-	ynh_secure_remove --file="/etc/systemd/system/dnsmasq.service"
-	mv /lib/systemd/system/.dnsmasq.service.backup_by_pihole /lib/systemd/system/dnsmasq.service
-	mv /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq
-
-	ynh_exec_warn_less systemctl enable dnsmasq --quiet
-	# Reload systemd config
-	systemctl daemon-reload
-fi
+ynh_systemd_action --action=stop --service_name=pihole-FTL
+
+# Restore dnsmasq as main DNS resolver
+# Move dnsmasq back to its original place
+#if [ -e "/usr/sbin/dnsmasq.backup_by_pihole" ]
+#then    # Remove dnsmasq only if we have its backup
+#    ynh_secure_remove --file="/usr/sbin/dnsmasq"
+#    mv /usr/sbin/dnsmasq.backup_by_pihole /usr/sbin/dnsmasq
+#fi
+
+# Move back the service configuration for dnsmasq
+#ynh_secure_remove --file="/etc/systemd/system/dnsmasq.service"
+#mv /lib/systemd/system/.dnsmasq.service.backup_by_pihole /lib/systemd/system/dnsmasq.service
+#mv /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq
+systemctl unmask dnsmasq.service
+
+#ynh_exec_warn_less systemctl enable dnsmasq --quiet
+# Reload systemd config
+systemctl daemon-reload
 
 ynh_secure_remove --file="/etc/init.d/pihole-FTL"
 ynh_secure_remove --file="/usr/bin/pihole-FTL"
@@ -185,11 +179,9 @@ ynh_systemd_action --action=restart --service_name=dnsmasq
 #=================================================
 ynh_script_progression --message="Removing the dedicated system user..." --weight=2
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	# Dirty hack to remove correctly the user
-	killall -u $app
-fi
+# Dirty hack to remove correctly the user
+killall -u $app
+
 ynh_system_user_delete --username=$app
 
 #=================================================

+ 32 - 50
scripts/restore

@@ -6,8 +6,7 @@
 # IMPORT GENERIC HELPERS
 #=================================================
 
-# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
-source ../settings/scripts/_variables
+# Load common variables for all scripts.
 source ../settings/scripts/_common.sh
 source /usr/share/yunohost/helpers
 
@@ -30,7 +29,6 @@ path_url=$(ynh_app_setting_get --app=$app --key=path)
 final_path=$(ynh_app_setting_get --app=$app --key=final_path)
 enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp)
 admin=$(ynh_app_setting_get --app=$app --key=admin)
-pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
 
 # Get variables from ynh_add_fpm_config
 fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
@@ -43,8 +41,7 @@ fpm_service=$(ynh_app_setting_get --app=$app --key=fpm_service)
 #=================================================
 ynh_script_progression --message="Validating restoration parameters..."
 
-test ! -d $final_path \
-	|| ynh_die --message="There is already a directory: $final_path "
+test ! -d $final_path || ynh_die --message="There is already a directory: $final_path "
 
 #=================================================
 # ACTIVATE MAINTENANCE MODE
@@ -106,7 +103,6 @@ ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --dedicated_ser
 #=================================================
 ynh_script_progression --message="Reinstalling dependencies..." --weight=12
 
-# Define and install dependencies
 ynh_install_app_dependencies $pkg_dependencies
 
 #=================================================
@@ -149,38 +145,36 @@ ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_
 # REPLACE THE DEFAULT DNSMASQ BY PIHOLE-FTL
 #=================================================
 
-if [ "$pihole_version" == "Last available" ]
-then
-	# Last version available
-	# Stopped dnsmasq to replace it by pihole-FTL
-	ynh_systemd_action --action=stop --service_name=dnsmasq
-
-	# 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
-
-	# 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
-
-	pihole_local_repo="/etc/.pihole"
-	cp -a $pihole_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
-
-	# Reload systemd config
-	systemctl daemon-reload
-fi
+# Last version available
+# Stopped dnsmasq to replace it by pihole-FTL
+ynh_systemd_action --action=stop --service_name=dnsmasq
+
+# 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
+
+# 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
+
+pihole_local_repo="/etc/.pihole"
+cp -a $pihole_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
+systemctl mask dnsmasq.service
+
+# Reload systemd config
+systemctl daemon-reload
 
 #=================================================
 # RESTORE DNSMASQ CONFIG
@@ -214,18 +208,6 @@ do
 		echo "$localipv4	$perdomain #Added by pihole#" >> /etc/hosts
 done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
 
-#=================================================
-# RESTART DNSMASQ
-#=================================================
-
-# Restart dnsmasq only for the version 3.X, otherwise we're going to restart it twice.
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	ynh_script_progression --message="Restarting Dnsmasq..."
-
-	ynh_systemd_action --action=restart --service_name=dnsmasq
-fi
-
 #=================================================
 # UPDATE VARIABLES FILE
 #=================================================

+ 87 - 96
scripts/upgrade

@@ -7,7 +7,6 @@
 #=================================================
 
 # Load common variables for all scripts.
-source _variables
 source _common.sh
 source /usr/share/yunohost/helpers
 
@@ -118,6 +117,36 @@ if [ -z "$pihole_version" ]; then
 	ynh_app_setting_set --app=$app --key=pihole_version --value="$pihole_version"
 fi
 
+#=================================================
+# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
+#=================================================
+ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=7
+
+# Backup the current version of the app
+ynh_backup_before_upgrade
+ynh_clean_setup () {
+    # restore it if the upgrade fails
+    ynh_restore_upgradebackup
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# ACTIVATE MAINTENANCE MODE
+#=================================================
+ynh_script_progression --message="Activating maintenance mode..."
+
+ynh_maintenance_mode_ON
+
+#=================================================
+# STANDARD UPGRADE STEPS
+#=================================================
+# INSTALL DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Upgrading dependencies..." --weight=6
+
+ynh_install_app_dependencies $pkg_dependencies
+
 #=================================================
 # CREATE DEDICATED USER
 #=================================================
@@ -133,19 +162,11 @@ ynh_system_user_create --username=$app
 pihole_local_repo="/etc/.pihole"
 if [ "$upgrade_type" == "UPGRADE_APP" ]
 then
-	ynh_script_progression --message="Upgrading source files..." --weight=4
-	if [ "$pihole_version" == "Last 3.X" ]
-	then
-		# Update the version 3.X
-		ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_3
-		# Update admin dashboard
-		ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_3
-	else
-		# Update the last version available
-		ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app_last
-		# Update admin dashboard
-		ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard_last
-	fi
+    ynh_script_progression --message="Upgrading source files..." --weight=4
+    # Update the last version available
+    ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app
+    # Update admin dashboard
+    ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard
 fi
 
 chown $app:www-data "$final_path"
@@ -207,12 +228,7 @@ cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.
 #=================================================
 
 # This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
-else
-	cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
-fi
+cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
 echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
 chmod 0440 /etc/sudoers.d/pihole
 
@@ -221,14 +237,7 @@ chmod 0440 /etc/sudoers.d/pihole
 #=================================================
 
 pihole_storage="/etc/pihole"
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
-	dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
-else
-	cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
-	dnsmasq_user=$(grep FTLUSER= /etc/init.d/pihole-FTL | cut -d'=' -f2)
-fi
+cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
 sed -i "/# su #/d;" "$pihole_storage/logrotate"
 
 #=================================================
@@ -240,26 +249,19 @@ ynh_systemd_action --action=stop --service_name=pihole-FTL
 
 if [ "$upgrade_type" == "UPGRADE_APP" ]
 then
-	# Get the source of Pi-Hole-FTL
-	FTL_temp_path=$(mktemp -d)
-	if [ "$pihole_version" == "Last 3.X" ]
-	then
-		# Install the version 3.3.1
-		ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_3
-	else
-		# Install the last version available
-		ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL_last
-	fi
-
-	# Instead of downloading a binary file, we're going to compile it
-	( cd "$FTL_temp_path"
-	if [ "$pihole_version" == "Last available" ]
-	then
-		ynh_exec_warn_less cmake .
-	fi
-	ynh_exec_warn_less make
-	ynh_exec_warn_less make install )
-	ynh_secure_remove --file="$FTL_temp_path"
+    # Get the source of Pi-Hole-FTL
+    FTL_temp_path=$(mktemp -d)
+    # Install the last version available
+    ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL
+
+    # Instead of downloading a binary file, we're going to compile it
+    ( 
+        cd "$FTL_temp_path"
+        ynh_exec_warn_less cmake .
+        ynh_exec_warn_less make
+        ynh_exec_warn_less make install
+    )
+    ynh_secure_remove --file="$FTL_temp_path"
 fi
 
 # Overwrite pihole-FTL config file only if it's allowed
@@ -268,48 +270,41 @@ then
 	ynh_add_config --template="../conf/pihole-FTL.conf" --destination="$pihole_storage/pihole-FTL.conf"
 fi
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	# Version 3.3.1
-	cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
-	chmod +x /etc/init.d/pihole-FTL
-	ynh_exec_warn_less systemctl enable pihole-FTL --quiet
-else
-	# Last version available
-	# Stopped dnsmasq to replace it by pihole-FTL
-	ynh_systemd_action --action=stop --service_name=dnsmasq
-
-	# 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
-	if [ ! -e "/lib/systemd/system/.dnsmasq.service.backup_by_pihole" ]; then
-		mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service.backup_by_pihole
-	fi
-	if [ ! -e "/etc/init.d/.dnsmasq.backup_by_pihole" ]; then
-		mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq.backup_by_pihole
-	fi
-
-	# Move dnsmasq to preserve the current binary
-	if [ ! -e "/usr/sbin/dnsmasq.backup_by_pihole" ]; then
-		mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.backup_by_pihole
-	fi
-	# 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 -sf /usr/bin/pihole-FTL /usr/sbin/dnsmasq
-
-	cp -a $pihole_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 -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
-
-	# Reload systemd config
-	systemctl daemon-reload
-fi
+# Last version available
+# Stopped dnsmasq to replace it by pihole-FTL
+ynh_systemd_action --action=stop --service_name=dnsmasq
+
+# 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
+#if [ ! -e "/lib/systemd/system/.dnsmasq.service.backup_by_pihole" ]; then
+#    mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service.backup_by_pihole
+#fi
+#if [ ! -e "/etc/init.d/.dnsmasq.backup_by_pihole" ]; then
+#    mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq.backup_by_pihole
+#fi
+
+# Move dnsmasq to preserve the current binary
+#if [ ! -e "/usr/sbin/dnsmasq.backup_by_pihole" ]; then
+#    mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.backup_by_pihole
+#fi
+# 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 -sf /usr/bin/pihole-FTL /usr/sbin/dnsmasq
+
+cp -a $pihole_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 -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
+systemctl mask dnsmasq.service
+
+# Reload systemd config
+systemctl daemon-reload
 
 #=================================================
 # BUILD VARIABLES FILE
@@ -353,12 +348,8 @@ echo "$pihole_core_version $dashboard_version $FTL_version" | tee $pihole_storag
 # UPDATE CRON JOB
 #=================================================
 
-if [ "$pihole_version" == "Last 3.X" ]
-then
-	cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
-else
-	cp $pihole_local_repo/advanced/Templates/pihole.cron /etc/cron.d/pihole
-fi
+cp $pihole_local_repo/advanced/Templates/pihole.cron /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