56 lines
2.0 KiB
Bash
56 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
# Makes test.locqr.dev and api.locqr.dev resolvable from a phone on the same
|
|
# LAN, for testing the companion stub (companion/, dev.md) against a real
|
|
# camera. Not needed for desktop-only development — that uses /etc/hosts
|
|
# (dev.md), which a phone can't be pointed at as easily.
|
|
#
|
|
# Runs dnsmasq in the foreground, bound only to the Wi-Fi interface (not a
|
|
# systemd service, doesn't touch /etc/resolv.conf or /etc/dnsmasq.conf):
|
|
# resolves the two dev hostnames to this machine's own LAN IP and forwards
|
|
# everything else to a real upstream resolver. Ctrl+C stops it; nothing
|
|
# persists after that.
|
|
#
|
|
# Requires sudo (binding port 53). Usage: sudo scripts/serve-lan-dns.sh [interface]
|
|
# If no interface is given, the script guesses the one carrying a private
|
|
# (RFC 1918) IPv4 address — print `ip -4 addr show` yourself if it guesses
|
|
# wrong on a machine with multiple such interfaces.
|
|
|
|
set -euo pipefail
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "Needs root (binds port 53). Re-run as: sudo $0 $*" >&2
|
|
exit 1
|
|
fi
|
|
|
|
IFACE="${1:-}"
|
|
if [[ -z "$IFACE" ]]; then
|
|
IFACE=$(ip -4 -o addr show scope global | awk '$4 ~ /^(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.)/ { print $2; exit }')
|
|
fi
|
|
if [[ -z "$IFACE" ]]; then
|
|
echo "Could not auto-detect a LAN interface. Pass one explicitly: $0 <interface>" >&2
|
|
echo "(check \`ip -4 addr show\` for the one with your 192.168.x.x / 10.x.x.x address)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
LAN_IP=$(ip -4 -o addr show dev "$IFACE" | awk '{ print $4 }' | cut -d/ -f1)
|
|
if [[ -z "$LAN_IP" ]]; then
|
|
echo "Interface '$IFACE' has no IPv4 address." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Resolving test.locqr.dev and api.locqr.dev -> $LAN_IP on interface $IFACE"
|
|
echo "Point your phone's Wi-Fi DNS server at $LAN_IP, then browse to https://test.locqr.dev:5174"
|
|
echo "(Ctrl+C to stop)"
|
|
echo
|
|
|
|
exec dnsmasq \
|
|
--no-daemon \
|
|
--no-resolv \
|
|
--no-hosts \
|
|
--server=1.1.1.1 \
|
|
--server=8.8.8.8 \
|
|
--interface="$IFACE" \
|
|
--bind-interfaces \
|
|
--address="/test.locqr.dev/$LAN_IP" \
|
|
--address="/api.locqr.dev/$LAN_IP"
|