fix: tailscale
This commit is contained in:
32
cattools.sh
32
cattools.sh
@@ -1300,29 +1300,46 @@ configure_tailscale() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! opkg info tailscale | grep "Package: tailscale"; then
|
if ! opkg list-installed | grep -q "tailscale "; then
|
||||||
echo "[INFO] 正在安装 tailscale 和 tailscaled 软件包..."
|
echo "[INFO] 正在安装 tailscale 和 tailscaled 软件包..."
|
||||||
|
opkg update
|
||||||
opkg install tailscale
|
opkg install tailscale
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "[ERROR] 安装 tailscale 失败,请先配置软件源。"
|
echo "[ERROR] 安装 tailscale 失败,请先配置软件源。"
|
||||||
menu
|
menu
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "[INFO] tailscale 已安装"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
subnet=$(ip -o -f inet addr show | awk '/scope global/ {print $4}' | head -n 1)
|
br_lan_ip=$(ip -o -f inet addr show br-lan | awk '{print $4}')
|
||||||
if [ -z "$subnet" ]; then
|
if [ -z "$br_lan_ip" ]; then
|
||||||
echo "[ERROR] 无法获取当前子网。"
|
echo "[ERROR] 无法获取 br-lan 接口的子网。"
|
||||||
|
menu
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
IFS='/' read -r ip mask <<< "$br_lan_ip"
|
||||||
|
IFS='.' read -r i1 i2 i3 i4 <<< "$ip"
|
||||||
|
subnet="$i1.$i2.$i3.0/$mask"
|
||||||
|
|
||||||
|
echo "[INFO] 下载配置..."
|
||||||
|
curl -fsSL https://raw.githubusercontent.com/miaoermua/cattools/main/configure/tailscale.sh -o /tmp/tailscale.sh
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "[ERROR] 下载配置失败..."
|
||||||
menu
|
menu
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tailscale up --advertise-routes=$subnet --accept-routes --advertise-exit-node
|
sed -i "s|--advertise-routes=.*|--advertise-routes=$subnet --accept-routes --advertise-exit-node|" /tmp/tailscale.sh
|
||||||
|
|
||||||
|
echo "[INFO] 开始配置 tailscale,请登录 tailscale 绑定设备"
|
||||||
|
chmod +x /tmp/tailscale.sh && sh /tmp/tailscale.sh
|
||||||
|
|
||||||
firewall_file="/etc/firewall.user"
|
firewall_file="/etc/firewall.user"
|
||||||
rules=("iptables -I FORWARD -i tailscale0 -j ACCEPT"
|
rules=("iptables -I FORWARD -i tailscale0 -j ACCEPT"
|
||||||
"iptables -I FORWARD -o tailscale0 -j ACCEPT"
|
"iptables -I FORWARD -o tailscale0 -j ACCEPT"
|
||||||
"iptables -t nat -I POSTROUTING -o tailscale0 -j MASQUERADE")
|
"iptables -t nat -I POSTROUTING -o tailscale0 -j MASQUERADE")
|
||||||
|
|
||||||
for rule in "${rules[@]}"; do
|
for rule in "${rules[@]}"; do
|
||||||
if ! grep -q "^$rule$" $firewall_file; then
|
if ! grep -q "^$rule$" $firewall_file; then
|
||||||
@@ -1330,6 +1347,7 @@ configure_tailscale() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
rm /tmp/tailscale.sh
|
||||||
lan_ip=$(uci get network.lan.ipaddr)
|
lan_ip=$(uci get network.lan.ipaddr)
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user