From 64a28233df42199ab7c8618aaef8e58756863ba8 Mon Sep 17 00:00:00 2001 From: quackerd Date: Wed, 3 Jun 2020 18:29:52 +0800 Subject: [PATCH] update setup script --- client.conf | 3 ++- setup.py | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/client.conf b/client.conf index d0236df..a929a67 100644 --- a/client.conf +++ b/client.conf @@ -69,7 +69,8 @@ "users": [ { "id": "{{ uuid }}", - "alterId": 64 + "alterId": 64, + "security": "none" } ] } diff --git a/setup.py b/setup.py index ff9122f..fda02f4 100644 --- a/setup.py +++ b/setup.py @@ -11,25 +11,39 @@ def randomString(stringLength=16): letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(stringLength)) +def read_conf(f): + ret = {} + f = open(f, "r") + lines = f.readlines() + for line in lines: + eline = line.split(' ') + if len(eline) >= 2: + ret[eline[0]] = eline[1] + return ret + def usage(): print("Usage: python setup.py [options]\n\n\ options:\n\ -h : show usage.\n\ -d domain : your domain - mydomain.tld.\n\ + [-u uuid] : the uuid of the user. Optional.\n\ + [-p path] : the path of the websocket. Optional.\n\ [-s subdomain] : your subdomain. Optional.\n\ - [-e email] : your email. Optional.\n") + [-e email] : your email. Optional.\n\ + [-c conf] : load config from file. Optional.\n\n") def main(): email = None subdomain = None domain = None + conf_file = None uid = os.getuid() gid = os.getgid() - v_uuid = uuid.uuid4() - v_path = randomString() + v_uuid = None + v_path = None try: - opts , args = getopt.getopt(sys.argv[1:], "hd:s:e:") + opts , args = getopt.getopt(sys.argv[1:], "hd:s:e:c:u:p:") except getopt.GetoptError as err: print(str(err)) usage() @@ -56,6 +70,33 @@ def main(): print("Can specify maximum ONE email.") else: email = a + elif o == "-c": + conf_file = a + elif o == "-u": + v_uuid = a + elif o == "-s": + v_path = a + + # overwrite stuff with conf file + conf = read_conf(conf_file) + + if "d" in conf: + domain = conf["d"] + if "s" in conf: + subdomain = conf["s"] + if "e" in conf: + email = conf["e"] + if "u" in conf: + v_uuid = conf["u"] + if "p" in conf: + v_path = conf["p"] + + # generate settings if not specified + if v_uuid == None: + v_uuid = uuid.uuid4() + + if v_path == None: + v_path = randomString() if domain == None: print("Must specify a domain.")