Add one-command server mod updates: build_mods.py --push via update.sh (stop/sync/start, prunes stale jars)
This commit is contained in:
+26
-2
@@ -8,13 +8,17 @@ For every .jar in the pack instance it:
|
||||
- drops the 19 client-only mods
|
||||
and writes the server manifest to mods.json.
|
||||
|
||||
Usage: python3 build_mods.py
|
||||
Usage: python3 build_mods.py regenerate server/mods.json
|
||||
python3 build_mods.py --push regenerate, then update the live server
|
||||
(stop -> sync mods -> start, via SSH)
|
||||
"""
|
||||
import hashlib, json, os, subprocess, sys, time
|
||||
import argparse, hashlib, json, os, subprocess, sys, time
|
||||
|
||||
INSTANCE = os.path.expanduser(
|
||||
"~/.local/share/PrismLauncher/instances/Reaper's Sky - dev/.minecraft/mods")
|
||||
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mods.json")
|
||||
UPDATE_SH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "update.sh")
|
||||
SERVER_HOST = os.environ.get("RS_SERVER_HOST", "root@ReapersSky")
|
||||
MC_VERSION = "1.21.1"
|
||||
NEOFORGE_VERSION = "21.1.248"
|
||||
|
||||
@@ -67,7 +71,25 @@ def resolve(jar, digest):
|
||||
return ""
|
||||
|
||||
|
||||
def push():
|
||||
"""Upload mods.json to the server and run update.sh there (stop/sync/start)."""
|
||||
print(f"Uploading manifest to {SERVER_HOST}:/tmp/reaper-sky-mods.json ...")
|
||||
with open(OUT, "rb") as f:
|
||||
subprocess.run(["ssh", SERVER_HOST, "cat > /tmp/reaper-sky-mods.json"],
|
||||
stdin=f, check=True)
|
||||
print("Running update.sh on the server (stop -> sync -> start) ...")
|
||||
with open(UPDATE_SH, "rb") as f:
|
||||
subprocess.run(["ssh", SERVER_HOST, "bash -s -- /tmp/reaper-sky-mods.json"],
|
||||
stdin=f, check=True)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--push", action="store_true",
|
||||
help="also update the live server: stop it, sync mods "
|
||||
"(prune + download + sha1-verify), start it again")
|
||||
args = parser.parse_args()
|
||||
|
||||
mods = []
|
||||
for jar in sorted(os.listdir(INSTANCE)):
|
||||
if not jar.endswith(".jar"):
|
||||
@@ -85,6 +107,8 @@ def main():
|
||||
with open(OUT, "w") as f:
|
||||
json.dump(manifest, f, indent=2)
|
||||
print(f"Wrote {len(mods)} server mods to {OUT}")
|
||||
if args.push:
|
||||
push()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user