|
|
@@ -1,6 +1,46 @@
|
|
|
|
|
|
def com_update(args):
|
|
|
- pass
|
|
|
+ from urllib.request import urlopen
|
|
|
+ import shutil
|
|
|
+ import tempfile
|
|
|
+ import os
|
|
|
+ import time
|
|
|
+ from subprocess import run
|
|
|
+ update_url = "https://tsimnet.eu/releases/bootstrap_captive/build/bootstrap_captive"
|
|
|
+ checksum_url = update_url + ".sha256"
|
|
|
+ checksum_path = os.path.join(args.install_dir, "checksum.sha256")
|
|
|
+ tries = 0
|
|
|
+ checkfile = b""
|
|
|
+ while (args.tries <= 0) or args.tries > tries:
|
|
|
+ try:
|
|
|
+ print("Trying to connect...", checksum_url)
|
|
|
+ with urlopen(checksum_url) as res:
|
|
|
+ checksum = res.read()
|
|
|
+ print("Checksum:", checksum.decode())
|
|
|
+ if os.path.isfile(checksum_path):
|
|
|
+ with open(checksum_path, "rb") as fd:
|
|
|
+ checkfile = fd.read()
|
|
|
+ print("Checksum File:", checkfile.decode())
|
|
|
+ if checkfile != checksum:
|
|
|
+ print("Downloading Update...", update_url)
|
|
|
+ with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
|
|
+ with urlopen(update_url) as res:
|
|
|
+ shutil.copyfileobj(res, tmp)
|
|
|
+ run(["chmod", "+x", tmp.name], check=True)
|
|
|
+ print("Installing Update from", tmp.name)
|
|
|
+ run([tmp.name, "install"], check=True)
|
|
|
+ run(["rm", tmp.name])
|
|
|
+ with open(checksum_path, "wb") as fd:
|
|
|
+ fd.write(checksum)
|
|
|
+ return 0
|
|
|
+ else:
|
|
|
+ print("Version is current.")
|
|
|
+ return 0
|
|
|
+ except Exception as ex:
|
|
|
+ print("Update Error:", ex)
|
|
|
+ tries += 1
|
|
|
+ print("Sleeping 10s....",tries)
|
|
|
+ time.sleep(10)
|
|
|
|
|
|
def com_unpack(args):
|
|
|
import os
|