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 #19 from YunoHost-Apps/testing

Update helpers
This commit is contained in:
Maniack Crudelis 2018-03-14 23:39:57 +01:00 committed by GitHub
commit 65a5d9a18f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 104 additions and 65 deletions

View file

@ -35,7 +35,8 @@ Use the admin panel of your Pi-hole to configure this app.
#### Supported architectures #### Supported architectures
* Tested on x86_64 * 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)/)
* ARMv8-A - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/)
## Limitations ## Limitations

View file

@ -35,7 +35,8 @@ Utiliser le panneau d'administration de votre Pi-hole pour configurer cette appl
#### Architectures supportées. #### Architectures supportées.
* Testé sur x86_64 * 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)/)
* ARMv8-A - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/pihole%20(Community)%20(%7EARM%7E)/)
## Limitations ## Limitations

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~ynh1", "version": "3.3~ynh2",
"url": "https://pi-hole.net/", "url": "https://pi-hole.net/",
"license": "EUPL-1.2", "license": "EUPL-1.2",
"maintainer": { "maintainer": {

View file

@ -212,15 +212,17 @@ EOF
# Start or restart a service and follow its booting # Start or restart a service and follow its booting
# #
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] # usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
# #
# | arg: Line to match - The line to find in the log to attest the service have finished to boot. # | arg: Line to match - The line to find in the log to attest the service have finished to boot.
# | arg: Log file - The log file to watch # | arg: Log file - The log file to watch
# | arg: Service name
# /var/log/$app/$app.log will be used if no other log is defined. # /var/log/$app/$app.log will be used if no other log is defined.
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds. # | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
ynh_check_starting () { ynh_check_starting () {
local line_to_match="$1" local line_to_match="$1"
local app_log="${2:-/var/log/$app/$app.log}" local service_name="${4:-$app}"
local app_log="${2:-/var/log/$service_name/$service_name.log}"
local timeout=${3:-300} local timeout=${3:-300}
ynh_clean_check_starting () { ynh_clean_check_starting () {
@ -229,13 +231,14 @@ ynh_check_starting () {
ynh_secure_remove "$templog" 2>&1 ynh_secure_remove "$templog" 2>&1
} }
echo "Starting of $app" >&2 echo "Starting of $service_name" >&2
systemctl restart $app systemctl stop $service_name
local templog="$(mktemp)" local templog="$(mktemp)"
# Following the starting of the app in its log # Following the starting of the app in its log
tail -f -n1 "$app_log" > "$templog" & tail -F -n0 "$app_log" > "$templog" &
# Get the PID of the tail command # Get the PID of the tail command
local pid_tail=$! local pid_tail=$!
systemctl start $service_name
local i=0 local i=0
for i in `seq 1 $timeout` for i in `seq 1 $timeout`
@ -243,7 +246,7 @@ ynh_check_starting () {
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_to_match" "$templog" if grep --quiet "$line_to_match" "$templog"
then then
echo "The service $app has correctly started." >&2 echo "The service $service_name has correctly started." >&2
break break
fi fi
echo -n "." >&2 echo -n "." >&2
@ -251,7 +254,7 @@ ynh_check_starting () {
done done
if [ $i -eq $timeout ] if [ $i -eq $timeout ]
then then
echo "The service $app didn't fully started before the timeout." >&2 echo "The service $service_name didn't fully started before the timeout." >&2
fi fi
echo "" echo ""
@ -439,7 +442,7 @@ enabled = true
port = $ports port = $ports
filter = $app filter = $app
logpath = $logpath logpath = $logpath
maxretry = $max_retry" maxretry = $max_retry
EOF EOF
sudo tee $finalfail2banfilterconf <<EOF sudo tee $finalfail2banfilterconf <<EOF
@ -447,16 +450,17 @@ EOF
before = common.conf before = common.conf
[Definition] [Definition]
failregex = $failregex failregex = $failregex
ignoreregrex =" ignoreregex =
EOF EOF
ynh_store_file_checksum "$finalfail2banjailconf" ynh_store_file_checksum "$finalfail2banjailconf"
ynh_store_file_checksum "$finalfail2banfilterconf" ynh_store_file_checksum "$finalfail2banfilterconf"
sudo systemctl restart fail2ban systemctl restart fail2ban
if local fail2ban_error="$(tail -n50 /var/log/fail2ban.log | grep "WARNING Command.*$app.*addfailregex")" local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
if [ -n "$fail2ban_error" ]
then then
echo "[ERR] Fail2ban fail to load the jail for $app" >&2 echo "[ERR] Fail2ban failed to load the jail for $app" >&2
echo "WARNING${fail2ban_error#*WARNING}" >&2 echo "WARNING${fail2ban_error#*WARNING}" >&2
fi fi
} }
@ -480,7 +484,7 @@ ynh_remove_fail2ban_config () {
ynh_read_manifest () { ynh_read_manifest () {
manifest="$1" manifest="$1"
key="$2" key="$2"
python3 -c "import sys, json;print(json.load(open('$manifest'))['$key'])" python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])"
} }
# Exit without error if the package is up to date # Exit without error if the package is up to date
@ -525,7 +529,7 @@ ynh_abort_if_up_to_date () {
# 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"
ynh_send_readme_to_admin() { ynh_send_readme_to_admin() {
local app_message="${1:-...No specific informations...}" local app_message="${1:-...No specific information...}"
local recipients="${2:-root}" local recipients="${2:-root}"
# Retrieve the email of users # Retrieve the email of users
@ -556,7 +560,7 @@ ynh_send_readme_to_admin() {
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.
Specific informations for the application $app. Specific information for the application $app.
$app_message $app_message
@ -569,6 +573,45 @@ $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
} }
#=================================================
# Reload (or other actions) a service and print a log in case of failure.
#
# usage: ynh_system_reload service_name [action]
# | arg: service_name - Name of the service to reload
# | arg: action - Action to perform with systemctl. Default: reload
ynh_system_reload () {
local service_name=$1
local action=${2:-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
}
is_stretch () {
if [ "$(ynh_debian_release)" == "stretch" ]
then
return 0
else
return 1
fi
}
is_jessie () {
if [ "$(ynh_debian_release)" == "jessie" ]
then
return 0
else
return 1
fi
}
#================================================= #=================================================
#============= FUTURE YUNOHOST HELPER ============ #============= FUTURE YUNOHOST HELPER ============
#================================================= #=================================================

View file

@ -93,4 +93,4 @@ fi
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
sudo systemctl reload nginx ynh_system_reload nginx

View file

@ -212,7 +212,7 @@ ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichi
# SET UP THE DNSMASQ CONFIG # SET UP THE DNSMASQ CONFIG
#================================================= #=================================================
systemctl stop dnsmasq ynh_system_reload dnsmasq stop
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
@ -295,7 +295,7 @@ ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
# RESTART DNSMASQ # RESTART DNSMASQ
#================================================= #=================================================
systemctl start dnsmasq ynh_system_reload dnsmasq restart
#================================================= #=================================================
# INSTALL THE CRON JOB # INSTALL THE CRON JOB
@ -316,7 +316,7 @@ ynh_exec_warn_less /opt/pihole/gravity.sh
# START PIHOLE-FTL # START PIHOLE-FTL
#================================================= #=================================================
systemctl start pihole-FTL ynh_system_reload pihole-FTL restart
#================================================= #=================================================
# SET UP THE CONF_REGEN HOOK # SET UP THE CONF_REGEN HOOK
@ -342,7 +342,7 @@ yunohost app addaccess --users=$admin $app
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
systemctl reload nginx ynh_system_reload nginx
#================================================= #=================================================
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN

View file

@ -34,7 +34,7 @@ fi
# STOP THE SERVICE PIHOLE-FTL # STOP THE SERVICE PIHOLE-FTL
#================================================= #=================================================
systemctl stop pihole-FTL ynh_system_reload pihole-FTL stop
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"
@ -108,7 +108,7 @@ ynh_secure_remove "/etc/sudoers.d/pihole"
# REMOVE THE DNSMASQ CONFIG # REMOVE THE DNSMASQ CONFIG
#================================================= #=================================================
systemctl stop dnsmasq ynh_system_reload dnsmasq stop
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"
@ -130,7 +130,7 @@ sed -i "/#Added by pihole#/d" /etc/hosts
# RESTART DNSMASQ # RESTART DNSMASQ
#================================================= #=================================================
systemctl start dnsmasq ynh_system_reload dnsmasq restart
#================================================= #=================================================
# REMOVE THE CONF_REGEN HOOK # REMOVE THE CONF_REGEN HOOK

View file

@ -131,7 +131,7 @@ ynh_restore_file "/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
# RESTORE OF DNSMASQ CONFIG # RESTORE OF DNSMASQ CONFIG
#================================================= #=================================================
systemctl stop dnsmasq ynh_system_reload dnsmasq stop
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" && \
@ -168,7 +168,7 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
# RESTART DNSMASQ # RESTART DNSMASQ
#================================================= #=================================================
systemctl start dnsmasq ynh_system_reload dnsmasq restart
#================================================= #=================================================
# UPDATE THE VARIABLES FILE # UPDATE THE VARIABLES FILE
@ -187,7 +187,7 @@ ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichi
#================================================= #=================================================
ynh_exec_warn_less systemctl enable pihole-FTL ynh_exec_warn_less systemctl enable pihole-FTL
systemctl start pihole-FTL ynh_system_reload pihole-FTL restart
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
@ -195,8 +195,8 @@ systemctl start pihole-FTL
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
systemctl reload php5-fpm ynh_system_reload php5-fpm
systemctl reload nginx ynh_system_reload nginx
#================================================= #=================================================
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN

View file

@ -132,7 +132,7 @@ sed -i "/# su #/d;" "$pihole_storage/logrotate"
# UPDATE OF PIHOLE-FTL # UPDATE OF PIHOLE-FTL
#================================================= #=================================================
systemctl stop pihole-FTL ynh_system_reload pihole-FTL stop
# Get the source of Pi-Hole-FTL # Get the source of Pi-Hole-FTL
FTL_temp_path=$(mktemp -d) FTL_temp_path=$(mktemp -d)
@ -185,13 +185,7 @@ ynh_replace_string ".*updatechecker.*" "#&" /etc/cron.d/pihole
# START PIHOLE-FTL # START PIHOLE-FTL
#================================================= #=================================================
systemctl start pihole-FTL ynh_system_reload pihole-FTL restart
#=================================================
# START PIHOLE-FTL
#=================================================
systemctl start pihole-FTL
#================================================= #=================================================
# UPDATE THE CONF_REGEN HOOK # UPDATE THE CONF_REGEN HOOK
@ -203,4 +197,4 @@ cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmas
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
systemctl reload nginx ynh_system_reload nginx