From 0fd75e059e730ccac5417f213696f6e9a2cf3655 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 5 Sep 2017 23:50:20 +0200 Subject: [PATCH] Update helpers & fix backup --- manifest.json | 6 ++--- scripts/_variables | 4 ++++ scripts/backup | 60 ++++++++++++++++++++++------------------------ scripts/install | 35 ++++++++++++++------------- scripts/remove | 12 +++++----- scripts/restore | 38 ++++++++++++++--------------- scripts/upgrade | 11 +++++---- 7 files changed, 87 insertions(+), 79 deletions(-) create mode 100644 scripts/_variables diff --git a/manifest.json b/manifest.json index d43e8a3..70417a2 100644 --- a/manifest.json +++ b/manifest.json @@ -2,9 +2,6 @@ "name": "Pi-hole", "id": "pihole", "packaging_format": 1, - "requirements": { - "yunohost": ">= 2.6.4" - }, "description": { "en": "Network-wide ad blocking via your own DNS server.", "fr": "Filtrage publicitaire sur l'ensemble du réseau via votre propre serveur DNS." @@ -16,6 +13,9 @@ "name": "Maniack Crudelis", "email": "maniackc_dev@crudelis.fr" }, + "requirements": { + "yunohost": ">= 2.7.2" + }, "multi_instance": false, "services": [ "nginx", diff --git a/scripts/_variables b/scripts/_variables new file mode 100644 index 0000000..a6ba261 --- /dev/null +++ b/scripts/_variables @@ -0,0 +1,4 @@ +#!/bin/bash + +# Dependencies +app_depencencies="dhcpcd5" diff --git a/scripts/backup b/scripts/backup index 47aac76..3b51a77 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,26 +1,26 @@ #!/bin/bash #================================================= -# GENERIC STARTING -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - -# Exit on command errors and treat unset variables as an error -set -eu - +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= if [ ! -e _common.sh ]; then - # Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh fi source _common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= @@ -37,29 +37,29 @@ domain=$(ynh_app_setting_get $app domain) #================================================= CHECK_SIZE "$final_path" -ynh_backup "$final_path" "${YNH_APP_BACKUP_DIR}$final_path" +ynh_backup "$final_path" CHECK_SIZE "/etc/.pihole" -ynh_backup "/etc/.pihole" "${YNH_APP_BACKUP_DIR}/etc/.pihole" +ynh_backup "/etc/.pihole" CHECK_SIZE "/etc/pihole" -ynh_backup "/etc/pihole" "${YNH_APP_BACKUP_DIR}/etc/pihole" +ynh_backup "/etc/pihole" CHECK_SIZE "/opt/pihole" -ynh_backup "/opt/pihole" "${YNH_APP_BACKUP_DIR}/opt/pihole" +ynh_backup "/opt/pihole" #================================================= # BACKUP OF THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${YNH_APP_BACKUP_DIR}/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP OF THE PHP-FPM CONFIGURATION #================================================= -ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "${YNH_APP_BACKUP_DIR}/etc/php5/fpm/pool.d/$app.conf" -ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "${YNH_APP_BACKUP_DIR}/etc/php5/fpm/conf.d/20-$app.ini" +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" #================================================= # SPECIFIC BACKUP @@ -67,31 +67,29 @@ ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "${YNH_APP_BACKUP_DIR}/etc/php5/fp # BACKUP OF THE CRON FILE #================================================= -ynh_backup "/etc/cron.d/pihole" "${YNH_APP_BACKUP_DIR}/etc/cron.d/pihole" +ynh_backup "/etc/cron.d/pihole" #================================================= # BACKUP OF SPECIFIC FILES #================================================= -ynh_backup "/usr/local/bin/pihole" "${YNH_APP_BACKUP_DIR}/usr/local/bin/pihole" -ynh_backup "/etc/bash_completion.d/pihole" "${YNH_APP_BACKUP_DIR}/etc/bash_completion.d/pihole" +ynh_backup "/usr/local/bin/pihole" +ynh_backup "/etc/bash_completion.d/pihole" -ynh_backup "/etc/sudoers.d/pihole" "${YNH_APP_BACKUP_DIR}/etc/sudoers.d/pihole" +ynh_backup "/etc/sudoers.d/pihole" -ynh_backup "/etc/init.d/pihole-FTL" "${YNH_APP_BACKUP_DIR}/etc/init.d/pihole-FTL" -ynh_backup "/usr/bin/pihole-FTL" "${YNH_APP_BACKUP_DIR}/usr/bin/pihole-FTL" -ynh_backup "/var/run/pihole-FTL.pid" "${YNH_APP_BACKUP_DIR}/var/run/pihole-FTL.pid" -ynh_backup "/var/run/pihole-FTL.port" "${YNH_APP_BACKUP_DIR}/var/run/pihole-FTL.port" +ynh_backup "/etc/init.d/pihole-FTL" +ynh_backup "/usr/bin/pihole-FTL" -ynh_backup "/etc/dnsmasq.d/01-pihole.conf" "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/01-pihole.conf" +ynh_backup "/etc/dnsmasq.d/01-pihole.conf" if test -e "/etc/dnsmasq.d/02-pihole-dhcp.conf"; then - ynh_backup "/etc/dnsmasq.d/02-pihole-dhcp.conf" "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/02-pihole-dhcp.conf" + ynh_backup "/etc/dnsmasq.d/02-pihole-dhcp.conf" fi if test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf"; then - ynh_backup "/etc/dnsmasq.d/03-pihole-wildcard.conf" "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" + ynh_backup "/etc/dnsmasq.d/03-pihole-wildcard.conf" fi if test -e "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"; then - ynh_backup "/etc/dnsmasq.d/04-pihole-static-dhcp.conf" "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" + ynh_backup "/etc/dnsmasq.d/04-pihole-static-dhcp.conf" fi -ynh_backup "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" "${YNH_APP_BACKUP_DIR}/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" +ynh_backup "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" diff --git a/scripts/install b/scripts/install index 51bfeea..fcea5a6 100644 --- a/scripts/install +++ b/scripts/install @@ -8,16 +8,13 @@ source _common.sh source /usr/share/yunohost/helpers +# Load common variables for all scripts. +source _variables #================================================= # MANAGE FAILURE OF THE SCRIPT #================================================= -ynh_clean_setup () { -# Nettoyage des résidus d'installation non pris en charge par le script remove. -# Pas de nettoyage supplémentaire nécessaire ici... - echo "" -} ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. #================================================= @@ -36,9 +33,16 @@ app=$YNH_APP_INSTANCE_NAME # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= -path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path. -CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine. -CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. +final_path=/var/www/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST @@ -72,8 +76,7 @@ ALL_QUIET yunohost firewall allow Both 53 --no-upnp # INSTALL DEPENDENCIES #================================================= -# ynh_install_app_dependencies dhcpcd5 dialog netcat php5-cgi -ynh_install_app_dependencies dhcpcd5 +ynh_install_app_dependencies $app_depencencies #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -230,7 +233,7 @@ do # Et ajoute une résolution sur l'ip local à la place, si elle n'existe pas déjà grep -q "^$localipv4.*$perdomain" /etc/hosts || \ echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts -done <<< "$(sudo yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" +done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" #================================================= # ENABLE DHCP SERVER @@ -252,10 +255,10 @@ then # Get the gateway gateway=$(route | grep default | awk '{print $2;}' | head -n1) # And the mac adress - hw_adress=$(sudo ifconfig | grep "eth0" | awk '{print $5;}') + hw_adress=$(ifconfig | grep "eth0" | awk '{print $5;}') # Copy the config file - sudo cp "../conf/02-pihole-dhcp.conf" "/etc/dnsmasq.d/" + cp "../conf/02-pihole-dhcp.conf" "/etc/dnsmasq.d/" # And set the config ynh_replace_string "__A_RANGE__" "$ip_beginning_part.$a_range" "/etc/dnsmasq.d/02-pihole-dhcp.conf" @@ -306,16 +309,16 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas # ENABLE SERVICE IN ADMIN PANEL #================================================= -sudo yunohost service add pihole-FTL --log "/var/log/pihole-FTL.log" +yunohost service add pihole-FTL --log "/var/log/pihole-FTL.log" #================================================= # RESTRAIN THE ACCESS TO THE ADMIN ONLY #================================================= -sudo yunohost app addaccess --users=$admin $app +yunohost app addaccess --users=$admin $app #================================================= # RELOAD NGINX #================================================= -sudo systemctl reload nginx +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove index f5d9e96..25e551d 100755 --- a/scripts/remove +++ b/scripts/remove @@ -24,10 +24,10 @@ port=$(ynh_app_setting_get $app port) # DISABLE SERVICE IN ADMIN PANEL #================================================= -if sudo yunohost service status | grep -q pihole-FTL # Test l'existence du service dans Yunohost +if yunohost service status | grep -q pihole-FTL # Test l'existence du service dans Yunohost then echo "Remove pihole-FTL service" - sudo yunohost service remove pihole-FTL + yunohost service remove pihole-FTL fi #================================================= @@ -69,16 +69,16 @@ ynh_remove_fpm_config # Suppression de la configuration du pool php-fpm # CLOSE A PORT #================================================= -if sudo yunohost firewall list | grep -q "\- $port$" +if yunohost firewall list | grep -q "\- $port$" then echo "Close port $port" - QUIET sudo yunohost firewall disallow TCP $port + QUIET yunohost firewall disallow TCP $port fi -if sudo yunohost firewall list | grep -q "\- 67$" +if yunohost firewall list | grep -q "\- 67$" then echo "Close port 67" - QUIET sudo yunohost firewall disallow UDP 67 + QUIET yunohost firewall disallow UDP 67 fi #================================================= diff --git a/scripts/restore b/scripts/restore index b8ea9e8..5b10c82 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,25 +1,27 @@ #!/bin/bash #================================================= -# GENERIC STARTING -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - -# Exit on command errors and treat unset variables as an error -set -eu - +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= if [ ! -e _common.sh ]; then - # Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh fi source _common.sh source /usr/share/yunohost/helpers +# Load common variables for all scripts. +source ../settings/scripts/_variables + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # LOAD SETTINGS @@ -35,7 +37,7 @@ final_path=$(ynh_app_setting_get $app final_path) # CHECK IF THE APP CAN BE RESTORED #================================================= -sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ +yunohost app checkurl "${domain}${path_url}" -a "$app" \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die "There is already a directory: $final_path " @@ -86,13 +88,13 @@ ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini" # REINSTALL DEPENDENCIES #================================================= -ynh_install_app_dependencies dhcpcd5 +ynh_install_app_dependencies $app_depencencies #================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= -sudo yunohost service add pihole-FTL --log "/var/log/pihole-FTL.log" +yunohost service add pihole-FTL --log "/var/log/pihole-FTL.log" #================================================= # RESTORE OF THE CRON FILE @@ -120,8 +122,6 @@ ynh_restore_file "/etc/sudoers.d/pihole" ynh_restore_file "/etc/init.d/pihole-FTL" ynh_restore_file "/usr/bin/pihole-FTL" -ynh_restore_file "/var/run/pihole-FTL.pid" -ynh_restore_file "/var/run/pihole-FTL.port" ynh_restore_file "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" @@ -160,7 +160,7 @@ do # Et ajoute une résolution sur l'ip local à la place, si elle n'existe pas déjà grep -q "^$localipv4.*$perdomain" /etc/hosts || \ echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts -done <<< "$(sudo yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" +done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" #================================================= # RESTART DNSMASQ @@ -193,5 +193,5 @@ systemctl start pihole-FTL # RELOAD NGINX AND PHP-FPM #================================================= -sudo systemctl reload php5-fpm -sudo systemctl reload nginx +systemctl reload php5-fpm +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index b3f0fbf..6e81d14 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,11 +26,14 @@ port=$(ynh_app_setting_get $app port) # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -BACKUP_BEFORE_UPGRADE # Backup the current version of the app +# Backup the current version of the app +ynh_backup_before_upgrade ynh_clean_setup () { - BACKUP_FAIL_UPGRADE # restore it if the upgrade fails + # restore it if the upgrade fails + ynh_restore_upgradebackup } -ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # CHECK THE PATH @@ -174,4 +177,4 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas # RELOAD NGINX #================================================= -sudo systemctl reload nginx +systemctl reload nginx