#!/bin/sh
# /usr/lib/aethex_gpio/fix_4g_metric.sh
# 在 4G 接口获得默认路由后，将 metric 从 10 修正为 2048
# 使 end1 (metric=100) 优先于 4G

IFACE="wwu1u2i4"
TARGET_METRIC=2048

sleep 3  # 等待 quectel-CM 设置完路由

# 获取当前 4G 默认路由网关
GW=$(ip route show default dev "$IFACE" 2>/dev/null | awk '/default/{print $3; exit}')

if [ -n "$GW" ]; then
    # 删除低 metric 路由，添加高 metric 路由
    ip route del default via "$GW" dev "$IFACE" 2>/dev/null
    ip route add default via "$GW" dev "$IFACE" metric "$TARGET_METRIC" 2>/dev/null
    logger -t fix_4g_metric "Fixed $IFACE default route: via $GW metric $TARGET_METRIC"
fi
