diff --git a/get_mods.py b/get_mods.py new file mode 100644 index 0000000..a722da6 --- /dev/null +++ b/get_mods.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import io +import os +import shutil +import sys +import urllib.request +import zipfile + +worldmods = os.path.normpath(sys.argv[1]) +if not os.path.exists(worldmods): + print("The provided path does not exist") + exit(1) + +mods = ( + ("https://codeload.github.com/minetest-mods/mesecons/zip/master", "mesecons"), + ("https://codeload.github.com/LNJ2/carpet/zip/master", "carpet"), + ("https://codeload.github.com/minetest-mods/crops/zip/master", "crops"), + ("https://codeload.github.com/minetest-mods/flowerpot/zip/master", "flowerpot"), + ("https://codeload.github.com/minetest-mods/lapis/zip/master", "lapis"), + ("https://codeload.github.com/minetest-mods/quartz/zip/master", "quartz"), + ("https://codeload.github.com/minetest-mods/xdecor/zip/master", "xdecor"), + ("https://codeload.github.com/oOChainLynxOo/hardenedclay/zip/master", "hardenedclay"), + ("https://codeload.github.com/minetest-mods/nether/zip/master", "nether"), + ("https://codeload.github.com/ShadowNinja/minetest_bedrock/zip/master", "minetest_bedrock"), + ("https://gitlab.com/VanessaE/basic_materials/-/archive/master/basic_materials-master.zip", "basic_materials"), + ("https://gitlab.com/VanessaE/biome_lib/-/archive/master/biome_lib-master.zip", "biome_lib"), + ("https://gitlab.com/VanessaE/plantlife_modpack/-/archive/master/plantlife_modpack-master.zip", "plantlife_modpack"), + ("https://gitlab.com/VanessaE/signs_lib/-/archive/master/signs_lib-master.zip", "signs_lib") + ) + +# Some servers don't recognize the default Python-urllib user agent +headers = { 'User-Agent':'Mozilla' } + +for url, mod in mods: + print("Fetching:", mod); + request = urllib.request.Request(url, None, headers) + with urllib.request.urlopen(request) as response: + with zipfile.ZipFile(io.BytesIO(response.read()), 'r') as mod_zip: + mod_zip.extractall(worldmods) + mod = os.path.normpath(worldmods+"/"+mod) + os.rename(mod+"-master", mod) +minetest_bedrock = os.path.normpath(worldmods+"/"+"minetest_bedrock") +bedrock = os.path.normpath(worldmods+"/"+"bedrock") +os.rename(minetest_bedrock, bedrock) + +# Remove unneeded/unwanted submods +prune = ( "dryplants", "along_shore", "molehills", "woodsoils", "bushes", "bushes_classic", "youngtrees", "3dmushrooms", "cavestuff", "poisonivy", "trunks" ) +for ex in prune: + ex = "plantlife_modpack/" + ex + print("Pruning:", ex) + ex = os.path.normpath(worldmods+"/"+ex) + shutil.rmtree(ex) diff --git a/mcimport.py b/mcimport.py index 83eb569..607b077 100644 --- a/mcimport.py +++ b/mcimport.py @@ -50,55 +50,6 @@ sn.write(" vm:update_map()\n") sn.write("end)\n\n") -if not os.path.exists(sys.argv[2]+"/get-mods.sh"): - path = sys.argv[2]+"/get-mods.sh" - with open(path, "w") as md: - md.write('''\ -#!/bin/sh - -# run this script to automatically get all the required mods - -mods=( - https://codeload.github.com/minetest-mods/mesecons/zip/master,mesecons - https://codeload.github.com/LNJ2/carpet/zip/master,carpet - https://codeload.github.com/minetest-mods/crops/zip/master,crops - https://codeload.github.com/minetest-mods/flowerpot/zip/master,flowerpot - https://codeload.github.com/minetest-mods/lapis/zip/master,lapis - https://codeload.github.com/minetest-mods/quartz/zip/master,quartz - https://codeload.github.com/minetest-mods/xdecor/zip/master,xdecor - https://codeload.github.com/oOChainLynxOo/hardenedclay/zip/master,hardenedclay - https://codeload.github.com/minetest-mods/nether/zip/master,nether - https://codeload.github.com/ShadowNinja/minetest_bedrock/zip/master,minetest_bedrock - https://gitlab.com/VanessaE/basic_materials/-/archive/master/basic_materials-master.zip,basic_materials - https://gitlab.com/VanessaE/biome_lib/-/archive/master/biome_lib-master.zip,biome_lib - https://gitlab.com/VanessaE/plantlife_modpack/-/archive/master/plantlife_modpack-master.zip,plantlife_modpack - https://gitlab.com/VanessaE/signs_lib/-/archive/master/signs_lib-master.zip,signs_lib -) - -cd worldmods - -for item in ${mods[@]} ; do -( - url=$(echo $item | cut -d, -f1) - mod=$(echo $item | cut -d, -f2) - echo "Fetching: $mod" - curl -q -L -o $mod.zip $url - unzip -qq $mod.zip - rm $mod.zip - mv $mod-master $mod - mv minetest_bedrock bedrock -) -done - -# remove unneeded/unwanted submods -for ex in plantlife_modpack/dryplants plantlife_modpack/along_shore plantlife_modpack/molehills plantlife_modpack/woodsoils plantlife_modpack/bushes plantlife_modpack/bushes_classic plantlife_modpack/youngtrees plantlife_modpack/3dmushrooms plantlife_modpack/cavestuff plantlife_modpack/poisonivy plantlife_modpack/trunks; do - echo "Pruning: $ex" - rm -rf $ex -done -''') - st = os.stat(path) - os.chmod(path, st.st_mode | stat.S_IXUSR) - mcmap = MCMap(sys.argv[1]) mtmap = MTMap(sys.argv[2]) @@ -107,4 +58,4 @@ mtmap.save() print("Conversion finished!\n") -print("Run \"sh get-mods.sh\" in the new world folder to automatically download all required mods.") +print("Pass the new world folder to get_mods.py to automatically download all required mods." diff --git a/mcimport.sh b/mcimport.sh index 8d8b726..f677ceb 100755 --- a/mcimport.sh +++ b/mcimport.sh @@ -40,9 +40,8 @@ if [ $? == 0 ]; then if ! zenity --width=800 --question --title="Download required mods?" --text="The world was succesfully converted. Do you want me to download and install all the required mods now? This should be done for each converted world."; then exit 0 fi - cd "${HOME}/.minetest/worlds/$OUT" ( - bash get-mods.sh + python3 get_mods.py "${HOME}/.minetest/worlds/$OUT" echo "=====================" echo "Finished! You can now close this window!" ) | zenity --text-info --width=800 --height=600 --title='Downloading required mods.' --text='Downloading...'