set -e force=$1 . /usr/share/yunohost/helpers function safe_copy () { if [[ "$force" == "True" ]]; then sudo yunohost service safecopy \ -s dnsmasq $1 $2 --force else sudo yunohost service safecopy \ -s dnsmasq $1 $2 fi } cd /usr/share/yunohost/templates/dnsmasq # Get IPv4 address ip=$(curl -s -4 https://ip.yunohost.org 2>/dev/null || true) ynh_validate_ip4 $ip || ip='0.0.0.0' # Get IPv6 IP address ipv6=$(curl -s -6 http://ip6.yunohost.org 2>/dev/null || true) ynh_validate_ip6 $ipv6 || ipv6='' sudo mkdir -p /etc/dnsmasq.d domain_list=$(sudo yunohost domain list --output-as plain) # Copy a configuration file for each YunoHost domain for domain in $domain_list; do cat domain.sed \ | sed "s/{{ domain }}/$domain/g" \ | sed "s/{{ ip }}/$ip/g" \ | sudo tee $domain if [[ "$ipv6" != "" ]]; then echo "address=/$domain/$ipv6" | sudo tee -a $domain fi safe_copy $domain /etc/dnsmasq.d/$domain done # Remove old domains files for file in /etc/dnsmasq.d/*.*; do domain=$(echo $file | sed 's|/etc/dnsmasq.d/||') [[ $domain_list =~ $domain ]] \ || sudo yunohost service saferemove -s dnsmasq $file done sudo service dnsmasq reload \ || sudo service dnsmasq restart