aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--latest-urls.txt7
-rw-r--r--pack-location.txt1
-rw-r--r--prev-downloads.txt (renamed from downloads.txt)0
-rwxr-xr-xupdate.py106
4 files changed, 77 insertions, 37 deletions
diff --git a/latest-urls.txt b/latest-urls.txt
new file mode 100644
index 0000000..5314591
--- /dev/null
+++ b/latest-urls.txt
@@ -0,0 +1,7 @@
+# fill this file with the same as downloads.txt but with links to the latest urls instead
+# e.g.
+thaumcraft.jar https://minecraft.curseforge.com/projects/thaumcraft/files/latest
+baubles.jar https://minecraft.curseforge.com/projects/baubles/files/latest
+opencomputers.jar https://minecraft.curseforge.com/projects/opencomputers/files/latest
+twilightforest.jar https://minecraft.curseforge.com/projects/the-twilight-forest/files/latest
+connectedtextures.jar https://minecraft.curseforge.com/projects/ctm/files/latest
diff --git a/pack-location.txt b/pack-location.txt
deleted file mode 100644
index cbb7e66..0000000
--- a/pack-location.txt
+++ /dev/null
@@ -1 +0,0 @@
-/ P A T H / T O / M O D S / F O L D E R
diff --git a/downloads.txt b/prev-downloads.txt
index 0e3c6d2..0e3c6d2 100644
--- a/downloads.txt
+++ b/prev-downloads.txt
diff --git a/update.py b/update.py
index 4e4dad1..40d7c21 100755
--- a/update.py
+++ b/update.py
@@ -1,41 +1,75 @@
-#!/bin/python3
-
-from requests import get
-from os import listdir, remove
-from shutil import rmtree, copyfileobj
+#!/usr/bin/env python3
+import hashlib
+import requests
+import os
+import shutil
+import sys
+# Initalize from config
INSTALL_DIR = ""
with open("pack-location.txt", "r") as f:
INSTALL_DIR = f.read().strip()
-DOWNLOADS = []
-NAMES = set()
-FILES = listdir(INSTALL_DIR)
-
-with open("downloads.txt", "r") as f:
- for line in f:
- dl = line.strip().split(" ")
- if len(line) > 3 and len(dl) == 2 and line[0] != '#':
- dl[0] = dl[0].strip()
- dl[1] = dl[1].strip()
- DOWNLOADS.append(dl)
- NAMES.add(dl[0])
-
-print("Updating pack...")
-for mod in DOWNLOADS:
- if mod[0] in FILES:
- print("Skipping " + mod[0] + ", already up-to-date")
- else:
- print("Installing " + mod[0] + " from " + mod[1] + "...")
- download_obj = get(mod[1], stream=True)
- with open(INSTALL_DIR + "/" + mod[0], "wb") as write_file:
- copyfileobj(download_obj.raw, write_file)
- print("Done!")
-
-print("\nRemoving old versions...")
-for jar in FILES:
- if jar not in NAMES and jar[-4:] == ".jar":
- remove(INSTALL_DIR + "/" + jar)
- print("Removing '" + jar + "'")
-
-print("\nFinished updating pack!")
+
+def apply_updates():
+ print("Updating pack...")
+ # (fname, url)
+ mods = []
+ # Set of jar file names
+ names = set()
+
+ with open("downloads.txt", "r") as f:
+ for line in f:
+ dl = line.strip().split(" ")
+ if len(line) > 3 and len(dl) == 2 and line[0] != '#':
+ dl[0] = dl[0].strip()
+ dl[1] = dl[1].strip()
+ mods.append(dl)
+ names.add(dl[0])
+ for mod in mods:
+ if mod[0] in os.listdir(INSTALL_DIR):
+ print("Skipping " + mod[0] + ", already up to date")
+ else:
+ print("Installing " + mod[0] + " from " + mod[1] + "...")
+ download_obj = requests.get(mod[1], stream=True)
+ with open(os.path.join(INSTALL_DIR, mod[0]), "wb") as write_file:
+ shutil.copyfileobj(download_obj.raw, write_file)
+ print("Done!")
+
+ print("\nRemoving old versions...")
+ for jar in os.listdir(INSTALL_DIR):
+ if jar not in names and os.path.splitext(jar)[1] == ".jar":
+ os.remove(os.path.join(INSTALL_DIR, jar))
+ print(f"Removing '{jar}'")
+
+ print("\nFinished updating pack!")
+
+def find_updates():
+ print("Reading update file...")
+ mods = set()
+ with open('updates.txt') as f:
+ for line in f:
+ mod = line.strip().split()
+ if len(line) > 3 and len(mod) == 2 and line[0] != '#':
+ # run strip on each element
+ mod = tuple(map(lambda x: x.strip(), mod))
+ mods.add(mod)
+ print("Downloading new versions of all mods...")
+ with open('downloads.txt', 'w') as f:
+ f.write('# Format: <jarname> <hex digested sha1> <direct download url>\n')
+ for mod in mods:
+ resp = requests.get(mod[1])
+ hsh = hashlib.sha1(resp.content)
+ f.write(f'{mod[0]} {hsh.hexdigest()} {resp.url}\n')
+
+
+if len(sys.argv) < 2:
+ print(f"Usage: {sys.argv[0]} <update|find_updates>")
+ sys.exit(-1)
+elif sys.argv[1] == 'update':
+ update()
+elif sys.argv[1] == 'find_updates':
+ find_updates()
+else:
+ print(f"Usage: {sys.argv[0]} <update|find_updates>")
+ sys.exit(-1)