# ---------------------------------------------------------------------------- # "THE TSCHUNK LICENSE" (Revision 42): # wrote this file. As long as you retain this notice # you can do whatever you want with this stuff. If we meet some day, and you # think this stuff is worth it, you can buy me a Tschunk in return. # ---------------------------------------------------------------------------- import configparser import sys import requests Import('env') config = configparser.ConfigParser() config.read("platformio.ini") room = config.get('common', 'mqtt_room') device = config.get('common', 'mqtt_device') version = config.get('common', 'firmware_version') sign_prog = config.get('uploadconfig', 'sign_prog') sign_key = config.get('uploadconfig', 'sign_key') sign_cert = config.get('uploadconfig', 'sign_cert') upl_url = config.get('uploadconfig', 'upl_url') upl_token = config.get('uploadconfig', 'upl_token') def fw_publish(source, target, env): fw_path = str(source[0]) env.Execute(sign_prog + ' --mode sign --privatekey ' + sign_key + ' --bin ' + fw_path + ' --out ' + fw_path + '.signed') headers = { "Content-type": "application/octet-stream", "x-Room": room, "x-Device": device, "x-Version": version, "x-Token": upl_token } try: res = requests.put(upl_url, data=open(fw_path + '.signed', 'rb'), headers=headers) res.raise_for_status() except requests.exceptions.RequestException as e: print("Upload failed: %s\n" % ("%s %s" % (res.status_code, res.text) if res else str(e))) env.Exit(1) print('Upload successful') env.Replace(UPLOADCMD=fw_publish) cert = '' try: with open(sign_cert, 'r') as f: for line in f: cert += line.replace("\n", "\\n") env.Append(BUILD_FLAGS='\'-DPUBLIC_SIGN_KEY="' + cert + '"\'') except FileNotFoundError: sys.stderr.write("No public key for signing found! Continuing without update support!\n") pass