docker-gitolite/docker-entrypoint.sh

38 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2016-02-24 10:24:26 +01:00
#!/bin/sh
# if command is sshd, set it up correctly
if [ "${1}" = 'sshd' ]; then
set -- /usr/sbin/sshd -D
# Setup SSH HostKeys if needed
2025-01-05 19:43:13 +01:00
for algorithm in rsa ecdsa ed25519
2016-02-24 10:24:26 +01:00
do
keyfile=/etc/ssh/keys/ssh_host_${algorithm}_key
[ -f $keyfile ] || ssh-keygen -q -N '' -f $keyfile -t $algorithm
grep -q "HostKey $keyfile" /etc/ssh/sshd_config || echo "HostKey $keyfile" >> /etc/ssh/sshd_config
done
fi
2017-04-13 11:12:52 +02:00
# Fix permissions at every startup
chown -R git:git ~git
2016-02-24 10:24:26 +01:00
# Setup gitolite admin
if [ ! -f ~git/.ssh/authorized_keys ]; then
if [ -n "$SSH_KEY" ]; then
[ -n "$SSH_KEY_NAME" ] || SSH_KEY_NAME=admin
echo "$SSH_KEY" > "/tmp/$SSH_KEY_NAME.pub"
su - git -c "gitolite setup -pk \"/tmp/$SSH_KEY_NAME.pub\""
rm "/tmp/$SSH_KEY_NAME.pub"
else
echo "You need to specify SSH_KEY on first run to setup gitolite"
echo "You can also use SSH_KEY_NAME to specify the key name (optional)"
echo 'Example: docker run -e SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" -e SSH_KEY_NAME="$(whoami)" jgiannuzzi/gitolite'
exit 1
fi
# Check setup at every startup
else
su - git -c "gitolite setup"
fi
exec "$@"