diff --git a/net/shadowsocks-libev/Makefile b/net/shadowsocks-libev/Makefile index 970a41a07f..ff2b3a8e97 100644 --- a/net/shadowsocks-libev/Makefile +++ b/net/shadowsocks-libev/Makefile @@ -14,7 +14,7 @@ include $(TOPDIR)/rules.mk # PKG_NAME:=shadowsocks-libev PKG_VERSION:=3.2.3 -PKG_RELEASE:=7 +PKG_RELEASE:=8 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://github.com/shadowsocks/shadowsocks-libev/releases/download/v$(PKG_VERSION) diff --git a/net/shadowsocks-libev/files/shadowsocks-libev.init b/net/shadowsocks-libev/files/shadowsocks-libev.init index 9ab1051c87..e6a7b062cf 100644 --- a/net/shadowsocks-libev/files/shadowsocks-libev.init +++ b/net/shadowsocks-libev/files/shadowsocks-libev.init @@ -11,26 +11,6 @@ START=99 ss_confdir=/var/etc/shadowsocks-libev 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() { local cfgserver @@ -45,32 +25,11 @@ ss_mkjson_server_conf() { ss_mkjson_server_conf_() { [ -n "$server_port" ] || return 1 - password="${password//\"/\\\"}" - cat <<-EOF - ${server:+${q}server${q}: ${q}$server${q},} - "server_port": $server_port, - ${method:+${q}method${q}: ${q}$method${q},} - ${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 + [ -z "$server" ] || json_add_string server "$server" + json_add_int server_port "$server_port" + [ -z "$method" ] || json_add_string method "$method" + [ -z "$key" ] || json_add_string key "$key" + [ -z "$password" ] || json_add_string password "$password" } ss_mkjson_ss_local_conf() { @@ -88,9 +47,7 @@ ss_mkjson_ss_server_conf() { ss_mkjson_ss_tunnel_conf() { ss_mkjson_server_conf || return 1 [ -n "$tunnel_address" ] || return 1 - cat <<-EOF - ${tunnel_address:+${q}tunnel_address${q}: ${q}$tunnel_address${q},} - EOF + json_add_string tunnel_address "$tunnel_address" } ss_xxx() { @@ -101,23 +58,32 @@ ss_xxx() { [ -x "$bin" ] || return eval "$("validate_${cfgtype}_section" "$cfg" ss_validate_mklocal)" - "validate_${cfgtype}_section" "$cfg" || return 1 + "validate_${cfgtype}_section" "$cfg" || return [ "$disabled" = 0 ] || return - if ss_mkjson \ - ss_mkjson_common_conf \ - ss_mkjson_${cfgtype}_conf \ - ; then - 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 - fi + json_init + ss_mkjson_${cfgtype}_conf || return + json_add_boolean use_syslog 1 + json_add_boolean ipv6_first "$ipv6_first" + json_add_boolean fast_open "$fast_open" + json_add_boolean reuse_port "$reuse_port" + [ -z "$local_address" ] || json_add_string local_address "$local_address" + [ -z "$local_port" ] || json_add_int local_port "$local_port" + [ -z "$mode" ] || json_add_string mode "$mode" + [ -z "$mtu" ] || json_add_int mtu "$mtu" + [ -z "$timeout" ] || json_add_int timeout "$timeout" + [ -z "$user" ] || json_add_string user "$user" + json_dump -i >"$confjson" + + 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() {