Skip to content

Commit

Permalink
Replace null with empty when jq fails to get value.
Browse files Browse the repository at this point in the history
  • Loading branch information
loyess committed May 30, 2022
1 parent 0884b72 commit ec648e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions service/go-shadowsocks2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ get_config_args(){
exit 1
fi

ServerPort=$(cat ${JsonFilePath} | jq -r .server_port)
ServerPort=$(cat ${JsonFilePath} | jq -r '.server_port // empty')
[ -z "$ServerPort" ] && echo -e "Configuration option 'server_port' acquisition failed" && exit 1
Password=$(cat ${JsonFilePath} | jq -r .password)
Password=$(cat ${JsonFilePath} | jq -r '.password // empty')
[ -z "$Password" ] && echo -e "Configuration option 'password' acquisition failed" && exit 1
Method=$(cat ${JsonFilePath} | jq -r .method)
Method=$(cat ${JsonFilePath} | jq -r '.method // empty')
[ -z "$Method" ] && echo -e "Configuration option 'method' acquisition failed" && exit 1
Mode=$(cat ${JsonFilePath} | jq -r .mode)
Mode=$(cat ${JsonFilePath} | jq -r '.mode // empty')
[ -z "$Mode" ] && echo -e "Configuration option 'Mode' acquisition failed" && exit 1

if [[ ${Method} == "aes-128-gcm" ]]; then
Expand All @@ -99,9 +99,9 @@ get_config_args(){
fi

if $(cat ${JsonFilePath} | grep -qE 'plugin|plugin_opts'); then
Plugin=$(cat ${JsonFilePath} | jq -r .plugin)
Plugin=$(cat ${JsonFilePath} | jq -r '.plugin // empty')
[ -z "$Plugin" ] && echo -e "Configuration option 'plugin' acquisition failed" && exit 1
PluginOpts=$(cat ${JsonFilePath} | jq -r .plugin_opts)
PluginOpts=$(cat ${JsonFilePath} | jq -r '.plugin_opts // empty')
[ -z "$PluginOpts" ] && echo -e "Configuration option 'plugin_opts' acquisition failed" && exit 1
fi
}
Expand Down
8 changes: 4 additions & 4 deletions service/rabbit-tcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ if [ ! "$(command -v jq)" ]; then
exit 1
fi

Mode=$(cat ${CONF} | jq -r .mode)
Mode=$(cat ${CONF} | jq -r '.mode // empty')
[ -z "$Mode" ] && echo -e "Configuration option 'mode' acquisition failed" && exit 1
RabbitAddr=$(cat ${CONF} | jq -r .rabbit_addr)
RabbitAddr=$(cat ${CONF} | jq -r '.rabbit_addr // empty')
[ -z "$RabbitAddr" ] && echo -e "Configuration option 'rabbit_addr' acquisition failed" && exit 1
PassWord=$(cat ${CONF} | jq -r .password)
PassWord=$(cat ${CONF} | jq -r '.password // empty')
[ -z "$PassWord" ] && echo -e "Configuration option 'password' acquisition failed" && exit 1
Verbose=$(cat ${CONF} | jq -r .verbose)
Verbose=$(cat ${CONF} | jq -r '.verbose // empty')
[ -z "$Verbose" ] && echo -e "Configuration option 'verbose' acquisition failed" && exit 1


Expand Down
4 changes: 3 additions & 1 deletion service/shadowsocks-rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ get_config_args(){
exit 1
fi

NameServer=$(cat ${JsonFilePath} | jq -r .nameserver)
# ref: https://stackoverflow.com/questions/53135035/jq-returning-null-as-string-if-the-json-is-empty
# ref: https://github.com/stedolan/jq/issues/354#issuecomment-43147898
NameServer=$(cat ${JsonFilePath} | jq -r '.nameserver // empty')
[ -z "$NameServer" ] && echo -e "Configuration option 'nameserver' acquisition failed" && exit 1
}

Expand Down

0 comments on commit ec648e9

Please sign in to comment.