diff --git a/conf/FTL_last.src b/conf/FTL_last.src index fa244a6..60342ce 100644 --- a/conf/FTL_last.src +++ b/conf/FTL_last.src @@ -1,10 +1,6 @@ -SOURCE_URL=https://github.com/pi-hole/FTL/archive/894a3c74a8e17b92c68a986e990d5f7f3c127ae2.zip -SOURCE_SUM=e7a75a792fdc836389b71808165bca18 +SOURCE_URL=https://github.com/pi-hole/FTL/archive/v4.3.1.tar.gz +SOURCE_SUM=1c0df5fa42e7f7b89c7e704fdc1b5154 SOURCE_SUM_PRG=md5sum -SOURCE_FORMAT=zip +SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true SOURCE_FILENAME= - -#SOURCE_old_URL=https://github.com/pi-hole/FTL/archive/v4.3.1.tar.gz -#SOURCE_old_SUM=1c0df5fa42e7f7b89c7e704fdc1b5154 -#SOURCE_old_FORMAT=tar.gz diff --git a/scripts/install b/scripts/install index 82ffe81..9d93e60 100644 --- a/scripts/install +++ b/scripts/install @@ -236,52 +236,30 @@ else # Stopped dnsmasq to replace it by pihole-FTL ynh_systemd_action --action=stop --service_name=dnsmasq -systemctl disable dnsmasq -# rm /lib/systemd/system/dnsmasq.service -mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service -# rm /etc/init.d/dnsmasq -mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq + # Disable the real dnsmasq service + ynh_exec_warn_less systemctl disable 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 - # Move dnsmasq to preserve the current version + # 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 - update-alternatives --install /usr/sbin/dnsmasq dnsmasq /usr/bin/pihole-FTL 50 - update-alternatives --install /usr/sbin/dnsmasq dnsmasq /usr/sbin/dnsmasq.backup_by_pihole 40 + ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq -# cp /etc/init.d/pihole-FTL /etc/init.d/dnsmasq -# systemctl enable dnsmasq - -# ln --symbolic /run/pihole-FTL.pid /run/dnsmasq/dnsmasq.pid - -# lrwxrwxrwx 1 root root 35 Jun 22 2018 /etc/systemd/system/multi-user.target.wants/dnsmasq.service -> /lib/systemd/system/dnsmasq.service -# /run/systemd/generator.late/pihole-FTL.service -sudo ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/multi-user.target.wants/dnsmasq.service -sudo systemctl daemon-reload - -# sudo yunohost app install github/pihole_ynh/ --args "admin=mcrudelis&pihole_version=Last available&" -f -n - -# >>> It does work, as we have both dnsmasq and pihole-FTL as the same. -# But no more dns resolution... - -# sudo systemctl daemon-reload - -# /lib/systemd/system/dnsmasq.service -# /etc/init.d/dnsmasq - -# systemctl stop dnsmasq -# systemctl disable dnsmasq -# If I remove /lib/systemd/system/dnsmasq.service and /etc/init.d/dnsmasq, it works. -# sudo systemctl daemon-reload - -# But we don't have dnsmasq anymore... -# Duplicating /etc/init.d/pihole-FTL in /etc/init.d/dnsmasq does work + 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 + # 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/multi-user.target.wants/dnsmasq.service + # Reload systemd config + systemctl daemon-reload fi #================================================= @@ -412,22 +390,22 @@ ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --ta #================================================= # RESTART DNSMASQ #================================================= -ynh_script_progression --message="Restarting Dnsmasq..." --weight=2 -# ynh_systemd_action --action=restart --service_name=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 +fi #================================================= # START PIHOLE-FTL #================================================= -if [ "$pihole_version" == "Last 3.X" ] -then - ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2 +ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2 - ynh_systemd_action --action=restart --service_name=pihole-FTL -fi - -sleep 5 +ynh_systemd_action --action=restart --service_name=pihole-FTL #================================================= # BUILD THE LISTS WITH GRAVITY @@ -454,10 +432,7 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -if [ "$pihole_version" == "Last 3.X" ] -then - yunohost service add pihole-FTL --description "PiHole backend service" --log "/var/log/pihole-FTL.log" -fi +yunohost service add pihole-FTL --description "PiHole backend service" --log "/var/log/pihole-FTL.log" #================================================= # RESTRAIN THE ACCESS TO THE ADMIN ONLY diff --git a/scripts/remove b/scripts/remove index a0e0d67..7b3a87b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -26,14 +26,11 @@ pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)" # REMOVE SERVICE FROM ADMIN PANEL #================================================= -if [ "$pihole_version" == "Last 3.X" ] +# Check if the service is declared in YunoHost +if ynh_exec_fully_quiet yunohost service status pihole-FTL then - # Check if the service is declared in YunoHost - if ynh_exec_fully_quiet yunohost service status pihole-FTL - then - ynh_script_progression --message="Removing pihole-FTL service..." --weight=2 - yunohost service remove pihole-FTL - fi + ynh_script_progression --message="Removing pihole-FTL service..." --weight=2 + yunohost service remove pihole-FTL fi #================================================= @@ -46,15 +43,30 @@ then ynh_systemd_action --action=stop --service_name=pihole-FTL ynh_exec_warn_less systemctl disable pihole-FTL else - ynh_systemd_action --action=stop --service_name=dnsmasq + ynh_systemd_action --action=stop --service_name=pihole-FTL + # Restore dnsmasq as main DNS resolver - # Remove alternatives - update-alternatives --remove dnsmasq /usr/bin/pihole-FTL - update-alternatives --remove dnsmasq /usr/sbin/dnsmasq.backup_by_pihole # Move dnsmasq back to its original place - mv /usr/sbin/dnsmasq.backup_by_pihole /usr/sbin/dnsmasq + 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/multi-user.target.wants/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 + # Reload systemd config + systemctl daemon-reload fi -rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "/var/run/pihole-FTL.port" + +ynh_secure_remove --file="/etc/init.d/pihole-FTL" +ynh_secure_remove --file="/usr/bin/pihole-FTL" +ynh_secure_remove --file="/var/run/pihole-FTL.pid" +ynh_secure_remove --file="/var/run/pihole-FTL.port" #================================================= # REMOVE DEPENDENCIES diff --git a/sources/patches/.gitignore b/sources/patches/.gitignore new file mode 100644 index 0000000..d38c149 --- /dev/null +++ b/sources/patches/.gitignore @@ -0,0 +1,2 @@ +*.swp +*~ diff --git a/sources/patches/FTL_last-dns_replacement.patch b/sources/patches/FTL_last-dns_replacement.patch new file mode 100644 index 0000000..9f24389 --- /dev/null +++ b/sources/patches/FTL_last-dns_replacement.patch @@ -0,0 +1,131 @@ +--- a/args.c 2019-05-25 21:37:26.000000000 +0200 ++++ b/args.c 2020-04-24 00:32:27.000000000 +0200 +@@ -17,20 +17,88 @@ + int argc_dnsmasq = 0; + const char** argv_dnsmasq = NULL; + ++static inline bool strEndsWith(const char *input, const char *end){ ++ return strcmp(input + strlen(input) - strlen(end), end) == 0; ++} ++ + void parse_args(int argc, char* argv[]) + { +- int i; +- + // Regardless of any arguments, we always pass "-k" (nofork) to dnsmasq + argc_dnsmasq = 2; + argv_dnsmasq = calloc(argc_dnsmasq, sizeof(char*)); + argv_dnsmasq[0] = ""; + argv_dnsmasq[1] = "-k"; + +- // start from 1, as argv[0] is the executable name "pihole-FTL" +- for(i=1; i < argc; i++) ++ bool consume_for_dnsmasq = false; ++ // If the binary name is "dnsmasq" (e.g., symlink /usr/bin/dnsmasq -> /usr/bin/pihole-FTL), ++ // we operate in drop-in mode and consume all arguments for the embedded dnsmasq core ++ if(strEndsWith(argv[0], "dnsmasq")) ++ consume_for_dnsmasq = true; ++ ++ // start from 1, as argv[0] is the executable name ++ for(int i = 1; i < argc; i++) + { + bool ok = false; ++ ++ // Implement dnsmasq's test function, no need to prepare the entire FTL ++ // environment (initialize shared memory, lead queries from long-term ++ // database, ...) when the task is a simple (dnsmasq) syntax check ++ if(strcmp(argv[i], "dnsmasq-test") == 0 || ++ strcmp(argv[i], "--test") == 0) ++ { ++ const char *arg[2]; ++ arg[0] = ""; ++ arg[1] = "--test"; ++ main_dnsmasq(2, arg); ++ ok = true; ++ } ++ ++ // If we find "--" we collect everything behind that for dnsmasq ++ if(strcmp(argv[i], "--") == 0) ++ { ++ // Remember that the rest is for dnsmasq ... ++ consume_for_dnsmasq = true; ++ ++ // ... and skip the current argument ("--") ++ continue; ++ } ++ ++ // If consume_for_dnsmasq is true, we collect all remaining options for ++ // dnsmasq ++ if(consume_for_dnsmasq) ++ { ++ argc_dnsmasq = argc - i + 2; ++ if(argv_dnsmasq != NULL) ++ free(argv_dnsmasq); ++ ++ argv_dnsmasq = calloc(argc_dnsmasq, sizeof(const char*)); ++ argv_dnsmasq[0] = ""; ++ ++ if(debug) ++ argv_dnsmasq[1] = "-d"; ++ else ++ argv_dnsmasq[1] = "-k"; ++ ++ if(debug) ++ { ++ printf("dnsmasq options: [0]: %s\n", argv_dnsmasq[0]); ++ printf("dnsmasq options: [1]: %s\n", argv_dnsmasq[1]); ++ } ++ ++ int j = 2; ++ while(i < argc) ++ { ++ argv_dnsmasq[j++] = strdup(argv[i++]); ++ if(debug) ++ printf("dnsmasq options: [%i]: %s\n", j-1, argv_dnsmasq[j-1]); ++ } ++ ++ // Return early: We have consumes all available command line arguments ++ return; ++ } ++ ++ // What follows beyond this point are FTL internal command line arguments ++ + if(strcmp(argv[i], "d") == 0 || + strcmp(argv[i], "debug") == 0) + { +@@ -97,35 +165,6 @@ + ok = true; + } + +- // Implement dnsmasq's test function +- if(strcmp(argv[i], "dnsmasq-test") == 0) +- { +- const char *arg[2]; +- arg[0] = ""; +- arg[1] = "--test"; +- main_dnsmasq(2, arg); +- ok = true; +- } +- +- // If we find "--" we collect everything behind that for dnsmasq +- if(strcmp(argv[i], "--") == 0) +- { +- int j; +- argc_dnsmasq = argc - i + 1; +- if(argv_dnsmasq != NULL) free(argv_dnsmasq); +- argv_dnsmasq = calloc(argc_dnsmasq + 2,sizeof(const char*)); +- argv_dnsmasq[0] = ""; +- if(debug) argv_dnsmasq[1] = "-d"; +- else argv_dnsmasq[1] = "-k"; +- +- for(j=2; j < argc_dnsmasq; j++) +- { +- argv_dnsmasq[j] = strdup(argv[i+j-1]); +- if(debug) logg("dnsmasq options: [%i]: %s",j,argv_dnsmasq[j]); +- } +- return; +- } +- + // List of implemented arguments + if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "help") == 0 || strcmp(argv[i], "--help") == 0) + {