2022-11-17 13:01:07 +01:00
#!/usr/bin/env bash
2022-11-17 15:27:51 +01:00
PROJECT_PATH = $( realpath $( dirname $0 ) )
2022-11-17 13:01:07 +01:00
which myssh > /dev/null 2>& 1
if [ $? -eq 1 ]
then
mkdir -p $HOME /bin
2022-11-17 15:27:51 +01:00
cp $PROJECT_PATH /script/myssh $HOME /bin/myssh
2022-11-17 13:01:07 +01:00
if [ [ ! $PATH = ~ $HOME /bin ] ]
then
if [ [ $SHELL = ~ bin/bash$ ] ]
then
echo -e 'PATH=$PATH:$HOME/bin' >> $HOME /.bashrc
elif [ [ $SHELL = ~ bin/zsh$ ] ]
then
echo -e 'PATH=$PATH:$HOME/bin' >> $HOME /.zshrc
fi
fi
fi
2022-11-17 15:27:51 +01:00
if [ ! -f $PROJECT_PATH /etc/ssh/ssh_host_ed25519_key ]
2022-11-11 15:38:59 +01:00
then
echo "Generating sqlproxy SSHD keys"
2022-11-17 15:27:51 +01:00
ssh-keygen -f $PROJECT_PATH -A
2022-11-11 15:38:59 +01:00
fi
read -r -p "Auto generate client keys+config? [Y/n] " GEN_KEYS
case $GEN_KEYS in
[ yY] *)
mkdir -p ~/.ssh
read -r -p "Key Name (should not already exist in ~/.ssh): " KEY_NAME
2022-11-11 22:29:26 +01:00
ssh-keygen -t ed25519 -f ~/.ssh/$KEY_NAME .key -C " $( date --iso-8601) _ $( whoami) @ $HOST "
2022-11-11 15:38:59 +01:00
read -r -p "Target Host: " HOST_NAME
echo -ne " \n\nHost $HOST_NAME \n User sqlproxy\n IdentityFile ~/.ssh/ $KEY_NAME .key " >> ~/.ssh/config
2022-11-17 15:27:51 +01:00
echo -e command = \" /sqlproxy_cli.sh\" $( cat ~/.ssh/$KEY_NAME .key.pub) >> $PROJECT_PATH /etc/ssh/.ssh/authorized_keys; ;
*) 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 " ; ;
2022-11-11 15:38:59 +01:00
esac