Refactor restart_splify function for clarity
This commit is contained in:
1 parent
9e22e5acf3
commit
2ff163cbb3
1 file changed
+39
-4
+39
-4
@@ -143,10 +143,30 @@ if ! curl -fsSL --max-time 60 "$II" -o "$REG" >/dev/null 2>&1; then echo -e "${R
|
||||
PRIV="$(jq -r '.result.key' "$REG")"; WARP_PEER="$(jq -r '.result.config.peers[0].public_key' "$REG")"; WARP_V4="$(jq -r '.result.config.interface.addresses.v4' "$REG")"; WARP_V6="$(jq -r '.result.config.interface.addresses.v6 // empty' "$REG")"; fi; if [ -z "$WARP_PEER" ]
|
||||
then WARP_PEER="$(jq -r '.config.peers[0].public_key' "$REG")"; WARP_V4="$(jq -r '.config.interface.addresses.v4' "$REG")"; WARP_V6="$(jq -r '.config.interface.addresses.v6 // empty' "$REG")"; fi
|
||||
[ -n "$WARP_PEER" ] && [ "$WARP_PEER" != "null" ] || { echo -e "${RED}Нет peer public_key${NC}"; PAUSE; return 1; }; [ -n "$WARP_V4" ] && [ "$WARP_V4" != "null" ] || { echo -e "${RED}Нет IPv4${NC}"; PAUSE; return 1; }; echo -e "WARP ${GREEN}сгенерирован!${NC}"; }
|
||||
restart_splify() { echo -e "\n${MAGENTA}Перезапускаем splify${NC}"; echo -en "${YELLOW}Подождите...${NC}"; /usr/local/sbin/splify-disable >/dev/null 2>&1; /etc/init.d/splify enable >/dev/null 2>&1; /etc/init.d/splify-agent enable >/dev/null 2>&1; /usr/local/sbin/splify-apply >/dev/null 2>&1
|
||||
uci commit network; ifdown "$WARP_IFACE" >/dev/null 2>&1; ifup "$WARP_IFACE" >/dev/null 2>&1; uci commit network
|
||||
|
||||
restart_splify() {
|
||||
|
||||
echo -e "\n${MAGENTA}Перезапускаем splify${NC}"
|
||||
echo -en "${YELLOW}Подождите...${NC}"
|
||||
/usr/local/sbin/splify-disable >/dev/null 2>&1
|
||||
|
||||
/etc/init.d/splify enable >/dev/null 2>&1
|
||||
/etc/init.d/splify-agent enable >/dev/null 2>&1
|
||||
|
||||
uci -q set splify.global.telemetry="0" && uci commit splify
|
||||
/etc/init.d/splify restart >/dev/null 2>&1; /etc/init.d/splify-agent restart >/dev/null 2>&1; /usr/local/sbin/splify-apply >/dev/null 2>&1; echo -e "\n\nsplify ${GREEN}перезапущен!${NC}"; }
|
||||
|
||||
/etc/init.d/splify restart >/dev/null 2>&1
|
||||
sleep 3
|
||||
/etc/init.d/splify-agent restart >/dev/null 2>&1
|
||||
sleep 3
|
||||
|
||||
/usr/local/sbin/splify-apply >/dev/null 2>&1
|
||||
sleep 10
|
||||
echo -e "\n\nsplify ${GREEN}перезапущен!${NC}"
|
||||
echo -e "\n${YELLOW}Инициализация splify может занять несколько минут!${NC}"
|
||||
}
|
||||
|
||||
|
||||
WARP_TO_ROOT() { printf '%s\n' "[Interface]" "PrivateKey = $PRIV" "Address = $WARP_V4${WARP_V6:+, $WARP_V6}" "DNS = 8.8.8.8, 8.8.4.4, 2001:4860:4860::8888, 2001:4860:4860::8844" "MTU = 1280" "S1 = $AWG_S1" "S2 = $AWG_S2" "Jc = $AWG_JC" "Jmin = $AWG_JMIN" "Jmax = $AWG_JMAX" "H1 = $AWG_H1" "H2 = $AWG_H2" "H3 = $AWG_H3" "H4 = $AWG_H4" "I1 = $AWG_I1" "" "[Peer]" "PublicKey = $WARP_PEER" "AllowedIPs = 0.0.0.0/0, ::/0" "Endpoint = $WARP_EP" "PersistentKeepalive = 25" > /root/WARP.conf; echo -e "${YELLOW}Файл ${NC}WARP${YELLOW} сохранён в ${NC}/root/WARP.conf"; }
|
||||
# ──────────────────────────── 5. create warp0 interface ─────────────────────
|
||||
create_warp_iface() { echo -e "\n${MAGENTA}Создаём интерфейс $WARP_IFACE${NC}"; if [ -n "$(uci -q get "network.$WARP_IFACE")" ]; then echo -e "${CYAN}Перенастраиваем интерфейс ${NC}$WARP_IFACE"; ifdown "$WARP_IFACE" >/dev/null 2>&1; fi
|
||||
@@ -156,7 +176,22 @@ uci set "network.$WARP_IFACE.route_allowed_ips=0"; uci set "network.$WARP_IFACE.
|
||||
uci set "network.$WARP_IFACE.awg_h2=$AWG_H2"; uci set "network.$WARP_IFACE.awg_h3=$AWG_H3"; uci set "network.$WARP_IFACE.awg_h4=$AWG_H4"; uci set "network.$WARP_IFACE.awg_s1=$AWG_S1"; uci set "network.$WARP_IFACE.awg_s2=$AWG_S2"
|
||||
uci set "network.$WARP_IFACE.awg_i1=$AWG_I1"; _pt="amneziawg_$WARP_IFACE"; while [ -n "$(uci -q get "network.@${_pt}[0]")" ]; do uci -q delete "network.@${_pt}[0]"; done; uci add network "$_pt" >/dev/null; uci set "network.@${_pt}[-1].public_key=$WARP_PEER"
|
||||
uci -q delete "network.@${_pt}[-1].allowed_ips"; uci add_list "network.@${_pt}[-1].allowed_ips=0.0.0.0/0"; uci add_list "network.@${_pt}[-1].allowed_ips=::/0"; uci set "network.@${_pt}[-1].endpoint_host=${WARP_EP%:*}"
|
||||
uci set "network.@${_pt}[-1].endpoint_port=${WARP_EP##*:}"; uci set "network.@${_pt}[-1].persistent_keepalive=25"; echo -e "${CYAN}Перезапускаем сеть${NC}"; uci commit network; /etc/init.d/network restart; /etc/init.d/ttyd restart >/dev/null 2>&1; ifup "$WARP_IFACE" >/dev/null 2>&1 || { echo -e "\n${RED}Не удалось запустить ${NC}$WARP_IFACE\n"; PAUSE; return 1; }; }
|
||||
uci set "network.@${_pt}[-1].endpoint_port=${WARP_EP##*:}"; uci set "network.@${_pt}[-1].persistent_keepalive=25"
|
||||
|
||||
echo -e "${CYAN}Перезапускаем сеть${NC}"
|
||||
|
||||
uci commit network >/dev/null 2>&1
|
||||
/etc/init.d/rpcd restart >/dev/null 2>&1
|
||||
/etc/init.d/uhttpd restart >/dev/null 2>&1
|
||||
rm -rf /tmp/luci-* >/dev/null 2>&1
|
||||
ip link del "$WARP_IFACE" >/dev/null 2>&1
|
||||
killall netifd >/dev/null 2>&1
|
||||
sleep 3
|
||||
ifup "$WARP_IFACE" >/dev/null 2>&1
|
||||
sleep 3
|
||||
|
||||
}
|
||||
|
||||
# ──────────────────────────── 6. register endpoint in splify ────────────────
|
||||
register_in_splify() { _ei=0; while [ -n "$(uci -q get "splify.@endpoint[$_ei]" 2>/dev/null)" ]; do _ei_if="$(uci -q get "splify.@endpoint[$_ei].iface" 2>/dev/null)"; if [ -n "$_ei_if" ] && [ -z "$(uci -q get "network.$_ei_if" 2>/dev/null)" ]
|
||||
then uci -q delete "splify.@endpoint[$_ei]"; else _ei=$((_ei + 1)); fi; done; uci commit splify; grep -q "option iface '$WARP_IFACE'" /etc/config/splify 2>/dev/null || printf "\nconfig endpoint\n\toption iface '$WARP_IFACE'\n\toption priority '1'\n\toption type 'wg'\n" >> /etc/config/splify; }
|
||||
|
||||
Reference in new issue
Block a user