AutoDevReverseProxy/script/sqlproxy_cli.sh

28 lines
603 B
Bash
Raw Normal View History

2022-11-11 22:29:26 +01:00
#!/usr/bin/env sh
2022-12-21 19:30:38 +01:00
DB_DATA_FILE="${DB_DATA_FILE:-/config/sqlproxy.json}"
2022-11-11 22:29:26 +01:00
ls_hosts() {
2022-12-21 19:30:38 +01:00
jq -r '.[].host' < "${DB_DATA_FILE}"
}
get_host() {
export HOST=$(echo "${SSH_ORIGINAL_COMMAND}" | cut -d ' ' -f2)
if [ "${HOST}" != 'get' ]
then
jq -r 'first(.[] | select(.host == $ENV.HOST)) | [ .type, .ip, .port, .user, .password ] | join(" ")' < "${DB_DATA_FILE}"
fi
2022-11-11 22:29:26 +01:00
}
idle() {
2022-12-21 19:30:38 +01:00
printf "Press CTRL C to quit this connection\n"
2022-11-11 22:29:26 +01:00
sleep infinity
}
2022-12-21 19:30:38 +01:00
case "${SSH_ORIGINAL_COMMAND}" in
2022-11-17 13:01:07 +01:00
"") idle;;
ls) ls_hosts;;
2022-12-21 19:30:38 +01:00
get*) get_host;;
2022-11-17 13:01:07 +01:00
q|quit) exit 0;;
*) exit 1;;
esac