mirror of
https://github.com/YunoHost-Apps/pihole_ynh.git
synced 2024-09-03 20:05:58 +02:00
commit
2ed3e8a81f
13 changed files with 550 additions and 460 deletions
12
README.md
12
README.md
|
@ -39,14 +39,14 @@ Use the admin panel of your Pi-hole to configure this app.
|
|||
|
||||
#### Supported architectures
|
||||
|
||||
* x86-64b - [/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)/)
|
||||
* ARMv8-A - [%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/)
|
||||
* Jessie x86-64b - [/badge/icon)](https://ci-stretch.nohost.me/jenkins/job/pihole%20(Community)/)
|
||||
* x86-64b - [](https://ci-apps.yunohost.org/ci/apps/pihole/)
|
||||
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/pihole/)
|
||||
* Jessie x86-64b - [](https://ci-stretch.nohost.me/ci/apps/pihole/)
|
||||
|
||||
## Limitations
|
||||
|
||||
* 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
|
||||
|
||||
|
@ -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.
|
||||
```
|
||||
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
|
||||
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
|
||||
```
|
||||
|
|
12
README_fr.md
12
README_fr.md
|
@ -39,14 +39,14 @@ Utiliser le panneau d'administration de votre Pi-hole pour configurer cette appl
|
|||
|
||||
#### Architectures supportées.
|
||||
|
||||
* x86-64b - [/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)/)
|
||||
* ARMv8-A - [%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/)
|
||||
* Jessie x86-64b - [/badge/icon)](https://ci-stretch.nohost.me/jenkins/job/pihole%20(Community)/)
|
||||
* x86-64b - [](https://ci-apps.yunohost.org/ci/apps/pihole/)
|
||||
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/pihole/)
|
||||
* Jessie x86-64b - [](https://ci-stretch.nohost.me/ci/apps/pihole/)
|
||||
|
||||
## Limitations
|
||||
|
||||
* 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
|
||||
|
||||
|
@ -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.
|
||||
```
|
||||
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
|
||||
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
|
||||
```
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
; upload_max_filesize=100M
|
||||
; post_max_size=100M
|
||||
; max_execution_time=60
|
|
@ -6,7 +6,7 @@
|
|||
"en": "Network-wide ad blocking via your own DNS server.",
|
||||
"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/",
|
||||
"license": "EUPL-1.2",
|
||||
"maintainer": {
|
||||
|
@ -14,7 +14,7 @@
|
|||
"email": "maniackc_dev@crudelis.fr"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.7.14"
|
||||
"yunohost": ">= 3.3.3"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
|
|
|
@ -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]
|
||||
#
|
||||
# example: function my_helper()
|
||||
# {
|
||||
# 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)
|
||||
# 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 key=""
|
||||
for key in "${!args_array[@]}"
|
||||
local option_flag=""
|
||||
for option_flag in "${!args_array[@]}"
|
||||
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
|
||||
# If the value of a key 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
|
||||
if [ "${args_array[$key]: -1}" = "=" ]
|
||||
# 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 option_flag
|
||||
if [ "${args_array[$option_flag]: -1}" = "=" ]
|
||||
then
|
||||
# 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
|
||||
getopts_parameters="${getopts_parameters}${key}"
|
||||
getopts_parameters="${getopts_parameters}${option_flag}"
|
||||
fi
|
||||
# Check each argument given to the function
|
||||
local arg=""
|
||||
# ${#arguments[@]} is the size of the array
|
||||
for arg in `seq 0 $(( ${#arguments[@]} - 1 ))`
|
||||
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)
|
||||
# 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 =
|
||||
arguments[arg]="${arguments[arg]//--${args_array[$key]%=}/-${key}}"
|
||||
arguments[arg]="${arguments[arg]//--${args_array[$option_flag]%=}/-${option_flag}}"
|
||||
done
|
||||
done
|
||||
|
||||
|
@ -148,10 +150,10 @@ ynh_handle_getopts_args () {
|
|||
|
||||
if [ "$parameter" = "?" ]
|
||||
then
|
||||
ynh_die "Invalid argument: -${OPTARG:-}"
|
||||
ynh_die --message="Invalid argument: -${OPTARG:-}"
|
||||
elif [ "$parameter" = ":" ]
|
||||
then
|
||||
ynh_die "-$OPTARG parameter requires an argument."
|
||||
ynh_die --message="-$OPTARG parameter requires an argument."
|
||||
else
|
||||
local shift_value=1
|
||||
# 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 ))
|
||||
fi
|
||||
|
||||
# Declare the content of option_var as a variable.
|
||||
eval ${option_var}=""
|
||||
# Then read the array value per value
|
||||
local i
|
||||
for i in `seq 0 $(( ${#all_args[@]} - 1 ))`
|
||||
do
|
||||
# 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
|
||||
# Ignore the first value of the array, which is the option itself
|
||||
if [ "$i" -ne 0 ]; then
|
||||
break
|
||||
fi
|
||||
else
|
||||
# Declare the content of option_var as a variable.
|
||||
eval ${option_var}=""
|
||||
# Else, add this value to this option
|
||||
# Each value will be separated by ';'
|
||||
if [ -n "${!option_var}" ]
|
||||
|
@ -215,25 +218,33 @@ ynh_handle_getopts_args () {
|
|||
# Check if there's getopts arguments
|
||||
if [ "${arguments[0]:0:1}" != "-" ]
|
||||
then
|
||||
# If not, enter in legacy mode and manage the arguments as positionnal ones.
|
||||
echo "! Helper used in legacy mode !"
|
||||
# If not, enter in legacy mode and manage the arguments as positionnal ones..
|
||||
# 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 ))`
|
||||
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
|
||||
getopts_parameters=${getopts_parameters//:}
|
||||
# Get the key from getopts_parameters, by using the key according to the position of the argument.
|
||||
key=${getopts_parameters:$i:1}
|
||||
# Use the long option, corresponding to the key, as a variable
|
||||
getopts_parameters=${legacy_args:-${getopts_parameters//:}}
|
||||
# Get the option_flag from getopts_parameters, by using the option_flag according to the position of the argument.
|
||||
option_flag=${getopts_parameters:$i:1}
|
||||
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)
|
||||
# Also, remove '=' at the end of the long option
|
||||
# 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
|
||||
# The values will be stored in the same order than $args_array
|
||||
eval ${option_var}+=\"${arguments[$i]}\"
|
||||
done
|
||||
unset legacy_args
|
||||
else
|
||||
# END LEGACY MODE
|
||||
# Call parse_arg and pass the modified list of args as an array of arguments.
|
||||
|
@ -245,197 +256,28 @@ 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
|
||||
#
|
||||
# usage: ynh_multimedia_build_main_dir
|
||||
ynh_multimedia_build_main_dir () {
|
||||
local ynh_media_release="v1.0"
|
||||
local checksum="4852c8607db820ad51f348da0dcf0c88"
|
||||
local ynh_media_release="v1.2"
|
||||
local checksum="806a827ba1902d6911095602a9221181"
|
||||
|
||||
# Download yunohost.multimedia scripts
|
||||
wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
|
||||
# Download yunohost.multimedia scripts
|
||||
wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
|
||||
|
||||
# Check the control sum
|
||||
echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
|
||||
|| ynh_die "Corrupt source"
|
||||
# Check the control sum
|
||||
echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
|
||||
|| ynh_die "Corrupt source"
|
||||
|
||||
# Extract
|
||||
mkdir yunohost.multimedia-master
|
||||
tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
|
||||
./yunohost.multimedia-master/script/ynh_media_build.sh
|
||||
# Check if the package acl is installed. Or install it.
|
||||
ynh_package_is_installed 'acl' \
|
||||
|| ynh_package_install acl
|
||||
|
||||
# Extract
|
||||
mkdir yunohost.multimedia-master
|
||||
tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
|
||||
./yunohost.multimedia-master/script/ynh_media_build.sh
|
||||
}
|
||||
|
||||
# Add a directory in yunohost.multimedia
|
||||
|
@ -496,26 +338,31 @@ ynh_multimedia_addaccess () {
|
|||
# Create a dedicated fail2ban config (jail and filter conf files)
|
||||
#
|
||||
# usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]]
|
||||
# | arg: log_file - Log file to be checked by fail2ban
|
||||
# | arg: failregex - Failregex to be looked for by fail2ban
|
||||
# | arg: 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: -l, --logpath= - Log file to be checked by fail2ban
|
||||
# | arg: -r, --failregex= - Failregex to be looked for by fail2ban
|
||||
# | arg: -m, --max_retry= - Maximum number of retries allowed before banning IP address - default: 3
|
||||
# | arg: -p, --ports= - Ports blocked for a banned IP address - default: http,https
|
||||
ynh_add_fail2ban_config () {
|
||||
# Process parameters
|
||||
logpath=$1
|
||||
failregex=$2
|
||||
max_retry=${3:-3}
|
||||
ports=${4:-http,https}
|
||||
# Declare an array to define the options of this helper.
|
||||
declare -Ar args_array=( [l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= )
|
||||
local logpath
|
||||
local failregex
|
||||
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 "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second 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."
|
||||
|
||||
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
|
||||
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
|
||||
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
|
||||
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
|
||||
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
|
||||
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
|
||||
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
|
||||
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
|
||||
|
||||
sudo tee $finalfail2banjailconf <<EOF
|
||||
tee $finalfail2banjailconf <<EOF
|
||||
[$app]
|
||||
enabled = true
|
||||
port = $ports
|
||||
|
@ -524,7 +371,7 @@ logpath = $logpath
|
|||
maxretry = $max_retry
|
||||
EOF
|
||||
|
||||
sudo tee $finalfail2banfilterconf <<EOF
|
||||
tee $finalfail2banfilterconf <<EOF
|
||||
[INCLUDES]
|
||||
before = common.conf
|
||||
[Definition]
|
||||
|
@ -532,25 +379,33 @@ failregex = $failregex
|
|||
ignoreregex =
|
||||
EOF
|
||||
|
||||
ynh_store_file_checksum "$finalfail2banjailconf"
|
||||
ynh_store_file_checksum "$finalfail2banfilterconf"
|
||||
ynh_store_file_checksum "$finalfail2banjailconf"
|
||||
ynh_store_file_checksum "$finalfail2banfilterconf"
|
||||
|
||||
systemctl restart fail2ban
|
||||
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
||||
if [ -n "$fail2ban_error" ]
|
||||
then
|
||||
echo "[ERR] Fail2ban failed to load the jail for $app" >&2
|
||||
echo "WARNING${fail2ban_error#*WARNING}" >&2
|
||||
fi
|
||||
if [ "$(lsb_release --codename --short)" != "jessie" ]; then
|
||||
systemctl reload fail2ban
|
||||
else
|
||||
systemctl restart fail2ban
|
||||
fi
|
||||
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
||||
if [ -n "$fail2ban_error" ]
|
||||
then
|
||||
echo "[ERR] Fail2ban failed to load the jail for $app" >&2
|
||||
echo "WARNING${fail2ban_error#*WARNING}" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove the dedicated fail2ban config (jail and filter conf files)
|
||||
#
|
||||
# usage: ynh_remove_fail2ban_config
|
||||
ynh_remove_fail2ban_config () {
|
||||
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
|
||||
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
|
||||
systemctl restart fail2ban
|
||||
ynh_secure_remove "/etc/fail2ban/jail.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
|
||||
fi
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
@ -558,12 +413,17 @@ ynh_remove_fail2ban_config () {
|
|||
# Read the value of a key in a ynh manifest file
|
||||
#
|
||||
# usage: ynh_read_manifest manifest key
|
||||
# | arg: manifest - Path of the manifest to read
|
||||
# | arg: key - Name of the key to find
|
||||
# | arg: -m, --manifest= - Path of the manifest to read
|
||||
# | arg: -k, --key= - Name of the key to find
|
||||
ynh_read_manifest () {
|
||||
manifest="$1"
|
||||
key="$2"
|
||||
python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])"
|
||||
# Declare an array to define the options of this helper.
|
||||
declare -Ar args_array=( [m]=manifest= [k]=manifest_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
|
||||
|
@ -572,16 +432,21 @@ ynh_read_manifest () {
|
|||
# This include the number before ~ynh
|
||||
# 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 () {
|
||||
manifest_path="../manifest.json"
|
||||
if [ ! -e "$manifest_path" ]; then
|
||||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||
fi
|
||||
version_key=$(ynh_read_manifest "$manifest_path" "version")
|
||||
echo "${version_key/~ynh*/}"
|
||||
}
|
||||
declare -Ar args_array=( [m]=manifest= )
|
||||
local manifest
|
||||
# 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
|
||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
||||
echo "${version_key/~ynh*/}"
|
||||
}
|
||||
|
||||
# Read package version from the manifest
|
||||
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
|
||||
|
@ -589,14 +454,20 @@ ynh_app_upstream_version () {
|
|||
# This include the number after ~ynh
|
||||
# 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 () {
|
||||
manifest_path="../manifest.json"
|
||||
if [ ! -e "$manifest_path" ]; then
|
||||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||
fi
|
||||
version_key=$(ynh_read_manifest "$manifest_path" "version")
|
||||
echo "${version_key/*~ynh/}"
|
||||
declare -Ar args_array=( [m]=manifest= )
|
||||
local manifest
|
||||
# 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
|
||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
||||
echo "${version_key/*~ynh/}"
|
||||
}
|
||||
|
||||
# Checks the app version to upgrade with the existing app version and returns:
|
||||
|
@ -611,58 +482,173 @@ ynh_app_package_version () {
|
|||
# To force an upgrade, even if the package is up to date,
|
||||
# you have to set the variable YNH_FORCE_UPGRADE before.
|
||||
# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
|
||||
|
||||
#
|
||||
# usage: ynh_check_app_version_changed
|
||||
ynh_check_app_version_changed () {
|
||||
local force_upgrade=${YNH_FORCE_UPGRADE:-0}
|
||||
local package_check=${PACKAGE_CHECK_EXEC:-0}
|
||||
local force_upgrade=${YNH_FORCE_UPGRADE:-0}
|
||||
local package_check=${PACKAGE_CHECK_EXEC:-0}
|
||||
|
||||
# By default, upstream app version has changed
|
||||
local return_value="UPGRADE_APP"
|
||||
# By default, upstream app version has changed
|
||||
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_upstream_version="${current_version/~ynh*/}"
|
||||
local update_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0)
|
||||
local update_upstream_version="${update_version/~ynh*/}"
|
||||
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="$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json")"
|
||||
local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0)
|
||||
local update_upstream_version="$(ynh_app_upstream_version)"
|
||||
|
||||
if [ "$current_version" == "$update_version" ] ; then
|
||||
# Complete versions are the same
|
||||
if [ "$force_upgrade" != "0" ]
|
||||
then
|
||||
echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2
|
||||
unset YNH_FORCE_UPGRADE
|
||||
elif [ "$package_check" != "0" ]
|
||||
then
|
||||
echo "Upgrade forced for package check." >&2
|
||||
else
|
||||
ynh_die "Up-to-date, nothing to do" 0
|
||||
fi
|
||||
elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then
|
||||
# Upstream versions are the same, only YunoHost package versions differ
|
||||
return_value="UPGRADE_PACKAGE"
|
||||
fi
|
||||
echo $return_value
|
||||
if [ "$current_version" == "$update_version" ] ; then
|
||||
# Complete versions are the same
|
||||
if [ "$force_upgrade" != "0" ]
|
||||
then
|
||||
echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2
|
||||
unset YNH_FORCE_UPGRADE
|
||||
elif [ "$package_check" != "0" ]
|
||||
then
|
||||
echo "Upgrade forced for package check." >&2
|
||||
else
|
||||
ynh_die "Up-to-date, nothing to do" 0
|
||||
fi
|
||||
elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then
|
||||
# Upstream versions are the same, only YunoHost package versions differ
|
||||
return_value="UPGRADE_PACKAGE"
|
||||
fi
|
||||
echo $return_value
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
||||
# 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
|
||||
#
|
||||
# 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: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
|
||||
# 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
|
||||
# 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() {
|
||||
# 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 recipients
|
||||
local type
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
local app_message="${app_message:-...No specific information...}"
|
||||
local recipients="${recipients:-root}"
|
||||
app_message="${app_message:-...No specific information...}"
|
||||
recipients="${recipients:-root}"
|
||||
type="${type:-install}"
|
||||
|
||||
# Retrieve the email of users
|
||||
find_mails () {
|
||||
|
@ -688,7 +674,23 @@ ynh_send_readme_to_admin() {
|
|||
}
|
||||
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.
|
||||
|
||||
|
@ -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 () {
|
||||
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 () {
|
||||
# Load value of $path_url and $domain from the config if their not set
|
||||
if [ -z $path_url ]; then
|
||||
|
@ -848,3 +817,69 @@ ynh_maintenance_mode_OFF () {
|
|||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# Dependencies
|
||||
app_depencencies="sqlite idn2"
|
||||
# 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"
|
||||
else
|
||||
app_depencencies="$app_depencencies php5-sqlite"
|
||||
|
|
|
@ -41,7 +41,7 @@ if [ "$file" = "setupVars.conf" ]
|
|||
then
|
||||
# Recreate the default config
|
||||
# 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 "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
|
||||
echo "IPV6_ADDRESS=" >> "$config_file"
|
||||
|
@ -61,7 +61,7 @@ then
|
|||
cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
|
||||
|
||||
# Restart pihole-FTL
|
||||
ynh_system_reload --service_name=pihole-FTL --action=restart
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL
|
||||
fi
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
|
|
|
@ -29,7 +29,7 @@ domain=$(ynh_app_setting_get $app domain)
|
|||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP OF THE MAIN DIRECTORIES OF THE APP
|
||||
# BACKUP THE MAIN APP DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
CHECK_SIZE "$final_path"
|
||||
|
@ -45,28 +45,27 @@ CHECK_SIZE "/opt/pihole"
|
|||
ynh_backup "/opt/pihole"
|
||||
|
||||
#=================================================
|
||||
# BACKUP OF THE NGINX CONFIGURATION
|
||||
# BACKUP NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
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/conf.d/20-$app.ini"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC BACKUP
|
||||
#=================================================
|
||||
# BACKUP OF THE CRON FILE
|
||||
# BACKUP CRON FILE
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/cron.d/pihole"
|
||||
|
||||
#=================================================
|
||||
# BACKUP OF SPECIFIC FILES
|
||||
# BACKUP SPECIFIC FILES
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/usr/local/bin/pihole"
|
||||
|
|
|
@ -109,7 +109,7 @@ fi
|
|||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
ynh_system_reload --service_name=nginx
|
||||
ynh_systemd_action --action=reload --service_name=nginx
|
||||
|
||||
#=================================================
|
||||
# DEACTIVE MAINTENANCE MODE
|
||||
|
|
|
@ -15,7 +15,8 @@ source _variables
|
|||
# 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
|
||||
|
@ -39,8 +40,6 @@ test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|||
# Normalize the url path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
# Check web path availability
|
||||
ynh_webpath_available $domain $path_url
|
||||
# Register (book) web path
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
|
||||
|
@ -64,16 +63,17 @@ ynh_app_setting_set $app overwrite_phpfpm "1"
|
|||
# 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 ]
|
||||
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."
|
||||
fi
|
||||
# Ouvre le port dans le firewall
|
||||
# Open this port
|
||||
ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $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 allow Both 53 --no-upnp
|
||||
|
||||
|
@ -88,34 +88,37 @@ ynh_install_app_dependencies $app_depencencies
|
|||
#=================================================
|
||||
|
||||
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"
|
||||
ynh_setup_source "$pihole_local_repo"
|
||||
# Installe le dashboard admin
|
||||
# Install admin dashboard
|
||||
ynh_setup_source "$final_path" admin_dashboard
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# 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
|
||||
#=================================================
|
||||
|
||||
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
|
||||
#=================================================
|
||||
# CREATE THE DIRECTORIES AND POPULATE THEM
|
||||
# CREATE DIRECTORIES AND POPULATE THEM
|
||||
#=================================================
|
||||
|
||||
pihole_storage="/etc/pihole"
|
||||
|
@ -125,7 +128,7 @@ chown $app: -R "$pihole_storage"
|
|||
pihole_dir="/opt/pihole"
|
||||
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/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/"
|
||||
|
||||
#=================================================
|
||||
# COPY THE PI-HOLE MAIN SCRIPT
|
||||
# COPY PI-HOLE MAIN SCRIPT
|
||||
#=================================================
|
||||
|
||||
cp -a "$pihole_local_repo/pihole" /usr/local/bin/
|
||||
|
@ -152,7 +155,7 @@ chown $dnsmasq_user:root /var/log/pihole.log
|
|||
# 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
|
||||
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
|
||||
|
@ -173,27 +176,28 @@ sed -i "/# su #/d;" "$pihole_storage/logrotate"
|
|||
FTL_temp_path=$(mktemp -d)
|
||||
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"
|
||||
ynh_exec_warn_less make
|
||||
ynh_exec_warn_less make install )
|
||||
ynh_secure_remove "$FTL_temp_path"
|
||||
|
||||
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
|
||||
chmod +x /etc/init.d/pihole-FTL
|
||||
ynh_exec_warn_less systemctl enable pihole-FTL
|
||||
|
||||
#=================================================
|
||||
# BUILD THE VARIABLES FILE
|
||||
# BUILD VARIABLES FILE
|
||||
#=================================================
|
||||
|
||||
setupVars="$pihole_storage/setupVars.conf"
|
||||
|
||||
# Trouve l'interface réseau par défaut
|
||||
main_iface=$(ip route | grep default | awk '{print $5;}')
|
||||
# Get the default network interface
|
||||
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
|
||||
echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
|
||||
echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
|
||||
echo "IPV6_ADDRESS=" >> $setupVars
|
||||
|
@ -207,17 +211,18 @@ fi
|
|||
echo "QUERY_LOGGING=$query_logging" >> $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"
|
||||
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 "@DNS2@" "" $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.
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# 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)
|
||||
|
||||
# Liste les domaines de yunohost
|
||||
# List all YunoHost domains
|
||||
while read perdomain
|
||||
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
|
||||
|
||||
# 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 || \
|
||||
echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts
|
||||
done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
|
||||
|
@ -296,10 +302,10 @@ ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
|
|||
# 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
|
||||
|
@ -317,10 +323,10 @@ ynh_exec_warn_less /opt/pihole/gravity.sh
|
|||
# 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
|
||||
|
@ -328,7 +334,7 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas
|
|||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# ENABLE SERVICE IN ADMIN PANEL
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
|
||||
yunohost service add pihole-FTL --log "/var/log/pihole-FTL.log"
|
||||
|
@ -343,12 +349,15 @@ yunohost app addaccess --users=$admin $app
|
|||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
ynh_system_reload --service_name=nginx
|
||||
ynh_systemd_action --action=reload --service_name=nginx
|
||||
|
||||
#=================================================
|
||||
# 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.
|
||||
|
@ -359,6 +368,9 @@ else
|
|||
dhcp_alert=""
|
||||
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"
|
||||
|
|
|
@ -21,20 +21,21 @@ port=$(ynh_app_setting_get $app port)
|
|||
#=================================================
|
||||
# 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
|
||||
ynh_print_info "Remove pihole-FTL service" >&2
|
||||
yunohost service remove pihole-FTL
|
||||
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
|
||||
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 metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE DIRECTORIES OF THE APP
|
||||
#=================================================
|
||||
|
||||
ynh_secure_remove "/etc/pihole" # Suppression du dossier de stockage l'application
|
||||
ynh_secure_remove "/opt/pihole" # Suppression du dossier l'application
|
||||
ynh_secure_remove "/var/www/pihole" # Suppression de l'interface de l'application
|
||||
ynh_secure_remove "/etc/.pihole" # Suppression du clone local du dépôt
|
||||
# Remove storage directory
|
||||
ynh_secure_remove "/etc/pihole"
|
||||
# Remove app directory
|
||||
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$"
|
||||
|
@ -84,7 +92,7 @@ fi
|
|||
#=================================================
|
||||
# SPECIFIC REMOVE
|
||||
#=================================================
|
||||
# REMOVE THE CRON FILE
|
||||
# REMOVE CRON FILE
|
||||
#=================================================
|
||||
|
||||
ynh_secure_remove "/etc/cron.d/pihole"
|
||||
|
@ -93,22 +101,22 @@ ynh_secure_remove "/etc/cron.d/pihole"
|
|||
# REMOVE OTHER FILES
|
||||
#=================================================
|
||||
|
||||
# Suppression des log
|
||||
# Remove logs
|
||||
ynh_secure_remove "/var/log/pihole.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 "/etc/bash_completion.d/pihole"
|
||||
|
||||
# Remove the sudoer file
|
||||
# Remove sudoer file
|
||||
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/02-pihole-dhcp.conf"
|
||||
rm -f "/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||
|
@ -120,20 +128,20 @@ ynh_replace_string "#pihole# " "" /etc/dnsmasq.conf
|
|||
# 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
|
||||
|
||||
# Et supprime les lignes ajoutées par pihole
|
||||
# And remove extra lines, added by PiHole
|
||||
sed -i "/#Added by pihole#/d" /etc/hosts
|
||||
|
||||
#=================================================
|
||||
# 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
|
||||
|
|
|
@ -48,13 +48,13 @@ ynh_maintenance_mode_ON
|
|||
#=================================================
|
||||
# STANDARD RESTORE STEPS
|
||||
#=================================================
|
||||
# RESTORE OF THE NGINX CONFIGURATION
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
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"
|
||||
|
@ -66,26 +66,26 @@ ynh_restore_file "/etc/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
|
||||
#=================================================
|
||||
|
||||
# Les fichiers appartiennent à root
|
||||
# Restore permissions on app files
|
||||
chown $app: -R "/etc/pihole"
|
||||
# /etc/pihole/logrotate have to belong to root, otherwise logrotate will failed silently...
|
||||
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/conf.d/20-$app.ini"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORE
|
||||
|
@ -96,13 +96,13 @@ ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
|
|||
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"
|
||||
|
||||
#=================================================
|
||||
# RESTORE OF THE CRON FILE
|
||||
# RESTORE THE CRON FILE
|
||||
#=================================================
|
||||
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# RESTORE OF SPECIFIC FILES
|
||||
# RESTORE SPECIFIC FILES
|
||||
#=================================================
|
||||
|
||||
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"
|
||||
|
||||
#=================================================
|
||||
# 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"
|
||||
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" && \
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# CONFIGURE DNS FOR THE LOCAL DOMAINS
|
||||
#=================================================
|
||||
|
||||
# Trouve l'interface réseau par défaut
|
||||
main_iface=$(ip route | grep default | awk '{print $5;}')
|
||||
# Trouve l'ipv4 associée à l'interface trouvée
|
||||
# Get the default network interface
|
||||
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
|
||||
# Find the IP associated to the network interface
|
||||
localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
|
||||
|
||||
# Liste les domaines de yunohost
|
||||
# List all YunoHost domains
|
||||
while read perdomain
|
||||
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
|
||||
|
||||
# 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 || \
|
||||
echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts
|
||||
done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
|
||||
|
@ -171,10 +171,10 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
|
|||
# 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"
|
||||
|
@ -183,14 +183,15 @@ echo "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_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
|
||||
#=================================================
|
||||
|
||||
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
|
||||
|
@ -198,8 +199,8 @@ ynh_system_reload --service_name=pihole-FTL --action=restart
|
|||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
|
||||
ynh_system_reload --service_name=php5-fpm
|
||||
ynh_system_reload --service_name=nginx
|
||||
ynh_systemd_action --action=reload --service_name=php5-fpm
|
||||
ynh_systemd_action --action=reload --service_name=nginx
|
||||
|
||||
#=================================================
|
||||
# DEACTIVE MAINTENANCE MODE
|
||||
|
@ -211,6 +212,9 @@ 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.
|
||||
|
@ -221,6 +225,9 @@ else
|
|||
dhcp_alert=""
|
||||
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"
|
||||
|
|
|
@ -22,6 +22,7 @@ path_url=$(ynh_app_setting_get $app path)
|
|||
admin=$(ynh_app_setting_get $app admin)
|
||||
query_logging=$(ynh_app_setting_get $app query_logging)
|
||||
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)
|
||||
overwrite_setupvars=$(ynh_app_setting_get $app overwrite_setupvars)
|
||||
overwrite_ftl=$(ynh_app_setting_get $app overwrite_ftl)
|
||||
|
@ -79,7 +80,8 @@ ynh_abort_if_errors
|
|||
# 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
|
||||
|
@ -102,9 +104,9 @@ ynh_install_app_dependencies $app_depencencies
|
|||
pihole_local_repo="/etc/.pihole"
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
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"
|
||||
# Update le dashboard admin
|
||||
# Update admin dashboard
|
||||
ynh_setup_source "$final_path" admin_dashboard
|
||||
fi
|
||||
|
||||
|
@ -115,6 +117,7 @@ fi
|
|||
# Overwrite the nginx configuration only if it's allowed
|
||||
if [ $overwrite_nginx -eq 1 ]
|
||||
then
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
fi
|
||||
|
||||
|
@ -122,7 +125,8 @@ fi
|
|||
# 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
|
||||
|
@ -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
|
||||
if [ $overwrite_phpfpm -eq 1 ]
|
||||
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
|
||||
|
||||
#=================================================
|
||||
|
@ -140,7 +145,6 @@ fi
|
|||
# UPDATE PI-HOLE SCRIPTS
|
||||
#=================================================
|
||||
|
||||
# Update les scripts de Pi-hole
|
||||
pihole_dir="/opt/pihole"
|
||||
cp -a "$pihole_local_repo/gravity.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/"
|
||||
|
||||
#=================================================
|
||||
# Copy the Pi-hole main script
|
||||
# COPY PI-HOLE MAIN SCRIPT
|
||||
#=================================================
|
||||
|
||||
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
|
||||
#=================================================
|
||||
|
||||
# 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
|
||||
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /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"
|
||||
|
||||
#=================================================
|
||||
# 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" ]
|
||||
then
|
||||
|
@ -185,19 +189,21 @@ then
|
|||
FTL_temp_path=$(mktemp -d)
|
||||
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"
|
||||
ynh_exec_warn_less make
|
||||
ynh_exec_warn_less make install )
|
||||
ynh_secure_remove "$FTL_temp_path"
|
||||
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 ]
|
||||
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"
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# BUILD THE VARIABLES FILE
|
||||
# BUILD VARIABLES FILE
|
||||
#=================================================
|
||||
|
||||
setupVars="$pihole_storage/setupVars.conf"
|
||||
|
@ -213,10 +219,11 @@ setupVars="$pihole_storage/setupVars.conf"
|
|||
# Overwrite the setupVars config file only if it's allowed
|
||||
if [ $overwrite_setupvars -eq 1 ]
|
||||
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
|
||||
main_iface=$(ip route | grep default | awk '{print $5;}')
|
||||
# Get the default network interface
|
||||
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
|
||||
echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
|
||||
echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
|
||||
echo "IPV6_ADDRESS=" >> $setupVars
|
||||
|
@ -230,11 +237,12 @@ then
|
|||
echo "QUERY_LOGGING=$query_logging" >> $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
|
||||
|
||||
#=================================================
|
||||
# UPDATE THE CRON JOB
|
||||
# UPDATE CRON JOB
|
||||
#=================================================
|
||||
|
||||
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
|
||||
#=================================================
|
||||
|
||||
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
|
||||
|
@ -257,10 +265,34 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas
|
|||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
ynh_system_reload --service_name=nginx
|
||||
ynh_systemd_action --action=reload --service_name=nginx
|
||||
|
||||
#=================================================
|
||||
# DEACTIVE MAINTENANCE MODE
|
||||
#=================================================
|
||||
|
||||
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"
|
||||
|
|
Loading…
Add table
Reference in a new issue