[v1,2/2] installer-ui: use sys_api backend for frontend dialogs

Message ID 20260119055335.1006446-3-kasturi.shekar@siemens.com
State Under Review
Headers show
Series installer: split backend APIs from frontend UI | expand

Commit Message

Kasturi Shekar Jan. 19, 2026, 5:53 a.m. UTC
Signed-off-by: Kasturi Shekar <kasturi.shekar@siemens.com>
---
 .../files/usr/bin/installer_ui.sh             | 86 +++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100755 meta-isar/recipes-installer/deploy-image/files/usr/bin/installer_ui.sh

Patch

diff --git a/meta-isar/recipes-installer/deploy-image/files/usr/bin/installer_ui.sh b/meta-isar/recipes-installer/deploy-image/files/usr/bin/installer_ui.sh
new file mode 100755
index 00000000..33685c6f
--- /dev/null
+++ b/meta-isar/recipes-installer/deploy-image/files/usr/bin/installer_ui.sh
@@ -0,0 +1,86 @@ 
+#!/usr/bin/env bash
+#
+# installer_ui.sh — Attended installer frontend
+# ------------------------------------------------
+
+SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
+INSTALL_DATA=${INSTALL_DATA:-./install}
+
+# Backend APIs
+. "$SCRIPT_DIR/sys_api.sh"
+
+# ------------------------------------------------
+# Helpers
+# ------------------------------------------------
+die() {
+    dialog --msgbox "$1" 6 60
+    exit 1
+}
+
+# ------------------------------------------------
+# UI: Select image
+# ------------------------------------------------
+ui_select_image() {
+    local images json list=()
+
+    # On failure, show error dialog and exit
+    json=$(sys_locate_disk_images search_path="$INSTALL_DATA") || \
+        die "No installable images found in $INSTALL_DATA"
+
+    # Extract image paths from JSON
+    images=$(echo "$json" | sed -n 's/.*"images":\[\(.*\)\].*/\1/p' | tr -d '"' | tr ',' '\n')
+
+    # Building dialog menu entries
+    for img in $images; do
+        base=$(basename "$img")
+        list+=("$img" "$base")
+    done
+
+    # Display menu and capture selection
+    INSTALL_IMAGE=$(dialog --no-tags \
+        --menu "Select image to install" 10 70 5 \
+        "${list[@]}" \
+        --output-fd 1) || exit 0
+}
+
+# ------------------------------------------------
+# UI: Select target device
+# ------------------------------------------------
+ui_select_target_device() {
+    local list=()
+
+    devices=$(sys_list_valid_target_devices) || \
+        die "No valid target devices found"
+
+    for dev in $devices; do
+        [ -b "$dev" ] || continue
+
+        size=$(lsblk --nodeps --noheadings -o SIZE "$dev" 2>/dev/null | tr -d " ")
+        [ -z "$size" ] && size="unknown"
+
+        if cmp /dev/zero "$dev" -n 1M >/dev/null 2>&1; then
+            state="empty"
+        else
+            state="contains data"
+        fi
+
+        list+=("$dev" "$dev ($size, $state)")
+    done
+
+    if [ "${#list[@]}" -lt 2 ]; then
+        die "no installable target devices available"
+    fi
+
+    TARGET_DEVICE=$(dialog --no-tags \
+        --menu "Select target device" 10 70 6 \
+        "${list[@]}" \
+        --output-fd 1) || exit 0
+}
+
+run_interactive_installer() {
+    clear
+    ui_select_image
+    ui_select_target_device
+}
+
+run_interactive_installer