2024-05-14 02:34:28 +00:00
|
|
|
#! /bin/bash
|
2023-01-17 11:41:01 +00:00
|
|
|
set -eo pipefail
|
|
|
|
|
2023-02-22 16:49:54 +00:00
|
|
|
# Get DataDir location
|
|
|
|
DATA_DIR="/data"
|
|
|
|
case "$(ubnt-device-info firmware || true)" in
|
|
|
|
1*)
|
2024-05-14 02:34:28 +00:00
|
|
|
DATA_DIR="/mnt/data"
|
|
|
|
;;
|
|
|
|
2* | 3* | 4*)
|
|
|
|
DATA_DIR="/data"
|
|
|
|
;;
|
2023-02-22 16:49:54 +00:00
|
|
|
*)
|
2024-05-14 02:34:28 +00:00
|
|
|
echo "ERROR: No persistent storage found." 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2023-02-22 16:49:54 +00:00
|
|
|
esac
|
|
|
|
# Check if the directory exists
|
2023-02-22 16:54:05 +00:00
|
|
|
if [ ! -d "$DATA_DIR/att-ipv6" ]; then
|
2023-02-22 16:49:54 +00:00
|
|
|
# If it does not exist, create the directory
|
2023-02-22 16:54:05 +00:00
|
|
|
mkdir -p "$DATA_DIR/att-ipv6"
|
|
|
|
echo "Directory '$DATA_DIR/att-ipv6' created."
|
2023-02-22 16:49:54 +00:00
|
|
|
else
|
|
|
|
# If it already exists, print a message
|
2023-02-22 16:54:05 +00:00
|
|
|
echo "Directory '$DATA_DIR/att-ipv6' already exists. Moving on."
|
2023-02-22 16:49:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
wan_iface="eth8" # "eth9" for UDM Pro WAN2
|
|
|
|
vlans="br0" # "br0 br100 br101..."
|
|
|
|
domain="example.invalid" # DNS domain
|
2023-01-17 11:41:01 +00:00
|
|
|
dns6="[2001:4860:4860::8888],[2001:4860:4860::8844]" # Google
|
|
|
|
|
|
|
|
CONTAINER=att-ipv6
|
2023-02-22 16:49:54 +00:00
|
|
|
confdir=${DATA_DIR}/att-ipv6
|
2023-01-17 11:41:01 +00:00
|
|
|
|
|
|
|
# main
|
|
|
|
mkdir -p "${confdir}/dhcpcd"
|
|
|
|
|
|
|
|
test -f "${confdir}/dhcpcd.conf" || {
|
2023-02-22 16:49:54 +00:00
|
|
|
: >"${confdir}/dhcpcd.conf.tmp"
|
|
|
|
cat >>"${confdir}/dhcpcd.conf.tmp" <<EOF
|
2023-01-17 11:41:01 +00:00
|
|
|
allowinterfaces ${wan_iface}
|
2023-02-07 05:16:58 +00:00
|
|
|
nodev
|
|
|
|
noup
|
2023-01-17 11:41:01 +00:00
|
|
|
ipv6only
|
|
|
|
nooption domain_name_servers
|
|
|
|
nooption domain_name
|
|
|
|
duid
|
|
|
|
persistent
|
|
|
|
option rapid_commit
|
|
|
|
option interface_mtu
|
|
|
|
require dhcp_server_identifier
|
|
|
|
slaac private
|
|
|
|
noipv6rs
|
|
|
|
|
|
|
|
interface ${wan_iface}
|
|
|
|
ipv6rs
|
|
|
|
ia_na 0
|
|
|
|
EOF
|
|
|
|
|
|
|
|
ix=0
|
|
|
|
for vv in $vlans; do
|
|
|
|
echo " ia_pd ${ix} ${vv}/0"
|
2023-02-22 16:49:54 +00:00
|
|
|
ix=$((ix + 1))
|
|
|
|
done >>"${confdir}/dhcpcd.conf.tmp"
|
2023-01-17 11:41:01 +00:00
|
|
|
mv "${confdir}/dhcpcd.conf.tmp" "${confdir}/dhcpcd.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
test -f "${confdir}/att-ipv6-dnsmasq.conf" || {
|
2023-02-22 16:49:54 +00:00
|
|
|
: >"${confdir}/att-ipv6-dnsmasq.conf.tmp"
|
|
|
|
cat >>"${confdir}/att-ipv6-dnsmasq.conf.tmp" <<EOF
|
2023-01-17 11:41:01 +00:00
|
|
|
#
|
|
|
|
# via att-ipv6
|
|
|
|
#
|
|
|
|
enable-ra
|
|
|
|
no-dhcp-interface=lo
|
|
|
|
no-ping
|
|
|
|
EOF
|
|
|
|
|
|
|
|
for vv in $vlans; do
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
interface=${vv}
|
|
|
|
dhcp-range=set:att-ipv6-${vv},::2,::7d1,constructor:${vv},slaac,ra-names,64,86400
|
|
|
|
dhcp-option=tag:att-ipv6-${vv},option6:dns-server,${dns6}
|
|
|
|
domain=${domain}|${vv}
|
|
|
|
ra-param=${vv},high,0
|
|
|
|
EOF
|
2023-02-22 16:49:54 +00:00
|
|
|
done >>"${confdir}/att-ipv6-dnsmasq.conf.tmp"
|
|
|
|
mv "${confdir}/att-ipv6-dnsmasq.conf.tmp" "${confdir}/att-ipv6-dnsmasq.conf"
|
2023-01-17 11:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if podman container exists "$CONTAINER"; then
|
|
|
|
podman start "$CONTAINER"
|
|
|
|
else
|
|
|
|
podman run -d --restart=always --name "$CONTAINER" -v "${confdir}/dhcpcd.conf:/etc/dhcpcd.conf" -v "${confdir}/dhcpcd:/var/lib/dhcpcd" --net=host --privileged ghcr.io/michaelw/dhcpcd
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Fix DHCP, assumes DHCPv6 is turned off in UI
|
|
|
|
cp "${confdir}/att-ipv6-dnsmasq.conf" /run/dnsmasq.conf.d/
|
|
|
|
start-stop-daemon -K -q -x /usr/sbin/dnsmasq
|