mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 10:18:25 +00:00
macscript: create file if it doesn't exist.
This commit is contained in:
@@ -11,20 +11,26 @@ action="$1"
|
|||||||
mac="$2" # IPv4
|
mac="$2" # IPv4
|
||||||
ip="$3"
|
ip="$3"
|
||||||
|
|
||||||
|
# ensure it always exists.
|
||||||
|
|
||||||
|
if [ ! -f "$STATUS_FILE" ]; then
|
||||||
|
touch "$STATUS_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$DNSMASQ_IAID" ]; then
|
if [ -n "$DNSMASQ_IAID" ]; then
|
||||||
if [ -z "$DNSMASQ_MAC" -a "$action" = "old" ]; then
|
|
||||||
# MAC not known by dnsmasq, probably due to restart.
|
|
||||||
exit 0;
|
|
||||||
fi
|
|
||||||
mac="$DNSMASQ_MAC" # IPv6
|
mac="$DNSMASQ_MAC" # IPv6
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# worry about an add or old action when the MAC address is not known:
|
||||||
|
# leave any old one in place in that case.
|
||||||
|
|
||||||
if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then
|
if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then
|
||||||
if [ -f "$STATUS_FILE" ]; then
|
if [ -n "$mac" -o "$action" = "del" ]; then
|
||||||
sed "/^${ip//./\.} / d" "$STATUS_FILE" > "$STATUS_FILE".new
|
sed "/^${ip//./\.} / d" "$STATUS_FILE" > "$STATUS_FILE".new
|
||||||
fi
|
|
||||||
if [ "$action" = "add" -o "$action" = "old" ]; then
|
if [ "$action" = "add" -o "$action" = "old" ]; then
|
||||||
echo "$ip $mac" >> "$STATUS_FILE".new
|
echo "$ip $mac" >> "$STATUS_FILE".new
|
||||||
fi
|
fi
|
||||||
mv "$STATUS_FILE".new "$STATUS_FILE" # atomic update.
|
mv "$STATUS_FILE".new "$STATUS_FILE" # atomic update.
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user