mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-10 18:34:18 +08:00
181 lines
5.5 KiB
Bash
Executable File
181 lines
5.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# Migration script for fchomo node
|
|
# Used to migrate LuCI application nodes option.
|
|
|
|
. /lib/functions.sh
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
CONF=fchomo
|
|
|
|
config_load "$CONF"
|
|
|
|
# isDefined <section> <option>
|
|
isDefined() {
|
|
local opt=CONFIG_${1}_${2};
|
|
|
|
eval "[ -n \"\${$opt+x}\" ] && return 0 || return 1"
|
|
}
|
|
|
|
# add_list <value> <config> <section> <option>
|
|
add_list() {
|
|
uci_add_list "$2" "$3" "$4" "$1"
|
|
}
|
|
|
|
migrate() {
|
|
# mieru_port_range -> mieru_ports
|
|
if isDefined "$1" mieru_port_range; then
|
|
local mieru_port_range
|
|
config_get mieru_port_range "$1" mieru_port_range ""
|
|
uci_remove "$CONF" "$1" mieru_port_range
|
|
uci_add_list "$CONF" "$1" mieru_ports "$mieru_port_range"
|
|
fi
|
|
|
|
# vless_encryption -> vless_encryption_encryption
|
|
if isDefined "$1" vless_encryption; then
|
|
local vless_encryption
|
|
config_get vless_encryption "$1" vless_encryption "0"
|
|
if [ "$vless_encryption" != "1" -a "$vless_encryption" != "0" ]; then
|
|
uci_set "$CONF" "$1" vless_encryption "1"
|
|
uci_set "$CONF" "$1" vless_encryption_encryption "$vless_encryption"
|
|
fi
|
|
fi
|
|
|
|
# tuic_congestion_controller -> congestion_controller
|
|
if isDefined "$1" tuic_congestion_controller; then
|
|
local tuic_congestion_controller
|
|
config_get tuic_congestion_controller "$1" tuic_congestion_controller ""
|
|
uci_remove "$CONF" "$1" tuic_congestion_controller
|
|
uci_set "$CONF" "$1" congestion_controller "$tuic_congestion_controller"
|
|
fi
|
|
|
|
# masque_congestion_controller -> congestion_controller
|
|
if isDefined "$1" masque_congestion_controller; then
|
|
local masque_congestion_controller
|
|
config_get masque_congestion_controller "$1" masque_congestion_controller ""
|
|
uci_remove "$CONF" "$1" masque_congestion_controller
|
|
uci_set "$CONF" "$1" congestion_controller "$masque_congestion_controller"
|
|
fi
|
|
|
|
# tuic_max_open_streams -> max_open_streams
|
|
if isDefined "$1" tuic_max_open_streams; then
|
|
local tuic_max_open_streams
|
|
config_get tuic_max_open_streams "$1" tuic_max_open_streams ""
|
|
uci_remove "$CONF" "$1" tuic_max_open_streams
|
|
uci_set "$CONF" "$1" max_open_streams "$tuic_max_open_streams"
|
|
fi
|
|
|
|
# hysteria_up_mbps -> brutal_up_mbps
|
|
if isDefined "$1" hysteria_up_mbps; then
|
|
local hysteria_up_mbps
|
|
config_get hysteria_up_mbps "$1" hysteria_up_mbps ""
|
|
uci_remove "$CONF" "$1" hysteria_up_mbps
|
|
uci_set "$CONF" "$1" brutal_up_mbps "$hysteria_up_mbps"
|
|
fi
|
|
|
|
# hysteria_down_mbps -> brutal_down_mbps
|
|
if isDefined "$1" hysteria_down_mbps; then
|
|
local hysteria_down_mbps
|
|
config_get hysteria_down_mbps "$1" hysteria_down_mbps ""
|
|
uci_remove "$CONF" "$1" hysteria_down_mbps
|
|
uci_set "$CONF" "$1" brutal_down_mbps "$hysteria_down_mbps"
|
|
fi
|
|
|
|
# plugin -> plugin_type
|
|
if isDefined "$1" plugin && ! isDefined "$1" plugin_type; then
|
|
local plugin
|
|
config_get plugin "$1" plugin ""
|
|
uci_set "$CONF" "$1" plugin "1"
|
|
uci_set "$CONF" "$1" plugin_type "$plugin"
|
|
fi
|
|
|
|
# wireguard_ip -> endpoint_ip
|
|
if isDefined "$1" wireguard_ip; then
|
|
local wireguard_ip
|
|
config_get wireguard_ip "$1" wireguard_ip ""
|
|
uci_remove "$CONF" "$1" wireguard_ip
|
|
uci_set "$CONF" "$1" endpoint_ip "$wireguard_ip"
|
|
fi
|
|
|
|
# masque_ip -> endpoint_ip
|
|
if isDefined "$1" masque_ip; then
|
|
local masque_ip
|
|
config_get masque_ip "$1" masque_ip ""
|
|
uci_remove "$CONF" "$1" masque_ip
|
|
uci_set "$CONF" "$1" endpoint_ip "$masque_ip"
|
|
fi
|
|
|
|
# wireguard_ipv6 -> endpoint_ipv6
|
|
if isDefined "$1" wireguard_ipv6; then
|
|
local wireguard_ipv6
|
|
config_get wireguard_ipv6 "$1" wireguard_ipv6 ""
|
|
uci_remove "$CONF" "$1" wireguard_ipv6
|
|
uci_set "$CONF" "$1" endpoint_ipv6 "$wireguard_ipv6"
|
|
fi
|
|
|
|
# masque_ipv6 -> endpoint_ipv6
|
|
if isDefined "$1" masque_ipv6; then
|
|
local masque_ipv6
|
|
config_get masque_ipv6 "$1" masque_ipv6 ""
|
|
uci_remove "$CONF" "$1" masque_ipv6
|
|
uci_set "$CONF" "$1" endpoint_ipv6 "$masque_ipv6"
|
|
fi
|
|
|
|
# wireguard_mtu -> endpoint_mtu
|
|
if isDefined "$1" wireguard_mtu; then
|
|
local wireguard_mtu
|
|
config_get wireguard_mtu "$1" wireguard_mtu ""
|
|
uci_remove "$CONF" "$1" wireguard_mtu
|
|
uci_set "$CONF" "$1" endpoint_mtu "$wireguard_mtu"
|
|
fi
|
|
|
|
# masque_mtu -> endpoint_mtu
|
|
if isDefined "$1" masque_mtu; then
|
|
local masque_mtu
|
|
config_get masque_mtu "$1" masque_mtu ""
|
|
uci_remove "$CONF" "$1" masque_mtu
|
|
uci_set "$CONF" "$1" endpoint_mtu "$masque_mtu"
|
|
fi
|
|
|
|
# wireguard_remote_dns_resolve -> endpoint_remote_dns_resolve
|
|
if isDefined "$1" wireguard_remote_dns_resolve; then
|
|
local wireguard_remote_dns_resolve
|
|
config_get wireguard_remote_dns_resolve "$1" wireguard_remote_dns_resolve ""
|
|
uci_remove "$CONF" "$1" wireguard_remote_dns_resolve
|
|
uci_set "$CONF" "$1" endpoint_remote_dns_resolve "$wireguard_remote_dns_resolve"
|
|
fi
|
|
|
|
# masque_remote_dns_resolve -> endpoint_remote_dns_resolve
|
|
if isDefined "$1" masque_remote_dns_resolve; then
|
|
local masque_remote_dns_resolve
|
|
config_get masque_remote_dns_resolve "$1" masque_remote_dns_resolve ""
|
|
uci_remove "$CONF" "$1" masque_remote_dns_resolve
|
|
uci_set "$CONF" "$1" endpoint_remote_dns_resolve "$masque_remote_dns_resolve"
|
|
fi
|
|
|
|
# wireguard_dns -> endpoint_dns
|
|
if isDefined "$1" wireguard_dns; then
|
|
config_list_foreach "$1" wireguard_dns add_list "$CONF" "$1" endpoint_dns
|
|
uci_remove "$CONF" "$1" wireguard_dns
|
|
fi
|
|
|
|
# masque_dns -> endpoint_dns
|
|
if isDefined "$1" masque_dns; then
|
|
config_list_foreach "$1" masque_dns add_list "$CONF" "$1" endpoint_dns
|
|
uci_remove "$CONF" "$1" masque_dns
|
|
fi
|
|
|
|
# zerotier_ipstack -> ipstack
|
|
if isDefined "$1" zerotier_ipstack; then
|
|
local zerotier_ipstack
|
|
config_get zerotier_ipstack "$1" zerotier_ipstack ""
|
|
uci_remove "$CONF" "$1" zerotier_ipstack
|
|
uci_set "$CONF" "$1" ipstack "$zerotier_ipstack"
|
|
fi
|
|
}
|
|
|
|
config_foreach migrate node
|
|
|
|
uci_commit "$CONF"
|
|
|
|
exit 0
|