feat:5g代码迁移&修改配置文件

This commit is contained in:
nnbcccscdscdsc
2026-04-13 15:55:25 +08:00
parent d819f9ca4d
commit 7dc47d310d
5 changed files with 852 additions and 31 deletions

View File

@@ -7,23 +7,48 @@ source "${SCRIPT_DIR}/common.sh"
STEP="5g-dial"
run_dial() {
local rc
read_detected_interface() {
local info_json="$1"
export TERM="${TERM:-xterm}"
export LANG="${LANG:-C.UTF-8}"
export LC_ALL="${LC_ALL:-C.UTF-8}"
blitz_log "${STEP}" "dial-env" "start" "TERM=${TERM} LANG=${LANG} LC_ALL=${LC_ALL} interface=${BLITZ_5G_INTERFACE}" 0
if blitz_run "${STEP}" "dial" python3 rndis_dial.py --serial-port "${BLITZ_5G_SERIAL_PORT}" --interface "${BLITZ_5G_INTERFACE}"; then
return 0
if [[ ! -f "${info_json}" ]]; then
return 1
fi
rc=$?
blitz_log "${STEP}" "dial-retry" "start" "first dial attempt failed rc=${rc}; retrying after 3s" "${rc}"
sleep 3
blitz_run "${STEP}" "dial-retry" python3 rndis_dial.py --serial-port "${BLITZ_5G_SERIAL_PORT}" --interface "${BLITZ_5G_INTERFACE}"
python3 -c 'import json, sys; print((json.load(open(sys.argv[1], encoding="utf-8")).get("interface") or "").strip())' "${info_json}"
}
disable_interfaces() {
local raw_list="$1"
local iface
local nmcli_available=0
if [[ -z "${raw_list}" ]]; then
return 0
fi
if command -v nmcli >/dev/null 2>&1; then
nmcli_available=1
fi
for iface in ${raw_list//,/ }; do
if [[ -z "${iface}" ]]; then
continue
fi
blitz_log "${STEP}" "disable-interface" "start" "iface=${iface}" 0
if [[ "${nmcli_available}" -eq 1 ]]; then
nmcli device disconnect "${iface}" >/dev/null 2>&1 || true
fi
if ip link show dev "${iface}" >/dev/null 2>&1; then
if ip link set dev "${iface}" down; then
blitz_log "${STEP}" "disable-interface" "success" "iface=${iface}" 0
else
rc=$?
blitz_log "${STEP}" "disable-interface" "failure" "iface=${iface}" "${rc}"
return "${rc}"
fi
else
blitz_log "${STEP}" "disable-interface" "success" "iface=${iface} not present, skipping" 0
fi
done
}
wait_for_serial() {
@@ -81,22 +106,53 @@ if [[ -z "${BLITZ_TIME_SERVER_IP}" ]]; then
blitz_log "${STEP}" "precheck" "failure" "BLITZ_TIME_SERVER_IP is empty and no fallback could be derived" 1
exit 1
fi
if [[ -z "${BLITZ_5G_INTERFACE:-}" ]]; then
blitz_log "${STEP}" "precheck" "failure" "BLITZ_5G_INTERFACE must not be empty" 1
exit 1
fi
route_output="$(blitz_route_ready "${BLITZ_TIME_SERVER_IP}" "${BLITZ_5G_INTERFACE}" || true)"
if [[ -n "${route_output}" ]]; then
blitz_log "${STEP}" "dial" "already_up" "target_ip=${BLITZ_TIME_SERVER_IP} interface=${BLITZ_5G_INTERFACE} route=${route_output}" 0
exit 0
disable_interfaces "${BLITZ_5G_DISABLE_INTERFACES:-}"
if [[ -n "${BLITZ_5G_INTERFACE:-}" ]]; then
route_output="$(blitz_route_ready "${BLITZ_TIME_SERVER_IP}" "${BLITZ_5G_INTERFACE}" || true)"
if [[ -n "${route_output}" ]]; then
blitz_log "${STEP}" "dial" "already_up" "target_ip=${BLITZ_TIME_SERVER_IP} interface=${BLITZ_5G_INTERFACE} route=${route_output}" 0
exit 0
fi
else
blitz_log "${STEP}" "route-check" "info" "BLITZ_5G_INTERFACE is empty, skipping pre-dial route shortcut and using auto-detect mode" 0
fi
wait_for_serial "${BLITZ_5G_SERIAL_PORT}" "${BLITZ_5G_SERIAL_WAIT_SEC}"
dial_cmd=(
python3
rndis_dial.py
--serial-port "${BLITZ_5G_SERIAL_PORT}"
--modem-subnet "${BLITZ_5G_MODEM_SUBNET}"
)
if [[ -n "${BLITZ_5G_INTERFACE:-}" ]]; then
dial_cmd+=(--interface "${BLITZ_5G_INTERFACE}")
fi
case "${BLITZ_5G_SKIP_DHCP:-0}" in
1|true|TRUE|yes|YES)
dial_cmd+=(--skip-dhcp)
;;
esac
pushd "${BLITZ_5G_DIAL_DIR}" >/dev/null
run_dial
blitz_run "${STEP}" "dial" "${dial_cmd[@]}"
popd >/dev/null
wait_for_route "${BLITZ_TIME_SERVER_IP}" "${BLITZ_5G_ROUTE_WAIT_SEC}" "${BLITZ_5G_INTERFACE}"
blitz_log "${STEP}" "complete" "success" "5G dial completed and route is ready on ${BLITZ_5G_INTERFACE}" 0
resolved_interface="${BLITZ_5G_INTERFACE:-}"
if [[ -z "${resolved_interface}" ]]; then
resolved_interface="$(read_detected_interface "${BLITZ_5G_INFO_JSON}" || true)"
if [[ -n "${resolved_interface}" ]]; then
blitz_log "${STEP}" "resolve-interface" "success" "resolved interface from ${BLITZ_5G_INFO_JSON}: ${resolved_interface}" 0
else
blitz_log "${STEP}" "resolve-interface" "failure" "failed to read detected interface from ${BLITZ_5G_INFO_JSON}" 1
fi
fi
if [[ -n "${resolved_interface}" ]]; then
wait_for_route "${BLITZ_TIME_SERVER_IP}" "${BLITZ_5G_ROUTE_WAIT_SEC}" "${resolved_interface}"
blitz_log "${STEP}" "complete" "success" "5G dial completed and route is ready on ${resolved_interface}" 0
else
blitz_log "${STEP}" "complete" "success" "5G dial completed but route wait was skipped because no interface could be resolved; refer to rndis_dial.py logs" 0
fi