aboutsummaryrefslogtreecommitdiff
path: root/kolla/docker/letsencrypt/letsencrypt-base/extend_start.sh
blob: 3a0481bcd94491a74c2577285cc214a24612f39a (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
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

# Structure for lego and webserver

FOLDERS_LEGO="/etc/letsencrypt /etc/letsencrypt/lego /etc/letsencrypt/lego/internal /etc/letsencrypt/lego/external"
FOLDERS_WEBSERVER="/etc/letsencrypt/http-01 /etc/letsencrypt/http-01/.well-known /etc/letsencrypt/http-01/.well-known/acme-challenge"

if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu ]]; then
    USER="www-data"
    GROUP="www-data"
    USERGROUP_WEBSERVER="${USER}:${GROUP}"
    USERGROUP="haproxy:haproxy"
else
    USER="apache"
    GROUP="apache"
    USERGROUP_WEBSERVER="${USER}:${GROUP}"
    USERGROUP="haproxy:haproxy"
fi

for folder in ${FOLDERS_LEGO}; do
    if [[ ! -d "${folder}" ]]; then
        mkdir -p ${folder}
    fi

    if [[ $(stat -c %U:%G ${folder}) != "${USERGROUP}" ]]; then
        if getent passwd ${USER} 2 > /dev/null; then
            chown ${USERGROUP} ${folder}
        fi
    fi

    if [[ "${folder}" == "/etc/letsencrypt" ]]; then
        if [[ $(stat -c %a ${folder}) != "751" ]]; then
            chmod 751 ${folder}
        fi
    else
        if [[ $(stat -c %a ${folder}) != "755" ]]; then
            chmod 755 ${folder}
        fi
    fi
done

for folder in ${FOLDERS_WEBSERVER}; do
    if [[ ! -d "${folder}" ]]; then
        mkdir -p ${folder}
    fi

    if [[ $(stat -c %U:%G ${folder}) != "${USERGROUP_WEBSERVER}" ]]; then
        if getent passwd ${USER} 2 > /dev/null; then
            chown ${USERGROUP_WEBSERVER} ${folder}
        fi
    fi

    if [[ $(stat -c %a ${folder}) != "755" ]]; then
        chmod 755 ${folder}
    fi
done

if [ -e /usr/local/bin/kolla_letsencrypt_extend_start ]; then
    . /usr/local/bin/kolla_letsencrypt_extend_start
fi