Fixed installation of alternate firmware version

Required version info was not being downloaded when alternate (not latest)
version is selected rsulting in the error "Could not read locally cached
release information."
This commit is contained in:
Chad Attermann 2024-03-05 19:02:47 -07:00
parent 1b7b131adc
commit 5565349255
1 changed files with 70 additions and 68 deletions

View File

@ -999,83 +999,85 @@ def ensure_firmware_file(fw_filename):
else: else:
try: try:
if selected_version == None: if not upd_nocheck:
if not upd_nocheck: try:
try: # if custom firmware url, download latest release
try: if selected_version == None and fw_url == None:
# if custom firmware url, download latest release version_url = firmware_version_url+fw_filename
if fw_url != None: RNS.log("Retrieving latest version info from "+version_url)
try: urlretrieve(firmware_version_url+fw_filename, UPD_DIR+"/"+fw_filename+".version.latest")
RNS.log("Retrieving latest version from custom url "+fw_url+"latest/download/release.json") else:
urlretrieve(fw_url+"latest/download/release.json", UPD_DIR+"/fallback_release_info.json") if fw_url != None:
import json if selected_version == None:
with open(UPD_DIR+"/fallback_release_info.json", "rb") as rif: version_url = fw_url+"latest/download/release.json"
rdat = json.loads(rif.read())
variant = rdat[fw_filename]
with open(UPD_DIR+"/"+fw_filename+".version.latest", "wb") as verf:
inf_str = str(variant["version"])+" "+str(variant["hash"])
verf.write(inf_str.encode("utf-8"))
except Exception as e:
RNS.log("Error while trying custom URL: "+str(e))
raise e
else: else:
urlretrieve(firmware_version_url+fw_filename, UPD_DIR+"/"+fw_filename+".version.latest") version_url = fw_url+"download/"+selected_version+"/release.json"
else:
version_url = firmware_update_url+selected_version+"/release.json"
try:
RNS.log("Retrieving specified version info from "+version_url)
urlretrieve(version_url, UPD_DIR+"/version_release_info.json")
import json
with open(UPD_DIR+"/version_release_info.json", "rb") as rif:
rdat = json.loads(rif.read())
variant = rdat[fw_filename]
with open(UPD_DIR+"/"+fw_filename+".version.latest", "wb") as verf:
inf_str = str(variant["version"])+" "+str(variant["hash"])
verf.write(inf_str.encode("utf-8"))
except Exception as e: except Exception as e:
# if custom firmware url, don't fallback RNS.log("Failed to retrive version information for your board.")
if fw_url != None: RNS.log("Check your internet connection and try again.")
RNS.log("Failed to retrive latest version information for your board from the specified url.") RNS.log("If you don't have Internet access currently, use the --fw-version option to manually specify a version.")
RNS.log("Check your internet connection and try again.") RNS.log("You can also use --extract to copy the firmware from a known-good RNode of the same model.")
RNS.log("If you don't have Internet access currently, use the --fw-version option to manually specify a version.") exit()
RNS.log("You can also use --extract to copy the firmware from a known-good RNode of the same model.") except Exception as e:
exit() # if custom firmware url, don't fallback
if fw_url != None:
RNS.log("") RNS.log("Failed to retrive version information for your board from the specified url.")
RNS.log("WARNING!")
RNS.log("Failed to retrieve latest version information for your board from the default server")
RNS.log("Will retry using the following fallback URL: "+fallback_firmware_version_url)
RNS.log("")
RNS.log("Hit enter if you want to proceed")
input()
try:
urlretrieve(fallback_firmware_version_url, UPD_DIR+"/fallback_release_info.json")
import json
with open(UPD_DIR+"/fallback_release_info.json", "rb") as rif:
rdat = json.loads(rif.read())
variant = rdat[fw_filename]
with open(UPD_DIR+"/"+fw_filename+".version.latest", "wb") as verf:
inf_str = str(variant["version"])+" "+str(variant["hash"])
verf.write(inf_str.encode("utf-8"))
except Exception as e:
RNS.log("Error while trying fallback URL: "+str(e))
raise e
except Exception as e:
RNS.log("Failed to retrive latest version information for your board.")
RNS.log("Check your internet connection and try again.") RNS.log("Check your internet connection and try again.")
RNS.log("If you don't have Internet access currently, use the --fw-version option to manually specify a version.") RNS.log("If you don't have Internet access currently, use the --fw-version option to manually specify a version.")
RNS.log("You can also use --extract to copy the firmware from a known-good RNode of the same model.") RNS.log("You can also use --extract to copy the firmware from a known-good RNode of the same model.")
exit() exit()
import shutil RNS.log("")
file = open(UPD_DIR+"/"+fw_filename+".version.latest", "rb") RNS.log("WARNING!")
release_info = file.read().decode("utf-8").strip() RNS.log("Failed to retrieve latest version information for your board from the default server.")
selected_version = release_info.split()[0] RNS.log("Will retry using the following fallback URL: "+fallback_firmware_version_url)
if selected_version == "not": RNS.log("")
RNS.log("No valid version found for this board, exiting.") RNS.log("Hit enter if you want to proceed")
exit(199) input()
try:
urlretrieve(fallback_firmware_version_url, UPD_DIR+"/fallback_release_info.json")
import json
with open(UPD_DIR+"/fallback_release_info.json", "rb") as rif:
rdat = json.loads(rif.read())
variant = rdat[fw_filename]
with open(UPD_DIR+"/"+fw_filename+".version.latest", "wb") as verf:
inf_str = str(variant["version"])+" "+str(variant["hash"])
verf.write(inf_str.encode("utf-8"))
selected_hash = release_info.split()[1] except Exception as e:
if not os.path.isdir(UPD_DIR+"/"+selected_version): RNS.log("Error while trying fallback URL: "+str(e))
os.makedirs(UPD_DIR+"/"+selected_version) raise e
shutil.copy(UPD_DIR+"/"+fw_filename+".version.latest", UPD_DIR+"/"+selected_version+"/"+fw_filename+".version")
RNS.log("The latest firmware for this board is version "+selected_version)
else: import shutil
RNS.log("Online firmware version check was disabled, but no firmware version specified for install.") file = open(UPD_DIR+"/"+fw_filename+".version.latest", "rb")
RNS.log("use the --fw-version option to manually specify a version.") release_info = file.read().decode("utf-8").strip()
exit(98) selected_version = release_info.split()[0]
if selected_version == "not":
RNS.log("No valid version found for this board, exiting.")
exit(199)
selected_hash = release_info.split()[1]
if not os.path.isdir(UPD_DIR+"/"+selected_version):
os.makedirs(UPD_DIR+"/"+selected_version)
shutil.copy(UPD_DIR+"/"+fw_filename+".version.latest", UPD_DIR+"/"+selected_version+"/"+fw_filename+".version")
RNS.log("The selected firmware for this board is version "+selected_version)
else:
RNS.log("Online firmware version check was disabled, but no firmware version specified for install.")
RNS.log("use the --fw-version option to manually specify a version.")
exit(98)
# if custom firmware url, use it # if custom firmware url, use it
if fw_url != None: if fw_url != None: