sqlproxy setup: use Project Path instead of relative paths

This commit is contained in:
Kevin Baensch 2022-11-17 15:27:51 +01:00
parent 5c9bdad642
commit 81c588b5e4

View file

@ -1,10 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
PROJECT_PATH=$(realpath $(dirname $0))
which myssh > /dev/null 2>&1 which myssh > /dev/null 2>&1
if [ $? -eq 1 ] if [ $? -eq 1 ]
then then
mkdir -p $HOME/bin mkdir -p $HOME/bin
cp ./script/myssh $HOME/bin/myssh cp $PROJECT_PATH/script/myssh $HOME/bin/myssh
if [[ ! $PATH =~ $HOME/bin ]] if [[ ! $PATH =~ $HOME/bin ]]
then then
if [[ $SHELL =~ bin/bash$ ]] if [[ $SHELL =~ bin/bash$ ]]
@ -17,10 +18,10 @@ then
fi fi
fi fi
if [ ! -f ./etc/ssh/ssh_host_ed25519_key ] if [ ! -f $PROJECT_PATH/etc/ssh/ssh_host_ed25519_key ]
then then
echo "Generating sqlproxy SSHD keys" echo "Generating sqlproxy SSHD keys"
ssh-keygen -f ./ -A ssh-keygen -f $PROJECT_PATH -A
fi fi
read -r -p "Auto generate client keys+config? [Y/n] " GEN_KEYS read -r -p "Auto generate client keys+config? [Y/n] " GEN_KEYS
@ -31,7 +32,6 @@ case $GEN_KEYS in
ssh-keygen -t ed25519 -f ~/.ssh/$KEY_NAME.key -C "$(date --iso-8601)_$(whoami)@$HOST" ssh-keygen -t ed25519 -f ~/.ssh/$KEY_NAME.key -C "$(date --iso-8601)_$(whoami)@$HOST"
read -r -p "Target Host: " HOST_NAME read -r -p "Target Host: " HOST_NAME
echo -ne "\n\nHost $HOST_NAME\n User sqlproxy\n IdentityFile ~/.ssh/$KEY_NAME.key" >> ~/.ssh/config echo -ne "\n\nHost $HOST_NAME\n User sqlproxy\n IdentityFile ~/.ssh/$KEY_NAME.key" >> ~/.ssh/config
echo -e command=\"/sqlproxy_cli.sh\" $(cat ~/.ssh/$KEY_NAME.key.pub) >> ./etc/ssh/.ssh/authorized_keys echo -e command=\"/sqlproxy_cli.sh\" $(cat ~/.ssh/$KEY_NAME.key.pub) >> $PROJECT_PATH/etc/ssh/.ssh/authorized_keys;;
break;; *) echo -e "Not generating client ssh key.\nPlease put your desired public keys into $PROJECT_PATH/etc/ssh/.ssh/authorized_keys\nAlso add 'command=\"/sqlproxy_cli.sh\" ' in front of your key";;
*) echo -e "Not generating client ssh key.\nPlease put your desired public keys into ./etc/ssh/.ssh/authorized_keys\nAlso add 'command=\"/sqlproxy_cli.sh\" ' in front of your key";;
esac esac