summaryrefslogtreecommitdiff
path: root/caddy/entrypoint.sh
blob: 16edf3632cc3fe534bd3eb68aec1e747c93eb916 (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
#!/bin/sh
set -e

PROXY_CONF=/tmp/proxy_forward.caddy

# Build basicauth lines from shared users.conf (skip if PROXY_NO_AUTH=1)
AUTH_LINES=""
if [ "${PROXY_NO_AUTH:-0}" != "1" ] && [ -f /etc/proxy/users.conf ]; then
    while IFS=' ' read -r user pass || [ -n "$user" ]; do
        [ -z "$user" ] && continue
        case "$user" in \#*) continue ;; esac
        AUTH_LINES="${AUTH_LINES}        basicauth ${user} ${pass}\n"
    done < /etc/proxy/users.conf
fi
AUTH_BLOCK=$(printf '%b' "$AUTH_LINES")

cat > "$PROXY_CONF" <<EOF
http://proxy.yyamashita.com {
    forward_proxy {
${AUTH_BLOCK}        hide_ip
        hide_via
    }
}
https://proxy.yyamashita.com {
    tls {
        key_type rsa4096
    }
    forward_proxy {
${AUTH_BLOCK}        hide_ip
        hide_via
    }
}
EOF

exec "$@"