v2raya: init: convert arguments into env variables
authorTianling Shen <cnsztl@immortalwrt.org>
Fri, 4 Feb 2022 10:12:09 +0000 (18:12 +0800)
committerRosen Penev <rosenp@gmail.com>
Fri, 4 Feb 2022 16:28:41 +0000 (08:28 -0800)
Suggested by upstream, to provide forward compatibility.

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
net/v2raya/files/v2raya.init

index cb8173711105dd45db949385e20611d680f2ed2b..f1374914d42ff8a19332dc64e03df42735ab0247 100755 (executable)
@@ -17,18 +17,18 @@ is_enabled() {
        fi
 }
 
-append_param() {
-       procd_append_param command "$1" $2
+append_env() {
+       procd_append_param env "V2RAYA_$(echo "$1" | tr "[a-z]" "[A-Z]")"="$2"
 }
 
-append_param_arg() {
+append_env_arg() {
        local value
        config_get value "$1" "$2" $3
-       [ -n "$value" ] && append_param "--${2//_/-}" "$value"
+       [ -n "$value" ] && append_env "$2" "$value"
 }
 
-append_param_bool() {
-       is_enabled "$1" "$2" && append_param "--${2//_/-}"
+append_env_bool() {
+       is_enabled "$1" "$2" && append_env "$2" "true"
 }
 
 start_service() {
@@ -39,17 +39,17 @@ start_service() {
        procd_open_instance "$CONF"
        procd_set_param command "$PROG"
 
-       append_param_arg "config" "address" "0.0.0.0:2017"
-       append_param_arg "config" "config" "/etc/v2raya"
-       append_param_arg "config" "ipv6_support" "auto"
-       append_param_arg "config" "log_level" "info"
-       append_param_arg "config" "log_file" "/tmp/v2raya.log"
-       append_param_arg "config" "log_max_days" "3"
-       append_param_arg "config" "v2ray_bin"
-       append_param_arg "config" "v2ray_confdir"
-       append_param_arg "config" "vless_grpc_inbound_cert_key"
-       append_param_bool "config" "log_disable_color"
-       append_param_bool "config" "log_disable_timestamp"
+       append_env_arg "config" "address" "0.0.0.0:2017"
+       append_env_arg "config" "config" "/etc/v2raya"
+       append_env_arg "config" "ipv6_support" "auto"
+       append_env_arg "config" "log_level" "info"
+       append_env_arg "config" "log_file" "/tmp/v2raya.log"
+       append_env_arg "config" "log_max_days" "3"
+       append_env_arg "config" "v2ray_bin"
+       append_env_arg "config" "v2ray_confdir"
+       append_env_arg "config" "vless_grpc_inbound_cert_key"
+       append_env_bool "config" "log_disable_color"
+       append_env_bool "config" "log_disable_timestamp"
 
        procd_set_param limits core="unlimited"
        procd_set_param respawn