-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
expose-gitlab-ssh-port.sh
33 lines (26 loc) · 1.27 KB
/
expose-gitlab-ssh-port.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
set -ev
GITLAB_USERGROUP=${GITLAB_USERGROUP:-1010}
GITLAB_SSH_PORT=${GITLAB_SSH_PORT:-9922}
if ! id -u git >> /dev/null 2>&1; then
groupadd -g ${GITLAB_USERGROUP} git
useradd -m -u ${GITLAB_USERGROUP} -g git -s /bin/sh -d /home/git git
fi
su git -c "mkdir -p /home/git/.ssh/"
su git -c "if [ ! -f /home/git/.ssh/id_rsa ]; then ssh-keygen -t rsa -b 4096 -N \"\" -f /home/git/.ssh/id_rsa; fi"
su git -c "if [ -f /home/git/.ssh/id_rsa.pub ]; then mv /home/git/.ssh/id_rsa.pub /home/git/.ssh/authorized_keys_proxy; fi"
mkdir -p /home/git/gitlab-shell/bin/
rm -f /home/git/gitlab-shell/bin/gitlab-shell
tee -a /home/git/gitlab-shell/bin/gitlab-shell > /dev/null <<EOF
#!/bin/sh
ssh -i /home/git/.ssh/id_rsa -p ${GITLAB_SSH_PORT} -o StrictHostKeyChecking=no [email protected] "SSH_ORIGINAL_COMMAND=\"\$SSH_ORIGINAL_COMMAND\" \$0 \$@"
EOF
chown git:git /home/git/gitlab-shell/bin/gitlab-shell
chmod u+x /home/git/gitlab-shell/bin/gitlab-shell
mkdir -p /var/lib/gitlab/data/.ssh/
chown git:git -R /var/lib/gitlab/data/.ssh/
chown git:git -R /home/git/.ssh
su git -c "touch /var/lib/gitlab/data/.ssh/authorized_keys"
rm -f /home/git/.ssh/authorized_keys
su git -c "ln -s /var/lib/gitlab/data/.ssh/authorized_keys /home/git/.ssh/authorized_keys"
echo "Next start GitLab container"