mirror of
https://github.com/YunoHost-Apps/adguardhome_ynh.git
synced 2024-09-03 18:06:23 +02:00
Set the ip or the port if needed
This commit is contained in:
parent
c436afd6bf
commit
cef6d80583
2 changed files with 50 additions and 1 deletions
|
@ -5,7 +5,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# dependencies used by the app
|
# dependencies used by the app
|
||||||
pkg_dependencies="python3-bcrypt"
|
pkg_dependencies="python3-bcrypt python3-yaml"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PERSONAL HELPERS
|
# PERSONAL HELPERS
|
||||||
|
|
|
@ -116,6 +116,55 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
||||||
|
|
||||||
ynh_install_app_dependencies $pkg_dependencies
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# UPDATE A CONFIG FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
||||||
|
|
||||||
|
ipv4_route_output=$(ip -4 route get 1.2.3.4 | head -n1)
|
||||||
|
ipv6_route_output=$(ip -6 route get ::1.2.3.4 | head -n1)
|
||||||
|
|
||||||
|
ipv4_addr=""
|
||||||
|
for i in $(seq "$(echo $ipv4_route_output | wc -w)" -1 1); do
|
||||||
|
ip=$(echo $ipv4_route_output | awk "{print \$$i}")
|
||||||
|
if ynh_validate_ip4 --ip_address=$ip; then
|
||||||
|
ipv4_addr="$ip"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
ipv6_addr=""
|
||||||
|
for i in $(seq "$(echo $ipv6_route_output | wc -w)" -1 1); do
|
||||||
|
ip=$(echo $ipv6_route_output | awk "{print \$$i}")
|
||||||
|
if ynh_validate_ip6 --ip_address=$ip; then
|
||||||
|
ipv6_addr="$ip"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Reset the bind_hosts if the current ip is 0.0.0.0
|
||||||
|
python3 -c "import yaml
|
||||||
|
with open(\"$final_path/AdGuardHome.yaml\", 'r') as file:
|
||||||
|
conf_file = yaml.safe_load(file)
|
||||||
|
|
||||||
|
need_file_update = False
|
||||||
|
|
||||||
|
if \"0.0.0.0\" in conf_file[\"dns\"][\"bind_hosts\"]:
|
||||||
|
conf_file[\"dns\"][\"bind_hosts\"] = [\"$ipv4_addr\", \"$ipv6_addr\"]
|
||||||
|
need_file_update = True
|
||||||
|
|
||||||
|
if conf_file[\"dns\"][\"port\"] != $adguard_port:
|
||||||
|
conf_file[\"dns\"][\"port\"] = $adguard_port
|
||||||
|
need_file_update = True
|
||||||
|
|
||||||
|
if need_file_update:
|
||||||
|
with open(\"$final_path/AdGuardHome.yaml\", 'w') as file:
|
||||||
|
yaml.dump(conf_file, file)
|
||||||
|
"
|
||||||
|
|
||||||
|
chmod 600 "$final_path/AdGuardHome.yaml"
|
||||||
|
chown -R $app: "$final_path/AdGuardHome.yaml"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# SETUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue