1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-09-19 22:33:25 +01:00
tcl_ota_check/tclcheck.py

74 lines
2.3 KiB
Python
Raw Normal View History

2017-08-15 14:20:26 +01:00
#!/usr/bin/env python3
2017-08-18 23:49:12 +01:00
# -*- coding: utf-8 -*-
# pylint: disable=C0111,C0326,C0103
2017-08-15 14:20:26 +01:00
import os
import random
2017-08-08 05:24:16 +01:00
import sys
import tcllib
2017-08-05 15:25:42 +01:00
2017-09-01 12:43:10 +01:00
fc = tcllib.FotaCheck()
fc.serid = "3531510"
#fc.osvs = "7.1.1"
2017-10-10 20:25:38 +01:00
dp = tcllib.DefaultParser(__file__)
2017-12-26 23:35:00 +00:00
dp.description = """
Checks for the latest FULL updates for the specified PRD number or for an OTA from the
version specified as fvver.
"""
dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011")
dp.add_argument("fvver", nargs="?", help="Firmware version to check for updates, e.g. AAM481", default="AAA000")
dp.add_argument("--mode", help="type of update to check for (auto, full, ota), defaults to auto", default="auto")
dp.add_argument("--type", help="type of check to run (auto, desktop, mobile), defaults to auto", default="auto")
2017-10-10 20:25:38 +01:00
args = dp.parse_args(sys.argv[1:])
2017-12-26 23:35:00 +00:00
def sel_mode(txtmode, autoval):
if txtmode == "auto":
return autoval
elif txtmode == "ota":
return fc.MODE.OTA
return fc.MODE.FULL
def sel_cltp(txtmode, autoval):
if txtmode == "auto":
return autoval
elif txtmode == "desktop":
return fc.CLTP.DESKTOP
return fc.CLTP.MOBILE
fc.curef = args.prd[0]
fc.fv = args.fvver
if args.fvver == "AAA000":
fc.mode = sel_mode(args.mode, fc.MODE.FULL)
fc.cltp = sel_cltp(args.type, fc.CLTP.DESKTOP)
else:
fc.mode = sel_mode(args.mode, fc.MODE.OTA)
fc.cltp = sel_cltp(args.type, fc.CLTP.MOBILE)
2017-09-01 12:43:10 +01:00
check_xml = fc.do_check()
print(fc.pretty_xml(check_xml))
2017-09-01 12:43:10 +01:00
curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml)
req_xml = fc.do_request(curef, fv, tv, fw_id)
print(fc.pretty_xml(req_xml))
fileid, fileurl, slaves, encslaves = fc.parse_request(req_xml)
for s in slaves:
print("http://{}{}".format(s, fileurl))
2017-10-15 01:02:24 +01:00
if fc.mode == fc.MODE.FULL:
header = fc.do_encrypt_header(random.choice(encslaves), fileurl)
headname = "header_{}.bin".format(tv)
headdir = "headers"
if not os.path.exists(headdir):
os.makedirs(headdir)
if len(header) == 4194320:
print("Header length check passed. Writing to {}.".format(headname))
with open(os.path.join(headdir, headname), "wb") as f:
f.write(header)
else:
print("Header length invalid ({}).".format(len(header)))
tcllib.FotaCheck.write_info_if_dumps_found()