Setup script remove realpath (not available on MacOS)

This commit is contained in:
Kevin Baensch 2022-11-22 16:40:01 +01:00
parent 6ba9099e7c
commit 90c0bb52e3

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
PROJECT_PATH=$(realpath $(dirname $0))
PROJECT_PATH=$(dirname $0)
# Always copy newest version to bin
mkdir -p $HOME/bin
@ -43,11 +43,23 @@ case $GEN_KEYS in
then
echo -ne "\nHost $HOST_NAME\n Port 3022\n User sqlproxy\n IdentityFile ~/.ssh/$KEY_NAME.key" >> $HOME/.ssh/config
fi
# Fix permssions if necessary
if [[ ! -w $PROJECT_PATH/etc/ssh/.ssh ]] || [[ ! $PROJECT_PATH/etc/ssh/.ssh/authorized_keys ]]
then
WHOAMI=$(id -un)
echo -e "Missing file permissions for authorized key file\nrunning: 'sudo chown -R $WHOAMI:$WHOAMI $PROJECT_PATH'"
sudo chown -R $WHOAMI:$WHOAMI $PROJECT_PATH
fi
# Check if public key is already in the containers authorized_keys file
grep -qe "$(cat $HOME/.ssh/$KEY_NAME.key.pub)$" $PROJECT_PATH/etc/ssh/.ssh/authorized_keys
if [ $? -ne 0 ]
then
echo -e command=\"/sqlproxy_cli.sh\" $(cat $HOME/.ssh/$KEY_NAME.key.pub) >> $PROJECT_PATH/etc/ssh/.ssh/authorized_keys
fi
# Restart sshd if permissions were changed
if [ ! -z $WHOAMI ]
then
docker compose --project-directory $PROJECT_PATH -f $PROJECT_PATH/docker-compose.yml -f $PROJECT_PATH/docker-compose-sqlproxy.yml restart sshd
fi;;
*) 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";;
esac