Created
April 18, 2012 09:02
-
-
Save sh4nks/2412188 to your computer and use it in GitHub Desktop.
python3 minecraft installer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# License: You can do whatever you want with this script as long as you keep it open source :) | |
import os | |
import urllib.request | |
import shutil | |
import sys | |
import subprocess | |
launcher_folder = os.path.join(os.environ['HOME'], ".local/share/applications") | |
mc_folder = os.path.join(os.environ['HOME'], ".minecraft") | |
mc_jar = os.path.join(mc_folder, "minecraft.jar") | |
mc_net = "http://minecraft.net/download/minecraft.jar" | |
mc_desktop = os.path.join(mc_folder, "minecraft.desktop") | |
mc_desktop_content = """ | |
[Desktop Entry] | |
Type=Application | |
Encoding=UTF-8 | |
Name=Minecraft | |
Comment=Awesome Sandbox Game | |
Exec=java -jar {} | |
Icon={} | |
Categories=Game | |
Terminal=false | |
""".format(mc_jar, os.path.join(mc_folder, "icon.png")) | |
def install_minecraft(): | |
if os.path.isfile(mc_jar): | |
print("Minecraft is already installed.\n") | |
else: | |
if not os.path.isdir(mc_folder): | |
print("Creating", mc_folder, "folder...") | |
os.mkdir(mc_folder) | |
print("downloading minecraft.jar from minecraft.net...") | |
urllib.request.urlretrieve(mc_net, mc_jar) | |
urllib.request.urlretrieve("http://www.minecraft.net/favicon.png", | |
os.path.join(mc_folder, "icon.png")) | |
print("writing desktop shortcut...") | |
with open(mc_desktop, 'w') as f: | |
f.write(mc_desktop_content) | |
f.close() | |
os.chmod(mc_desktop, 0o775) | |
print("Copying minecraft.desktop to Desktop...") | |
shutil.copy(mc_desktop, os.path.join(os.environ['HOME'], | |
"Arbeitsfläche/minecraft.desktop")) | |
print("Copying minecraft.desktop to ~/.local/share/applications...") | |
if not launcher_folder: | |
os.makedirs(launcher_folder) | |
else: | |
shutil.copy(mc_desktop, os.path.join(launcher_folder, | |
"minecraft.desktop")) | |
print("Congratulations, Minecraft has been successfully \ | |
downloaded and installed!\nHappy Mining!\n") | |
def uninstall_minecraft(): | |
confirm_uninstall = input("Are you sure that you want to uninstall Minecraft? (yes/no): ") | |
if confirm_uninstall == "yes": | |
if not os.path.isdir(mc_folder): | |
print("Minecraft isn\'t installed\n") | |
else: | |
print("Removing Minecraft:", mc_folder) | |
shutil.rmtree(mc_folder) | |
print("Looking for launcher and desktop shortcuts...") | |
if os.path.isfile(os.path.join(launcher_folder, "minecraft.desktop")): | |
print("Removing launcher...") | |
os.remove(os.path.join(launcher_folder, "minecraft.desktop")) | |
if os.path.isfile(os.path.join(os.environ['HOME'], | |
"Arbeitsfläche/minecraft.desktop")): | |
os.remove(os.path.join(os.environ['HOME'], | |
"Arbeitsfläche/minecraft.desktop")) | |
print("You have successfully uninstalled Minecraft :(\n") | |
else: | |
print("Good choice! :)\n") | |
# # | |
# Troubleshooting | |
# # | |
def install_openjdk(): | |
# On my Computer Minecraft is running smoothly with OpenJDK6 | |
print("Installing OpenJDK6...") | |
subprocess.call("sudo aptitude install openjdk-6-jre", shell=True) | |
print("Finished!\n") | |
def openjdk_default_jre(): | |
print("Making OpenJDK6 the default java runtime environment") | |
print("Don't worry if you see a lot of errors") | |
subprocess.call("sudo update-java-alternatives -s java-6-sun", shell=True) | |
print("Finished!\n") | |
def run(menu): | |
category = "root" | |
while True: | |
main_menu = menu[category] | |
for index, item in enumerate(main_menu, 1): | |
print("{} {}".format(index, item[0])) | |
try: | |
choice = int(input("Your choice: ")) - 1 | |
if 0 <= choice < len(main_menu): | |
command = main_menu[choice][1] | |
else: | |
raise IndexError | |
except (ValueError, IndexError): | |
print("Only numbers between 1 and {} are allowed".format(len(menu))) | |
if isinstance(command, str): | |
category = command | |
else: | |
command() | |
menu = { | |
"root": ( | |
("Install Minecraft", install_minecraft), | |
("Uninstall Minecraft", uninstall_minecraft), | |
("Troublshooting", "submenu"), | |
("Exit", lambda: sys.exit(0)) | |
), | |
"submenu": ( | |
("Install OpenJDK", install_openjdk), | |
("Use OpenJDK6 to run Minecraft", openjdk_default_jre), | |
("Back", "root"), | |
) | |
} | |
if __name__ == "__main__": | |
run(menu) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment