AutoDevReverseProxy/script/sqlproxy_cli.sh
2022-12-21 19:30:38 +01:00

27 lines
603 B
Bash
Executable file

#!/usr/bin/env sh
DB_DATA_FILE="${DB_DATA_FILE:-/config/sqlproxy.json}"
ls_hosts() {
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
}
idle() {
printf "Press CTRL C to quit this connection\n"
sleep infinity
}
case "${SSH_ORIGINAL_COMMAND}" in
"") idle;;
ls) ls_hosts;;
get*) get_host;;
q|quit) exit 0;;
*) exit 1;;
esac