mirror of
https://github.com/YunoHost-Apps/pihole_ynh.git
synced 2024-09-03 20:05:58 +02:00
Yolorework the regenconf script
This commit is contained in:
parent
57c86aaa15
commit
e68ad3f8ba
1 changed files with 62 additions and 71 deletions
|
@ -2,38 +2,50 @@
|
|||
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
force=${2:-0} # 0/1 --force argument
|
||||
dryrun=${3:-0} # 0/1 --dry-run argument
|
||||
pending_conf=$4 # Path of the pending conf file
|
||||
app="__APP__"
|
||||
|
||||
do_pre_regen() {
|
||||
if [ $dryrun -eq 0 ]
|
||||
then
|
||||
dnsmasq_dir="${pending_conf}/etc/dnsmasq.d"
|
||||
mkdir -p "$dnsmasq_dir"
|
||||
cp -a "/etc/dnsmasq.conf" "${pending_conf}/etc/dnsmasq.conf"
|
||||
# Créer une sauvegarde des config dnsmasq de pi-hole. Que la regen-conf va sauvagement supprimer
|
||||
cp -a "/etc/.pihole/advanced/01-pihole.conf" "$dnsmasq_dir/"
|
||||
ynh_replace_string --match_string="@DNS1@" --replace_string="" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
ynh_replace_string --match_string="@DNS2@" --replace_string="" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
action=$1
|
||||
pending_conf=$4/../dnsmasq
|
||||
|
||||
ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
if [ "$query_logging" = "true" ]; then
|
||||
[[ "$action" == "pre" ]] || exit 0
|
||||
[[ -d "$pending_conf" ]] || exit 0
|
||||
|
||||
#
|
||||
# Regen /etc/dnsmasq.d/01-pihole.conf
|
||||
#
|
||||
dnsmasq_dir="${pending_conf}/etc/dnsmasq.d"
|
||||
mkdir -p "$dnsmasq_dir"
|
||||
|
||||
cp -a "/etc/.pihole/advanced/01-pihole.conf" "$dnsmasq_dir/"
|
||||
|
||||
ynh_replace_string --match_string="@DNS1@" --replace_string="" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
ynh_replace_string --match_string="@DNS2@" --replace_string="" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
|
||||
ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
# FIXME : query_logging ain't defined
|
||||
if [ "$query_logging" = "true" ]; then
|
||||
ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
else
|
||||
else
|
||||
ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fix a too recent option for our dnsmasq version.
|
||||
ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
# Fix a too recent option for our dnsmasq version.
|
||||
ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf"
|
||||
|
||||
ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf"
|
||||
#
|
||||
# Tweak dnsmsasq's general conf cache-size
|
||||
#
|
||||
|
||||
enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp)
|
||||
if [ $enable_dhcp -eq 1 ]
|
||||
then
|
||||
ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf"
|
||||
|
||||
#
|
||||
# Regen /etc/dnsmasq.d/02-pihole-dhcp.conf
|
||||
#
|
||||
|
||||
enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp)
|
||||
if [ $enable_dhcp -eq 1 ]
|
||||
then
|
||||
|
||||
# Get the default network interface
|
||||
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
|
||||
|
@ -66,27 +78,6 @@ do_pre_regen() {
|
|||
ynh_replace_string --match_string="__GATEWAY__" --replace_string="$gateway" --target_file="${pending_conf}/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
|
||||
# Set a static ip for the server.
|
||||
echo "dhcp-host=$hw_adress,$localipv4" > "${pending_conf}/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
do_post_regen() {
|
||||
# Reload dnsmasq
|
||||
systemctl reload dnsmasq
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
pre)
|
||||
do_pre_regen
|
||||
;;
|
||||
post)
|
||||
do_post_regen
|
||||
;;
|
||||
*)
|
||||
echo "Hook called with unknown argument \`$1'" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "dhcp-host=$hw_adress,$localipv4" > "${dnsmasq_dir}/04-pihole-static-dhcp.conf"
|
||||
fi
|
||||
exit 0
|
||||
|
|
Loading…
Add table
Reference in a new issue