more work

This commit is contained in:
Joey Eamigh
2023-06-21 18:22:39 -04:00
parent 2e74130b2e
commit 3aeb275a65
4 changed files with 106 additions and 46 deletions

View File

@@ -37,28 +37,6 @@ if (-not (Get-Command "java" -ErrorAction SilentlyContinue)) {
}
# Check that git is installed
if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) {
Write-Host "Error: git is not installed." -Foreground Red
if ($winget) {
Write-Host "Attempting to install git."
winget install --id Git.Git -e --source winget
}
else {
Write-Host "Please install git to continue." -Foreground Red
exit 1
}
}
# Check that multimc is installed
if (-not (Get-Command "multimc" -ErrorAction SilentlyContinue)) {
Write-Host "Error: multimc is not installed." -Foreground Red
Write-Host "Please install multimc to continue." -Foreground Red
exit 1
}
if (Test-Path ".venv") { } else { python -m venv .venv }
. ./.venv/bin/Activate.ps1

View File

@@ -1,27 +1,113 @@
#!/usr/bin/env python3
import os, sys, shutil, requests, tempfile, glob
from termcolor import cprint
from typing import Any
OS = sys.platform
MOD_DOWNLOADER_URL = "https://github.com/North-West-Wind/CurseForge-CLI/releases/latest/download/curseforge.zip"
REPO_URL = "https://git.233hfd.com/joey/FishPogPixelmon"
MODPACK_RELEASES_URL = "https://git.233hfd.com/api/v1/repos/joey/FishPogPixelmon/releases?limit=1"
MULTIMC_DOWNLOAD_URL_WINDOWS = "https://files.multimc.org/downloads/mmc-develop-win32.zip"
MULTIMC_PARENT_DIR = ""
MULTIMC_DIR = ""
if OS == "darwin":
cprint("no support for macos yet", "red")
exit(1)
if OS == "linux":
MULTIMC_PARENT_DIR = f"{os.getenv('HOME')}/.local/share"
MULTIMC_DIR = f"{MULTIMC_PARENT_DIR}/multimc"
if OS == "windows":
MULTIMC_PARENT_DIR = f"{os.getenv('APPDATA')}/FishPog"
MULTIMC_DIR = f"{MULTIMC_PARENT_DIR}/MultiMC"
INSTANCE_DIR = f"{MULTIMC_DIR}/instances/FishPogPixelmon"
# main
def __main__():
header()
warning()
multimc()
# info
def warning():
cprint(
"This updater may remove your singleplayer worlds. Please use a different instance for singleplayer.", "yellow"
)
if input("Continue? [Y/n] ").lower() == "n":
exit()
else:
print("")
# multimc
def instance():
release = most_recent_release()
if not os.path.exists(INSTANCE_DIR):
download_instance(release)
f = open(".version", "r")
version = f.read()
if version != release["tag_name"]:
download_instance(release)
def download_instance(release: dict[str, Any]):
os.makedirs(f"{INSTANCE_DIR}/.minecraft")
TMP = tempfile.mkdtemp()
os.chdir(TMP)
download_url = get_release_asset(release)
r = requests.get(download_url, allow_redirects=True)
open("instance.zip", "wb").write(r.content)
shutil.unpack_archive("multimc.zip", ".")
os.remove("multimc.zip")
for file in glob.glob(f"{TMP}/overrides/*"):
shutil.move(file, f"INSTANCE_DIR/.minecraft")
shutil.rmtree(f"{TMP}/overrides")
for file in glob.glob(f"{TMP}/*"):
shutil.move(file, INSTANCE_DIR)
shutil.rmtree(TMP)
f = open(".version", "w")
f.write(release["tag_name"])
f.close()
def multimc():
if os.path.exists(MULTIMC_DIR):
return
if OS != "windows":
cprint("multimc is not installed - please install it", "yellow")
exit(1)
os.makedirs(MULTIMC_PARENT_DIR)
os.chdir(MULTIMC_PARENT_DIR)
cprint("multimc is not installed - installing", "yellow")
r = requests.get(MULTIMC_DOWNLOAD_URL_WINDOWS, allow_redirects=True)
open("multimc.zip", "wb").write(r.content)
shutil.unpack_archive("multimc.zip", ".")
os.remove("multimc.zip")
return
# releases
def most_recent_release() -> dict[str, Any]:
r = requests.get(MODPACK_RELEASES_URL)
releases: list[dict[str, Any]] = r.json()
return releases[0]
def most_recent_version(release: dict[str, Any]) -> str:
return release["tag_name"]
def get_release_asset(release: dict[str, Any]):
return release["assets"][0]["browser_download_url"]
# ascii art lol

View File

@@ -12,13 +12,7 @@ if ! [ -x "$(command -v java)" ]; then
exit 1
fi
# check that git is installed
if ! [ -x "$(command -v git)" ]; then
echo 'Error: git is not installed. Please install it to continue.' >&2
exit 1
fi
# check that git is installed
# check that multimc is installed
if ! [ -x "$(command -v multimc)" ]; then
echo 'Error: multimc is not installed. Please install it to continue.' >&2
exit 1