aboutsummaryrefslogtreecommitdiff
path: root/roles/git/files/gitolite-cgit/entrypoint.sh
blob: 3ad094f5a491e63785bb17cbc79faa42d9d52359 (plain) (blame)
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
51
52
53
54
55
56
#!/bin/sh

# Fixup permissions.
chown git:git -R /var/lib/git
# Ensure password is set for git user (required for gitolite).
echo "git:$(head -c 16 /dev/urandom | base64)" | chpasswd

# -- SETUP: gitolite -----------------------------------------------------------

if [ ! -f /var/lib/git/.gitolite.rc ]; then
    cp /etc/gitolite.rc /var/lib/git/.gitolite.rc
    chown git:git /var/lib/git/.gitolite.rc
fi

if [ ! -f /var/lib/git/.ssh/authorized_keys ]; then
    if [ -z ${SSH_KEY} ]; then
        echo "ERROR: Must pass admin key ass SSH_KEY!"
        exit 1
    fi

    echo "${SSH_KEY}" > /tmp/admin.pub
    su - git -c 'gitolite setup --pubkey /tmp/admin.pub'
    rm -f /tmp/admin.pub

    # Change default git branch.
    # IMPORTANT:
    #   Only do this after gitolite is initialized, as gitolite only applies
    #   changes made to the *master* branch in the gitolite-admin repository.
    su - git -c 'git config --global init.defaultBranch main'
else
    # Fixup gitolite, eg in case a new repo was added manually.
    su - git -c 'gitolite setup'
fi

# -- SETUP: cgit ---------------------------------------------------------------

# Ensure default cache directory exists.
# Adapt if cache-root is changed in cgitrc(5).
mkdir -p /var/cache/cgit

# -- SETUP: sshd ---------------------------------------------------------------

# Generate ssh host keys (nop if keys already exist).
ssh-keygen -A

# -- SETUP: nginx --------------------------------------------------------------

rm -f /etc/nginx/http.d/default.conf

# -- Launch processes ----------------------------------------------------------

spawn-fcgi -s /run/fcgiwrap.sock -U nginx -- /usr/bin/fcgiwrap
nginx

# Start sshd non-detached.
/usr/sbin/sshd -D