library-syncer/server/build/entrypoint.sh

33 lines
945 B
Bash
Raw Normal View History

2022-08-05 21:29:22 +00:00
#!/bin/sh
set -e
2022-08-15 22:00:18 +00:00
# create user
if [ ! $(id syncer) ]; then
adduser -u ${SYNCER_UID:-31337} -h /home/syncer -D -s /bin/sh syncer
fi
2022-08-05 21:29:22 +00:00
2022-08-15 22:00:18 +00:00
# set ssh config permissions
2022-08-05 21:29:22 +00:00
echo "$SYNC_CMD $(cat /home/syncer/.ssh/id_syncer.pub)" > /home/syncer/.ssh/authorized_keys
2022-08-15 22:00:18 +00:00
chown -R syncer:syncer /home/syncer \
&& chmod 700 /home/syncer/.ssh \
&& chmod 600 /home/syncer/.ssh/authorized_keys
2022-08-05 21:29:22 +00:00
if [ $(getent shadow syncer | awk 'BEGIN { FS = ":" } ; { print $2 }') == '!' ]; then
passwd -u syncer
fi
2022-08-15 22:00:18 +00:00
# generate host keys
2022-08-05 21:29:22 +00:00
if [ ! -f "/etc/ssh/ssh_host_rsa_key" ]; then
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
fi
if [ ! -f "/etc/ssh/ssh_host_dsa_key" ]; then
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
fi
if [ ! -d "/var/run/sshd" ]; then
mkdir -p /var/run/sshd
fi
sed -i "s/^#PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
echo -e "\n[$(date +"%Y/%m/%d-%H:%M:%S")] Starting sshd..."
exec "$@"