#!/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, .dbname, .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