diff --git a/firmware/Cerbo_Release/Cerbo Rollout Guidance.pdf b/firmware/Cerbo_Release/Cerbo Rollout Guidance.pdf index db71e3813..ac81be705 100644 Binary files a/firmware/Cerbo_Release/Cerbo Rollout Guidance.pdf and b/firmware/Cerbo_Release/Cerbo Rollout Guidance.pdf differ diff --git a/firmware/Cerbo_Release/update_Cerbo.py b/firmware/Cerbo_Release/update_Cerbo.py index 188b2a32c..385fad2ce 100644 --- a/firmware/Cerbo_Release/update_Cerbo.py +++ b/firmware/Cerbo_Release/update_Cerbo.py @@ -88,6 +88,10 @@ async def import_pika(remote_host): command = f"{change_dir_command} && {install_command}" return await run_remote_command(remote_host, command) +async def make_rclocal_executable(remote_host): + command = "chmod +x /data/rc.local" + return await run_remote_command(remote_host, command) + async def reboot(remote_host): command = "reboot" return await run_remote_command(remote_host, command) @@ -144,24 +148,30 @@ async def upload_files(remote_host,which_file): return f"An error occurred while uploading files: {str(e)}" async def check_connection(remote_host): - # Check if the remote host is reachable - ping_command = ['ping', '-c', '1', remote_host] - result = subprocess.run(ping_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - return result.returncode == 0 + result = await run_remote_command(remote_host, 'echo Connection successful') + return "Connection successful" in result async def main(remote_host): + ##### 1. check connection ###### + print("Check connection!") + if not await check_connection(remote_host): + sys.exit("Failed to ssh!") ##################################################### Part 1 ################################################################ - ##### 1. upload VPN and battery files ###### - print("Upload VPN and battery files!") - if(await upload_files(remote_host,1)!="All files uploaded successfully."): - sys.exit("Failed to upload files!") - else: - print(await upload_files(remote_host,1)) - - ##### 2. update firmware with normal image ##### gx_type = await check_GX_type(remote_host) if gx_type == "einstein\n": + ##### 2. upload VPN and battery files ###### + print("Upload VPN and battery files!") + if(await upload_files(remote_host,1)!="All files uploaded successfully."): + sys.exit("Failed to upload files!") + else: + print(await upload_files(remote_host,1)) + + ##### 3. upload VPN and battery files ###### + print("Make rc.local executable!") + print(await make_rclocal_executable(remote_host)) + + ##### 4. update firmware with normal image ##### print("Update Cerbo GX firmware now!") print(await update_cerbo_firmware(remote_host)) else: @@ -169,23 +179,14 @@ async def main(remote_host): ##################################################### Part 1 ################################################################ # Wait for remote computer to come back online + await asyncio.sleep(5) while not await check_connection(remote_host): print("Waiting for remote computer to come back online...") - await asyncio.sleep(10) # Adjust timeout as needed + await asyncio.sleep(10) # 10 seconds - ##################################################### Part 2 ################################################################ - #### 3. udpate to MK3 ##### - if (await check_mkVersion(remote_host) == "value = 1170212\n" and await check_allow_mkVersion_update_or_not(remote_host) == "0\n"): - print("Update MK3!") - print(await update_mkVersion(remote_host)) - else: - print("No need to update to MK3!") - - #### 4. import pika #### - print("Import pika!") - print(await import_pika(remote_host)) - - ##### 5. update firmware with large image ##### + #################################################### Part 2 ################################################################ + + #### 5. update firmware with large image #### print("Set update feed to official release now!") print(await set_official_update_feed(remote_host)) print("Enable large image now!") @@ -196,34 +197,54 @@ async def main(remote_host): print(await update_firmware(remote_host)) else: sys.exit("Failed to enable large image!") - ##################################################### Part 2 ################################################################ + #################################################### Part 2 ################################################################ # Wait for remote computer to come back online + await asyncio.sleep(5) while not await check_connection(remote_host): print("Waiting for remote computer to come back online...") - await asyncio.sleep(10) # Adjust timeout as needed + await asyncio.sleep(10) # 10 seconds ##################################################### Part 3 ################################################################ #### 6. resize /dev/root ##### print("Resize /dev/root now!") - print(await resize(remote_host)) + resize_result = await resize(remote_host) + if "Failed" in resize_result: + sys.exit(f"Failed to resize: {resize_result}") + else: + print(resize_result) + + #### 7. import pika #### + print("Import pika!") + import_result = await import_pika(remote_host) + if "Failed" in import_result: + sys.exit(f"Failed to import pika: {import_result}") + else: + print(import_result) - #### 7. enable Node Red ##### + #### 8. udpate to MK3 ##### + if (await check_mkVersion(remote_host) == "value = 1170212\n" and await check_allow_mkVersion_update_or_not(remote_host) == "0\n"): + print("Update MK3!") + print(await update_mkVersion(remote_host)) + else: + print("No need to update to MK3!") + + #### 9. enable Node Red ##### print("Enable Node Red now!") print(await enable_NodeRed(remote_host)) if(await check_NodeRed_enabled_or_not(remote_host) == "value = 1\n"): - ##### 8. download Node Red Dashboard ##### + ##### 10. download Node Red Dashboard ##### print("Download Node Red Dashboard now!") print(await download_node_red_dashboard(remote_host)) else: sys.exit("Failed to enable Node Red!") - ##### 9. upload files related to Node Red ##### + ##### 11. upload files related to Node Red ##### print("Upload files related to Node Red now!") if(await upload_files(remote_host,2)!="All files uploaded successfully."): sys.exit("Failed to upload files!") - #### 10. restart Node Red to load and deploy flows ##### + #### 12. restart Node Red to load and deploy flows ##### print("Disable Node Red!") if(await disable_NodeRed(remote_host) == "retval = 0\n"): print("Re-enable Node Red!")