diff --git a/trezorctl b/trezorctl index e884d2da9b..1347725c6a 100755 --- a/trezorctl +++ b/trezorctl @@ -4,6 +4,8 @@ import binascii import argparse import json import base64 +import urllib +import tempfile from trezorlib.client import TrezorClient, TrezorClientDebug from trezorlib.tx_api import TXAPIBitcoin @@ -203,14 +205,34 @@ class Commands(object): return ret def firmware_update(self, args): - if not args.file: - raise Exception("Must provide firmware filename") - fp = open(args.file, 'r') + if not args.file and not args.url: + raise Exception("Must provide firmware filename or URL") + + if args.file: + fp = open(args.file, 'r') + elif args.url: + print "Downloading from", args.url + resp = urllib.urlretrieve(args.url) + fp = open(resp[0], 'r') + urllib.urlcleanup() # We still keep file pointer open + + if fp.read(8) == '54525a52': + print "Converting firmware to binary" + + fp.seek(0) + fp_old = fp + + fp = tempfile.TemporaryFile() + fp.write(binascii.unhexlify(fp_old.read())) + + fp_old.close() + fp.seek(0) + if fp.read(4) != 'TRZR': raise Exception("Trezor firmware header expected") fp.seek(0) - return self.client.firmware_update(fp=open(args.file, 'r')) + return self.client.firmware_update(fp=fp) list.help = 'List connected Trezor USB devices' ping.help = 'Send ping message' @@ -335,6 +357,7 @@ class Commands(object): firmware_update.arguments = ( (('-f', '--file'), {'type': str}), + (('-u', '--url'), {'type': str}), ) def list_usb():