Share your "hooks" to apply custom configurations- Partagez vos "hooks" pour appliquer des configurations personnelles

Tu peux essayer de faire un hook en effet… J’essaierai cela, sans être sûr, à tester:

/etc/yunohost/hooks.d/conf_regen/17-nginx_jellyfin

#!/bin/bash
action=$1
pending_dir=$4
nginx_dir=$pending_dir/../nginx/etc/nginx
nginx_jellyfin_conf=$(find /etc/nginx -name jellyfin.conf)
[[ $action == "pre" ]] || exit 0
[[ -d $nginx_dir ]] || exit 0
[[ -e $nginx_jellyfin_conf ]] || exit 0
echo '
        allow X.X.X.X/8;
        allow X.X.X.X.X;
        deny all;' >> $nginx_jellyfin_conf

Merci d’avoir pris le temps. Cela s’exécute bien mais le echo est mis après le “}” et non juste avant du coup je pense que la config sera foireuse tel que. Mais en tout cas ça s’execute bien.

il faudrait mettre le pointeur avant le “}”.

Bonjour,

Dans ce cas remplace echo par sed.
Plusieurs solutions selon comment est fait ton fichier. Si le “}” est en fin de fichier comme je crois le comprendre, tu peux essayer ceci:

action=$1
pending_dir=$4
nginx_dir=$pending_dir/../nginx/etc/nginx
nginx_jellyfin_conf=$(find /etc/nginx -name jellyfin.conf)
[[ $action == "pre" ]] || exit 0
[[ -d $nginx_dir ]] || exit 0
[[ -e $nginx_jellyfin_conf ]] || exit 0
sed -i "$ i allow X.X.X.X/8;\nallow X.X.X.X.X;\ndeny all;"  $nginx_jellyfin_conf

Merci.

J’ai donc essayé et le contenu se place après le dernier “}”. Du coup après quelque recherche voici la bonne formule.

#!/bin/bash
action=$1
pending_dir=$4
nginx_dir=$pending_dir/../nginx/etc/nginx
nginx_jellyfin_conf=$(find /etc/nginx -name jellyfin.conf)
[[ $action == "pre" ]] || exit 0
[[ -d $nginx_dir ]] || exit 0
[[ -e $nginx_jellyfin_conf ]] || exit 0
sed -i '/}/i'"allow XXX.XXX.XXX.XXX/8;\nallow XXX.XXX.XXX.XXX;\ndeny all;"  $nginx_jellyfin_conf

Merciiiiiii

C’est étonnant, je viens de tester et ça fonctionne bien comme je l’ai indiqué avec un fichier de test semblable. :thinking:
N’aurais-tu pas oublié le i? Dans ce cas le 1er “A” de allow est considéré comme l’option append de sed et le bloc se place à la fin mais la 1ère ligne serait en plus tronquée, il manquerait le “A” sur allow.

Ta solution fonctionne évidemment mais uniquement s’il y a un seul } dans le fichier. Si ce n’était pas le cas, tu ajouterais le bloc allow/deny avant chaque }.

J’ai copié collé tel que ton message, j’ai testé deux fois quand même au cas ou et il m’a bien collé le texte à la suite. C’est pour ça que je me suis orienté ailleurs. Mais merci de m’avoir orienté sur SED ;).

Le fichier de JF comporte qu’un seul “}” donc pas dérangeant dans le cas présent ;).

Merciii.

Hi All, I have a hook script
/etc/yunohost/hooks.d/conf_regen/01_ssh_stream_local_bind_unlink

When I run yunohost tools regen-conf ssh -f the setting does not get applied. I have made the sure conf_regen directory and the script are executable. Any tips?

#!/bin/bash

# This should allow forwarding ssh and gpg keys.
# It is supposed to append StreamLocalBindUnlink yes
# in the ssh user tunnelling section

action=$1
pending_dir=$4
ssh_conf=$pending_dir/../ssh/etc/ssh/sshd_config

[[ "$action" == "pre" ]] || exit 0
[[ -e $ssh_conf ]] || exit 0

sed -i '/PermitUserRC yes/a StreamLocalBindUnlink yes' $ssh_conf

it probably should be 01-ssh_.... (dash instead of underscore)

Or even maybe 01-ssh_streamlocalbindunlink, i don’t know how yunohost will react if there’s so many _

I changed it to the second suggestion. It still doesn’t get run. ¯\(ツ)

Hi,

Changed it like this : 04-ssh_streamlocalbindunlink

the number is the priority of the hook. Look in the folder /usr/share/yunohost/hooks/conf_regen , you see a default hook 03-ssh. If you give a smaller number, this hook is execute after yours and overwrite your modifications.

With a bigger number, your hook execute after the default one and the modifications can be applied.
I suggest you to read the link i post in the first message of this topic to understand how to create a hook.

2 Likes

Thank you, that was the missing step. I understand better how the hook system works. I passed over the links in your first post since they are in French.

A hook that allow to send mail with group mail aliases (more info with yunohost user group add-mailalias --help:

/etc/yunohost/hooks.d/conf_regen/20-postfix_mailgroup

#!/bin/bash

action=$1
pending_dir=$4
postfix_conf=$pending_dir/../postfix/etc/postfix/main.cf

[[ $action == "pre" ]] || exit 0
[[ -e $postfix_conf ]] || exit 0
sed -i '/Regular Yunohost accounts/a\   ldap:/etc/postfix/ldap-groups.cf,' $postfix_conf

A hook that allows accessing ldap externally via TLS

#!/bin/bash

action=$1
pending_dir=$4
etc_default_slapd=$pending_dir/../slapd/etc/default/slapd
etc_ldap_ldap_conf=$pending_dir/../slapd/etc/ldap/ldap.conf

[[ "$action" == "pre" ]] || exit 0
[[ -e $etc_default_slapd ]] || exit 0
[[ -e $etc_ldap_ldap_conf ]] || exit 0

# from https://stackoverflow.com/a/50624719 matches the second occurence
# the hook gods don't seem to like this one so I will just replace all occurrences
# sed -i ':a;N$!ba;s/ldaps:\/\/\//ldaps:\/\/10.10.2.19:636\//2' $etc_default_slapd
sed -i 's/ldaps:\/\/\//ldaps:\/\/10.10.2.19:636\//g' $etc_default_slapd

# from https://stackoverflow.com/a/9591835
sed -i '/ldap:\/\/localhost:389/ s/$/ ldaps:\/\/10.10.2.19:636/' $etc_ldap_ldap_conf

Est il possible de créer des Hooks afin de répondre à la demande du site https://www.smtp2go.com/ pour valider des " Verified Senders" avec 2 CNAME pour un nom de domaine en noho.st par exemple ?

Is it possible to create Hooks in order to meet the request of the https://www.smtp2go.com/ site to validate “Verified Senders” with 2 CNAME for a domain name in noho.st for example?