1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/adguardhome_ynh.git synced 2024-09-03 18:06:23 +02:00

declare needs_exposed_ports according to real user need

This commit is contained in:
OniriCorpe 2024-01-01 04:06:53 +01:00
parent 7f32cd77c0
commit 4ba2351269
4 changed files with 67 additions and 25 deletions

View file

@ -15,19 +15,19 @@ ynh_abort_if_errors
# SPECIFIC SETTERS
#=================================================
set__open_port_53() {
set__expose_port_53() {
if [ "$open_port_53" == "true" ]; then
if [ "$expose_port_53" == "true" ]; then
ynh_print_info --message="Opening port 53..."
# if the user would expose port 53 to the Internet, open it
ynh_exec_warn_less yunohost firewall allow Both 53
elif [ "$open_port_53" == "false" ]; then
elif [ "$expose_port_53" == "false" ]; then
# else if false, close it
ynh_print_info --message="Closing port 53..."
ynh_exec_warn_less yunohost firewall disallow Both 53
else
# else, throw error
ynh_print_warn --message="The variable 'open_port_53' should be 'true' or 'false' but isn't, please report this."
ynh_print_warn --message="The variable 'expose_port_53' should be 'true' or 'false' but isn't, please report this."
fi
# regenerate config, needed to add or delete public IPs following the user's choice
@ -49,8 +49,18 @@ set__open_port_53() {
ynh_print_info --message="Updating the AGH config file..."
update_agh_ip_config
if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $dns_over_https == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53"
else
yunohost service add "$app" --description="Ads & trackers blocking DNS server"
fi
# save the new setting
ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53"
ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53"
}
set__dns_over_https() {
@ -73,6 +83,16 @@ set__dns_over_https() {
ynh_print_warn --message="The variable 'dns_over_https' should be 'true' or 'false' but isn't, please report this."
fi
if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $dns_over_https == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53"
else
yunohost service add "$app" --description="Ads & trackers blocking DNS server"
fi
# save the new setting in the AGH config file
ynh_write_var_in_file --file="$install_dir/AdGuardHome.yaml" --key="enabled" --after="tls:" --value="$dns_over_https"

View file

@ -29,17 +29,15 @@ fi
ynh_app_setting_set --app="$app" --key=dns_over_https --value="$dns_over_https"
if [[ $open_port_53 == 0 ]]; then
open_port_53="true"
# if open_port_53 is true, we need to open port 53
ynh_print_info --message="Opening port 53..."
ynh_exec_warn_less yunohost firewall allow Both 53
ynh_print_info --message="Opening port 53..."
ynh_exec_warn_less yunohost firewall allow Both 53
if [[ $expose_port_53 == 0 ]]; then
expose_port_53="true"
else
open_port_53="false"
ynh_print_info --message="Port 53 is closed."
expose_port_53="false"
fi
ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53"
ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -111,7 +109,15 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $dns_over_https == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53"
else
yunohost service add "$app" --description="Ads & trackers blocking DNS server"
fi
#=================================================
# START SYSTEMD SERVICE

View file

@ -22,8 +22,8 @@ if [ "$dns_over_https" == "false" ]; then
ynh_exec_warn_less yunohost firewall disallow UDP "$port_dns_over_quic"
fi
if [ "$open_port_53" == "true" ]; then
# if open_port_53 is true, we need to open port 53
if [ "$expose_port_53" == "true" ]; then
# if expose_port_53 is true, we need to open port 53
ynh_exec_warn_less yunohost firewall allow Both 53
fi
@ -80,7 +80,15 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $dns_over_https == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53"
else
yunohost service add "$app" --description="Ads & trackers blocking DNS server"
fi
#=================================================
# START SYSTEMD SERVICE

View file

@ -29,15 +29,15 @@ ynh_systemd_action --service_name="$app" --action="stop"
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if [ -z "${open_port_53:-}" ] && [ "${open_port_53:-}" = true ]; then
open_port_53="true"
ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53"
# if open_port_53 is true, we need to open port 53
if [ -z "${expose_port_53:-}" ] && [ "${expose_port_53:-}" = true ]; then
expose_port_53="true"
ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53"
# if expose_port_53 is true, we need to open port 53
ynh_print_info --message="Opening port 53..."
ynh_exec_warn_less yunohost firewall allow Both 53
elif [ -n "${open_port_53:-}" ] || [ "${open_port_53:-}" = false ]; then
open_port_53="false"
ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53"
elif [ -n "${expose_port_53:-}" ] || [ "${expose_port_53:-}" = false ]; then
expose_port_53="false"
ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53"
ynh_print_info --message="Port 53 is closed."
fi
@ -111,7 +111,15 @@ ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $dns_over_https == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic"
elif [[ $expose_port_53 == 0 ]]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53"
else
yunohost service add "$app" --description="Ads & trackers blocking DNS server"
fi
#=================================================
# SPECIFIC UPGRADE