summaryrefslogtreecommitdiff
path: root/entrypoint.sh
blob: 3737a7e8fde2d7eca2134911b1cf6ccdeff649b2 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
set -Eeuo pipefail

# Copy over the secrets to fix permissions
mkdir -p /run/git-host/secrets
cp /etc/git-host/secrets/authorized_keys /run/git-host/secrets/authorized_keys
cp /etc/git-host/secrets/htpasswd /run/git-host/secrets/htpasswd
cp /etc/git-host/secrets/ssh_host_ed25519_key /run/git-host/secrets/ssh_host_ed25519_key
cp /etc/git-host/secrets/ssh_host_ed25519_key.pub /run/git-host/secrets/ssh_host_ed25519_key.pub
cp /etc/git-host/secrets/ssh_host_rsa_key /run/git-host/secrets/ssh_host_rsa_key
cp /etc/git-host/secrets/ssh_host_rsa_key.pub /run/git-host/secrets/ssh_host_rsa_key.pub
chown -R root:root /run/git-host/secrets
chown root:git /run/git-host/secrets/authorized_keys
chown root:git /run/git-host/secrets/htpasswd
chown root:root /run/git-host/secrets/ssh_host_ed25519_key
chown root:root /run/git-host/secrets/ssh_host_ed25519_key.pub
chown root:root /run/git-host/secrets/ssh_host_rsa_key
chown root:root /run/git-host/secrets/ssh_host_rsa_key.pub
chmod 0755 /run/git-host /run/git-host/secrets
chmod 0640 /run/git-host/secrets/authorized_keys
chmod 0640 /run/git-host/secrets/htpasswd
chmod 0600 /run/git-host/secrets/ssh_host_ed25519_key
chmod 0644 /run/git-host/secrets/ssh_host_ed25519_key.pub
chmod 0600 /run/git-host/secrets/ssh_host_rsa_key
chmod 0644 /run/git-host/secrets/ssh_host_rsa_key.pub

# Validate
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
lighttpd -tt -f /etc/lighttpd/lighttpd.conf

# Start servers
/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config &
sshd_pid=$!

lighttpd -D -f /etc/lighttpd/lighttpd.conf &
lighttpd_pid=$!

# Wait for them to end, kill if either does
terminate() {
  kill "${sshd_pid}" "${lighttpd_pid}" 2>/dev/null || true
}

trap terminate INT TERM

status=0
wait -n "${sshd_pid}" "${lighttpd_pid}" || status=$?
terminate
wait "${sshd_pid}" 2>/dev/null || true
wait "${lighttpd_pid}" 2>/dev/null || true
exit "${status}"