Skip to content

Instantly share code, notes, and snippets.

Created January 31, 2015 19:52
Show Gist options
  • Save anonymous/84c165cbd6f7b825b21f to your computer and use it in GitHub Desktop.
Save anonymous/84c165cbd6f7b825b21f to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
#
# Technic server update script by rewbycraft
# License: MIT
#
# This script is rather hackish.
# It requires:
# - cp
# - rm
# - unzip
# - python3-urllib3
# - wget
#
import urllib3
import json
import os
import glob
import subprocess
import hashlib
#API url + modpack slug (no trailing /)
baseUrl = "http://solder.pagefortress.com/api/modpack/techcavern-experimental-pack"
#mods not to put on the server (mostly client-only plugins)
ignoredMods = ['nei', 'neiintegration', 'waila', 'wailaplugins', 'journeymap']
print("BEGINNING FULL UPGRADE")
def hashfile(afile, hasher, blocksize=65536):
buf = afile.read(blocksize)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(blocksize)
return hasher.hexdigest()
def shl(args):
print("+ " + ' '.join(args))
subprocess.call(args)
def fileMatch(filename, expected):
print("===> Checking file: " + filename)
filehash = hashfile(open(filename, 'rb'), hashlib.md5())
print("====> Expected: " + expected)
print("====> Found: " + filehash)
return filehash == expected
print("=> Ignored mods:")
print("==> " + ', '.join(ignoredMods))
os.makedirs("./cache", 0o777, True)
print("=> Resetting mod and config directories...")
shl(['rm', '-r', 'mods', 'config'])
os.makedirs("./mods", 0o777, True)
os.makedirs("./config", 0o777, True)
print("=> Processing mods...")
response = json.loads(urllib3.PoolManager().request('GET', baseUrl).data.decode("utf-8"))
response = json.loads(urllib3.PoolManager().request('GET', baseUrl + '/' + response["recommended"]).data.decode("utf-8"))
for mod in response['mods']:
if not mod['name'] in ignoredMods:
print("==> Processing: " + mod['name'])
filename = mod['url'].split('/')[-1]
if not (os.path.isfile("cache/" + filename) and fileMatch("cache/"+filename, mod['md5'])):
print("===> Downloading...")
shl(['wget', '-O', "cache/"+filename, mod['url']])
print("===> Unpacking...")
shl(['unzip', '-o', "cache/"+filename])
else:
print("==> Ignoring mod: " + mod['name'])
print("=> Applying custom stuffs...")
shl(['cp', '-r'] + glob.glob('./custommods/*') + ['mods/'])
shl(['cp', '-r'] + glob.glob('./customconfig/*') + ['config/'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment