Changeset View
Changeset View
Standalone View
Standalone View
pdnsd.in
| #!/bin/sh | #!/bin/sh | ||||
| # Copyright (c) 2010-2018 Roy Marples | # Copyright (c) 2010-2023 Roy Marples | ||||
| # All rights reserved | # All rights reserved | ||||
| # pdnsd subscriber for resolvconf | # pdnsd subscriber for resolvconf | ||||
| # Redistribution and use in source and binary forms, with or without | # Redistribution and use in source and binary forms, with or without | ||||
| # modification, are permitted provided that the following conditions | # modification, are permitted provided that the following conditions | ||||
| # are met: | # are met: | ||||
| # * Redistributions of source code must retain the above copyright | # * Redistributions of source code must retain the above copyright | ||||
| Show All 30 Lines | |||||
| # but sed may not always be available at the time. | # but sed may not always be available at the time. | ||||
| remove_markers() | remove_markers() | ||||
| { | { | ||||
| m1="$1" | m1="$1" | ||||
| m2="$2" | m2="$2" | ||||
| in_marker=0 | in_marker=0 | ||||
| shift; shift | shift; shift | ||||
| if type sed >/dev/null 2>&1; then | if command -v sed >/dev/null 2>&1; then | ||||
| sed "/^$m1/,/^$m2/d" $@ | sed "/^$m1/,/^$m2/d" $@ | ||||
| else | else | ||||
| for x do | for x do | ||||
| while read line; do | while read line; do | ||||
| case "$line" in | case "$line" in | ||||
| "$m1"*) in_marker=1;; | "$m1"*) in_marker=1;; | ||||
| "$m2"*) in_marker=0;; | "$m2"*) in_marker=0;; | ||||
| *) [ $in_marker = 0 ] && echo "$line";; | *) [ $in_marker = 0 ] && echo "$line";; | ||||
| esac | esac | ||||
| done < "$x" | done < "$x" | ||||
| done | done | ||||
| fi | fi | ||||
| } | } | ||||
| # Compare two files | # Compare two files | ||||
| # If different, replace first with second otherwise remove second | # If different, replace first with second otherwise remove second | ||||
| change_file() | change_file() | ||||
| { | { | ||||
| if [ -e "$1" ]; then | if [ -e "$1" ]; then | ||||
| if type cmp >/dev/null 2>&1; then | if command -v cmp >/dev/null 2>&1; then | ||||
| cmp -s "$1" "$2" | cmp -s "$1" "$2" | ||||
| elif type diff >/dev/null 2>&1; then | elif command -v diff >/dev/null 2>&1; then | ||||
| diff -q "$1" "$2" >/dev/null | diff -q "$1" "$2" >/dev/null | ||||
| else | else | ||||
| # Hopefully we're only working on small text files ... | # Hopefully we're only working on small text files ... | ||||
| [ "$(cat "$1")" = "$(cat "$2")" ] | [ "$(cat "$1")" = "$(cat "$2")" ] | ||||
| fi | fi | ||||
| if [ $? -eq 0 ]; then | if [ $? -eq 0 ]; then | ||||
| rm -f "$2" | rm -f "$2" | ||||
| return 1 | return 1 | ||||
| fi | fi | ||||
| fi | fi | ||||
| cat "$2" > "$1" | cat "$2" > "$1" | ||||
| rm -f "$2" | rm -f "$2" | ||||
| return 0 | return 0 | ||||
| } | } | ||||
| newresolv="# Generated by resolvconf$NL" | newresolv="# Generated by resolvconf$NL" | ||||
| changed=false | changed=false | ||||
| # Try to ensure that config dirs exist | # Try to ensure that config dirs exist | ||||
| if type config_mkdirs >/dev/null 2>&1; then | if command -v config_mkdirs >/dev/null 2>&1; then | ||||
| config_mkdirs "$pdnsd_resolv" "$pdnsd_conf" | config_mkdirs "$pdnsd_resolv" "$pdnsd_conf" | ||||
| else | else | ||||
| @SBINDIR@/resolvconf -D "$pdnsd_resolv" "$pdnsd_conf" | @SBINDIR@/resolvconf -D "$pdnsd_resolv" "$pdnsd_conf" | ||||
| fi | fi | ||||
| if [ -n "$pdnsd_resolv" ]; then | if [ -n "$pdnsd_resolv" ]; then | ||||
| for n in $NAMESERVERS; do | for n in $NAMESERVERS; do | ||||
| newresolv="${newresolv}nameserver $n$NL" | newresolv="${newresolv}nameserver $n$NL" | ||||
| ▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines | |||||