diff options
author | crupest <crupest@outlook.com> | 2022-10-30 22:44:26 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-10-30 22:44:26 +0800 |
commit | efdfc6feb5744d8ad4bd07e35fa8d662925e3e96 (patch) | |
tree | 54352395daf743185d88c6e9540b690e95f7e5d0 /template/generate.py | |
parent | fc3eb7968a204c78153946e260289ff2f4c695e7 (diff) | |
download | crupest-efdfc6feb5744d8ad4bd07e35fa8d662925e3e96.tar.gz crupest-efdfc6feb5744d8ad4bd07e35fa8d662925e3e96.tar.bz2 crupest-efdfc6feb5744d8ad4bd07e35fa8d662925e3e96.zip |
...
Diffstat (limited to 'template/generate.py')
-rwxr-xr-x | template/generate.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/template/generate.py b/template/generate.py index d00a84f..1c94cda 100755 --- a/template/generate.py +++ b/template/generate.py @@ -3,9 +3,11 @@ import os import os.path import re -from sys import argv +import pwd +import grp +import sys -required_config_keys = set(["CRUPEST_DOMAIN", "CRUPEST_UID", +required_config_keys = set(["CRUPEST_DOMAIN", "CRUPEST_USER", "CRUPEST_GROUP", "CRUPEST_UID", "CRUPEST_GID", "CRUPEST_HALO_DB_PASSWORD"]) print("It's happy to see you!\n") @@ -28,7 +30,7 @@ for filename in filenames: print("") # if command is 'clean' -if len(argv) > 1 and argv[1] == "clean": +if len(sys.argv) > 1 and sys.argv[1] == "clean": print("Are you sure you want to delete all generated files? (y/N)") if input() == "y": print("Deleting all generated files...") @@ -88,12 +90,17 @@ config_path = os.path.join(project_dir, "data/config") # check if there exists a config file if not os.path.exists(config_path): + config = {} print("No existing config file found. Don't worry. Let's create one! Just tell me your domain name:") - domain = input() - my_uid = os.getuid() - my_gid = os.getgid() - halo_db_password = os.urandom(8).hex() - config_content = f"CRUPEST_DOMAIN={domain}\nCRUPEST_UID={my_uid}\nCRUPEST_GID={my_gid}\nCRUPEST_HALO_DB_PASSWORD={halo_db_password}\n" + config["CRUPEST_DOMAIN"] = input() + config["CRUPEST_USER"] = pwd.getpwuid(os.getuid()).pw_name + config["CRUPEST_GROUP"] = grp.getgrgid(os.getgid()).gr_name + config["CRUPEST_UID"] = str(os.getuid()) + config["CRUPEST_GID"] = str(os.getgid()) + config["CRUPEST_HALO_DB_PASSWORD"] = os.urandom(8).hex() + config_content = "" + for key in config: + config_content += f"{key}={config[key]}\n" # create data dir if not exist if not os.path.exists(os.path.join(project_dir, "data")): os.mkdir(os.path.join(project_dir, "data")) |