From a40c3e627c66f8a58814431371131227603e7d18 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Tue, 20 Aug 2024 11:46:58 +0400 Subject: [PATCH] feat(core): add base image to `/etc/ubo_base_image` and about page --- .github/workflows/integration_delivery.yml | 8 +++++--- CHANGELOG.md | 1 + scripts/packer/image.pkr.hcl | 5 +++++ .../app_runs_and_exits/store-desktop-000.jsonc | 3 ++- .../app_runs_and_exits/store-rpi-000.jsonc | 3 ++- .../store-desktop-000.jsonc | 3 ++- .../all_services_register/store-rpi-000.jsonc | 3 ++- ubo_app/services/030-wifi/setup.py | 5 +++++ ubo_app/store/core/_menus.py | 8 ++++++-- ubo_app/store/update_manager/__init__.py | 4 +++- ubo_app/store/update_manager/reducer.py | 1 + ubo_app/store/update_manager/utils.py | 18 ++++++++++++++++++ 12 files changed, 52 insertions(+), 10 deletions(-) diff --git a/.github/workflows/integration_delivery.yml b/.github/workflows/integration_delivery.yml index 46a68726..672cfa30 100644 --- a/.github/workflows/integration_delivery.yml +++ b/.github/workflows/integration_delivery.yml @@ -364,17 +364,18 @@ jobs: - name: Generate Image URL and Checksum id: generate-image-url run: | + SUFFIX="" if [ -n "${{ matrix.suffix }}" ]; then SUFFIX="_${{ matrix.suffix }}" - else - SUFFIX="${{ matrix.suffix }}" fi DASHED_SUFFIX=$(echo $SUFFIX | sed 's/_/-/g') - IMAGE_URL="https://downloads.raspberrypi.com/raspios${SUFFIX}_arm64/images/raspios${SUFFIX}_arm64-2024-07-04/2024-07-04-raspios-bookworm-arm64${DASHED_SUFFIX}.img.xz" + IMAGE_NAME="2024-07-04-raspios-bookworm-arm64${DASHED_SUFFIX}" + IMAGE_URL="https://downloads.raspberrypi.com/raspios${SUFFIX}_arm64/images/raspios${SUFFIX}_arm64-2024-07-04/${IMAGE_NAME}.img.xz" CHECKSUM_URL="${IMAGE_URL}.sha256" echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT" echo "dashed_suffix=$DASHED_SUFFIX" >> "$GITHUB_OUTPUT" echo "image_url=$IMAGE_URL" >> "$GITHUB_OUTPUT" + echo "image_name=$IMAGE_NAME" >> "$GITHUB_OUTPUT" echo "image_checksum_url=$CHECKSUM_URL" >> "$GITHUB_OUTPUT" IMAGE_SIZE_GB=${{ matrix.suffix == 'lite' && '4.25' || matrix.suffix == '' && '6.5' || '13' }} IMAGE_SIZE=$(awk -v IMAGE_SIZE_GB=$IMAGE_SIZE_GB 'BEGIN {printf "%.0f", IMAGE_SIZE_GB * 1024 ^ 3}') @@ -384,6 +385,7 @@ jobs: env: PKR_VAR_ubo_app_version: ${{ needs.build.outputs.version }} PKR_VAR_image_url: ${{ steps.generate-image-url.outputs.image_url }} + PKR_VAR_image_name: ${{ steps.generate-image-url.outputs.image_name }} PKR_VAR_image_checksum_url: ${{ steps.generate-image-url.outputs.image_checksum_url }} PKR_VAR_target_image_size: diff --git a/CHANGELOG.md b/CHANGELOG.md index dc31ae10..b4ee947c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Version 0.15.8 - fix(wifi): improve the logic of wifi onboarding notification +- feat(core): add base image to `/etc/ubo_base_image` and about page ## Version 0.15.7 diff --git a/scripts/packer/image.pkr.hcl b/scripts/packer/image.pkr.hcl index 554d38f4..b330d387 100644 --- a/scripts/packer/image.pkr.hcl +++ b/scripts/packer/image.pkr.hcl @@ -6,6 +6,10 @@ variable "image_url" { type = string } +variable "image_name" { + type = string +} + variable "image_checksum_url" { type = string } @@ -69,6 +73,7 @@ build { provisioner "shell" { inline = [ + "echo \"${var.image_name}\" > /etc/ubo_base_image", "chmod +x /install.sh", "/install.sh --in-packer --with-docker --source=/ubo_app-${var.ubo_app_version}-py3-none-any.whl", "rm /install.sh /ubo_app-${var.ubo_app_version}-py3-none-any.whl", diff --git a/tests/integration/results/test_core/app_runs_and_exits/store-desktop-000.jsonc b/tests/integration/results/test_core/app_runs_and_exits/store-desktop-000.jsonc index 1a452695..a227e7e6 100644 --- a/tests/integration/results/test_core/app_runs_and_exits/store-desktop-000.jsonc +++ b/tests/integration/results/test_core/app_runs_and_exits/store-desktop-000.jsonc @@ -192,7 +192,7 @@ } ], "placeholder": null, - "sub_heading": "A universal dashboard for your Raspberry Pi", + "sub_heading": "Base image: [unknown]\n", "title": "About" } } @@ -280,6 +280,7 @@ "icons": [] }, "update_manager": { + "base_image_variant": "[unknown]", "current_version": "0.0.0", "is_update_service_active": false, "latest_version": "0.0.0", diff --git a/tests/integration/results/test_core/app_runs_and_exits/store-rpi-000.jsonc b/tests/integration/results/test_core/app_runs_and_exits/store-rpi-000.jsonc index 7283d852..52f6338f 100644 --- a/tests/integration/results/test_core/app_runs_and_exits/store-rpi-000.jsonc +++ b/tests/integration/results/test_core/app_runs_and_exits/store-rpi-000.jsonc @@ -192,7 +192,7 @@ } ], "placeholder": null, - "sub_heading": "A universal dashboard for your Raspberry Pi", + "sub_heading": "Base image: [unknown]\n", "title": "About" } } @@ -280,6 +280,7 @@ "icons": [] }, "update_manager": { + "base_image_variant": "[unknown]", "current_version": "0.0.0", "is_update_service_active": false, "latest_version": "0.0.0", diff --git a/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc b/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc index 530a7e40..f9a86564 100644 --- a/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc +++ b/tests/integration/results/test_services/all_services_register/store-desktop-000.jsonc @@ -611,7 +611,7 @@ } ], "placeholder": null, - "sub_heading": "A universal dashboard for your Raspberry Pi", + "sub_heading": "Base image: [unknown]\n", "title": "About" } } @@ -752,6 +752,7 @@ ] }, "update_manager": { + "base_image_variant": "[unknown]", "current_version": "0.0.0", "is_update_service_active": false, "latest_version": "0.0.0", diff --git a/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc b/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc index 9d3a5156..b08e9a36 100644 --- a/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc +++ b/tests/integration/results/test_services/all_services_register/store-rpi-000.jsonc @@ -611,7 +611,7 @@ } ], "placeholder": null, - "sub_heading": "A universal dashboard for your Raspberry Pi", + "sub_heading": "Base image: [unknown]\n", "title": "About" } } @@ -752,6 +752,7 @@ ] }, "update_manager": { + "base_image_variant": "[unknown]", "current_version": "0.0.0", "is_update_service_active": false, "latest_version": "0.0.0", diff --git a/ubo_app/services/030-wifi/setup.py b/ubo_app/services/030-wifi/setup.py index 9ea07fe7..ee7195ad 100644 --- a/ubo_app/services/030-wifi/setup.py +++ b/ubo_app/services/030-wifi/setup.py @@ -133,6 +133,11 @@ async def init_service() -> None: options=AutorunOptions(default_value=None), ) def check_onboarding(is_connected: bool | None) -> None: + try: + _ = check_onboarding + except NameError: + return + if is_connected is False and not read_from_persistent_store( key='wifi_has_visited_onboarding', default=False, diff --git a/ubo_app/store/core/_menus.py b/ubo_app/store/core/_menus.py index 154a2a32..d4ddc4a3 100644 --- a/ubo_app/store/core/_menus.py +++ b/ubo_app/store/core/_menus.py @@ -26,7 +26,11 @@ NotificationDisplayType, NotificationsDisplayEvent, ) -from ubo_app.store.update_manager.utils import CURRENT_VERSION, about_menu_items +from ubo_app.store.update_manager.utils import ( + BASE_IMAGE, + CURRENT_VERSION, + about_menu_items, +) if TYPE_CHECKING: from collections.abc import Sequence @@ -80,7 +84,7 @@ sub_menu=HeadedMenu( title='About', heading=f'Ubo v{CURRENT_VERSION}', - sub_heading='A universal dashboard for your Raspberry Pi', + sub_heading=f'Base image: {BASE_IMAGE[:11]}\n{BASE_IMAGE[11:]}', items=about_menu_items, ), ), diff --git a/ubo_app/store/update_manager/__init__.py b/ubo_app/store/update_manager/__init__.py index 503df652..935e4b48 100644 --- a/ubo_app/store/update_manager/__init__.py +++ b/ubo_app/store/update_manager/__init__.py @@ -14,8 +14,9 @@ class UpdateManagerAction(BaseAction): ... class UpdateManagerSetVersionsAction(UpdateManagerAction): flash_notification: bool - latest_version: str current_version: str + base_image_variant: str + latest_version: str serial_number: str @@ -51,6 +52,7 @@ class UpdateManagerState(Immutable): serial_number: str | None = None current_version: str | None = None + base_image_variant: str | None = None latest_version: str | None = None update_status: UpdateStatus = UpdateStatus.CHECKING is_update_service_active: bool = False diff --git a/ubo_app/store/update_manager/reducer.py b/ubo_app/store/update_manager/reducer.py index adf54301..9fb4c6bb 100644 --- a/ubo_app/store/update_manager/reducer.py +++ b/ubo_app/store/update_manager/reducer.py @@ -52,6 +52,7 @@ def reducer( state = replace( state, current_version=action.current_version, + base_image_variant=action.base_image_variant, latest_version=action.latest_version, serial_number=action.serial_number, ) diff --git a/ubo_app/store/update_manager/utils.py b/ubo_app/store/update_manager/utils.py index eb6fdc7b..07a49121 100644 --- a/ubo_app/store/update_manager/utils.py +++ b/ubo_app/store/update_manager/utils.py @@ -37,9 +37,26 @@ UpdateManagerState, UpdateStatus, ) +from ubo_app.utils import IS_RPI from ubo_app.utils.eeprom import read_serial_number CURRENT_VERSION = importlib.metadata.version('ubo_app') +if IS_RPI: + try: + BASE_IMAGE = Path('/etc/ubo_base_image').read_text() + except FileNotFoundError: + BASE_IMAGE = '[unknown]' +else: + BASE_IMAGE = '[unknown]' +BASE_IMAGE_VARIANT = ( + BASE_IMAGE == '[unknown]' + and '[unknown]' + or BASE_IMAGE.endswith('-lite') + and 'lite' + or BASE_IMAGE.endswith('-full') + and 'full' + or 'desktop' +) async def check_version() -> None: @@ -67,6 +84,7 @@ async def check_version() -> None: flash_notification=state is None or state.main.path[:2] != ['main', 'about'], current_version=CURRENT_VERSION, + base_image_variant=BASE_IMAGE_VARIANT, latest_version=latest_version, serial_number=serial_number, ),