summaryrefslogtreecommitdiff
path: root/docker/cgit/docker-init.py
blob: c5b47b8db46428f652dfe47fcf9b5d8851f28064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3


import sys, os
import re


with open("/etc/cgitrc", "r") as file: cgitrc = file.read()


for env_name, env_value in os.environ.items():
    if env_name.startswith('CGIT_'):
        rc_name = env_name[5:].lower().replace('_', '-')
        p = re.compile(r"({0}=)([\w\d]+)".format(rc_name))

        if p.search(cgitrc):
            cgitrc = p.sub(r"\1{0}".format(env_value), cgitrc)
        else:
            cgitrc += ("\n" + "{0}={1}".format(rc_name, env_value) + "\n")


with open("/etc/cgitrc", "w") as file: file.write(cgitrc)