mirror of
https://git.openwrt.org/feed/packages.git
synced 2024-06-13 10:59:13 +02:00
shadowsocks-libev: use jshn.sh for making json config
As suggested by Jeffery To in openwrt/packages#8233 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
This commit is contained in:
parent
89df405736
commit
9cfa29b873
|
@ -14,7 +14,7 @@ include $(TOPDIR)/rules.mk
|
||||||
#
|
#
|
||||||
PKG_NAME:=shadowsocks-libev
|
PKG_NAME:=shadowsocks-libev
|
||||||
PKG_VERSION:=3.2.3
|
PKG_VERSION:=3.2.3
|
||||||
PKG_RELEASE:=7
|
PKG_RELEASE:=8
|
||||||
|
|
||||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||||
PKG_SOURCE_URL:=https://github.com/shadowsocks/shadowsocks-libev/releases/download/v$(PKG_VERSION)
|
PKG_SOURCE_URL:=https://github.com/shadowsocks/shadowsocks-libev/releases/download/v$(PKG_VERSION)
|
||||||
|
|
|
@ -11,26 +11,6 @@ START=99
|
||||||
|
|
||||||
ss_confdir=/var/etc/shadowsocks-libev
|
ss_confdir=/var/etc/shadowsocks-libev
|
||||||
ss_bindir=/usr/bin
|
ss_bindir=/usr/bin
|
||||||
q='"'
|
|
||||||
|
|
||||||
ss_mkjson() {
|
|
||||||
echo "{" >"$confjson"
|
|
||||||
if ss_mkjson_ "$@" >>$confjson; then
|
|
||||||
sed -i -e '/^\s*$/d' -e '2,$s/^/\t/' -e '$s/,$//' "$confjson"
|
|
||||||
echo "}" >>"$confjson"
|
|
||||||
else
|
|
||||||
rm -f "$confjson"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ss_mkjson_() {
|
|
||||||
local func
|
|
||||||
|
|
||||||
for func in "$@"; do
|
|
||||||
"$func" || return 1
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
ss_mkjson_server_conf() {
|
ss_mkjson_server_conf() {
|
||||||
local cfgserver
|
local cfgserver
|
||||||
|
@ -45,32 +25,11 @@ ss_mkjson_server_conf() {
|
||||||
|
|
||||||
ss_mkjson_server_conf_() {
|
ss_mkjson_server_conf_() {
|
||||||
[ -n "$server_port" ] || return 1
|
[ -n "$server_port" ] || return 1
|
||||||
password="${password//\"/\\\"}"
|
[ -z "$server" ] || json_add_string server "$server"
|
||||||
cat <<-EOF
|
json_add_int server_port "$server_port"
|
||||||
${server:+${q}server${q}: ${q}$server${q},}
|
[ -z "$method" ] || json_add_string method "$method"
|
||||||
"server_port": $server_port,
|
[ -z "$key" ] || json_add_string key "$key"
|
||||||
${method:+${q}method${q}: ${q}$method${q},}
|
[ -z "$password" ] || json_add_string password "$password"
|
||||||
${key:+${q}key${q}: ${q}$key${q},}
|
|
||||||
${password:+${q}password${q}: ${q}$password${q},}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
ss_mkjson_common_conf() {
|
|
||||||
[ "$ipv6_first" = 0 ] && ipv6_first=false || ipv6_first=true
|
|
||||||
[ "$fast_open" = 0 ] && fast_open=false || fast_open=true
|
|
||||||
[ "$reuse_port" = 0 ] && reuse_port=false || reuse_port=true
|
|
||||||
cat <<-EOF
|
|
||||||
"use_syslog": true,
|
|
||||||
"ipv6_first": $ipv6_first,
|
|
||||||
"fast_open": $fast_open,
|
|
||||||
"reuse_port": $reuse_port,
|
|
||||||
${local_address:+${q}local_address${q}: ${q}$local_address${q},}
|
|
||||||
${local_port:+${q}local_port${q}: $local_port,}
|
|
||||||
${mode:+${q}mode${q}: ${q}$mode${q},}
|
|
||||||
${mtu:+${q}mtu${q}: $mtu,}
|
|
||||||
${timeout:+${q}timeout${q}: $timeout,}
|
|
||||||
${user:+${q}user${q}: ${q}$user${q},}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ss_mkjson_ss_local_conf() {
|
ss_mkjson_ss_local_conf() {
|
||||||
|
@ -88,9 +47,7 @@ ss_mkjson_ss_server_conf() {
|
||||||
ss_mkjson_ss_tunnel_conf() {
|
ss_mkjson_ss_tunnel_conf() {
|
||||||
ss_mkjson_server_conf || return 1
|
ss_mkjson_server_conf || return 1
|
||||||
[ -n "$tunnel_address" ] || return 1
|
[ -n "$tunnel_address" ] || return 1
|
||||||
cat <<-EOF
|
json_add_string tunnel_address "$tunnel_address"
|
||||||
${tunnel_address:+${q}tunnel_address${q}: ${q}$tunnel_address${q},}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ss_xxx() {
|
ss_xxx() {
|
||||||
|
@ -101,23 +58,32 @@ ss_xxx() {
|
||||||
|
|
||||||
[ -x "$bin" ] || return
|
[ -x "$bin" ] || return
|
||||||
eval "$("validate_${cfgtype}_section" "$cfg" ss_validate_mklocal)"
|
eval "$("validate_${cfgtype}_section" "$cfg" ss_validate_mklocal)"
|
||||||
"validate_${cfgtype}_section" "$cfg" || return 1
|
"validate_${cfgtype}_section" "$cfg" || return
|
||||||
[ "$disabled" = 0 ] || return
|
[ "$disabled" = 0 ] || return
|
||||||
|
|
||||||
if ss_mkjson \
|
json_init
|
||||||
ss_mkjson_common_conf \
|
ss_mkjson_${cfgtype}_conf || return
|
||||||
ss_mkjson_${cfgtype}_conf \
|
json_add_boolean use_syslog 1
|
||||||
; then
|
json_add_boolean ipv6_first "$ipv6_first"
|
||||||
procd_open_instance "$cfgtype.$cfg"
|
json_add_boolean fast_open "$fast_open"
|
||||||
procd_set_param command "$bin" -c "$confjson"
|
json_add_boolean reuse_port "$reuse_port"
|
||||||
[ "$verbose" = 0 ] || procd_append_param command -v
|
[ -z "$local_address" ] || json_add_string local_address "$local_address"
|
||||||
[ "$no_delay" = 0 ] || procd_append_param command --no-delay
|
[ -z "$local_port" ] || json_add_int local_port "$local_port"
|
||||||
[ -z "$bind_address" ] || procd_append_param command -b "$bind_address"
|
[ -z "$mode" ] || json_add_string mode "$mode"
|
||||||
procd_set_param file "$confjson"
|
[ -z "$mtu" ] || json_add_int mtu "$mtu"
|
||||||
procd_set_param respawn
|
[ -z "$timeout" ] || json_add_int timeout "$timeout"
|
||||||
procd_close_instance
|
[ -z "$user" ] || json_add_string user "$user"
|
||||||
ss_rules_cb
|
json_dump -i >"$confjson"
|
||||||
fi
|
|
||||||
|
procd_open_instance "$cfgtype.$cfg"
|
||||||
|
procd_set_param command "$bin" -c "$confjson"
|
||||||
|
[ "$verbose" = 0 ] || procd_append_param command -v
|
||||||
|
[ "$no_delay" = 0 ] || procd_append_param command --no-delay
|
||||||
|
[ -z "$bind_address" ] || procd_append_param command -b "$bind_address"
|
||||||
|
procd_set_param file "$confjson"
|
||||||
|
procd_set_param respawn
|
||||||
|
procd_close_instance
|
||||||
|
ss_rules_cb
|
||||||
}
|
}
|
||||||
|
|
||||||
ss_rules_cb() {
|
ss_rules_cb() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user