myssh: Allow override for sql cli command through template string

This commit is contained in:
Kevin Baensch 2022-11-18 11:58:52 +01:00
parent 8a896cda42
commit 0dac239d6d

View file

@ -1,5 +1,15 @@
#!/usr/bin/env bash
if [ -z $SQL_CLI_TEMPLATE ]
then
if [ $(uname -s) = "Linux" ]
then
SQL_CLI_TEMPLATE='mysql --protocol=TCP -u $MYSQL_USERNAME -p$MYSQL_PASSWORD -h localhost -P 3306'
else
SQL_CLI_TEMPLATE='open \"mysql://$MYSQL_USERNAME:$MYSQL_PASSWORD@localhost:3306\" -a \"Sequel Ace\"'
fi
fi
[ -z $SQL_PROXY_HOST ] && SQL_PROXY_HOST="localhost"
[ -z $SQL_PROXY_DB_PORT ] && SQL_PROXY_DB_PORT="3306"
CONNECTION_CACHE="$HOME/.cache/sqlproxy_$SQL_PROXY_HOST"
@ -54,12 +64,7 @@ ls_hosts() {
}
run_client() {
if [ $(uname -s) = "Linux" ]
then
mysql --protocol=TCP -u $1 -p$2 -h localhost -P 3306
else
open "mysql://$1:$2@localhost:3306" -a "Sequel Ace"
fi
$(eval echo $SQL_CLI_TEMPLATE)
}
MAIN_OPTION=$1
@ -88,7 +93,7 @@ case $MAIN_OPTION in
port_forward $TARGET_HOST
if [ ! -z $MYSQL_USERNAME ] && [ ! -z $MYSQL_PASSWORD ]
then
run_client $MYSQL_USERNAME $MYSQL_PASSWORD
run_client
fi
else
echo "Invalid Hostname: $TARGET_HOST."