2020-05-06 23:37:52 +02:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# "THE TSCHUNK LICENSE" (Revision 42):
|
|
|
|
# <christian@staudte.it> 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.
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
2020-05-06 21:16:19 +02:00
|
|
|
import configparser
|
2020-05-07 00:48:50 +02:00
|
|
|
import sys
|
2020-05-06 21:16:19 +02:00
|
|
|
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')
|
2020-05-07 00:48:50 +02:00
|
|
|
sign_cert = config.get('uploadconfig', 'sign_cert')
|
2020-05-06 21:16:19 +02:00
|
|
|
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)
|
2020-05-07 00:48:50 +02:00
|
|
|
|
|
|
|
cert = ''
|
|
|
|
try:
|
|
|
|
with open(sign_cert, 'r') as f:
|
|
|
|
for line in f:
|
2020-05-07 13:28:13 +02:00
|
|
|
cert += line.replace("\n", "\\n")
|
2020-05-07 00:48:50 +02:00
|
|
|
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
|