1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pihole_ynh.git synced 2024-09-03 20:05:58 +02:00

Update helpers & fix backup

This commit is contained in:
Maniack Crudelis 2017-09-05 23:50:20 +02:00
parent a7ce59065f
commit 0fd75e059e
7 changed files with 87 additions and 79 deletions

View file

@ -2,9 +2,6 @@
"name": "Pi-hole", "name": "Pi-hole",
"id": "pihole", "id": "pihole",
"packaging_format": 1, "packaging_format": 1,
"requirements": {
"yunohost": ">= 2.6.4"
},
"description": { "description": {
"en": "Network-wide ad blocking via your own DNS server.", "en": "Network-wide ad blocking via your own DNS server.",
"fr": "Filtrage publicitaire sur l'ensemble du réseau via votre propre serveur DNS." "fr": "Filtrage publicitaire sur l'ensemble du réseau via votre propre serveur DNS."
@ -16,6 +13,9 @@
"name": "Maniack Crudelis", "name": "Maniack Crudelis",
"email": "maniackc_dev@crudelis.fr" "email": "maniackc_dev@crudelis.fr"
}, },
"requirements": {
"yunohost": ">= 2.7.2"
},
"multi_instance": false, "multi_instance": false,
"services": [ "services": [
"nginx", "nginx",

4
scripts/_variables Normal file
View file

@ -0,0 +1,4 @@
#!/bin/bash
# Dependencies
app_depencencies="dhcpcd5"

View file

@ -1,26 +1,26 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# GENERIC STARTING # GENERIC START
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
# Exit on command errors and treat unset variables as an error
set -eu
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
if [ ! -e _common.sh ]; then if [ ! -e _common.sh ]; then
# Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant # Get the _common.sh file if it's not in the current directory
sudo cp ../settings/scripts/_common.sh ./_common.sh cp ../settings/scripts/_common.sh ./_common.sh
sudo chmod a+rx _common.sh chmod a+rx _common.sh
fi fi
source _common.sh source _common.sh
source /usr/share/yunohost/helpers 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 # LOAD SETTINGS
#================================================= #=================================================
@ -37,29 +37,29 @@ domain=$(ynh_app_setting_get $app domain)
#================================================= #=================================================
CHECK_SIZE "$final_path" CHECK_SIZE "$final_path"
ynh_backup "$final_path" "${YNH_APP_BACKUP_DIR}$final_path" ynh_backup "$final_path"
CHECK_SIZE "/etc/.pihole" CHECK_SIZE "/etc/.pihole"
ynh_backup "/etc/.pihole" "${YNH_APP_BACKUP_DIR}/etc/.pihole" ynh_backup "/etc/.pihole"
CHECK_SIZE "/etc/pihole" CHECK_SIZE "/etc/pihole"
ynh_backup "/etc/pihole" "${YNH_APP_BACKUP_DIR}/etc/pihole" ynh_backup "/etc/pihole"
CHECK_SIZE "/opt/pihole" CHECK_SIZE "/opt/pihole"
ynh_backup "/opt/pihole" "${YNH_APP_BACKUP_DIR}/opt/pihole" ynh_backup "/opt/pihole"
#================================================= #=================================================
# BACKUP OF THE NGINX CONFIGURATION # 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 # 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/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/conf.d/20-$app.ini"
#================================================= #=================================================
# SPECIFIC BACKUP # 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 # 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 # BACKUP OF SPECIFIC FILES
#================================================= #=================================================
ynh_backup "/usr/local/bin/pihole" "${YNH_APP_BACKUP_DIR}/usr/local/bin/pihole" ynh_backup "/usr/local/bin/pihole"
ynh_backup "/etc/bash_completion.d/pihole" "${YNH_APP_BACKUP_DIR}/etc/bash_completion.d/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 "/etc/init.d/pihole-FTL"
ynh_backup "/usr/bin/pihole-FTL" "${YNH_APP_BACKUP_DIR}/usr/bin/pihole-FTL" ynh_backup "/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/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 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 fi
if test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf"; then 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 fi
if test -e "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"; then 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 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"

View file

@ -8,16 +8,13 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source _variables
#================================================= #=================================================
# MANAGE FAILURE OF THE SCRIPT # 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. 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 # 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. final_path=/var/www/$app
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine. test ! -e "$final_path" || ynh_die "This path already contains a folder"
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
# 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 # STORE SETTINGS FROM MANIFEST
@ -72,8 +76,7 @@ ALL_QUIET yunohost firewall allow Both 53 --no-upnp
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
# ynh_install_app_dependencies dhcpcd5 dialog netcat php5-cgi ynh_install_app_dependencies $app_depencencies
ynh_install_app_dependencies dhcpcd5
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # 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à # Et ajoute une résolution sur l'ip local à la place, si elle n'existe pas déjà
grep -q "^$localipv4.*$perdomain" /etc/hosts || \ grep -q "^$localipv4.*$perdomain" /etc/hosts || \
echo "$localipv4 $perdomain #Added by pihole#" >> /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 # ENABLE DHCP SERVER
@ -252,10 +255,10 @@ then
# Get the gateway # Get the gateway
gateway=$(route | grep default | awk '{print $2;}' | head -n1) gateway=$(route | grep default | awk '{print $2;}' | head -n1)
# And the mac adress # 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 # 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 # And set the config
ynh_replace_string "__A_RANGE__" "$ip_beginning_part.$a_range" "/etc/dnsmasq.d/02-pihole-dhcp.conf" 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 # 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 # RESTRAIN THE ACCESS TO THE ADMIN ONLY
#================================================= #=================================================
sudo yunohost app addaccess --users=$admin $app yunohost app addaccess --users=$admin $app
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
sudo systemctl reload nginx systemctl reload nginx

View file

@ -24,10 +24,10 @@ port=$(ynh_app_setting_get $app port)
# DISABLE SERVICE IN ADMIN PANEL # 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 then
echo "Remove pihole-FTL service" echo "Remove pihole-FTL service"
sudo yunohost service remove pihole-FTL yunohost service remove pihole-FTL
fi fi
#================================================= #=================================================
@ -69,16 +69,16 @@ ynh_remove_fpm_config # Suppression de la configuration du pool php-fpm
# CLOSE A PORT # CLOSE A PORT
#================================================= #=================================================
if sudo yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
echo "Close port $port" echo "Close port $port"
QUIET sudo yunohost firewall disallow TCP $port QUIET yunohost firewall disallow TCP $port
fi fi
if sudo yunohost firewall list | grep -q "\- 67$" if yunohost firewall list | grep -q "\- 67$"
then then
echo "Close port 67" echo "Close port 67"
QUIET sudo yunohost firewall disallow UDP 67 QUIET yunohost firewall disallow UDP 67
fi fi
#================================================= #=================================================

View file

@ -1,25 +1,27 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# GENERIC STARTING # GENERIC START
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
# Exit on command errors and treat unset variables as an error
set -eu
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
if [ ! -e _common.sh ]; then if [ ! -e _common.sh ]; then
# Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant # Get the _common.sh file if it's not in the current directory
sudo cp ../settings/scripts/_common.sh ./_common.sh cp ../settings/scripts/_common.sh ./_common.sh
sudo chmod a+rx _common.sh chmod a+rx _common.sh
fi fi
source _common.sh source _common.sh
source /usr/share/yunohost/helpers 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 # LOAD SETTINGS
@ -35,7 +37,7 @@ final_path=$(ynh_app_setting_get $app final_path)
# CHECK IF THE APP CAN BE RESTORED # 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}" || ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die "There is already a directory: $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 # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_install_app_dependencies dhcpcd5 ynh_install_app_dependencies $app_depencencies
#================================================= #=================================================
# ENABLE SERVICE IN ADMIN PANEL # 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 # 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 "/etc/init.d/pihole-FTL"
ynh_restore_file "/usr/bin/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" 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à # Et ajoute une résolution sur l'ip local à la place, si elle n'existe pas déjà
grep -q "^$localipv4.*$perdomain" /etc/hosts || \ grep -q "^$localipv4.*$perdomain" /etc/hosts || \
echo "$localipv4 $perdomain #Added by pihole#" >> /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 # RESTART DNSMASQ
@ -193,5 +193,5 @@ systemctl start pihole-FTL
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
sudo systemctl reload php5-fpm systemctl reload php5-fpm
sudo systemctl reload nginx systemctl reload nginx

View file

@ -26,11 +26,14 @@ port=$(ynh_app_setting_get $app port)
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # 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 () { 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 # CHECK THE PATH
@ -174,4 +177,4 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
sudo systemctl reload nginx systemctl reload nginx