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

Merge pull request #36 from YunoHost-Apps/testing

Testing
This commit is contained in:
Maniack Crudelis 2019-01-21 14:04:48 +01:00 committed by GitHub
commit 2ed3e8a81f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 550 additions and 460 deletions

View file

@ -39,14 +39,14 @@ Use the admin panel of your Pi-hole to configure this app.
#### Supported architectures #### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)/) * x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/pihole%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/pihole/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/) * ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/pihole%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pihole/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/jenkins/job/pihole%20(Community)/badge/icon)](https://ci-stretch.nohost.me/jenkins/job/pihole%20(Community)/) * Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/pihole%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/pihole/)
## Limitations ## Limitations
* Activate DHCP with Pi-hole need a manuel configuration of your router. * Activate DHCP with Pi-hole need a manuel configuration of your router.
* Pi-Hole-FTL can't be upgrade above the version 2.13.2, because of the usage of an option of dnsmasq not yet available on Jessie. * Pi-Hole can't be updated beyond the version 3.3.1, because higher versions use an integrated version of dnsmasq. This would forces to disable the version of dnsmasq used by YunoHost.
## Additionnal informations ## Additionnal informations
@ -65,7 +65,7 @@ Please do your pull request to the [testing branch](https://github.com/YunoHost-
To try the testing branch, please proceed like that. To try the testing branch, please proceed like that.
``` ```
sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --verbose sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug
or or
sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --verbose sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug
``` ```

View file

@ -39,14 +39,14 @@ Utiliser le panneau d'administration de votre Pi-hole pour configurer cette appl
#### Architectures supportées. #### Architectures supportées.
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)/) * x86-64b - [![](https://ci-apps.yunohost.org/ci/logs/pihole%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/pihole/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/) * ARMv8-A - [![](https://ci-apps-arm.yunohost.org/ci/logs/pihole%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pihole/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/jenkins/job/pihole%20(Community)/badge/icon)](https://ci-stretch.nohost.me/jenkins/job/pihole%20(Community)/) * Jessie x86-64b - [![](https://ci-stretch.nohost.me/ci/logs/pihole%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/pihole/)
## Limitations ## Limitations
* Activer DHCP avec Pi-hole nécessite une configuration manuelle de votre routeur. * Activer DHCP avec Pi-hole nécessite une configuration manuelle de votre routeur.
* Pi-Hole-FTL ne peut pas être mis à jour au-delà de la version 2.13.2, à cause de l'utilisation d'une option de dnsmasq non encore disponible sur Jessie. * 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.
## Informations additionnelles ## Informations additionnelles
@ -65,7 +65,7 @@ Merci de faire vos pull request sur la [branche testing](https://github.com/Yuno
Pour tester la branche testing, merci de procéder ainsi. Pour tester la branche testing, merci de procéder ainsi.
``` ```
sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --verbose sudo yunohost app install https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug
ou ou
sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --verbose sudo yunohost app upgrade pihole -u https://github.com/YunoHost-Apps/pihole_ynh/tree/testing --debug
``` ```

View file

@ -1,3 +0,0 @@
; upload_max_filesize=100M
; post_max_size=100M
; max_execution_time=60

View file

@ -6,7 +6,7 @@
"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."
}, },
"version": "3.3.1~ynh3", "version": "3.3.1~ynh4",
"url": "https://pi-hole.net/", "url": "https://pi-hole.net/",
"license": "EUPL-1.2", "license": "EUPL-1.2",
"maintainer": { "maintainer": {
@ -14,7 +14,7 @@
"email": "maniackc_dev@crudelis.fr" "email": "maniackc_dev@crudelis.fr"
}, },
"requirements": { "requirements": {
"yunohost": ">= 2.7.14" "yunohost": ">= 3.3.3"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [

View file

@ -49,11 +49,13 @@ bool_to_true_false () {
} }
#================================================= #=================================================
# EXPERIMENTAL HELPERS # FUTUR OFFICIAL HELPERS
#================================================= #=================================================
# Internal helper design to allow helpers to use getopts to manage their arguments # Internal helper design to allow helpers to use getopts to manage their arguments
# #
# [internal]
#
# example: function my_helper() # example: function my_helper()
# { # {
# declare -Ar args_array=( [a]=arg1= [b]=arg2= [c]=arg3 ) # declare -Ar args_array=( [a]=arg1= [b]=arg2= [c]=arg3 )
@ -103,33 +105,33 @@ ynh_handle_getopts_args () {
# For each option in the array, reduce to short options for getopts (e.g. for [u]=user, --user will be -u) # For each option in the array, reduce to short options for getopts (e.g. for [u]=user, --user will be -u)
# And built parameters string for getopts # And built parameters string for getopts
# ${!args_array[@]} is the list of all keys in the array (A key is 'u' in [u]=user, user is a value) # ${!args_array[@]} is the list of all option_flags in the array (An option_flag is 'u' in [u]=user, user is a value)
local getopts_parameters="" local getopts_parameters=""
local key="" local option_flag=""
for key in "${!args_array[@]}" for option_flag in "${!args_array[@]}"
do do
# Concatenate each keys of the array to build the string of arguments for getopts # Concatenate each option_flags of the array to build the string of arguments for getopts
# Will looks like 'abcd' for -a -b -c -d # Will looks like 'abcd' for -a -b -c -d
# If the value of a key finish by =, it's an option with additionnal values. (e.g. --user bob or -u bob) # If the value of an option_flag finish by =, it's an option with additionnal values. (e.g. --user bob or -u bob)
# Check the last character of the value associate to the key # Check the last character of the value associate to the option_flag
if [ "${args_array[$key]: -1}" = "=" ] if [ "${args_array[$option_flag]: -1}" = "=" ]
then then
# For an option with additionnal values, add a ':' after the letter for getopts. # For an option with additionnal values, add a ':' after the letter for getopts.
getopts_parameters="${getopts_parameters}${key}:" getopts_parameters="${getopts_parameters}${option_flag}:"
else else
getopts_parameters="${getopts_parameters}${key}" getopts_parameters="${getopts_parameters}${option_flag}"
fi fi
# Check each argument given to the function # Check each argument given to the function
local arg="" local arg=""
# ${#arguments[@]} is the size of the array # ${#arguments[@]} is the size of the array
for arg in `seq 0 $(( ${#arguments[@]} - 1 ))` for arg in `seq 0 $(( ${#arguments[@]} - 1 ))`
do do
# And replace long option (value of the key) by the short option, the key itself # And replace long option (value of the option_flag) by the short option, the option_flag itself
# (e.g. for [u]=user, --user will be -u) # (e.g. for [u]=user, --user will be -u)
# Replace long option with = # Replace long option with =
arguments[arg]="${arguments[arg]//--${args_array[$key]}/-${key} }" arguments[arg]="${arguments[arg]//--${args_array[$option_flag]}/-${option_flag} }"
# And long option without = # And long option without =
arguments[arg]="${arguments[arg]//--${args_array[$key]%=}/-${key}}" arguments[arg]="${arguments[arg]//--${args_array[$option_flag]%=}/-${option_flag}}"
done done
done done
@ -148,10 +150,10 @@ ynh_handle_getopts_args () {
if [ "$parameter" = "?" ] if [ "$parameter" = "?" ]
then then
ynh_die "Invalid argument: -${OPTARG:-}" ynh_die --message="Invalid argument: -${OPTARG:-}"
elif [ "$parameter" = ":" ] elif [ "$parameter" = ":" ]
then then
ynh_die "-$OPTARG parameter requires an argument." ynh_die --message="-$OPTARG parameter requires an argument."
else else
local shift_value=1 local shift_value=1
# Use the long option, corresponding to the short option read by getopts, as a variable # Use the long option, corresponding to the short option read by getopts, as a variable
@ -179,19 +181,20 @@ ynh_handle_getopts_args () {
shift_value=$(( shift_value - 1 )) shift_value=$(( shift_value - 1 ))
fi fi
# Declare the content of option_var as a variable.
eval ${option_var}=""
# Then read the array value per value # Then read the array value per value
local i
for i in `seq 0 $(( ${#all_args[@]} - 1 ))` for i in `seq 0 $(( ${#all_args[@]} - 1 ))`
do do
# If this argument is an option, end here. # If this argument is an option, end here.
if [ "${all_args[$i]:0:1}" == "-" ] || [ -z "${all_args[$i]}" ] if [ "${all_args[$i]:0:1}" == "-" ]
then then
# Ignore the first value of the array, which is the option itself # Ignore the first value of the array, which is the option itself
if [ "$i" -ne 0 ]; then if [ "$i" -ne 0 ]; then
break break
fi fi
else else
# Declare the content of option_var as a variable.
eval ${option_var}=""
# Else, add this value to this option # Else, add this value to this option
# Each value will be separated by ';' # Each value will be separated by ';'
if [ -n "${!option_var}" ] if [ -n "${!option_var}" ]
@ -215,25 +218,33 @@ ynh_handle_getopts_args () {
# Check if there's getopts arguments # Check if there's getopts arguments
if [ "${arguments[0]:0:1}" != "-" ] if [ "${arguments[0]:0:1}" != "-" ]
then then
# If not, enter in legacy mode and manage the arguments as positionnal ones. # If not, enter in legacy mode and manage the arguments as positionnal ones..
echo "! Helper used in legacy mode !" # Dot not echo, to prevent to go through a helper output. But print only in the log.
set -x; echo "! Helper used in legacy mode !" > /dev/null; set +x
local i
for i in `seq 0 $(( ${#arguments[@]} -1 ))` for i in `seq 0 $(( ${#arguments[@]} -1 ))`
do do
# Use getopts_parameters as a list of key of the array args_array # Try to use legacy_args as a list of option_flag of the array args_array
# Otherwise, fallback to getopts_parameters to get the option_flag. But an associative arrays isn't always sorted in the correct order...
# Remove all ':' in getopts_parameters # Remove all ':' in getopts_parameters
getopts_parameters=${getopts_parameters//:} getopts_parameters=${legacy_args:-${getopts_parameters//:}}
# Get the key from getopts_parameters, by using the key according to the position of the argument. # Get the option_flag from getopts_parameters, by using the option_flag according to the position of the argument.
key=${getopts_parameters:$i:1} option_flag=${getopts_parameters:$i:1}
# Use the long option, corresponding to the key, as a variable if [ -z "$option_flag" ]; then
ynh_print_warn --message="Too many arguments ! \"${arguments[$i]}\" will be ignored."
continue
fi
# Use the long option, corresponding to the option_flag, as a variable
# (e.g. for [u]=user, 'user' will be used as a variable) # (e.g. for [u]=user, 'user' will be used as a variable)
# Also, remove '=' at the end of the long option # Also, remove '=' at the end of the long option
# The variable name will be stored in 'option_var' # The variable name will be stored in 'option_var'
local option_var="${args_array[$key]%=}" local option_var="${args_array[$option_flag]%=}"
# Store each value given as argument in the corresponding variable # Store each value given as argument in the corresponding variable
# The values will be stored in the same order than $args_array # The values will be stored in the same order than $args_array
eval ${option_var}+=\"${arguments[$i]}\" eval ${option_var}+=\"${arguments[$i]}\"
done done
unset legacy_args
else else
# END LEGACY MODE # END LEGACY MODE
# Call parse_arg and pass the modified list of args as an array of arguments. # Call parse_arg and pass the modified list of args as an array of arguments.
@ -245,185 +256,12 @@ ynh_handle_getopts_args () {
#================================================= #=================================================
# Start or restart a service and follow its booting
#
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
#
# | arg: -m, --line_to_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# | arg: -l, --app_log= - Log file - The log file to watch; specify "systemd" to read systemd journal for specified service
# /var/log/$app/$app.log will be used if no other log is defined.
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
# | arg: -n, --service_name= - Service name
ynh_check_starting () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=line_to_match= [l]=app_log= [t]=timeout= [n]=service_name= )
local line_to_match
local app_log
local timeout
local service_name
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local app_log="${app_log:-/var/log/$service_name/$service_name.log}"
local timeout=${timeout:-300}
local service_name="${service_name:-$app}"
echo "Starting of $service_name" >&2
systemctl stop $service_name
local templog="$(mktemp)"
# Following the starting of the app in its log
if [ "$app_log" == "systemd" ] ; then
# Read the systemd journal
journalctl -u $service_name -f --since=-45 > "$templog" &
else
# Read the specified log file
tail -F -n0 "$app_log" > "$templog" &
fi
# Get the PID of the last command
local pid_tail=$!
systemctl start $service_name
local i=0
for i in `seq 1 $timeout`
do
# Read the log until the sentence is found, which means the app finished starting. Or run until the timeout.
if grep --quiet "$line_to_match" "$templog"
then
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully start before the timeout." >&2
fi
echo ""
ynh_clean_check_starting
}
# Clean temporary process and file used by ynh_check_starting
# (usually used in ynh_clean_setup scripts)
#
# usage: ynh_clean_check_starting
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}
#=================================================
ynh_print_log () {
echo "${1}"
}
# Print an info on stdout
#
# usage: ynh_print_info "Text to print"
# | arg: text - The text to print
ynh_print_info () {
ynh_print_log "[INFO] ${1}"
}
# Print a warning on stderr
#
# usage: ynh_print_warn "Text to print"
# | arg: text - The text to print
ynh_print_warn () {
ynh_print_log "[WARN] ${1}" >&2
}
# Print a error on stderr
#
# usage: ynh_print_err "Text to print"
# | arg: text - The text to print
ynh_print_err () {
ynh_print_log "[ERR] ${1}" >&2
}
# Execute a command and print the result as an error
#
# usage: ynh_exec_err command to execute
# usage: ynh_exec_err "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_err () {
ynh_print_err "$(eval $@)"
}
# Execute a command and print the result as a warning
#
# usage: ynh_exec_warn command to execute
# usage: ynh_exec_warn "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_warn () {
ynh_print_warn "$(eval $@)"
}
# Execute a command and force the result to be printed on stdout
#
# usage: ynh_exec_warn_less command to execute
# usage: ynh_exec_warn_less "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_warn_less () {
eval $@ 2>&1
}
# Execute a command and redirect stdout in /dev/null
#
# usage: ynh_exec_quiet command to execute
# usage: ynh_exec_quiet "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_quiet () {
eval $@ > /dev/null
}
# Execute a command and redirect stdout and stderr in /dev/null
#
# usage: ynh_exec_fully_quiet command to execute
# usage: ynh_exec_fully_quiet "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_fully_quiet () {
eval $@ > /dev/null 2>&1
}
# Remove any logs for all the following commands.
#
# usage: ynh_print_OFF
# WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging.
ynh_print_OFF () {
set +x
}
# Restore the logging after ynh_print_OFF
#
# usage: ynh_print_ON
ynh_print_ON () {
set -x
# Print an echo only for the log, to be able to know that ynh_print_ON has been called.
echo ynh_print_ON > /dev/null
}
#=================================================
# Install or update the main directory yunohost.multimedia # Install or update the main directory yunohost.multimedia
# #
# usage: ynh_multimedia_build_main_dir # usage: ynh_multimedia_build_main_dir
ynh_multimedia_build_main_dir () { ynh_multimedia_build_main_dir () {
local ynh_media_release="v1.0" local ynh_media_release="v1.2"
local checksum="4852c8607db820ad51f348da0dcf0c88" local checksum="806a827ba1902d6911095602a9221181"
# Download yunohost.multimedia scripts # Download yunohost.multimedia scripts
wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
@ -432,6 +270,10 @@ ynh_multimedia_build_main_dir () {
echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \ echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
|| ynh_die "Corrupt source" || ynh_die "Corrupt source"
# Check if the package acl is installed. Or install it.
ynh_package_is_installed 'acl' \
|| ynh_package_install acl
# Extract # Extract
mkdir yunohost.multimedia-master mkdir yunohost.multimedia-master
tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1 tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
@ -496,16 +338,21 @@ ynh_multimedia_addaccess () {
# Create a dedicated fail2ban config (jail and filter conf files) # Create a dedicated fail2ban config (jail and filter conf files)
# #
# usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]] # usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]]
# | arg: log_file - Log file to be checked by fail2ban # | arg: -l, --logpath= - Log file to be checked by fail2ban
# | arg: failregex - Failregex to be looked for by fail2ban # | arg: -r, --failregex= - Failregex to be looked for by fail2ban
# | arg: max_retry - Maximum number of retries allowed before banning IP address - default: 3 # | arg: -m, --max_retry= - Maximum number of retries allowed before banning IP address - default: 3
# | arg: ports - Ports blocked for a banned IP address - default: http,https # | arg: -p, --ports= - Ports blocked for a banned IP address - default: http,https
ynh_add_fail2ban_config () { ynh_add_fail2ban_config () {
# Process parameters # Declare an array to define the options of this helper.
logpath=$1 declare -Ar args_array=( [l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= )
failregex=$2 local logpath
max_retry=${3:-3} local failregex
ports=${4:-http,https} local max_retry
local ports
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
max_retry=${max_retry:-3}
ports=${ports:-http,https}
test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing."
test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing." test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing."
@ -515,7 +362,7 @@ ynh_add_fail2ban_config () {
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1 ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1 ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
sudo tee $finalfail2banjailconf <<EOF tee $finalfail2banjailconf <<EOF
[$app] [$app]
enabled = true enabled = true
port = $ports port = $ports
@ -524,7 +371,7 @@ logpath = $logpath
maxretry = $max_retry maxretry = $max_retry
EOF EOF
sudo tee $finalfail2banfilterconf <<EOF tee $finalfail2banfilterconf <<EOF
[INCLUDES] [INCLUDES]
before = common.conf before = common.conf
[Definition] [Definition]
@ -535,7 +382,11 @@ EOF
ynh_store_file_checksum "$finalfail2banjailconf" ynh_store_file_checksum "$finalfail2banjailconf"
ynh_store_file_checksum "$finalfail2banfilterconf" ynh_store_file_checksum "$finalfail2banfilterconf"
if [ "$(lsb_release --codename --short)" != "jessie" ]; then
systemctl reload fail2ban
else
systemctl restart fail2ban systemctl restart fail2ban
fi
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")" local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
if [ -n "$fail2ban_error" ] if [ -n "$fail2ban_error" ]
then then
@ -550,7 +401,11 @@ EOF
ynh_remove_fail2ban_config () { ynh_remove_fail2ban_config () {
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf" ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf" ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
if [ "$(lsb_release --codename --short)" != "jessie" ]; then
systemctl reload fail2ban
else
systemctl restart fail2ban systemctl restart fail2ban
fi
} }
#================================================= #=================================================
@ -558,12 +413,17 @@ ynh_remove_fail2ban_config () {
# Read the value of a key in a ynh manifest file # Read the value of a key in a ynh manifest file
# #
# usage: ynh_read_manifest manifest key # usage: ynh_read_manifest manifest key
# | arg: manifest - Path of the manifest to read # | arg: -m, --manifest= - Path of the manifest to read
# | arg: key - Name of the key to find # | arg: -k, --key= - Name of the key to find
ynh_read_manifest () { ynh_read_manifest () {
manifest="$1" # Declare an array to define the options of this helper.
key="$2" declare -Ar args_array=( [m]=manifest= [k]=manifest_key= )
python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])" local manifest
local manifest_key
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$manifest_key'])"
} }
# Read the upstream version from the manifest # Read the upstream version from the manifest
@ -572,30 +432,41 @@ ynh_read_manifest () {
# This include the number before ~ynh # This include the number before ~ynh
# In the last example it return 4.3-2 # In the last example it return 4.3-2
# #
# usage: ynh_app_upstream_version # usage: ynh_app_upstream_version [-m manifest]
# | arg: -m, --manifest= - Path of the manifest to read
ynh_app_upstream_version () { ynh_app_upstream_version () {
manifest_path="../manifest.json" declare -Ar args_array=( [m]=manifest= )
if [ ! -e "$manifest_path" ]; then local manifest
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place # Manage arguments with getopts
ynh_handle_getopts_args "$@"
manifest="${manifest:-../manifest.json}"
if [ ! -e "$manifest" ]; then
manifest="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
fi fi
version_key=$(ynh_read_manifest "$manifest_path" "version") version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
echo "${version_key/~ynh*/}" echo "${version_key/~ynh*/}"
} }
# Read package version from the manifest # Read package version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion> # The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3 # For example : 4.3-2~ynh3
# This include the number after ~ynh # This include the number after ~ynh
# In the last example it return 3 # In the last example it return 3
# #
# usage: ynh_app_package_version # usage: ynh_app_package_version [-m manifest]
# | arg: -m, --manifest= - Path of the manifest to read
ynh_app_package_version () { ynh_app_package_version () {
manifest_path="../manifest.json" declare -Ar args_array=( [m]=manifest= )
if [ ! -e "$manifest_path" ]; then local manifest
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place # Manage arguments with getopts
ynh_handle_getopts_args "$@"
manifest="${manifest:-../manifest.json}"
if [ ! -e "$manifest" ]; then
manifest="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
fi fi
version_key=$(ynh_read_manifest "$manifest_path" "version") version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
echo "${version_key/*~ynh/}" echo "${version_key/*~ynh/}"
} }
@ -611,7 +482,7 @@ ynh_app_package_version () {
# To force an upgrade, even if the package is up to date, # To force an upgrade, even if the package is up to date,
# you have to set the variable YNH_FORCE_UPGRADE before. # you have to set the variable YNH_FORCE_UPGRADE before.
# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp # example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
#
# usage: ynh_check_app_version_changed # usage: ynh_check_app_version_changed
ynh_check_app_version_changed () { ynh_check_app_version_changed () {
local force_upgrade=${YNH_FORCE_UPGRADE:-0} local force_upgrade=${YNH_FORCE_UPGRADE:-0}
@ -620,10 +491,10 @@ ynh_check_app_version_changed () {
# By default, upstream app version has changed # By default, upstream app version has changed
local return_value="UPGRADE_APP" local return_value="UPGRADE_APP"
local current_version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)
local current_upstream_version="${current_version/~ynh*/}" local current_upstream_version="$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json")"
local update_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0)
local update_upstream_version="${update_version/~ynh*/}" local update_upstream_version="$(ynh_app_upstream_version)"
if [ "$current_version" == "$update_version" ] ; then if [ "$current_version" == "$update_version" ] ; then
# Complete versions are the same # Complete versions are the same
@ -646,23 +517,138 @@ ynh_check_app_version_changed () {
#================================================= #=================================================
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_remove_file_checksum file
# | arg: -f, --file= - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [f]=file= )
local file
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
#
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
# | arg: -n, --service_name= - Name of the service to reload. Default : $app
# | arg: -a, --action= - Action to perform with systemctl. Default: start
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# If not defined it don't wait until the service is completely started.
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
# | arg: -e, --length= - Length of the error log : Default : 20
ynh_systemd_action() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
local service_name
local action
local line_match
local length
local log_path
local timeout
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local service_name="${service_name:-$app}"
local action=${action:-start}
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
local length=${length:-20}
local timeout=${timeout:-300}
# Start to read the log
if [[ -n "${line_match:-}" ]]
then
local templog="$(mktemp)"
# Following the starting of the app in its log
if [ "$log_path" == "systemd" ] ; then
# Read the systemd journal
journalctl -u $service_name -f --since=-45 > "$templog" &
else
# Read the specified log file
tail -F -n0 "$log_path" > "$templog" &
fi
# Get the PID of the tail command
local pid_tail=$!
fi
echo "${action^} the service $service_name" >&2
systemctl $action $service_name \
|| ( journalctl --lines=$length -u $service_name >&2 \
; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \
; false )
# Start the timeout and try to find line_match
if [[ -n "${line_match:-}" ]]
then
local i=0
for i in $(seq 1 $timeout)
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_match" "$templog"
then
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully started before the timeout." >&2
echo "Please find here an extract of the end of the log of the service $service_name:"
journalctl --lines=$length -u $service_name >&2
test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2
fi
echo ""
ynh_clean_check_starting
fi
}
# Clean temporary process and file used by ynh_check_starting
# (usually used in ynh_clean_setup scripts)
#
# usage: ynh_clean_check_starting
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}
#=================================================
# Send an email to inform the administrator # Send an email to inform the administrator
# #
# usage: ynh_send_readme_to_admin app_message [recipients] # usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
# | arg: -m --app_message= - The message to send to the administrator. # | arg: -m --app_message= - The message to send to the administrator.
# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root # | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain" # example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you # If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2" # example: "root admin@domain user1 user2"
# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
ynh_send_readme_to_admin() { ynh_send_readme_to_admin() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=app_message= [r]=recipients= ) declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
local app_message local app_message
local recipients local recipients
local type
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
local app_message="${app_message:-...No specific information...}" app_message="${app_message:-...No specific information...}"
local recipients="${recipients:-root}" recipients="${recipients:-root}"
type="${type:-install}"
# Retrieve the email of users # Retrieve the email of users
find_mails () { find_mails () {
@ -688,7 +674,23 @@ ynh_send_readme_to_admin() {
} }
recipients=$(find_mails "$recipients") recipients=$(find_mails "$recipients")
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!" # Subject base
local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
# Adapt the subject according to the type of mail required.
if [ "$type" = "backup" ]; then
mail_subject="$mail_subject has just been backup."
elif [ "$type" = "change_url" ]; then
mail_subject="$mail_subject has just been moved to a new URL!"
elif [ "$type" = "remove" ]; then
mail_subject="$mail_subject has just been removed!"
elif [ "$type" = "restore" ]; then
mail_subject="$mail_subject has just been restored!"
elif [ "$type" = "upgrade" ]; then
mail_subject="$mail_subject has just been upgraded!"
else # install
mail_subject="$mail_subject has just been installed!"
fi
local mail_message="This is an automated message from your beloved YunoHost server. local mail_message="This is an automated message from your beloved YunoHost server.
@ -715,26 +717,6 @@ $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
#================================================= #=================================================
# Reload (or other actions) a service and print a log in case of failure.
#
# usage: ynh_system_reload service_name [action]
# | arg: -n, --service_name= - Name of the service to reload
# | arg: -a, --action= - Action to perform with systemctl. Default: reload
ynh_system_reload () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [n]=service_name= [a]=action= )
local service_name
local action
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local action=${action:-reload}
# Reload, restart or start and print the log if the service fail to start or reload
systemctl $action $service_name || ( journalctl --lines=20 -u $service_name >&2 && false)
}
#=================================================
ynh_debian_release () { ynh_debian_release () {
lsb_release --codename --short lsb_release --codename --short
} }
@ -759,19 +741,6 @@ is_jessie () {
#================================================= #=================================================
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}
#=================================================
ynh_maintenance_mode_ON () { ynh_maintenance_mode_ON () {
# Load value of $path_url and $domain from the config if their not set # Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then if [ -z $path_url ]; then
@ -848,3 +817,69 @@ ynh_maintenance_mode_OFF () {
systemctl reload nginx systemctl reload nginx
} }
#=================================================
# Download and check integrity of a file from app.src_file
#
# The file conf/app.src_file need to contains:
#
# FILE_URL=Address to download the file
# FILE_SUM=Control sum
# # (Optional) Program to check the integrity (sha256sum, md5sum...)
# # default: sha256
# FILE_SUM_PRG=sha256
# # (Optionnal) Name of the local archive (offline setup support)
# # default: Name of the downloaded file.
# FILENAME=example.deb
#
# usage: ynh_download_file --dest_dir="/destination/directory" [--source_id=myfile]
# | arg: -d, --dest_dir= - Directory where to download the file
# | arg: -s, --source_id= - Name of the source file 'app.src_file' if it isn't '$app'
ynh_download_file () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [d]=dest_dir= [s]=source_id= )
local dest_dir
local source_id
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
source_id=${source_id:-app} # If the argument is not given, source_id equals "$app"
# Load value from configuration file (see above for a small doc about this file
# format)
local src_file="$YNH_CWD/../conf/${source_id}.src_file"
# If the src_file doesn't exist, use the backup path instead, with a "settings" directory
if [ ! -e "$src_file" ]
then
src_file="$YNH_CWD/../settings/conf/${source_id}.src_file"
fi
local file_url=$(grep 'FILE_URL=' "$src_file" | cut -d= -f2-)
local file_sum=$(grep 'FILE_SUM=' "$src_file" | cut -d= -f2-)
local file_sumprg=$(grep 'FILE_SUM_PRG=' "$src_file" | cut -d= -f2-)
local filename=$(grep 'FILENAME=' "$src_file" | cut -d= -f2-)
# Default value
file_sumprg=${file_sumprg:-sha256sum}
if [ "$filename" = "" ] ; then
filename="$(basename "$file_url")"
fi
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${filename}"
if test -e "$local_src"
then # Use the local source file if it is present
cp $local_src $filename
else # If not, download the source
local out=`wget -nv -O $filename $file_url 2>&1` || ynh_print_err $out
fi
# Check the control sum
echo "${file_sum} ${filename}" | ${file_sumprg} -c --status \
|| ynh_die "Corrupt file"
# Create the destination directory, if it's not already.
mkdir -p "$dest_dir"
# Move the file to its destination
mv $filename $dest_dir
}

View file

@ -3,7 +3,7 @@
# Dependencies # Dependencies
app_depencencies="sqlite idn2" app_depencencies="sqlite idn2"
# dhcpcd5 has been removed because it can cause some problems with the internet connection. # dhcpcd5 has been removed because it can cause some problems with the internet connection.
if [ "$(lsb_release --codename --short)" != "jessie" ]; then if [ "$(ynh_debian_release)" != "jessie" ]; then
app_depencencies="$app_depencencies php-sqlite3" app_depencencies="$app_depencencies php-sqlite3"
else else
app_depencencies="$app_depencencies php5-sqlite" app_depencencies="$app_depencencies php5-sqlite"

View file

@ -41,7 +41,7 @@ if [ "$file" = "setupVars.conf" ]
then then
# Recreate the default config # Recreate the default config
# Trouve l'interface réseau par défaut # Trouve l'interface réseau par défaut
main_iface=$(ip route | grep default | awk '{print $5;}') main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
echo "PIHOLE_INTERFACE=$main_iface" > "$config_file" echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file" echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
echo "IPV6_ADDRESS=" >> "$config_file" echo "IPV6_ADDRESS=" >> "$config_file"
@ -61,7 +61,7 @@ then
cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file" cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
# Restart pihole-FTL # Restart pihole-FTL
ynh_system_reload --service_name=pihole-FTL --action=restart ynh_systemd_action --action=restart --service_name=pihole-FTL
fi fi
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings

View file

@ -29,7 +29,7 @@ domain=$(ynh_app_setting_get $app domain)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#================================================= #=================================================
# BACKUP OF THE MAIN DIRECTORIES OF THE APP # BACKUP THE MAIN APP DIRECTORIES
#================================================= #=================================================
CHECK_SIZE "$final_path" CHECK_SIZE "$final_path"
@ -45,28 +45,27 @@ CHECK_SIZE "/opt/pihole"
ynh_backup "/opt/pihole" ynh_backup "/opt/pihole"
#================================================= #=================================================
# BACKUP OF THE NGINX CONFIGURATION # BACKUP NGINX CONFIGURATION
#================================================= #=================================================
ynh_backup "/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 PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_backup "/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"
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
#================================================= #=================================================
# BACKUP OF THE CRON FILE # BACKUP CRON FILE
#================================================= #=================================================
ynh_backup "/etc/cron.d/pihole" ynh_backup "/etc/cron.d/pihole"
#================================================= #=================================================
# BACKUP OF SPECIFIC FILES # BACKUP SPECIFIC FILES
#================================================= #=================================================
ynh_backup "/usr/local/bin/pihole" ynh_backup "/usr/local/bin/pihole"

View file

@ -109,7 +109,7 @@ fi
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_system_reload --service_name=nginx ynh_systemd_action --action=reload --service_name=nginx
#================================================= #=================================================
# DEACTIVE MAINTENANCE MODE # DEACTIVE MAINTENANCE MODE

View file

@ -15,7 +15,8 @@ source _variables
# MANAGE FAILURE OF THE SCRIPT # MANAGE FAILURE OF THE SCRIPT
#================================================= #=================================================
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
#================================================= #=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST # RETRIEVE ARGUMENTS FROM THE MANIFEST
@ -39,8 +40,6 @@ test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax # Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url) path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register $app $domain $path_url
@ -64,16 +63,17 @@ ynh_app_setting_set $app overwrite_phpfpm "1"
# FIND AND OPEN A PORT # FIND AND OPEN A PORT
#================================================= #=================================================
port=$(ynh_find_port 4711) # Cherche un port libre. # Find a free port
port=$(ynh_find_port 4711)
if [ $port -gt 4720 ] if [ $port -gt 4720 ]
then then
ynh_die "The ports 4711 to 4720 are already in use. Pi-hole can't works on another port. Please try to free one of this ports." ynh_die "The ports 4711 to 4720 are already in use. Pi-hole can't works on another port. Please try to free one of this ports."
fi fi
# Ouvre le port dans le firewall # Open this port
ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port
ynh_app_setting_set $app port $port ynh_app_setting_set $app port $port
# Désactive le port 53 en upnp # Disable the port 53 for upnp
ynh_exec_fully_quiet yunohost firewall disallow Both 53 --no-reload ynh_exec_fully_quiet yunohost firewall disallow Both 53 --no-reload
ynh_exec_fully_quiet yunohost firewall allow Both 53 --no-upnp ynh_exec_fully_quiet yunohost firewall allow Both 53 --no-upnp
@ -88,34 +88,37 @@ ynh_install_app_dependencies $app_depencencies
#================================================= #=================================================
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set $app final_path $final_path
# Créer une copie du repo de pihole (nécessaire pour Gravity) # Make a copy of local pihole repository (for Gravity)
pihole_local_repo="/etc/.pihole" pihole_local_repo="/etc/.pihole"
ynh_setup_source "$pihole_local_repo" ynh_setup_source "$pihole_local_repo"
# Installe le dashboard admin # Install admin dashboard
ynh_setup_source "$final_path" admin_dashboard ynh_setup_source "$final_path" admin_dashboard
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
# Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_system_user_create $app # Créer un utilisateur système dédié à l'app # Create a dedicated system user
ynh_system_user_create $app
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure. # Create a dedicated php-fpm config
ynh_add_fpm_config
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# CREATE THE DIRECTORIES AND POPULATE THEM # CREATE DIRECTORIES AND POPULATE THEM
#================================================= #=================================================
pihole_storage="/etc/pihole" pihole_storage="/etc/pihole"
@ -125,7 +128,7 @@ chown $app: -R "$pihole_storage"
pihole_dir="/opt/pihole" pihole_dir="/opt/pihole"
mkdir -p "$pihole_dir" mkdir -p "$pihole_dir"
# Copie les scripts de Pi-hole # Make a copy of Pi-Hole scripts
cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/" cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/" cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
@ -133,7 +136,7 @@ cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/" cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
#================================================= #=================================================
# COPY THE PI-HOLE MAIN SCRIPT # COPY PI-HOLE MAIN SCRIPT
#================================================= #=================================================
cp -a "$pihole_local_repo/pihole" /usr/local/bin/ cp -a "$pihole_local_repo/pihole" /usr/local/bin/
@ -152,7 +155,7 @@ chown $dnsmasq_user:root /var/log/pihole.log
# CREATE SUDOER FILE # CREATE SUDOER FILE
#================================================= #=================================================
# Cette configuration sudoers autorise pihole à exécuter /usr/local/bin/pihole en root sans mot de passe. Pas plus. # 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 cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /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 # echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin" >> /etc/sudoers.d/pihole
@ -173,27 +176,28 @@ sed -i "/# su #/d;" "$pihole_storage/logrotate"
FTL_temp_path=$(mktemp -d) FTL_temp_path=$(mktemp -d)
ynh_setup_source "$FTL_temp_path" FTL ynh_setup_source "$FTL_temp_path" FTL
# Plutôt que télécharger le binaire C, on le compile nous-même. # Instead of downloading a binary file, we're going to compile it
( cd "$FTL_temp_path" ( cd "$FTL_temp_path"
ynh_exec_warn_less make ynh_exec_warn_less make
ynh_exec_warn_less make install ) ynh_exec_warn_less make install )
ynh_secure_remove "$FTL_temp_path" ynh_secure_remove "$FTL_temp_path"
cp "../conf/pihole-FTL.conf" "$pihole_storage" cp "../conf/pihole-FTL.conf" "$pihole_storage"
ynh_store_file_checksum "$pihole_storage/pihole-FTL.conf" # Enregistre la somme de contrôle du fichier de config # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$pihole_storage/pihole-FTL.conf"
cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
chmod +x /etc/init.d/pihole-FTL chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable pihole-FTL ynh_exec_warn_less systemctl enable pihole-FTL
#================================================= #=================================================
# BUILD THE VARIABLES FILE # BUILD VARIABLES FILE
#================================================= #=================================================
setupVars="$pihole_storage/setupVars.conf" setupVars="$pihole_storage/setupVars.conf"
# Trouve l'interface réseau par défaut # Get the default network interface
main_iface=$(ip route | grep default | awk '{print $5;}') main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
echo "PIHOLE_INTERFACE=$main_iface" > $setupVars echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
echo "IPV6_ADDRESS=" >> $setupVars echo "IPV6_ADDRESS=" >> $setupVars
@ -207,17 +211,18 @@ fi
echo "QUERY_LOGGING=$query_logging" >> $setupVars echo "QUERY_LOGGING=$query_logging" >> $setupVars
echo "INSTALL_WEB=true" >> $setupVars echo "INSTALL_WEB=true" >> $setupVars
ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichier de config # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$setupVars"
#================================================= #=================================================
# SET UP THE DNSMASQ CONFIG # SET UP DNSMASQ CONFIG
#================================================= #=================================================
ynh_system_reload --service_name=dnsmasq --action=stop ynh_systemd_action --action=stop --service_name=dnsmasq
pihole_dnsmasq_config="/etc/dnsmasq.d/01-pihole.conf" pihole_dnsmasq_config="/etc/dnsmasq.d/01-pihole.conf"
cp "$pihole_local_repo/advanced/01-pihole.conf" $pihole_dnsmasq_config cp "$pihole_local_repo/advanced/01-pihole.conf" $pihole_dnsmasq_config
# On utilise les dns de /etc/resolv.dnsmasq.conf # Use dns from /etc/resolv.dnsmasq.conf
ynh_replace_string "@DNS1@" "" $pihole_dnsmasq_config ynh_replace_string "@DNS1@" "" $pihole_dnsmasq_config
ynh_replace_string "@DNS2@" "" $pihole_dnsmasq_config ynh_replace_string "@DNS2@" "" $pihole_dnsmasq_config
ynh_replace_string "^no-resolv" "#no-resolv" $pihole_dnsmasq_config ynh_replace_string "^no-resolv" "#no-resolv" $pihole_dnsmasq_config
@ -232,25 +237,26 @@ fi
# Fix a too recent option for our dnsmasq version. # Fix a too recent option for our dnsmasq version.
ynh_replace_string "log-queries=extra" "log-queries" $pihole_dnsmasq_config ynh_replace_string "log-queries=extra" "log-queries" $pihole_dnsmasq_config
ynh_store_file_checksum "$pihole_dnsmasq_config" # Enregistre la somme de contrôle du fichier de config # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$pihole_dnsmasq_config"
# Pour éviter un conflit entre les config de dnsmasq, il faut commenter cache-size dans la config par défaut. # To prevent any conflict with the original dnsmasq config, comment cache-size in the original config.
ynh_replace_string "^cache-size=" "#pihole# cache-size=" /etc/dnsmasq.conf ynh_replace_string "^cache-size=" "#pihole# cache-size=" /etc/dnsmasq.conf
#================================================= #=================================================
# CONFIGURE DNS FOR THE LOCAL DOMAINS # CONFIGURE DNS FOR THE LOCAL DOMAINS
#================================================= #=================================================
# Trouve l'ipv4 associée à l'interface trouvée # Find the IP associated to the network interface
localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1) localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
# Liste les domaines de yunohost # List all YunoHost domains
while read perdomain while read perdomain
do do
# Commente les résolutions du domaine sur 127.0.0.1, qui risquerait de bloquer la résolution sur le réseau local # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution.
ynh_replace_string "^127.0.0.1.*$perdomain" "#Commented by pihole# &" /etc/hosts ynh_replace_string "^127.0.0.1.*$perdomain" "#Commented by pihole# &" /etc/hosts
# Et ajoute une résolution sur l'ip local à la place, si elle n'existe pas déjà # And add a resolution on the local IP instead
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 <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
@ -296,10 +302,10 @@ ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
# RESTART DNSMASQ # RESTART DNSMASQ
#================================================= #=================================================
ynh_system_reload --service_name=dnsmasq --action=restart ynh_systemd_action --action=restart --service_name=dnsmasq
#================================================= #=================================================
# INSTALL THE CRON JOB # INSTALL CRON JOB
#================================================= #=================================================
cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
@ -317,10 +323,10 @@ ynh_exec_warn_less /opt/pihole/gravity.sh
# START PIHOLE-FTL # START PIHOLE-FTL
#================================================= #=================================================
ynh_system_reload --service_name=pihole-FTL --action=restart ynh_systemd_action --action=restart --service_name=pihole-FTL
#================================================= #=================================================
# SET UP THE CONF_REGEN HOOK # SET UP CONF_REGEN HOOK
#================================================= #=================================================
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
@ -328,7 +334,7 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
#================================================= #=================================================
# ENABLE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add pihole-FTL --log "/var/log/pihole-FTL.log" yunohost service add pihole-FTL --log "/var/log/pihole-FTL.log"
@ -343,12 +349,15 @@ yunohost app addaccess --users=$admin $app
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_system_reload --service_name=nginx ynh_systemd_action --action=reload --service_name=nginx
#================================================= #=================================================
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN
#================================================= #=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
if [ $enable_dhcp -eq 1 ] if [ $enable_dhcp -eq 1 ]
then then
dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole. dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole.
@ -359,6 +368,9 @@ else
dhcp_alert="" dhcp_alert=""
fi fi
message="${dhcp_alert}If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/pihole_ynh" message="${dhcp_alert}You can configure this app easily by using the experimental config-panel feature: $admin_panel/config-panel.
You can also find some specific actions for this app by using the experimental action feature: $admin_panel/actions.
ynh_send_readme_to_admin --app_message="$message" --recipients="$admin" If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/pihole_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="$admin" --type="install"

View file

@ -21,20 +21,21 @@ port=$(ynh_app_setting_get $app port)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# DISABLE SERVICE IN ADMIN PANEL # REMOVE SERVICE FROM ADMIN PANEL
#================================================= #=================================================
if yunohost service status | grep -q pihole-FTL # Test l'existence du service dans Yunohost # Check if the service is declared in YunoHost
if yunohost service status | grep -q pihole-FTL
then then
ynh_print_info "Remove pihole-FTL service" >&2 ynh_print_info "Remove pihole-FTL service" >&2
yunohost service remove pihole-FTL yunohost service remove pihole-FTL
fi fi
#================================================= #=================================================
# STOP THE SERVICE PIHOLE-FTL # STOP PIHOLE-FTL SERVICE
#================================================= #=================================================
ynh_system_reload --service_name=pihole-FTL --action=stop ynh_systemd_action --action=stop --service_name=pihole-FTL
ynh_exec_warn_less systemctl disable pihole-FTL ynh_exec_warn_less systemctl disable pihole-FTL
rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "/var/run/pihole-FTL.port" rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "/var/run/pihole-FTL.port"
@ -42,31 +43,38 @@ rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE THE DIRECTORIES OF THE APP # REMOVE THE DIRECTORIES OF THE APP
#================================================= #=================================================
ynh_secure_remove "/etc/pihole" # Suppression du dossier de stockage l'application # Remove storage directory
ynh_secure_remove "/opt/pihole" # Suppression du dossier l'application ynh_secure_remove "/etc/pihole"
ynh_secure_remove "/var/www/pihole" # Suppression de l'interface de l'application # Remove app directory
ynh_secure_remove "/etc/.pihole" # Suppression du clone local du dépôt ynh_secure_remove "/opt/pihole"
# Remove admin panel directory
ynh_secure_remove "/var/www/pihole"
# Remove local clone of the repository
ynh_secure_remove "/etc/.pihole"
#================================================= #=================================================
# REMOVE THE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_remove_nginx_config # Suppression de la configuration nginx # Remove the dedicated nginx config
ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE THE PHP-FPM CONFIGURATION # REMOVE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_remove_fpm_config # Suppression de la configuration du pool php-fpm # Remove the dedicated php-fpm config
ynh_remove_fpm_config
#================================================= #=================================================
# CLOSE A PORT # CLOSE PORTS
#================================================= #=================================================
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
@ -84,7 +92,7 @@ fi
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE
#================================================= #=================================================
# REMOVE THE CRON FILE # REMOVE CRON FILE
#================================================= #=================================================
ynh_secure_remove "/etc/cron.d/pihole" ynh_secure_remove "/etc/cron.d/pihole"
@ -93,22 +101,22 @@ ynh_secure_remove "/etc/cron.d/pihole"
# REMOVE OTHER FILES # REMOVE OTHER FILES
#================================================= #=================================================
# Suppression des log # Remove logs
ynh_secure_remove "/var/log/pihole.log" ynh_secure_remove "/var/log/pihole.log"
ynh_secure_remove "/var/log/pihole-FTL.log" ynh_secure_remove "/var/log/pihole-FTL.log"
# Remove the main script # Remove main script
ynh_secure_remove "/usr/local/bin/pihole" ynh_secure_remove "/usr/local/bin/pihole"
ynh_secure_remove "/etc/bash_completion.d/pihole" ynh_secure_remove "/etc/bash_completion.d/pihole"
# Remove the sudoer file # Remove sudoer file
ynh_secure_remove "/etc/sudoers.d/pihole" ynh_secure_remove "/etc/sudoers.d/pihole"
#================================================= #=================================================
# REMOVE THE DNSMASQ CONFIG # REMOVE DNSMASQ CONFIG
#================================================= #=================================================
ynh_system_reload --service_name=dnsmasq --action=stop ynh_systemd_action --action=stop --service_name=dnsmasq
rm -f "/etc/dnsmasq.d/01-pihole.conf" rm -f "/etc/dnsmasq.d/01-pihole.conf"
rm -f "/etc/dnsmasq.d/02-pihole-dhcp.conf" rm -f "/etc/dnsmasq.d/02-pihole-dhcp.conf"
rm -f "/etc/dnsmasq.d/03-pihole-wildcard.conf" rm -f "/etc/dnsmasq.d/03-pihole-wildcard.conf"
@ -120,20 +128,20 @@ ynh_replace_string "#pihole# " "" /etc/dnsmasq.conf
# CLEAN /etc/hosts # CLEAN /etc/hosts
#================================================= #=================================================
# Restaure les résolutions qui avaient été commentées par pihole # Uncomment lines in /etc/hosts
sed -i "s/#Commented by pihole# //g" /etc/hosts sed -i "s/#Commented by pihole# //g" /etc/hosts
# Et supprime les lignes ajoutées par pihole # And remove extra lines, added by PiHole
sed -i "/#Added by pihole#/d" /etc/hosts sed -i "/#Added by pihole#/d" /etc/hosts
#================================================= #=================================================
# RESTART DNSMASQ # RESTART DNSMASQ
#================================================= #=================================================
ynh_system_reload --service_name=dnsmasq --action=restart ynh_systemd_action --action=restart --service_name=dnsmasq
#================================================= #=================================================
# REMOVE THE CONF_REGEN HOOK # REMOVE CONF_REGEN HOOK
#================================================= #=================================================
ynh_secure_remove /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app ynh_secure_remove /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app

View file

@ -48,13 +48,13 @@ ynh_maintenance_mode_ON
#================================================= #=================================================
# STANDARD RESTORE STEPS # STANDARD RESTORE STEPS
#================================================= #=================================================
# RESTORE OF THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE OF THE MAIN DIRECTORIES OF THE APP # RESTORE THE MAIN DIRECTORIES OF THE APP
#================================================= #=================================================
ynh_restore_file "$final_path" ynh_restore_file "$final_path"
@ -66,26 +66,26 @@ ynh_restore_file "/etc/pihole"
ynh_restore_file "/opt/pihole" ynh_restore_file "/opt/pihole"
#================================================= #=================================================
# RECREATE OF THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_system_user_create $app # Recreate the dedicated user, if not exist # Create the dedicated user (if not existing)
ynh_system_user_create $app
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
#================================================= #=================================================
# Les fichiers appartiennent à root # Restore permissions on app files
chown $app: -R "/etc/pihole" chown $app: -R "/etc/pihole"
# /etc/pihole/logrotate have to belong to root, otherwise logrotate will failed silently... # /etc/pihole/logrotate have to belong to root, otherwise logrotate will failed silently...
chown root: -R "/etc/pihole/logrotate" chown root: -R "/etc/pihole/logrotate"
#================================================= #=================================================
# RESTORE OF THE PHP-FPM CONFIGURATION # RESTORE THE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
#================================================= #=================================================
# SPECIFIC RESTORE # SPECIFIC RESTORE
@ -96,13 +96,13 @@ ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
ynh_install_app_dependencies $app_depencencies ynh_install_app_dependencies $app_depencencies
#================================================= #=================================================
# ENABLE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
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 THE CRON FILE
#================================================= #=================================================
ynh_restore_file "/etc/cron.d/pihole" ynh_restore_file "/etc/cron.d/pihole"
@ -117,7 +117,7 @@ dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
chown $dnsmasq_user:root /var/log/pihole.log chown $dnsmasq_user:root /var/log/pihole.log
#================================================= #=================================================
# RESTORE OF SPECIFIC FILES # RESTORE SPECIFIC FILES
#================================================= #=================================================
ynh_restore_file "/usr/local/bin/pihole" ynh_restore_file "/usr/local/bin/pihole"
@ -131,10 +131,10 @@ ynh_restore_file "/usr/bin/pihole-FTL"
ynh_restore_file "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" ynh_restore_file "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
#================================================= #=================================================
# RESTORE OF DNSMASQ CONFIG # RESTORE DNSMASQ CONFIG
#================================================= #=================================================
ynh_system_reload --service_name=dnsmasq --action=stop ynh_systemd_action --action=stop --service_name=dnsmasq
ynh_restore_file "/etc/dnsmasq.d/01-pihole.conf" ynh_restore_file "/etc/dnsmasq.d/01-pihole.conf"
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/02-pihole-dhcp.conf" && \ test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/02-pihole-dhcp.conf" && \
@ -144,25 +144,25 @@ test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" && \
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" && \ test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" && \
ynh_restore_file "/etc/dnsmasq.d/04-pihole-static-dhcp.conf" ynh_restore_file "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
# Pour éviter un conflit entre les config de dnsmasq, il faut commenter cache-size dans la config par défaut. # To prevent any conflict with the original dnsmasq config, comment cache-size in the original config.
ynh_replace_string "^cache-size=" "#pihole# cache-size=" /etc/dnsmasq.conf ynh_replace_string "^cache-size=" "#pihole# cache-size=" /etc/dnsmasq.conf
#================================================= #=================================================
# CONFIGURE DNS FOR THE LOCAL DOMAINS # CONFIGURE DNS FOR THE LOCAL DOMAINS
#================================================= #=================================================
# Trouve l'interface réseau par défaut # Get the default network interface
main_iface=$(ip route | grep default | awk '{print $5;}') main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
# Trouve l'ipv4 associée à l'interface trouvée # Find the IP associated to the network interface
localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1) localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
# Liste les domaines de yunohost # List all YunoHost domains
while read perdomain while read perdomain
do do
# Commente les résolutions du domaine sur 127.0.0.1, qui risquerait de bloquer la résolution sur le réseau local # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution.
sed -i "s/^127.0.0.1.*$perdomain/#Commented by pihole# &/g" /etc/hosts sed -i "s/^127.0.0.1.*$perdomain/#Commented by pihole# &/g" /etc/hosts
# Et ajoute une résolution sur l'ip local à la place, si elle n'existe pas déjà # And add a resolution on the local IP instead
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 <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')" done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
@ -171,10 +171,10 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
# RESTART DNSMASQ # RESTART DNSMASQ
#================================================= #=================================================
ynh_system_reload --service_name=dnsmasq --action=restart ynh_systemd_action --action=restart --service_name=dnsmasq
#================================================= #=================================================
# UPDATE THE VARIABLES FILE # UPDATE VARIABLES FILE
#================================================= #=================================================
setupVars="/etc/pihole/setupVars.conf" setupVars="/etc/pihole/setupVars.conf"
@ -183,14 +183,15 @@ echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
ynh_replace_string "^PIHOLE_INTERFACE=.*" "PIHOLE_INTERFACE=$main_iface" $setupVars ynh_replace_string "^PIHOLE_INTERFACE=.*" "PIHOLE_INTERFACE=$main_iface" $setupVars
ynh_replace_string "^IPV4_ADDRESS=.*" "IPV4_ADDRESS=127.0.0.1" $setupVars ynh_replace_string "^IPV4_ADDRESS=.*" "IPV4_ADDRESS=127.0.0.1" $setupVars
ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichier de config # Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$setupVars"
#================================================= #=================================================
# START PIHOLE-FTL # START PIHOLE-FTL
#================================================= #=================================================
ynh_exec_warn_less systemctl enable pihole-FTL ynh_exec_warn_less systemctl enable pihole-FTL
ynh_system_reload --service_name=pihole-FTL --action=restart ynh_systemd_action --action=restart --service_name=pihole-FTL
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
@ -198,8 +199,8 @@ ynh_system_reload --service_name=pihole-FTL --action=restart
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
ynh_system_reload --service_name=php5-fpm ynh_systemd_action --action=reload --service_name=php5-fpm
ynh_system_reload --service_name=nginx ynh_systemd_action --action=reload --service_name=nginx
#================================================= #=================================================
# DEACTIVE MAINTENANCE MODE # DEACTIVE MAINTENANCE MODE
@ -211,6 +212,9 @@ ynh_maintenance_mode_OFF
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN
#================================================= #=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
if [ $enable_dhcp -eq 1 ] if [ $enable_dhcp -eq 1 ]
then then
dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole. dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole.
@ -221,6 +225,9 @@ else
dhcp_alert="" dhcp_alert=""
fi fi
message="${dhcp_alert}If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/pihole_ynh" message="${dhcp_alert}You can configure this app easily by using the experimental config-panel feature: $admin_panel/config-panel.
You can also find some specific actions for this app by using the experimental action feature: $admin_panel/actions.
ynh_send_readme_to_admin --app_message="$message" --recipients="$admin" If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/pihole_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="$admin" --type="restore"

View file

@ -22,6 +22,7 @@ path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin) admin=$(ynh_app_setting_get $app admin)
query_logging=$(ynh_app_setting_get $app query_logging) query_logging=$(ynh_app_setting_get $app query_logging)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
enable_dhcp=$(ynh_app_setting_get $app enable_dhcp)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get $app port)
overwrite_setupvars=$(ynh_app_setting_get $app overwrite_setupvars) overwrite_setupvars=$(ynh_app_setting_get $app overwrite_setupvars)
overwrite_ftl=$(ynh_app_setting_get $app overwrite_ftl) overwrite_ftl=$(ynh_app_setting_get $app overwrite_ftl)
@ -79,7 +80,8 @@ ynh_abort_if_errors
# CHECK THE PATH # CHECK THE PATH
#================================================= #=================================================
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path. # Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#================================================= #=================================================
# ACTIVATE MAINTENANCE MODE # ACTIVATE MAINTENANCE MODE
@ -102,9 +104,9 @@ ynh_install_app_dependencies $app_depencencies
pihole_local_repo="/etc/.pihole" pihole_local_repo="/etc/.pihole"
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
# Update la copie du repo de pihole (nécessaire pour Gravity) # Update the local copy pihole repository (for Gravity)
ynh_setup_source "$pihole_local_repo" ynh_setup_source "$pihole_local_repo"
# Update le dashboard admin # Update admin dashboard
ynh_setup_source "$final_path" admin_dashboard ynh_setup_source "$final_path" admin_dashboard
fi fi
@ -115,6 +117,7 @@ fi
# Overwrite the nginx configuration only if it's allowed # Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ] if [ $overwrite_nginx -eq 1 ]
then then
# Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
fi fi
@ -122,7 +125,8 @@ fi
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_system_user_create $app # Create the dedicated user, if not exist # Create a dedicated user (if not existing)
ynh_system_user_create $app
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
@ -131,7 +135,8 @@ ynh_system_user_create $app # Create the dedicated user, if not exist
# Overwrite the php-fpm configuration only if it's allowed # Overwrite the php-fpm configuration only if it's allowed
if [ $overwrite_phpfpm -eq 1 ] if [ $overwrite_phpfpm -eq 1 ]
then then
ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure. # Create a dedicated php-fpm config
ynh_add_fpm_config
fi fi
#================================================= #=================================================
@ -140,7 +145,6 @@ fi
# UPDATE PI-HOLE SCRIPTS # UPDATE PI-HOLE SCRIPTS
#================================================= #=================================================
# Update les scripts de Pi-hole
pihole_dir="/opt/pihole" pihole_dir="/opt/pihole"
cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/" cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/" cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
@ -149,7 +153,7 @@ cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/" cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
#================================================= #=================================================
# Copy the Pi-hole main script # COPY PI-HOLE MAIN SCRIPT
#================================================= #=================================================
cp -a "$pihole_local_repo/pihole" /usr/local/bin/ cp -a "$pihole_local_repo/pihole" /usr/local/bin/
@ -159,7 +163,7 @@ cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.
# CREATE SUDOER FILE # CREATE SUDOER FILE
#================================================= #=================================================
# Cette configuration sudoers autorise pihole à exécuter /usr/local/bin/pihole en root sans mot de passe. Pas plus. # 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 cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
chmod 0440 /etc/sudoers.d/pihole chmod 0440 /etc/sudoers.d/pihole
@ -174,10 +178,10 @@ dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
sed -i "/# su #/d;" "$pihole_storage/logrotate" sed -i "/# su #/d;" "$pihole_storage/logrotate"
#================================================= #=================================================
# UPDATE OF PIHOLE-FTL # UPDATE PIHOLE-FTL
#================================================= #=================================================
ynh_system_reload --service_name=pihole-FTL --action=stop ynh_systemd_action --action=stop --service_name=pihole-FTL
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
@ -185,19 +189,21 @@ then
FTL_temp_path=$(mktemp -d) FTL_temp_path=$(mktemp -d)
ynh_setup_source "$FTL_temp_path" FTL ynh_setup_source "$FTL_temp_path" FTL
# Plutôt que télécharger le binaire C, on le compile nous-même. # Instead of downloading a binary file, we're going to compile it
( cd "$FTL_temp_path" ( cd "$FTL_temp_path"
ynh_exec_warn_less make ynh_exec_warn_less make
ynh_exec_warn_less make install ) ynh_exec_warn_less make install )
ynh_secure_remove "$FTL_temp_path" ynh_secure_remove "$FTL_temp_path"
fi fi
# Overwrite the pihole-FTL config file only if it's allowed # Overwrite pihole-FTL config file only if it's allowed
if [ $overwrite_ftl -eq 1 ] if [ $overwrite_ftl -eq 1 ]
then then
ynh_backup_if_checksum_is_different "$pihole_storage/pihole-FTL.conf" # Créé un backup du fichier de config si il a été modifié. # Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different "$pihole_storage/pihole-FTL.conf"
cp "../conf/pihole-FTL.conf" "$pihole_storage" cp "../conf/pihole-FTL.conf" "$pihole_storage"
ynh_store_file_checksum "$pihole_storage/pihole-FTL.conf" # Enregistre la somme de contrôle du fichier de config # Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$pihole_storage/pihole-FTL.conf"
fi fi
cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
@ -205,7 +211,7 @@ chmod +x /etc/init.d/pihole-FTL
ynh_exec_warn_less systemctl enable pihole-FTL ynh_exec_warn_less systemctl enable pihole-FTL
#================================================= #=================================================
# BUILD THE VARIABLES FILE # BUILD VARIABLES FILE
#================================================= #=================================================
setupVars="$pihole_storage/setupVars.conf" setupVars="$pihole_storage/setupVars.conf"
@ -213,10 +219,11 @@ setupVars="$pihole_storage/setupVars.conf"
# Overwrite the setupVars config file only if it's allowed # Overwrite the setupVars config file only if it's allowed
if [ $overwrite_setupvars -eq 1 ] if [ $overwrite_setupvars -eq 1 ]
then then
ynh_backup_if_checksum_is_different "$setupVars" # Créé un backup du fichier de config si il a été modifié. # Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different "$setupVars"
# Trouve l'interface réseau par défaut # Get the default network interface
main_iface=$(ip route | grep default | awk '{print $5;}') main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
echo "PIHOLE_INTERFACE=$main_iface" > $setupVars echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
echo "IPV6_ADDRESS=" >> $setupVars echo "IPV6_ADDRESS=" >> $setupVars
@ -230,11 +237,12 @@ then
echo "QUERY_LOGGING=$query_logging" >> $setupVars echo "QUERY_LOGGING=$query_logging" >> $setupVars
echo "INSTALL_WEB=true" >> $setupVars echo "INSTALL_WEB=true" >> $setupVars
ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichier de config # Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$setupVars"
fi fi
#================================================= #=================================================
# UPDATE THE CRON JOB # UPDATE CRON JOB
#================================================= #=================================================
cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
@ -245,10 +253,10 @@ ynh_replace_string ".*updatechecker.*" "#&" /etc/cron.d/pihole
# START PIHOLE-FTL # START PIHOLE-FTL
#================================================= #=================================================
ynh_system_reload --service_name=pihole-FTL --action=restart ynh_systemd_action --action=restart --service_name=pihole-FTL
#================================================= #=================================================
# UPDATE THE CONF_REGEN HOOK # UPDATE CONF_REGEN HOOK
#================================================= #=================================================
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
@ -257,10 +265,34 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_system_reload --service_name=nginx ynh_systemd_action --action=reload --service_name=nginx
#================================================= #=================================================
# DEACTIVE MAINTENANCE MODE # DEACTIVE MAINTENANCE MODE
#================================================= #=================================================
ynh_maintenance_mode_OFF ynh_maintenance_mode_OFF
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
if [ $enable_dhcp -eq 1 ]
then
dhcp_alert="You asked to use the internal DHCP server of dnsmasq with PiHole.
You should really read the documentation about that, https://github.com/YunoHost-Apps/pihole_ynh/blob/master/dhcp.md
"
else
dhcp_alert=""
fi
message="${dhcp_alert}You can configure this app easily by using the experimental config-panel feature: $admin_panel/config-panel.
You can also find some specific actions for this app by using the experimental action feature: $admin_panel/actions.
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/pihole_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="$admin" --type="upgrade"