- Config: Disable unused Improved Mobs integrations (Scaling Health, PlayerEX, LevelZ) - Config: Enforce 'caveMapping: NONE' across all JourneyMap dimension configs - Permissions: Reset 'runtime/data/' ownership to 'ubuntu:ubuntu' (UID 1000) - Docs: Add ENFORCE_SECURE_PROFILE="FALSE" and compose working dir note to README.md - Docs: Update mod-configs.md with LTS Auth, Improved Mobs, Majrusz, and JourneyMap changes
72 lines
3.4 KiB
Python
72 lines
3.4 KiB
Python
import os, shutil, subprocess, zipfile
|
|
|
|
JAR_HOST_PATH = "../../runtime/data/mods/lts_auth-1.0.1+mc1.20.1.jar"
|
|
BAK_HOST_PATH = "../../runtime/data/mods/lts_auth-1.0.1+mc1.20.1.jar.bak"
|
|
TMP_HOST_DIR = "../../runtime/data/tmp_lts_build"
|
|
TMP_CONTAINER_DIR = "/data/tmp_lts_build"
|
|
CONTAINER_NAME = "mc_forge_server"
|
|
|
|
def run_cmd(cmd):
|
|
res = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
if res.returncode != 0:
|
|
print("Command failed:", cmd)
|
|
print("Stderr:", res.stderr)
|
|
print("Stdout:", res.stdout)
|
|
return res.returncode == 0
|
|
|
|
def cleanup_tmp():
|
|
run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} rm -rf {TMP_CONTAINER_DIR}")
|
|
|
|
def prepare_tmp():
|
|
cleanup_tmp()
|
|
run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} mkdir -p {TMP_CONTAINER_DIR}")
|
|
run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} chmod -R 777 {TMP_CONTAINER_DIR}")
|
|
|
|
if os.path.exists(JAR_HOST_PATH):
|
|
if not os.path.exists(BAK_HOST_PATH):
|
|
shutil.copyfile(JAR_HOST_PATH, BAK_HOST_PATH)
|
|
|
|
prepare_tmp()
|
|
|
|
# Extract original JAR
|
|
with zipfile.ZipFile(JAR_HOST_PATH, "r") as z:
|
|
z.extractall(TMP_HOST_DIR)
|
|
|
|
# Copy local .java source files into TMP_HOST_DIR/src based on their package declaration
|
|
src_base = os.path.join(TMP_HOST_DIR, "src")
|
|
os.makedirs(src_base, exist_ok=True)
|
|
|
|
for root, _, files in os.walk("."):
|
|
for file in files:
|
|
if file.endswith(".java"):
|
|
filepath = os.path.join(root, file)
|
|
pkg = ""
|
|
with open(filepath, "r", encoding="utf-8") as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line.startswith("package ") and line.endswith(";"):
|
|
pkg = line[8:-1].strip()
|
|
break
|
|
target_dir = os.path.join(src_base, *pkg.split(".")) if pkg else src_base
|
|
os.makedirs(target_dir, exist_ok=True)
|
|
shutil.copyfile(filepath, os.path.join(target_dir, file))
|
|
|
|
# run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} apt-get update >/dev/null 2>&1")
|
|
# run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} apt-get install -y openjdk-17-jdk-headless >/dev/null 2>&1")
|
|
run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} chmod -R 777 {TMP_CONTAINER_DIR}")
|
|
|
|
compile_cmd = f'docker exec -i {CONTAINER_NAME} bash -c \'CP=$(find /data/libraries /data/mods -name "*.jar" | tr "\\n" ":"); javac -cp "$CP:{TMP_CONTAINER_DIR}" -d {TMP_CONTAINER_DIR} {TMP_CONTAINER_DIR}/src/com/rtxbb/lts_auth/LtsAuthMod.java {TMP_CONTAINER_DIR}/src/com/rtxbb/lts_auth/command/LoginCommand.java\''
|
|
if run_cmd(compile_cmd):
|
|
print("Compilation successful! Re-zipping mod JAR...")
|
|
run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} chmod -R 777 {TMP_CONTAINER_DIR}")
|
|
run_cmd(f"docker exec -u 0 -i {CONTAINER_NAME} chmod 777 /data/mods/lts_auth-1.0.1+mc1.20.1.jar")
|
|
with zipfile.ZipFile(JAR_HOST_PATH, "w", zipfile.ZIP_DEFLATED) as zip_out:
|
|
for root, _, files in os.walk(TMP_HOST_DIR):
|
|
for file in files:
|
|
if file.endswith(".java") or "src" in root:
|
|
continue
|
|
full_path = os.path.join(root, file)
|
|
arcname = os.path.relpath(full_path, TMP_HOST_DIR)
|
|
zip_out.write(full_path, arcname)
|
|
cleanup_tmp()
|
|
print("JAR successfully updated.")
|