From 2beb564e7cbf118d41991f40c6a7031412319f6a Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Wed, 22 Apr 2020 15:01:46 +0200 Subject: [PATCH] Start to work on an upgrade to 4.x --- conf/{FTL.src => FTL_3.src} | 0 conf/FTL_last.src | 6 + conf/adlists.default | 19 ++++ ...in_dashboard.src => admin_dashboard_3.src} | 0 conf/admin_dashboard_last.src | 6 + conf/{app.src => app_3.src} | 0 conf/app_last.src | 6 + manifest.json | 14 +++ scripts/_variables | 2 +- scripts/install | 105 ++++++++++++++---- scripts/remove | 27 ++++- 11 files changed, 156 insertions(+), 29 deletions(-) rename conf/{FTL.src => FTL_3.src} (100%) create mode 100644 conf/FTL_last.src create mode 100644 conf/adlists.default rename conf/{admin_dashboard.src => admin_dashboard_3.src} (100%) create mode 100644 conf/admin_dashboard_last.src rename conf/{app.src => app_3.src} (100%) create mode 100644 conf/app_last.src diff --git a/conf/FTL.src b/conf/FTL_3.src similarity index 100% rename from conf/FTL.src rename to conf/FTL_3.src diff --git a/conf/FTL_last.src b/conf/FTL_last.src new file mode 100644 index 0000000..60342ce --- /dev/null +++ b/conf/FTL_last.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/pi-hole/FTL/archive/v4.3.1.tar.gz +SOURCE_SUM=1c0df5fa42e7f7b89c7e704fdc1b5154 +SOURCE_SUM_PRG=md5sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/adlists.default b/conf/adlists.default new file mode 100644 index 0000000..d1b7ecd --- /dev/null +++ b/conf/adlists.default @@ -0,0 +1,19 @@ +# The below list amalgamates several lists we used previously. +# See `https://github.com/StevenBlack/hosts` for details +##StevenBlack's list +https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts + +##MalwareDomains +https://mirror1.malwaredomains.com/files/justdomains + +##Cameleon +http://sysctl.org/cameleon/hosts + +##Disconnect.me Tracking +https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt + +##Disconnect.me Ads +https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt + +##Hosts-file.net +https://hosts-file.net/ad_servers.txt diff --git a/conf/admin_dashboard.src b/conf/admin_dashboard_3.src similarity index 100% rename from conf/admin_dashboard.src rename to conf/admin_dashboard_3.src diff --git a/conf/admin_dashboard_last.src b/conf/admin_dashboard_last.src new file mode 100644 index 0000000..ee04744 --- /dev/null +++ b/conf/admin_dashboard_last.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/pi-hole/AdminLTE/archive/v4.3.3.tar.gz +SOURCE_SUM=3f9da0e1f9134393758b7a1425ca66f6 +SOURCE_SUM_PRG=md5sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/app.src b/conf/app_3.src similarity index 100% rename from conf/app.src rename to conf/app_3.src diff --git a/conf/app_last.src b/conf/app_last.src new file mode 100644 index 0000000..3e7c2a8 --- /dev/null +++ b/conf/app_last.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/pi-hole/pi-hole/archive/v4.4.tar.gz +SOURCE_SUM=970013bf8e273b868dd184ac2ffb1348 +SOURCE_SUM_PRG=md5sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/manifest.json b/manifest.json index 7f92313..7a603d8 100644 --- a/manifest.json +++ b/manifest.json @@ -76,6 +76,20 @@ "fr": "Si vous voulez faire ça, vous devez vraiment lire cela avant !" }, "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.", + "fr": "The last available version will replace the Debian version of dnsmasq by FTLDNS.
See the readme for more information." + }, + "choices" : ["Last 3.X","Last available"], + "default": "Last 3.X" } ] } diff --git a/scripts/_variables b/scripts/_variables index 1016b09..02834a9 100644 --- a/scripts/_variables +++ b/scripts/_variables @@ -1,4 +1,4 @@ #!/bin/bash # Dependencies -app_depencencies="sqlite idn2 php7.0-sqlite3" +app_depencencies="sqlite idn2 php7.0-sqlite3 nettle-dev libcap2-bin" diff --git a/scripts/install b/scripts/install index f1b05fb..8e045dd 100644 --- a/scripts/install +++ b/scripts/install @@ -28,6 +28,7 @@ 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,6 +53,7 @@ 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 @@ -95,9 +97,18 @@ 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" -ynh_setup_source --dest_dir="$pihole_local_repo" -# Install admin dashboard -ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard +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 #================================================= # NGINX CONFIGURATION @@ -166,7 +177,12 @@ chown $dnsmasq_user:root /var/log/pihole.log #================================================= # This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more. -cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole +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 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 @@ -175,7 +191,12 @@ chmod 0440 /etc/sudoers.d/pihole # INSTALL LOGROTATE SCRIPT FOR PI-HOLE #================================================= -cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate" +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 sed -i "/# su #/d;" "$pihole_storage/logrotate" #================================================= @@ -185,7 +206,14 @@ ynh_script_progression --message="Installing PiHole-FTL..." --weight=30 # Get the source of Pi-Hole-FTL FTL_temp_path=$(mktemp -d) -ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL +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" @@ -197,9 +225,24 @@ cp "../conf/pihole-FTL.conf" "$pihole_storage" # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$pihole_storage/pihole-FTL.conf" -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 +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/q + ynh_exec_warn_less systemctl enable pihole-FTL +else + # Last version available + # Stopped dnsmasq to replace it by pihole-FTL + ynh_systemd_action --action=stop --service_name=dnsmasq + # Move dnsmasq to preserve the current version + 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 +fi #================================================= # BUILD VARIABLES FILE @@ -312,6 +355,20 @@ fi # Open the UDP port 67 for dhcp ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp +#================================================= +# 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 + +# 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 #================================================= @@ -320,28 +377,29 @@ ynh_script_progression --message="Restarting Dnsmasq..." --weight=2 ynh_systemd_action --action=restart --service_name=dnsmasq #================================================= -# INSTALL CRON JOB +# START PIHOLE-FTL #================================================= -cp $pihole_local_repo/advanced/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 +if [ "$pihole_version" == "Last 3.X" ] +then + ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2 + + 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 -cp "$pihole_local_repo/adlists.default" "$pihole_storage/adlists.default" +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 ynh_exec_warn_less /opt/pihole/gravity.sh -#================================================= -# START PIHOLE-FTL -#================================================= -ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2 - -ynh_systemd_action --action=restart --service_name=pihole-FTL - #================================================= # SET UP CONF_REGEN HOOK #================================================= @@ -354,7 +412,10 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -yunohost service add pihole-FTL --description "PiHole backend service" --log "/var/log/pihole-FTL.log" +if [ "$pihole_version" == "Last 3.X" ] +then + yunohost service add pihole-FTL --description "PiHole backend service" --log "/var/log/pihole-FTL.log" +fi #================================================= # RESTRAIN THE ACCESS TO THE ADMIN ONLY diff --git a/scripts/remove b/scripts/remove index 928cb91..a0e0d67 100755 --- a/scripts/remove +++ b/scripts/remove @@ -18,6 +18,7 @@ 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 @@ -25,11 +26,14 @@ port=$(ynh_app_setting_get --app=$app --key=port) # REMOVE SERVICE FROM ADMIN PANEL #================================================= -# Check if the service is declared in YunoHost -if ynh_exec_fully_quiet yunohost service status pihole-FTL +if [ "$pihole_version" == "Last 3.X" ] then - ynh_script_progression --message="Removing pihole-FTL service..." --weight=2 - yunohost service remove pihole-FTL + # 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 fi #================================================= @@ -37,8 +41,19 @@ fi #================================================= ynh_script_progression --message="Stop and remove the service" -ynh_systemd_action --action=stop --service_name=pihole-FTL -ynh_exec_warn_less systemctl disable pihole-FTL +if [ "$pihole_version" == "Last 3.X" ] +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 + # 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 +fi rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "/var/run/pihole-FTL.port" #=================================================