mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-05 09:54:06 +08:00
🗽 Sync 2026-09-29 04:49:38
This commit is contained in:
1 parent
1ba92ebff1
commit
cec9f6bff2
87 files changed
+25281
No files matched your search
@@ -0,0 +1,68 @@
|
||||
config tailscale 'settings'
|
||||
# Set whether Tailcale is enabled or not
|
||||
option enabled '0'
|
||||
# Set the port to listen on for incoming Tailscale packets (default 41641)
|
||||
option port '41641'
|
||||
# Allow WAN inbound UDP traffic to the local Tailscale listen port for first-packet direct connections
|
||||
#option allow_wan_direct '0'
|
||||
# Firewall source zones used when WAN direct is enabled
|
||||
list wan_direct_zones 'wan'
|
||||
# Path to config file
|
||||
option config_path '/etc/tailscale'
|
||||
# Default to using nftables - change below to 'iptables' if still using iptables
|
||||
option fw_mode 'nftables'
|
||||
# Enable stdout log
|
||||
option log_stdout '1'
|
||||
# Enable stderr log
|
||||
option log_stderr '1'
|
||||
# Accept subnet routes that other nodes advertise
|
||||
#option accept_routes '1'
|
||||
# Provide a hostname to use for the device instead of the one provided by the OS
|
||||
#option hostname ''
|
||||
# Accept DNS configuration from the admin console. (default accept)
|
||||
option accept_dns '1'
|
||||
# Offer to be an exit node for outbound internet traffic from the Tailscale network
|
||||
#option advertise_exit_node '1'
|
||||
# Provide a Tailscale IP or machine name to use as an exit node
|
||||
#option exit_node ''
|
||||
# Expose physical subnet routes to your entire Tailscale network (e.g. 10.0.0.0/24)
|
||||
#list advertise_routes ''
|
||||
# Set to '1' to disable subnet route masquerading
|
||||
#option disable_snat_subnet_routes '1'
|
||||
# Set firewall zone (ts_ac_lan: Tailscale access LAN, ts_ac_wan: Tailscale access WAN:, lan_ac_ts: LAN access Tailscale, wan_ac_ts: WAN access Tailscale)
|
||||
# Documentation https://openwrt.org/docs/guide-user/services/vpn/tailscale/start
|
||||
#list access 'ts_ac_lan'
|
||||
#list access 'ts_ac_wan'
|
||||
#list access 'lan_ac_ts'
|
||||
#list access 'wan_ac_ts'
|
||||
# Enable periodic Tailscale pings to keep selected peer paths warm
|
||||
#option keepalive_enabled '0'
|
||||
# Select peer hostnames from tailscale status --json
|
||||
#list keepalive_peers ''
|
||||
# Seconds between keepalive probes
|
||||
option keepalive_interval '20'
|
||||
# Seconds between repeated failure log messages for the same peer
|
||||
option keepalive_failure_log_interval '300'
|
||||
# Enable automatic AdGuard Home upstream switching based on tailnet DNS health
|
||||
#option adguard_dns_switch_enabled '0'
|
||||
# Configure at least one default upstream in LuCI before enabling the switch
|
||||
#list adguard_default_upstreams ''
|
||||
# Configure at least one tailnet upstream in LuCI before enabling the switch
|
||||
#list adguard_tailnet_upstreams ''
|
||||
# Domain and expected IPs for tailnet DNS health checks through 100.100.100.100; fill both before enabling
|
||||
#option adguard_health_domain ''
|
||||
# Add at least one expected IP before enabling the AdGuard DNS switch
|
||||
#list adguard_health_expected_ips ''
|
||||
# Seconds between AdGuard DNS health checks
|
||||
option adguard_check_interval '10'
|
||||
# Consecutive health check results required before switching profiles
|
||||
option adguard_success_threshold '2'
|
||||
option adguard_failure_threshold '2'
|
||||
# AdGuard Home API endpoint and optional credentials
|
||||
option adguard_api_url 'http://127.0.0.1:3000'
|
||||
#option adguard_username ''
|
||||
# Set extra flags for enabling settings upon the initiation of Tailscale
|
||||
# Documentation https://tailscale.com/kb/1241/tailscale-up
|
||||
#list flags ''
|
||||
# Provide the base URL of a custom server instead of https://controlplane.tailscale.com
|
||||
#option login_server ''
|
||||
@@ -0,0 +1,2 @@
|
||||
config openclash 'settings'
|
||||
option enabled '1'
|
||||
@@ -0,0 +1,3 @@
|
||||
config settings 'settings'
|
||||
# Prefer Tailscale table 52 before mwan3 fwmark policy rules.
|
||||
option enabled '0'
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
POLICY_HELPER="${POLICY_HELPER:-/usr/sbin/tailscale_policy_routing}"
|
||||
LOGGER_CMD="${LOGGER_CMD:-logger}"
|
||||
|
||||
case "${ACTION:-}" in
|
||||
ifup|ifupdate) ;;
|
||||
*) exit 0 ;;
|
||||
esac
|
||||
|
||||
[ -x "$POLICY_HELPER" ] || exit 0
|
||||
|
||||
"$POLICY_HELPER" ensure >/dev/null 2>&1 || \
|
||||
"$LOGGER_CMD" -p daemon.err -t tailscale_policy_routing 'failed to restore Tailscale table 52 policy priority'
|
||||
Executable
+313
@@ -0,0 +1,313 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=90
|
||||
|
||||
USE_PROCD=1
|
||||
|
||||
PROG=/usr/sbin/tailscale_helper
|
||||
PROGK=/usr/sbin/tailscale_keepalive
|
||||
PROGA=/usr/sbin/tailscale_adguard_dns_switch
|
||||
PROGS=/usr/sbin/tailscale_secrets
|
||||
PROGD=/usr/sbin/tailscaled
|
||||
CONFIG_PATH=/var/lib/tailscale
|
||||
ADGUARD_DNS_STATE_DIR="${ADGUARD_DNS_STATE_DIR:-/var/run/tailscale_adguard_dns_switch}"
|
||||
FIREWALL_PENDING_STATE_FILE="${FIREWALL_PENDING_STATE_FILE:-/var/run/tailscale-firewall-pending}"
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "tailscale"
|
||||
}
|
||||
|
||||
reload_in_progress() {
|
||||
[ "${TAILSCALE_INTERNAL_RELOAD:-0}" = "1" ]
|
||||
}
|
||||
|
||||
section_enabled() {
|
||||
config_get_bool enabled "$1" 'enabled' 0
|
||||
[ $enabled -gt 0 ]
|
||||
}
|
||||
|
||||
append_wan_direct_zone() {
|
||||
wan_direct_zones="${wan_direct_zones:+$wan_direct_zones }$1"
|
||||
}
|
||||
|
||||
normalize_tailscale_port() {
|
||||
case "$1" in
|
||||
''|*[!0-9]*) printf '%s\n' 41641 ;;
|
||||
*)
|
||||
if [ "$1" -ge 1 ] 2>/dev/null && [ "$1" -le 65535 ] 2>/dev/null; then
|
||||
printf '%s\n' "$1"
|
||||
else
|
||||
printf '%s\n' 41641
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
tailscale_helper() {
|
||||
local cfg="$1"
|
||||
local state_was_present="${2:-0}"
|
||||
local accept_routes hostname accept_dns advertise_exit_node exit_node advertise_routes disable_snat_subnet_routes allow_wan_direct wan_direct_zones access flags login_server std_out std_err port
|
||||
|
||||
config_get port $cfg 'port'
|
||||
port="$(normalize_tailscale_port "$port")"
|
||||
config_get_bool accept_routes $cfg 'accept_routes' 0
|
||||
config_get hostname $cfg 'hostname'
|
||||
config_get_bool accept_dns $cfg 'accept_dns' 1
|
||||
config_get_bool advertise_exit_node $cfg 'advertise_exit_node' 0
|
||||
config_get exit_node $cfg 'exit_node'
|
||||
config_get advertise_routes $cfg 'advertise_routes'
|
||||
config_get_bool disable_snat_subnet_routes $cfg 'disable_snat_subnet_routes' 0
|
||||
config_get_bool allow_wan_direct $cfg 'allow_wan_direct' 0
|
||||
wan_direct_zones=""
|
||||
config_list_foreach "$cfg" 'wan_direct_zones' append_wan_direct_zone
|
||||
wan_direct_zones="${wan_direct_zones:-wan}"
|
||||
config_get access $cfg 'access'
|
||||
config_get flags $cfg 'flags'
|
||||
config_get login_server $cfg 'login_server'
|
||||
config_get_bool std_out $cfg 'log_stdout'
|
||||
config_get_bool std_err $cfg 'log_stderr'
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command $PROG --run
|
||||
|
||||
[ "$accept_routes" = "1" ] && procd_append_param command --accept-routes=true
|
||||
[ -n "$hostname" ] && procd_append_param command --hostname="$hostname"
|
||||
[ "$accept_dns" = "0" ] && procd_append_param command --accept-dns=false
|
||||
[ "$advertise_exit_node" = "1" ] && procd_append_param command --advertise-exit-node
|
||||
[ -n "$exit_node" ] && {
|
||||
procd_append_param command --exit-node="$exit_node"
|
||||
procd_append_param command --exit-node-allow-lan-access=true
|
||||
}
|
||||
[ -n "$advertise_routes" ] && procd_append_param command --advertise-routes="$(echo $advertise_routes | tr ' ' ',')"
|
||||
if [ "$disable_snat_subnet_routes" = "1" ]; then
|
||||
procd_append_param command --snat-subnet-routes=false
|
||||
else
|
||||
procd_append_param command --snat-subnet-routes=true
|
||||
fi
|
||||
[ -n "$flags" ] && procd_append_param command $flags
|
||||
[ -n "$login_server" ] && procd_append_param command --login-server="$login_server"
|
||||
|
||||
procd_set_param env \
|
||||
ACCEPT_DNS="$accept_dns" \
|
||||
EXIT_NODE="$exit_node" \
|
||||
ACCESS="$access" \
|
||||
DISABLE_SNAT_SUBNET_ROUTES="$disable_snat_subnet_routes" \
|
||||
ALLOW_WAN_DIRECT="$allow_wan_direct" \
|
||||
WAN_DIRECT_ZONES="$wan_direct_zones" \
|
||||
TAILSCALE_PORT="$port" \
|
||||
TAILSCALE_STATE_WAS_PRESENT="$state_was_present" \
|
||||
TAILSCALE_HELPER_STATE_DIR="$CONFIG_PATH" \
|
||||
FIREWALL_PENDING_STATE_FILE="$FIREWALL_PENDING_STATE_FILE"
|
||||
|
||||
procd_set_param stdout "$std_out"
|
||||
procd_set_param stderr "$std_err"
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
tailscale_keepalive() {
|
||||
local cfg="$1"
|
||||
local keepalive_enabled keepalive_peers keepalive_interval keepalive_failure_log_interval std_out std_err
|
||||
|
||||
config_get_bool keepalive_enabled $cfg 'keepalive_enabled' 0
|
||||
[ "$keepalive_enabled" = "1" ] || return 0
|
||||
|
||||
config_get keepalive_peers $cfg 'keepalive_peers'
|
||||
[ -n "$keepalive_peers" ] || {
|
||||
logger -p daemon.err -t tailscale "keepalive enabled but no peers configured"
|
||||
return 0
|
||||
}
|
||||
|
||||
config_get keepalive_interval $cfg 'keepalive_interval' 20
|
||||
config_get keepalive_failure_log_interval $cfg 'keepalive_failure_log_interval' 300
|
||||
config_get_bool std_out $cfg 'log_stdout'
|
||||
config_get_bool std_err $cfg 'log_stderr'
|
||||
|
||||
procd_open_instance keepalive
|
||||
procd_set_param command $PROGK --run "$keepalive_interval" "$keepalive_failure_log_interval"
|
||||
procd_append_param command $keepalive_peers
|
||||
procd_set_param respawn
|
||||
procd_set_param stdout "$std_out"
|
||||
procd_set_param stderr "$std_err"
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
tailscale_adguard_dns() {
|
||||
local cfg="$1"
|
||||
local adguard_dns_switch_enabled std_out std_err
|
||||
local adguard_health_domain adguard_health_expected_ips
|
||||
local adguard_default_upstreams adguard_tailnet_upstreams
|
||||
|
||||
config_get_bool adguard_dns_switch_enabled "$cfg" 'adguard_dns_switch_enabled' 0
|
||||
[ "$adguard_dns_switch_enabled" = "1" ] || return 0
|
||||
|
||||
config_get adguard_health_domain "$cfg" 'adguard_health_domain'
|
||||
config_get adguard_health_expected_ips "$cfg" 'adguard_health_expected_ips'
|
||||
config_get adguard_default_upstreams "$cfg" 'adguard_default_upstreams'
|
||||
config_get adguard_tailnet_upstreams "$cfg" 'adguard_tailnet_upstreams'
|
||||
|
||||
[ -n "$adguard_health_domain" ] || {
|
||||
logger -p daemon.err -t tailscale_adguard_dns "adguard_dns_switch_enabled=1 but adguard_health_domain is not configured"
|
||||
return 0
|
||||
}
|
||||
[ -n "$adguard_health_expected_ips" ] || {
|
||||
logger -p daemon.err -t tailscale_adguard_dns "adguard_dns_switch_enabled=1 but adguard_health_expected_ips is not configured"
|
||||
return 0
|
||||
}
|
||||
[ -n "$adguard_default_upstreams" ] || {
|
||||
logger -p daemon.err -t tailscale_adguard_dns "adguard_dns_switch_enabled=1 but adguard_default_upstreams is not configured"
|
||||
return 0
|
||||
}
|
||||
[ -n "$adguard_tailnet_upstreams" ] || {
|
||||
logger -p daemon.err -t tailscale_adguard_dns "adguard_dns_switch_enabled=1 but adguard_tailnet_upstreams is not configured"
|
||||
return 0
|
||||
}
|
||||
|
||||
config_get_bool std_out "$cfg" 'log_stdout' 1
|
||||
config_get_bool std_err "$cfg" 'log_stderr' 1
|
||||
|
||||
procd_open_instance adguard_dns
|
||||
procd_set_param command "$PROGA" --run
|
||||
procd_set_param respawn
|
||||
procd_set_param stdout "$std_out"
|
||||
procd_set_param stderr "$std_err"
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
tailscale_adguard_dns_apply_down() {
|
||||
local cfg="$1"
|
||||
local adguard_dns_switch_enabled adguard_current_profile
|
||||
|
||||
config_get_bool adguard_dns_switch_enabled "$cfg" 'adguard_dns_switch_enabled' 0
|
||||
adguard_current_profile="$(cat "$ADGUARD_DNS_STATE_DIR/current_profile" 2>/dev/null || true)"
|
||||
[ "$adguard_current_profile" != "down" ] || return 0
|
||||
[ "$adguard_dns_switch_enabled" = "1" ] || [ "$adguard_current_profile" = "up" ] || return 0
|
||||
|
||||
"$PROGA" --apply-profile down >/dev/null 2>&1 || {
|
||||
logger -p daemon.err -t tailscale_adguard_dns "failed to restore AdGuard DNS down profile"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
start_instance() {
|
||||
local cfg="$1"
|
||||
local port config_path fw_mode std_out std_err state_file state_was_present allow_wan_direct secrets_ref
|
||||
|
||||
config_get secrets_ref "$cfg" 'secrets_ref'
|
||||
if [ -n "$secrets_ref" ] && ! "$PROGS" activate "$secrets_ref"; then
|
||||
logger -p daemon.err -t tailscale "failed to activate protected credential version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! section_enabled "$cfg"; then
|
||||
TAILSCALE_HELPER_STATE_DIR="$CONFIG_PATH" \
|
||||
FIREWALL_PENDING_STATE_FILE="$FIREWALL_PENDING_STATE_FILE" \
|
||||
"$PROG" --cleanup-managed-firewall || logger -p daemon.err -t tailscale "failed to remove managed firewall state for disabled service"
|
||||
echo "disabled in /etc/config/tailscale"
|
||||
return 1
|
||||
fi
|
||||
|
||||
config_get port $cfg 'port'
|
||||
port="$(normalize_tailscale_port "$port")"
|
||||
config_get config_path $cfg 'config_path'
|
||||
config_get fw_mode $cfg 'fw_mode'
|
||||
config_get_bool std_out $cfg 'log_stdout'
|
||||
config_get_bool std_err $cfg 'log_stderr'
|
||||
config_get_bool allow_wan_direct $cfg 'allow_wan_direct' 0
|
||||
if [ "$allow_wan_direct" != "1" ]; then
|
||||
TAILSCALE_HELPER_STATE_DIR="$CONFIG_PATH" \
|
||||
FIREWALL_PENDING_STATE_FILE="$FIREWALL_PENDING_STATE_FILE" \
|
||||
"$PROG" --cleanup-wan-direct-firewall || return 1
|
||||
fi
|
||||
|
||||
[ -d $config_path ] || mkdir -p $config_path
|
||||
[ -d $CONFIG_PATH ] || mkdir -p $CONFIG_PATH
|
||||
state_file="$config_path/tailscaled.state"
|
||||
state_was_present=0
|
||||
[ ! -s "$state_file" ] || state_was_present=1
|
||||
|
||||
"$PROGD" --cleanup
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command $PROGD
|
||||
|
||||
procd_append_param command --port "$port"
|
||||
[ -n "$state_file" ] && procd_append_param command --state "$state_file"
|
||||
|
||||
procd_set_param env TS_DEBUG_FIREWALL_MODE="$fw_mode"
|
||||
|
||||
procd_set_param respawn
|
||||
procd_set_param stdout "$std_out"
|
||||
procd_set_param stderr "$std_err"
|
||||
procd_close_instance
|
||||
|
||||
tailscale_helper "$cfg" "$state_was_present"
|
||||
tailscale_keepalive "$cfg"
|
||||
tailscale_adguard_dns "$cfg"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
"$PROGS" migrate || {
|
||||
logger -p daemon.err -t tailscale "failed to migrate protected credentials"
|
||||
return 1
|
||||
}
|
||||
config_load 'tailscale'
|
||||
config_foreach start_instance 'tailscale'
|
||||
}
|
||||
|
||||
stop_instance() {
|
||||
local cfg="$1"
|
||||
local helper_cleanup_failed=0 cleanup_action
|
||||
|
||||
if reload_in_progress; then
|
||||
cleanup_action=--cleanup-exit-node-firewall
|
||||
else
|
||||
cleanup_action=--cleanup-managed-firewall
|
||||
fi
|
||||
TAILSCALE_HELPER_STATE_DIR="$CONFIG_PATH" \
|
||||
FIREWALL_PENDING_STATE_FILE="$FIREWALL_PENDING_STATE_FILE" \
|
||||
"$PROG" "$cleanup_action" || helper_cleanup_failed=1
|
||||
|
||||
# Remove dnsmasq settings
|
||||
MagicDNSSuffix=$(tailscale status --json | awk -F'"' '/"MagicDNSSuffix"/ {last=$(NF-1)} END {print last}')
|
||||
if [ -n "$MagicDNSSuffix" ]; then
|
||||
target_address="/$MagicDNSSuffix/100.100.100.100"
|
||||
indexes=$(uci show dhcp | sed -n 's/^dhcp\.@dnsmasq\[\([0-9][0-9]*\)\]=dnsmasq$/\1/p')
|
||||
for index in $indexes; do
|
||||
option="dhcp.@dnsmasq[$index].address"
|
||||
uci -q del_list "$option=$target_address"
|
||||
done
|
||||
fi
|
||||
|
||||
# Tailscale owns tailscale0, policy rules, and table 52 routes. Do not reload
|
||||
# network here; netifd must not manage tailscale0.
|
||||
[ -n "$(uci changes dhcp)" ] && uci commit dhcp && /etc/init.d/dnsmasq reload
|
||||
|
||||
"$PROGD" --cleanup
|
||||
|
||||
# Keep helper recovery state available when firewall cleanup needs a retry.
|
||||
[ "$helper_cleanup_failed" -ne 0 ] || rm -rf "$CONFIG_PATH"
|
||||
|
||||
[ "$helper_cleanup_failed" -eq 0 ]
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
config_load 'tailscale'
|
||||
config_foreach stop_instance 'tailscale'
|
||||
}
|
||||
|
||||
service_stopped() {
|
||||
config_load 'tailscale'
|
||||
config_foreach tailscale_adguard_dns_apply_down 'tailscale'
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
local reload_status=0
|
||||
TAILSCALE_INTERNAL_RELOAD=1
|
||||
stop || reload_status=1
|
||||
TAILSCALE_INTERNAL_RELOAD=0
|
||||
if ! start; then
|
||||
reload_status=1
|
||||
stop || reload_status=1
|
||||
fi
|
||||
return "$reload_status"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
PROG="${PROG:-/usr/sbin/tailscale_openclash_bypass}"
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "tailscale_openclash"
|
||||
}
|
||||
|
||||
sync_instance() {
|
||||
"$PROG" sync
|
||||
}
|
||||
|
||||
start_service() {
|
||||
sync_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
start_service
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
"$PROG" cleanup
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=91
|
||||
USE_PROCD=1
|
||||
|
||||
PROG="${PROG:-/usr/sbin/tailscale_policy_routing}"
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "tailscale_policy_routing"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
"$PROG" sync || true
|
||||
"$PROG" enabled || return 0
|
||||
|
||||
procd_open_instance monitor
|
||||
procd_set_param command "$PROG" monitor
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
start_service
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
# Persistent cleanup is reserved for an explicit disable or package removal.
|
||||
# A normal service stop must not erase the enabled UCI declaration.
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#!/bin/sh
|
||||
|
||||
UPGRADE_STATE_DIR="${UPGRADE_STATE_DIR:-/etc/.luci-app-tailscale-upgrade}"
|
||||
TAILSCALE_SECRETS_BIN="${TAILSCALE_SECRETS_BIN:-/usr/sbin/tailscale_secrets}"
|
||||
UCI_BIN="${UCI_BIN:-uci}"
|
||||
OPENCLASH_BYPASS_INIT="${OPENCLASH_BYPASS_INIT:-/etc/init.d/tailscale-openclash-bypass}"
|
||||
POLICY_ROUTING_INIT="${POLICY_ROUTING_INIT:-/etc/init.d/tailscale-policy-routing}"
|
||||
LEGACY_ADGUARD_DNS_INIT="${LEGACY_ADGUARD_DNS_INIT:-/etc/init.d/tailscale-adguard-dns}"
|
||||
LEGACY_ADGUARD_DNS_RC_DIR="${LEGACY_ADGUARD_DNS_RC_DIR:-/etc/rc.d}"
|
||||
LEGACY_ADGUARD_DNS_BACKUP_DIR="${LEGACY_ADGUARD_DNS_BACKUP_DIR:-/etc/tailscale/luci-app-tailscale-legacy}"
|
||||
LUCI_INDEX_CACHE="${LUCI_INDEX_CACHE:-/tmp/luci-indexcache}"
|
||||
|
||||
cleanup_upgrade_state() {
|
||||
rm -f "$UPGRADE_STATE_DIR/tailscale" "$UPGRADE_STATE_DIR/tailscale_openclash" \
|
||||
"$UPGRADE_STATE_DIR/tailscale_openclash.absent" "$UPGRADE_STATE_DIR/tailscale_policy_routing" \
|
||||
"$UPGRADE_STATE_DIR/.complete"
|
||||
rmdir "$UPGRADE_STATE_DIR" 2>/dev/null || true
|
||||
}
|
||||
|
||||
restore_upgrade_config() {
|
||||
local source_file="$1" target_file="$2" temporary_file
|
||||
|
||||
[ -f "$source_file" ] || return 0
|
||||
temporary_file="$target_file.luci-app-tailscale-upgrade.$$"
|
||||
cp "$source_file" "$temporary_file" || return 1
|
||||
mv "$temporary_file" "$target_file" || {
|
||||
rm -f "$temporary_file"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
cleanup_legacy_adguard_dns_service() {
|
||||
local backup_dir link
|
||||
|
||||
[ -e "$LEGACY_ADGUARD_DNS_INIT" ] || return 0
|
||||
backup_dir="$LEGACY_ADGUARD_DNS_BACKUP_DIR/tailscale-adguard-dns.$(date +%Y%m%d%H%M%S).$$"
|
||||
mkdir -p "$backup_dir" || return 1
|
||||
|
||||
for link in "$LEGACY_ADGUARD_DNS_RC_DIR"/*tailscale-adguard-dns; do
|
||||
[ -e "$link" ] || [ -L "$link" ] || continue
|
||||
printf '%s\t%s\n' "${link##*/}" "$(readlink "$link" 2>/dev/null || true)" >>"$backup_dir/rc-links"
|
||||
done
|
||||
|
||||
if [ -x "$LEGACY_ADGUARD_DNS_INIT" ]; then
|
||||
"$LEGACY_ADGUARD_DNS_INIT" stop || return 1
|
||||
"$LEGACY_ADGUARD_DNS_INIT" disable || true
|
||||
fi
|
||||
|
||||
cp -p "$LEGACY_ADGUARD_DNS_INIT" "$backup_dir/init" || return 1
|
||||
for link in "$LEGACY_ADGUARD_DNS_RC_DIR"/*tailscale-adguard-dns; do
|
||||
[ -e "$link" ] || [ -L "$link" ] || continue
|
||||
rm -f "$link" || return 1
|
||||
done
|
||||
mv "$LEGACY_ADGUARD_DNS_INIT" "$backup_dir/tailscale-adguard-dns.disabled" || return 1
|
||||
}
|
||||
|
||||
if [ -f "$UPGRADE_STATE_DIR/.complete" ]; then
|
||||
restore_upgrade_config "$UPGRADE_STATE_DIR/tailscale" /etc/config/tailscale || exit 1
|
||||
if [ -f "$UPGRADE_STATE_DIR/tailscale_openclash.absent" ]; then
|
||||
rm -f /etc/config/tailscale_openclash
|
||||
else
|
||||
restore_upgrade_config "$UPGRADE_STATE_DIR/tailscale_openclash" /etc/config/tailscale_openclash || exit 1
|
||||
fi
|
||||
restore_upgrade_config "$UPGRADE_STATE_DIR/tailscale_policy_routing" /etc/config/tailscale_policy_routing || exit 1
|
||||
cleanup_upgrade_state
|
||||
elif [ -d "$UPGRADE_STATE_DIR" ]; then
|
||||
cleanup_upgrade_state
|
||||
fi
|
||||
|
||||
cleanup_legacy_adguard_dns_service || exit 1
|
||||
|
||||
"$TAILSCALE_SECRETS_BIN" migrate || exit 1
|
||||
|
||||
openclash_bypass_enabled="$("$UCI_BIN" -q get tailscale_openclash.settings.enabled 2>/dev/null || true)"
|
||||
if [ "$openclash_bypass_enabled" = '1' ] && [ -x "$OPENCLASH_BYPASS_INIT" ]; then
|
||||
"$OPENCLASH_BYPASS_INIT" enable
|
||||
"$OPENCLASH_BYPASS_INIT" start
|
||||
fi
|
||||
|
||||
if [ -x "$POLICY_ROUTING_INIT" ]; then
|
||||
"$POLICY_ROUTING_INIT" enable
|
||||
"$POLICY_ROUTING_INIT" start
|
||||
fi
|
||||
|
||||
rm -f "$LUCI_INDEX_CACHE"
|
||||
exit 0
|
||||
Reference in new issue
Block a user