diff --git a/checks.py b/checks.py new file mode 100644 index 00000000..cb3d39b4 --- /dev/null +++ b/checks.py @@ -0,0 +1,28 @@ +import sys, main, os, uservar + +key = os.environ.get('MATRIX_KEY') + +def checks(): + if uservar.ip is None: + print("ERROR: IP variable empty") + sys.exit() + + if uservar.heisenberg_bridge == True and not uservar.heisenbridge_owner: + print("please fill in a matrix user") + sys.exit() + + if uservar.appservice_discord_bridge and not uservar.appservice_discord_brige_client_id or not uservar.appservice_discord_bridge_token: + print("ERROR: fill out all appservice variables") + sys.exit() + + if key is None and uservar.add_key == False: + homeserver_key = os.popen("pwgen -s 64 1").read() + homeserver_key = main.func(homeserver_key) + print("if ist durch") + with open('/home/{}/.bashrc'.format(main.user), 'a') as f: + f.write("export MATRIX_KEY={}".format(homeserver_key)) + f.close() + elif key is not None and uservar.add_key == False: + homeserver_key = key + elif uservar.add_key == True: + homeserver_key = uservar.homeserver_key diff --git a/main.py b/main.py index ee469e4a..d081a18f 100644 --- a/main.py +++ b/main.py @@ -1,147 +1,41 @@ -import os -import sys +import os, uservar, checks, setup, sys -domain="" -email="" -postgres_password="" -#leave empty for standard ssh port (22) -ssh_port = "" -#provide your public ip adress - you can lookup at wieistmeineip.at -ip = "" -#want to create the homeserver key on yourself? answer with True or False -add_key=True -#if True insert your generated key here (generate it with pwgen -s 64 1) -homeserver_key="" - -#bridges, set variable if you want to install them or e.g: mautrix-bridge=true -mautrix_discord_bridge=True -mautrix_signal_bridge=True -heisenberg_bridge=True -#write your username in matrix format e.g @your-username:domain -heisenbridge_owner="" - -#if true fill out client id and token, you would get that from the discord developers dashboard when creating a bot -appservice_discord_bridge=True -appservice_discord_brige_client_id="" # -appservice_discord_bridge_token="" - -#want to run your own nginx server? set the ports where matrix-nginx should run and reverse proxy it from your nginx -http_port= -https_port= - -if ip is None: - print("ERROR: IP variable empty") - sys.exit() - -if heisenberg_bridge == True and not heisenbridge_owner: - print("please fill in a matrix user") - sys.exit() - -if appservice_discord_bridge and not appservice_discord_brige_client_id or not appservice_discord_bridge_token: - print("ERROR: fill out all appservice variables") - sys.exit() #os.system("sudo dnf install pwgen -y") def func(string): return ''.join(string.splitlines()) user=os.environ.get('USER') -key = os.environ.get('MATRIX_KEY') -print(key) -if key is None and add_key == False: - homeserver_key=os.popen("pwgen -s 64 1").read() - homeserver_key=func(homeserver_key) - print("if ist durch") - with open('/home/{}/.bashrc'.format(user), 'a') as f: - f.write("export MATRIX_KEY={}".format(homeserver_key)) - f.close() -elif key is not None and add_key == False: - homeserver_key = key -print(key) + +#print(key) + + +#print(key) + file_path = os.path.dirname(os.path.realpath(__file__)) -yml_path= "{}/inventory/host_vars/matrix.{}".format(file_path, domain) +yml_path= "{}/inventory/host_uservar/matrix.{}".format(file_path, uservar.domain) hosts_path = "{}/inventory/".format(file_path) + +checks.checks() + try: if not os.path.exists(yml_path): os.makedirs(yml_path) #os.mkdir(yml_path) - os.system("touch {}/vars.yml".format(yml_path)) + os.system("touch {}/uservar.yml".format(yml_path)) os.system("touch {}/hosts".format(hosts_path)) with open('{}/hosts'.format(hosts_path), 'w') as f: hosts_write = [ "[matrix_servers]\n", - "matrix.{} ansible_host={} ansible_port={} ansible_ssh_user=root".format(domain, ip, ssh_port) + "matrix.{} ansible_host={} ansible_port={} ansible_ssh_user=root".format(uservar.domain, uservar.ip, uservar.ssh_port) ] f.writelines(hosts_write) except OSError as e: print(e) -with open('{}/foo.yml'.format(yml_path), 'r+') as f: - lines = [ - 'matrix_domain: {}\n'.format(domain), - 'matrix_homeserver_implementation: synapse\n', - "matrix_homeserver_generic_secret_key: '{}' \n".format(homeserver_key), - 'matrix_ssl_lets_encrypt_support_email: "{}" \n'.format(email), - "devture_postgres_connection_password: '{}' \n".format(postgres_password), - 'matrix_well_known_matrix_support_enabled: true\n', - 'matrix_nginx_proxy_base_domain_serving_enabled: true\n' - ] - content = f.read() - #if "matrix_homeserver_generic_secret_key:" not in content: - # lines[0] = "matrix_homeserver_generic_secret_key: '{}' \n".format(homeserver_key) - for i, line in enumerate(lines): - get_line = line.split(": ")[0].strip() - get_var = line.split(": ")[1].strip() - print(get_var) - print(line) - if get_line not in content: - print("get_line wurde aufgerufen") - lines[i] = "{}: {}\n".format(get_line, get_var) - elif get_var not in content: - print(i) - lines[i] = "{}: {}\n".format(get_line, get_var) - f.seek(0) - f.truncate() - f.writelines(lines) - f.close() - -if mautrix_discord_bridge: - with open('{}/foo.yml'.format(yml_path), 'a') as f: - f.write("matrix_mautrix_discord_enabled: true\n") - f.close() -if mautrix_signal_bridge: - with open('{}/foo.yml'.format(yml_path), 'a') as f: - f.write("matrix_mautrix_signal_enabled: true\n") - f.close() -if heisenberg_bridge: - with open('{}/foo.yml'.format(yml_path), 'a') as f: - heisenbridge = [ - "matrix_heisenbridge_enabled: true\n", - 'matrix_heisenbridge_owner: "{}"\n'.format(heisenbridge_owner), - "matrix_heisenbridge_identd_enabled: true\n" - ] - f.writelines(heisenbridge) - f.close() -if appservice_discord_bridge: - with open('{}/foo.yml'.format(yml_path), 'a') as f: - appservice = [ - "matrix_appservice_discord_enabled: true\n", - "matrix_appservice_discord_bridge_enableSelfServiceBridging: true\n", - 'matrix_appservice_discord_client_id: "{}"\n'.format(appservice_discord_brige_client_id), - 'matrix_appservice_discord_bot_token: "{}"\n'.format(appservice_discord_bridge_token) - ] - f.writelines(appservice) - f.close() - -if http_port is not None: - with open('{}/foo.yml'.format(yml_path), 'a') as f: - ports = [ - "matrix_nginx_proxy_container_http_host_bind_port: '{}'\n".format(http_port), - "matrix_nginx_proxy_container_https_host_bind_port: '{}'\n".format(https_port) - ] - f.writelines(ports) - f.close() - - +setup.setup() os.system("just roles") os.system("just install-all") + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..403f0f3c --- /dev/null +++ b/setup.py @@ -0,0 +1,68 @@ +import main, checks, uservar, setup + +def setup(): + with open('{}/uservar.yml'.format(main.yml_path), 'r+') as f: + lines = [ + 'matrix_domain: {}\n'.format(uservar.domain), + 'matrix_homeserver_implementation: synapse\n', + "matrix_homeserver_generic_secret_key: '{}' \n".format(checks.homeserver_key), + 'matrix_ssl_lets_encrypt_support_email: "{}" \n'.format(uservar.email), + "devture_postgres_connection_password: '{}' \n".format(uservar.postgres_password), + 'matrix_well_known_matrix_support_enabled: true\n', + 'matrix_nginx_proxy_base_domain_serving_enabled: true\n' + ] + content = f.read() + # if "matrix_homeserver_generic_secret_key:" not in content: + # lines[0] = "matrix_homeserver_generic_secret_key: '{}' \n".format(homeserver_key) + for i, line in enumerate(lines): + get_line = line.split(": ")[0].strip() + get_var = line.split(": ")[1].strip() + print(get_var) + print(line) + if get_line not in content: + print("get_line wurde aufgerufen") + lines[i] = "{}: {}\n".format(get_line, get_var) + elif get_var not in content: + print(i) + lines[i] = "{}: {}\n".format(get_line, get_var) + f.seek(0) + f.truncate() + f.writelines(lines) + f.close() + + if uservar.mautrix_discord_bridge: + with open('{}/foo.yml'.format(main.yml_path), 'a') as f: + f.write("matrix_mautrix_discord_enabled: true\n") + f.close() + if uservar.mautrix_signal_bridge: + with open('{}/foo.yml'.format(main.yml_path), 'a') as f: + f.write("matrix_mautrix_signal_enabled: true\n") + f.close() + if uservar.heisenberg_bridge: + with open('{}/foo.yml'.format(main.yml_path), 'a') as f: + heisenbridge = [ + "matrix_heisenbridge_enabled: true\n", + 'matrix_heisenbridge_owner: "{}"\n'.format(uservar.heisenbridge_owner), + "matrix_heisenbridge_identd_enabled: true\n" + ] + f.writelines(heisenbridge) + f.close() + if uservar.appservice_discord_bridge: + with open('{}/foo.yml'.format(main.yml_path), 'a') as f: + appservice = [ + "matrix_appservice_discord_enabled: true\n", + "matrix_appservice_discord_bridge_enableSelfServiceBridging: true\n", + 'matrix_appservice_discord_client_id: "{}"\n'.format(uservar.appservice_discord_brige_client_id), + 'matrix_appservice_discord_bot_token: "{}"\n'.format(uservar.appservice_discord_bridge_token) + ] + f.writelines(appservice) + f.close() + + if uservar.http_port is not None: + with open('{}/foo.yml'.format(main.yml_path), 'a') as f: + ports = [ + "matrix_nginx_proxy_container_http_host_bind_port: '{}'\n".format(uservar.http_port), + "matrix_nginx_proxy_container_https_host_bind_port: '{}'\n".format(uservar.https_port) + ] + f.writelines(ports) + f.close() diff --git a/uservar.py b/uservar.py new file mode 100644 index 00000000..8c4c7a8d --- /dev/null +++ b/uservar.py @@ -0,0 +1,27 @@ +domain="conorz.tk" +email="lukas.raub@pm.me" +postgres_password="" +#leave empty for standard ssh port (22) +ssh_port = "" +#provide your public ip adress - you can lookup at wieistmeineip.at +ip = "" +#want to create the homeserver key on yourself? answer with True or False +add_key=True +#if True insert your generated key here (generate it with pwgen -s 64 1) +homeserver_key="" + +#bridges, set variable if you want to install them or e.g: mautrix-bridge=true +mautrix_discord_bridge=True +mautrix_signal_bridge=True +heisenberg_bridge=True +#write your username in matrix format e.g @your-username:domain +heisenbridge_owner="@titanz:conorz.tk" + +#if true fill out client id and token, you would get that from the discord developers dashboard when creating a bot +appservice_discord_bridge=True +appservice_discord_brige_client_id="" # +appservice_discord_bridge_token="" + +#want to run your own nginx server? set the ports where matrix-nginx should run and reverse proxy it from your nginx +http_port= +https_port=