From e00844441b6c464b6a035382c8a7ad84c6b54c2e Mon Sep 17 00:00:00 2001 From: mickoissicko Date: Fri, 26 Jan 2024 22:27:47 +0100 Subject: [PATCH] kept chdir-ing into /bin/.. & not bin/.mc/.. privelleged command for batch shell --- dependencies/config.py | 40 ++++++++++++++++++---------------------- scripts/launcher.py | 11 +++++++++-- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/dependencies/config.py b/dependencies/config.py index 5aba4ac..fd9efee 100644 --- a/dependencies/config.py +++ b/dependencies/config.py @@ -1,5 +1,5 @@ import os -import urllib.request +import requests versions = [ ("1.20.4 (Last message, 12 years ago)", "https://piston-data.mojang.com/v1/objects/8dd1a28015f51b1803213892b50b7b4fc76e594d/server.jar"), @@ -24,28 +24,24 @@ ] os.chdir('..') -download_directory = "/bin/.mc/" +download_directory = "bin/.mc/" os.makedirs(download_directory, exist_ok=True) -print("Minecraft Server Downloader:") -for i, (version, _) in enumerate(versions, 1): - print(f"[{i}] {version}") +def download_server(version, url, download_directory): + file_name = os.path.join(download_directory, "server.jar") + response = requests.get(url) + with open(file_name, 'wb') as file: + file.write(response.content) + print(f"Downloaded {version} to {file_name}") -while True: - try: - choice = int(input("Choose a version to download (enter the corresponding number): ")) - if 1 <= choice <= len(versions): - break - else: - print("Invalid choice. Please enter a valid number.") - except ValueError: - print("Invalid input. Please enter a number.") - -selected_version = versions[choice - 1] -version_name, version_url = selected_version -download_path = os.path.join(download_directory, "server.jar") +if __name__ == "__main__": + print("Minecraft Server Downloader:") + for i, (version, _) in enumerate(versions, 1): + print(f"[{i}] {version}") -print("WARNING: STABILITY IS NOT GUARANTEED IF YOU ARE USING OLDER MINECRAFT VERSIONS!") -print(f"\nDownloading {version_name}...") -urllib.request.urlretrieve(version_url, download_path) -exit() + try: + choice = int(input("Enter the number corresponding to the version you want to download: ")) + selected_version = versions[choice - 1] + download_server(*selected_version, download_directory) + except (ValueError, IndexError): + print("Invalid choice. Please enter a valid number.") \ No newline at end of file diff --git a/scripts/launcher.py b/scripts/launcher.py index 8b0b659..551ce28 100644 --- a/scripts/launcher.py +++ b/scripts/launcher.py @@ -89,6 +89,10 @@ def ussr_for_win(): def mc_server(): clear_screen() + os.system('sudo python ../dependencies/config.py') + +def mc_server_win(): + clear_screen os.system('python ../dependencies/config.py') def configr(): @@ -142,8 +146,9 @@ def main_menu(): print("[2] Dependency setup for Arch") print("[3] USSR for Arch") print("[4] USSR for Windows") - print("[5] Install Minecraft") - print("[6] Configure USSR") + print("[5] Install Minecraft Server (Arc)") + print("[6] Install Minecraft Server (Win)") + print("[7] Configure USSR") print("[X] Quit") print("HEADS UP! Before you can proceed, please configure the paths if you haven't already.") print("Don't know how to? See the guide: https://mick.gdn/wiki/ussr.html") @@ -161,6 +166,8 @@ def main_menu(): elif choice == '5': mc_server() elif choice == '6': + mc_server_win() + elif choice == '7': configr() elif choice.lower() == 'x' or 'X': break