From 36ff26758ec29d503c5333ecba7c00310432a554 Mon Sep 17 00:00:00 2001 From: Chris Blake Date: Thu, 30 May 2024 18:06:33 -0500 Subject: [PATCH] fix: small python fixups * Error handling in our ustorage, to prevent crashes * Small change to ubnt-fw-parse so it works better on older python versions --- overlay/filesystem/usr/bin/ustorage | 38 +++++++++++++++++++---------- scripts/ubnt-fw-parse.py | 7 +++--- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/overlay/filesystem/usr/bin/ustorage b/overlay/filesystem/usr/bin/ustorage index 53371ab..5fec1c2 100755 --- a/overlay/filesystem/usr/bin/ustorage +++ b/overlay/filesystem/usr/bin/ustorage @@ -60,21 +60,33 @@ def __find_and_map_disks(): disk_smartdata = os.popen( f"{SMARTCTL_PATH} -iHA /dev/{disk_node}" ).read() - disk_temp = int( - __parse_smartctl( - disk_smartdata, - r"^194 [\w-]+\s+0x\d+\s+\d+\s+\d+\s+\d+\s+[\w-]+\s+\w+\s+\S+\s+(\d+)(?:\s[\(][^)]*[\)])?$", + + try: + disk_temp = int( + __parse_smartctl( + disk_smartdata, + r"^194 [\w-]+\s+0x\d+\s+\d+\s+\d+\s+\d+\s+[\w-]+\s+\w+\s+\S+\s+(\d+)(?:\s[\(][^)]*[\)])?$", + ) ) - ) - disk_bad_sectors = int( - __parse_smartctl( - disk_smartdata, - r"^ 5 [\w-]+\s+0x\d+\s+\d+\s+\d+\s+\d+\s+[\w-]+\s+\w+\s+\S+\s+(\d+)(?:\s[\(][^)]*[\)])?$", + except: + disk_temp = None + + try: + disk_bad_sectors = int( + __parse_smartctl( + disk_smartdata, + r"^ 5 [\w-]+\s+0x\d+\s+\d+\s+\d+\s+\d+\s+[\w-]+\s+\w+\s+\S+\s+(\d+)(?:\s[\(][^)]*[\)])?$", + ) ) - ) - disk_size = int(__read_file(f"/sys/block/{disk_node}/size")) * int( - __read_file(f"/sys/block/{disk_node}/queue/logical_block_size") - ) + except: + disk_bad_sectors = None + + try: + disk_size = int(__read_file(f"/sys/block/{disk_node}/size")) * int( + __read_file(f"/sys/block/{disk_node}/queue/logical_block_size") + ) + except: + disk_size = None # Do we pass SMART testing? if "PASSED" in __parse_smartctl( diff --git a/scripts/ubnt-fw-parse.py b/scripts/ubnt-fw-parse.py index bf1512b..2742b7c 100755 --- a/scripts/ubnt-fw-parse.py +++ b/scripts/ubnt-fw-parse.py @@ -68,9 +68,10 @@ def main(fwfile: str, savedir: str): file_header[4:33].decode("utf-8").rstrip("\x00") ) # Name/type of FILE file_length = int(file_header[48:52].hex(), 16) - print( - f"{file_name} is at offset {"0x%0.2X" % file_location}, {file_length} bytes" - ) + # Disabled because it's debug info and older python can't handle it + #print( + # f"{file_name} is at offset {"0x%0.2X" % file_location}, {file_length} bytes" + #) # print(int(file_header[52:56].hex(), 16)) # Maybe reserved memory or partition size? We don't use this tho fcount = fcount + 1 # Increment on find!