AdGuardHome/snap/local/adguard-home-web.sh

27 lines
587 B
Bash
Raw Permalink Normal View History

2023-07-03 12:10:40 +01:00
#!/bin/sh
2024-12-05 13:00:18 +00:00
# shellcheck disable=SC2154
2023-07-03 12:10:40 +01:00
conf_file="${SNAP_DATA}/AdGuardHome.yaml"
readonly conf_file
2024-12-05 13:00:18 +00:00
if ! [ -f "$conf_file" ]; then
xdg-open 'http://localhost:3000'
2023-07-03 12:10:40 +01:00
2024-12-05 13:00:18 +00:00
exit
2023-07-03 12:10:40 +01:00
fi
# Get the admin interface port from the configuration.
2024-12-05 13:00:18 +00:00
#
# shellcheck disable=SC2016
2023-07-03 12:10:40 +01:00
awk_prog='/^[^[:space:]]/ { is_http = /^http:/ };/^[[:space:]]+address:/ { if (is_http) print $2 }'
readonly awk_prog
2024-12-05 13:00:18 +00:00
bind_port="$(awk "$awk_prog" "$conf_file" | awk -F ':' '{print $NF}')"
2023-07-03 12:10:40 +01:00
readonly bind_port
2024-12-05 13:00:18 +00:00
if [ "$bind_port" = '' ]; then
2023-07-03 12:10:40 +01:00
xdg-open 'http://localhost:3000'
else
xdg-open "http://localhost:${bind_port}"
fi