From cbf5251de30cfff251d20c7c31689867b229f05b Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 2 Aug 2021 16:53:49 +0200 Subject: [PATCH] Added setupEnvironment to copy missing config-files --- daemon.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index aa2b38d..9a172dc 100755 --- a/daemon.py +++ b/daemon.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -import os, re, _thread, socket, sys, re, yaml, logging as log +import shutil, os, re, _thread, socket, sys, re, yaml, logging as log import dnslib as dns @@ -8,6 +8,7 @@ config = None def main(args): setupLogging(True) + setupEnvironment() global config config = readConfig("/data/config.yml") @@ -16,6 +17,31 @@ def main(args): startListen(s) +def setupEnvironment(): + if not os.path.exists('/data'): + os.mkdir("/data") + + (all, some) = copyAllFiles("data/", "/data") + if all: + log.warn("Configuration-files were created!") + log.warn(" Make sure to change them according to your setup") + elif some: + log.warn("Some configuration-files were recreated, because they were missing") + +def copyAllFiles(src, dst, overwrite=False): + all=True + some=False + for file in os.listdir(src): + src_file = os.path.join(src, file) + dst_file = os.path.join(dst, file) + if os.path.isfile(src_file): + if overwrite or not os.path.exists(dst_file): + shutil.copyfile(src_file, dst_file) + some=True + else: + all=False + return (all, some) + def setupSocket(address, port): # IPv4/IPv6-check if address == "" or ":" in address: