Files
staticzolaserver-docker/getOrCreateSshKeys.sh
T

41 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
LOCALUSER='swsuser'
LOCALGROUP='swsgroup'
#user is root
if [ $(id -u) -eq 0 ]
then
if [ -d /home/${LOCALUSER}/.ssh ]
then
mkdir /home/${LOCALUSER}/.ssh
chmod 700 .ssh
fi
if [ -r /run/secrets/id_ed25519 ] && [ -r /run/secrets/id_ed25519.pub ]
then
cp /run/secrets/id_ed25519 /home/${LOCALUSER}/.ssh/id_ed25519
cp /run/secrets/id_ed25519.pub /home/${LOCALUSER}/.ssh/id_ed25519.pub
chmod 600 /home/${LOCALUSER}/.ssh/id_ed25519.pub
chown ${LOCALUSER}:${LOCALGROUP} /home/${LOCALUSER}/.ssh/id_ed25519
chown ${LOCALUSER}:${LOCALGROUP} /home/${LOCALUSER}/.ssh/id_ed25519.pub
fi
# user is not root
else
if [ -d ~/.ssh ]
then
mkdir ~/.ssh
chmod 700 .ssh
fi
if [ -r /run/secrets/id_ed25519 ] && [ -r /run/secrets/id_ed25519.pub ]
then
cp /run/secrets/id_ed25519 ~/.ssh/id_ed25519
cp /run/secrets/id_ed25519.pub ~/.ssh/id_ed25519.pub
else
ssh-keygen -q -t ed25519 -C "swsuser@serinty.net" -f ~/.ssh/id_ed25519
echo "use this public key for git repo auth:"
cat /home/swsuser/.ssh/id_ed25519.pub
fi
fi