Last active
July 27, 2023 17:16
-
-
Save vimagick/e38f64f28fb5c0bae21d6af2788a1493 to your computer and use it in GitHub Desktop.
(OpenWrt) /etc/config/shadowsocks && /etc/init.d/ss-tunnel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config port_forward 'world' | |
| option local_port '5300' | |
| option destination '8.8.4.4:53' | |
| option mtu '1492' | |
| list server 'nil' | |
| config port_forward 'china' | |
| option protocol 'udp' | |
| option local_port '5353' | |
| option destination '223.5.5.5:53' | |
| option mtu '1492' | |
| list server 'nil' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh /etc/rc.common | |
| # Copyright (C) 2023 EasyPi Software Foundation | |
| # start after and stop before shadowsocks | |
| START=91 | |
| STOP=14 | |
| PIDCOUNT=0 | |
| USE_PROCD=1 | |
| PROG=/usr/bin/ss-tunnel | |
| NAME=ss-tunnel | |
| SERVER=hk | |
| validate_section_port_forward() | |
| { | |
| uci_validate_section shadowsocks port_forward "${1}" \ | |
| 'protocol:or("tcp", "udp", "both"):both' \ | |
| 'local_port:port' \ | |
| 'destination:string' \ | |
| 'mtu:uinteger' | |
| } | |
| port_forward_instance() | |
| { | |
| local local_port destination mtu | |
| validate_section_port_forward "${1}" || { | |
| echo "validation failed" | |
| return 1 | |
| } | |
| PIDCOUNT="$(( ${PIDCOUNT} + 1))" | |
| procd_open_instance | |
| procd_set_param command "${PROG}" -c /var/etc/shadowsocks.${SERVER}.json --no-delay | |
| [ -n "${local_port}" ] && procd_append_param command -l "${local_port}" | |
| [ -n "${destination}" ] && procd_append_param command -L "${destination}" | |
| [ -n "${mtu}" ] && procd_append_param command --mtu "${mtu}" | |
| case "${protocol}" in | |
| "both") procd_append_param command -u;; | |
| "udp") procd_append_param command -U;; | |
| "tcp") ;; | |
| esac | |
| procd_set_param pidfile /var/run/${NAME}-${PIDCOUNT}.pid | |
| procd_set_param respawn | |
| procd_close_instance | |
| } | |
| start_service() | |
| { | |
| config_load "shadowsocks" | |
| config_foreach port_forward_instance port_forward | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment