From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from shymkent.ilbers.de ([unix socket]) by shymkent (Cyrus 2.5.10-Debian-2.5.10-3+deb9u2) with LMTPA; Mon, 08 Jun 2026 07:19:53 +0200 X-Sieve: CMU Sieve 2.4 Received: from mail-pj1-f55.google.com (mail-pj1-f55.google.com [209.85.216.55]) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPS id 6585JpVt028716 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 8 Jun 2026 07:19:52 +0200 Received: by mail-pj1-f55.google.com with SMTP id 98e67ed59e1d1-36d98b74447sf2940827a91.2 for ; Sun, 07 Jun 2026 22:19:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1780895985; cv=pass; d=google.com; s=arc-20240605; b=Ni/P08tvJpl0wbEju8YeLy5kKrnMU4yXKnzQBFVOwfH28PquJKBsyCJWe9DIkgdTWX AOnqRDuHQ9Gip18CzPbmEuul9pkZS1Jodd+vb7/ox4F6rExZfpG44fNIQ85txGABsNY6 wgkG8ZzP5G9AQaOmUFf7OzNTGd9DxK2dPnfEq14ntG5fYz4uW8U37sp8B6RsNNP+gzN/ BVMrxS0xTEqLB26C9a2s+Y1Bxf8G9wwCpZnttRnnFPFJJkGBjENgBaLDf01FI8dNHuZd 58aAeYKSS59PB234kxyTHx23iZ4tPYXJx/0LFctvN9fUZ7d4fcjkRFxtsEhoNyiFaWlO C6JQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:feedback-id :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=0eyt0ESrKP7Ruwb20G3kHEndLNbwFtKVgBdvboEpmmY=; fh=FnJxSBkB3ArVxXNUO9s4RLUZbuP9J3KRA40OYeVkp94=; b=ijeNP+pGyJjgnCRjxZWsUN2TlKYwndt0RHXcYnciMU3K8X2PjqABwaRgQ5AvE/i9RP wZLbbP/79X8va+/4gwiotO7vBuKFXbdeGZCcXy0/fP1PoguR5I+t64ajgtJ2x5pY9MHX U/wYAq7NL+Of41OEFSbdnkuo4nREfy9pgSoJF9F/sqT8PjiIGoLmFYwpA+z+5VPu9fe8 2rNdabe8dLilXTfR5FCUMfzRhO7CqBivyXwPPf+xjNjyBm9RRRPn5vpRv3I9MNQBhXez oBH5o/jwU37BpMPFyzkiCMAfGAcsesPxEo0HFQnpNKQw35KO9vc1fHbFRbqCgURxVXDX nXeQ==; darn=ilbers.de ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=E+HbJvc3; spf=pass (google.com: domain of fm-1328757-20260608051940d74c8afa4c00020770-q_qju_@rts-flowmailer.siemens.com designates 185.136.65.225 as permitted sender) smtp.mailfrom=fm-1328757-20260608051940d74c8afa4c00020770-q_QJU_@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20251104; t=1780895985; x=1781500785; darn=ilbers.de; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:feedback-id :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0eyt0ESrKP7Ruwb20G3kHEndLNbwFtKVgBdvboEpmmY=; b=l9vuTVprzR35RWj/Ur60vKS1nfzQFB3fUB9ZnoJZ5doDXlKW2AWVUrY/RHRY083ya7 B1n5tXcNqNsvtuuTChgmm81I9lvyoZv3lpTiMWxzixPNl02+zwejOV5EVwbbKS8DJVaV GijykSKVdNxuEaM8SlK/gSvQCCdAsnPVEH2GQVEBqan6gquP/58qaY/FHGArDF/N2H2M NJ25NghOdQvBpxqVUVsXnDLg706fnNTkXCRuMXQdbcXDYgVZFtuVnubdYLA9Ba8cieGW B1T0e00iKwYdLxQLMBaSXdRjPbfdzlGx2z9kg00E27JTVSb9MTvQ9zmbNlSW/XMJP7xy U8mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780895985; x=1781500785; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:feedback-id :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0eyt0ESrKP7Ruwb20G3kHEndLNbwFtKVgBdvboEpmmY=; b=HgYZQzoRBCmc6MYrFapvTfAKyh+S6awQxJZsZnX72p0FN92duH2kR+BPhQgS9Hq2rW dmobKbFZRFD1oTy9CiB1oS50AFv/CFUUa1H1NbozRQ9TsWLnKlXto4DpC858zdM5iCyp 1GE8IOy8KtmzpaiF6ytZ6JaEoj1PvUrcL4xhVFW7U8YZnw4URjUXgHKagwluaeJk5Nac IInC67f6Fmxx4j7pjaBWLWZOh7UPfNJw4XdD79p9g/Wz+kZiLlqFxX2BeSGoZ6sA42+g Kccob6PjPfLKgIu8bgkQ43H/hy4KtKn1inEGZRfdQ2L4Ii/mmFVr30ISV4a1uQN/00Jh HJAg== X-Forwarded-Encrypted: i=2; AFNElJ9vihWhpBKmHNd04Uabnv2NQ3qEi+zSaHApry/gdXqAdh570g1F5XGHsDuLnDZ8RovgO8qM@ilbers.de X-Gm-Message-State: AOJu0YyBgcNVMBOyGKSB2d0ziSmiwnEzy9SuOI5QfB4J0umVjo1offxA XKXqmFkqx2vDYTjJVIyYpzUV84vGe4bB7x2uuY25Mq/ZKIGHOK8mDPGX X-Received: by 2002:a17:90b:1809:b0:368:6998:b49d with SMTP id 98e67ed59e1d1-370eeff6b37mr15395411a91.10.1780895985160; Sun, 07 Jun 2026 22:19:45 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com; h="AX0PUUeywf/JrAZq63nhsYdSUJrrSEYQ8P1JGO+Os4t17cMJ/w==" Received: by 2002:a17:90b:48c4:b0:36b:74e9:20e6 with SMTP id 98e67ed59e1d1-36f65d418e7ls5497579a91.1.-pod-prod-09-us; Sun, 07 Jun 2026 22:19:43 -0700 (PDT) X-Received: by 2002:a17:90b:1809:b0:368:6998:b49d with SMTP id 98e67ed59e1d1-370eeff6b37mr15395288a91.10.1780895983143; Sun, 07 Jun 2026 22:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780895983; cv=none; d=google.com; s=arc-20240605; b=IoySjSwHa+ViPLeWHoEvoHgv/KJ/Pg3XH8tqXsx07BY6cFPrSk9TANDBBsla30cmmO pWV05xN1ZHrnuET8iMxundGwPmd5Ft0Gg+k/Oe+PyfYABJMiFp1xynDtZWnBbIMiwTjZ Gl5TkY8qP0uoKVMK5giMOBJ+dzBwI3ttmus7tZaK+kdlgQmSdMDPF+Eqf7uKuBMu+ZCT hL6J+yA7MCQdnJQwLQGqbsCKVKYPlfrIoGvrm/GQ1Q+VqbTovXmkpZGFCkM7ZKXr3ska pMg5V8iXpaGUgoa36GarhBNFOAY1zeOtwBhElyNy0HUXhZO6H6a89yMtl9t5a7q1y1M+ mofg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=feedback-id:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=YsWzSu2h1OdZL9+OcLVg2KAEYfVdG5HEHGFTa5qx/vI=; fh=pR4tJPO4NbHlIB/rP4bIo54Z1zh5hd/ksAGQ0tcKkYM=; b=QtfVv1aUxHY7Y8Llwlr6a9Y3Nepoh6tvuQjz3oXxKZKe6MQ6hsQb2t8t+RdMbgHp0L 5Mxva1LCuCPzdh68yespUW+rjaOWJMoz7lm6g0LAvXcMSySXUFo62a21u8YSaCxX/5o6 xxbk23xPM/9g1erEhaTeSURT0BR7Dy9YPS6Qm2jeG5DBhp8RHho0Af+49IGobo+76BuZ BeSij56zVXJNK2HjruCgnpwu8C/2n7MZbCQ7PieQN7W5wmjc1sGbdH4o6O+r4eME402C 6VEsa0hlL/7445Jdru+dyLFbRDuDyrBqSdFUmA52b+cBR7FgJ4t468QxNzXtJ90MfS8D 3qRQ==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=E+HbJvc3; spf=pass (google.com: domain of fm-1328757-20260608051940d74c8afa4c00020770-q_qju_@rts-flowmailer.siemens.com designates 185.136.65.225 as permitted sender) smtp.mailfrom=fm-1328757-20260608051940d74c8afa4c00020770-q_QJU_@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from mta-65-225.siemens.flowmailer.net (mta-65-225.siemens.flowmailer.net. [185.136.65.225]) by gmr-mx.google.com with ESMTPS id 98e67ed59e1d1-37135d3a9efsi118027a91.2.2026.06.07.22.19.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Jun 2026 22:19:43 -0700 (PDT) Received-SPF: pass (google.com: domain of fm-1328757-20260608051940d74c8afa4c00020770-q_qju_@rts-flowmailer.siemens.com designates 185.136.65.225 as permitted sender) client-ip=185.136.65.225; Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20260608051940d74c8afa4c00020770 for ; Mon, 08 Jun 2026 07:19:40 +0200 From: "'Kasturi shekar' via isar-users" To: isar-users@googlegroups.com Cc: Kasturi Shekar Subject: [PATCH v3 1/4] installer: extract backend helpers to sys_api.sh Date: Mon, 8 Jun 2026 10:47:32 +0530 Message-ID: <20260608051737.946413-2-kasturi.shekar@siemens.com> In-Reply-To: <20260608051737.946413-1-kasturi.shekar@siemens.com> References: <8b658081-ce7b-4ffc-b108-1691f5a8ceaf@ilbers.de> <20260608051737.946413-1-kasturi.shekar@siemens.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-1328757:519-21489:flowmailer X-Original-Sender: kasturi.shekar@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=E+HbJvc3; spf=pass (google.com: domain of fm-1328757-20260608051940d74c8afa4c00020770-q_qju_@rts-flowmailer.siemens.com designates 185.136.65.225 as permitted sender) smtp.mailfrom=fm-1328757-20260608051940d74c8afa4c00020770-q_QJU_@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com X-Original-From: Kasturi shekar Reply-To: Kasturi shekar Precedence: list Mailing-list: list isar-users@googlegroups.com; contact isar-users+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: isar-users@googlegroups.com X-Google-Group-Id: 914930254986 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , X-Spam-Status: No, score=-4.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, RCVD_IN_RP_CERTIFIED,RCVD_IN_RP_RNBL,RCVD_IN_RP_SAFE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-TUID: M1032kCAhqQq From: Kasturi Shekar Move backend and system-facing installer logic into sys_api.sh This patch introduces backend helper APIs for: - install image discovery - target device discovery and filtering - root/live-device exclusion - RAID member and inactive md filtering - block device state and size helpers - bmap copy execution with locking and progress pipe support Signed-off-by: Kasturi Shekar --- .../deploy-image/files/usr/bin/sys_api.sh | 400 +++++++++++++++--- 1 file changed, 333 insertions(+), 67 deletions(-) diff --git a/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api= .sh b/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api.sh index b144419e..9c9c5840 100644 --- a/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api.sh +++ b/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api.sh @@ -1,84 +1,350 @@ #!/usr/bin/env bash +# This software is a part of ISAR. +# Copyright (C) Siemens AG, 2026 # -# sys_api.sh =E2=80=94 Ported installer system APIs -# ------------------------------------------------------------------- +# SPDX-License-Identifier: MIT =20 -# Load shared framework utilities -source ./func.sh || { - echo "Error: func.sh not found or not readable." >&2 - exit 1 +#-------------------------------------------------------------------------= - +# sys_api.sh - Backend APIs for deploy-image-wic installer. +# +# This file intentionally contains only system/backend logic: +# - image discovery +# - target device discovery and filtering +# - low-level install/copy flow +# +# UI concerns (dialog boxes, menus, confirmations) are implemented in +# installer_ui.sh and called by the main orchestrator script. +#-------------------------------------------------------------------------= - + +# Globals populated by sys_discover_target_devices(). +SYS_CURRENT_ROOT_DEV=3D"" +SYS_TARGET_DEVICES=3D() + +#-------------------------------------------------------------------------= - +# sys_first_default_image_name +# +# Returns: +# basename of matching *.wic* image (excluding *.wic.bmap), or empty. +#-------------------------------------------------------------------------= - +sys_first_default_image_name() { + local install_data_dir=3D"$1" + + find "$install_data_dir" -type f -iname "*.wic*" -a -not -iname "*.wic= .bmap" \ + -exec basename {} \; | head -n 1 +} + +#-------------------------------------------------------------------------= - +# sys_list_installable_entries +# +# Returns: +# relative file paths under install_data_dir, one per line. +# Files ending in *.wic.bmap are excluded. +#-------------------------------------------------------------------------= - +sys_list_installable_entries() { + local install_data_dir=3D"$1" + + ( + cd "$install_data_dir" || return 1 + find . -type f ! -iname "*.wic.bmap" -print | sed 's#^./##' + ) } =20 -# ------------------------------------------------------------------- -# API: locate_disk_images -# Description: -# Find disk image files (.wic, .wic.bz2) under given path. -# Usage: -# sys_locate_disk_images search_path=3D/install -# Returns JSON: -# {"error":"", "retval":"0", "images":["/install/image.wic", ...]} -# ------------------------------------------------------------------- -sys_locate_disk_images() { - local -A ARGS - local required=3D(search_path) - api_args ARGS required[@] "$@" || { - pack_return_data error "$_args_error" retval "1" - return 1 - } - - local fn=3D"${FUNCNAME[0]}" - local path=3D"${ARGS[search_path]}" - - log_info "$fn" "Searching for disk images in '$path'" - - local images - images=3D$(find "$path" -type f -iname "*.wic*" ! -iname "*.wic.bmap" = 2>/dev/null) - - # when no images found in /install - if [[ -z "$images" ]]; then - log_warn "$fn" "No images found." - pack_return_data error "No images found" retval "1" - return 1 +#-------------------------------------------------------------------------= - +# sys_resolve_image_path +# +# Arguments: +# install_data_dir - base directory where installable images are stored +# image_or_path - either a relative image filename under install_data_di= r +# or an explicit absolute/relative filesystem path +# +# Returns: +# absolute image path if resolvable, else non-zero return code. +#-------------------------------------------------------------------------= - +sys_resolve_image_path() { + local install_data_dir=3D"$1" + local image_or_path=3D"$2" + + if [ -f "$image_or_path" ]; then + echo "$image_or_path" + return 0 + fi + + if [ -f "$install_data_dir/$image_or_path" ]; then + echo "$install_data_dir/$image_or_path" + return 0 fi =20 - # Convert newline-separated paths into JSON array elements - local json_images - json_images=3D$(printf '"%s",' $images | sed 's/,$//') - # final JSON response on stdout - echo "{ \"error\":\"\", \"retval\":\"0\", \"images\":[${json_images}] = }" + return 1 } =20 +#-------------------------------------------------------------------------= - +# sys_discover_target_devices +# +# Populates globals: +# SYS_CURRENT_ROOT_DEV - current live root device identifier +# SYS_TARGET_DEVICES - array with valid target block devices (/dev/*) +# +# Filtering rules match legacy deploy-image-wic behavior, including: +# - skip installer/live root device and backing devices +# - skip loop/dm/ram/sr/mtd/zram +# - skip inactive md arrays and md members +#-------------------------------------------------------------------------= - +sys_discover_target_devices() { + local current_root_dev_type + local current_root_dev + local root_source + local root_source_resolved + local base_no_part + local slave + local slave_dev + local slave_base + local devices + local mmc_devices + local device + local is_raid_member + local holder_path + local holder_name + local state + local skip_device + local ex + + local exclude_list=3D() + + SYS_TARGET_DEVICES=3D() + + # Determine the live root device so we do not offer the current system= disk + # as an install target. For NFS roots use a special sentinel value. + + current_root_dev_type=3D$(findmnt / -o fstype -n) + if [ "$current_root_dev_type" =3D "nfs" ]; then + current_root_dev=3D"nfs" + exclude_list+=3D("nfs") + else + root_source=3D$(findmnt / -o source -n) + root_source_resolved=3D$(readlink -f "$root_source" 2>/dev/null ||= echo "$root_source") + current_root_dev=3D${root_source_resolved#/dev/} + + exclude_list+=3D("$current_root_dev") + + # Strip partition suffix for common disk names so the base device + # (e.g. /dev/sda or /dev/mmcblk0) also does not become selectable. + if [[ "$current_root_dev" =3D~ ^(mmcblk|nvme) ]]; then + base_no_part=3D"${current_root_dev%p[0-9]*}" + else + base_no_part=3D"${current_root_dev%%[0-9]*}" + fi + + if [ -n "$base_no_part" ]; then + exclude_list+=3D("$base_no_part") + fi + + # Exclude backing devices for the live root, such as multipath or = RAID + # underlying devices exposed via /sys/block//slaves. + if [ -d "/sys/block/$current_root_dev/slaves" ]; then + for slave in /sys/block/"$current_root_dev"/slaves/*; do + [ -e "$slave" ] || continue + slave_dev=3D$(basename "$slave") + exclude_list+=3D("$slave_dev") + slave_base=3D${slave_dev%%[0-9]*} + [ -n "$slave_base" ] && exclude_list+=3D("$slave_base") + done + fi + fi + + SYS_CURRENT_ROOT_DEV=3D"$current_root_dev" + + # Gather block devices from /sys/block while preserving mmcblk devices= that + # would otherwise be filtered by the main find expression. + devices=3D$(find /sys/block/ -type b,c,f,l -not -iname "mmcblk*" -prin= tf "%f\n") || true + mmc_devices=3D$(find /sys/block/ -type b,c,f,l -iname "mmcblk[0-9]" -p= rintf "%f\n") || true + devices=3D"$devices $mmc_devices" + + for device in $devices; do + is_raid_member=3D0 + + if [ -d "/sys/block/$device/holders" ] && [ ! -d "/sys/block/$devi= ce/md" ]; then + for holder_path in /sys/block/$device/holders/*; do + holder_name=3D$(basename "$holder_path") + case "$holder_name" in + md[0-9]*) + is_raid_member=3D1 + break + ;; + esac + done + fi + + if [ "$is_raid_member" -eq 1 ]; then + # Skip RAID member devices, because we only want whole block d= evices + # available for standalone image installation. + continue + fi + + if [[ "$device" =3D=3D md* ]]; then + # Accept only active or clean md arrays, reject degraded/inact= ive RAID sets. + if [ -f "/sys/block/$device/md/array_state" ]; then + state=3D$(cat /sys/block/$device/md/array_state | tr -d '\= n' | tr -d ' ') + if [ "$state" !=3D "active" ] && [ "$state" !=3D "clean" ]= ; then + echo "Skipping RAID device $device: state=3D'$state'" = >&2 + continue + fi + echo "Found RAID device $device: state=3D'$state'" >&2 + else + echo "Skipping RAID device $device: no array_state file" >= &2 + continue + fi + fi =20 -# ------------------------------------------------------------------- -# API: sys_list_valid_target_devices -# Description: -# Shell-friendly variant of sys_get_valid_target_devices. -# Prints one valid device per line (absolute path). -# Usage: -# sys_list_valid_target_devices -# Output: -# /dev/sdb -# /dev/sdc -# ------------------------------------------------------------------- -sys_list_valid_target_devices() { - local dev - - for dev in /sys/block/*; do - dev=3D$(basename "$dev") - - case "$dev" in - loop*|ram*|sr*|mtd*) + case "$device" in + dm-*|loop*|mtd*|sr*|ram*|zram*) continue ;; esac =20 - # skip inactive md devices - if [[ "$dev" =3D=3D md* ]]; then - [ -f "/sys/block/$dev/md/array_state" ] || continue - state=3D$(cat /sys/block/$dev/md/array_state) - [ "$state" =3D "active" ] || [ "$state" =3D "clean" ] || conti= nue - fi + skip_device=3D0 + for ex in "${exclude_list[@]}"; do + if [[ "$device" =3D=3D "$ex"* ]]; then + skip_device=3D1 + break + fi + done =20 - echo "/dev/$dev" + if [ "$skip_device" -eq 0 ]; then + SYS_TARGET_DEVICES+=3D("/dev/$device") + fi done } + +#-------------------------------------------------------------------------= - +# sys_device_size +# +# Returns: +# human-readable size string from lsblk, or empty if unavailable. +#-------------------------------------------------------------------------= - +sys_device_size() { + local device=3D"$1" + lsblk --nodeps --noheadings -o SIZE "$device" 2>/dev/null | tr -d " " +} + +#-------------------------------------------------------------------------= - +# sys_device_is_empty +# +# Returns: +# 0 when first 1 MiB is zero-filled, 1 otherwise. +#-------------------------------------------------------------------------= - +sys_device_is_empty() { + local device=3D"$1" + cmp /dev/zero "$device" -n 1M >/dev/null 2>&1 +} + +#-------------------------------------------------------------------------= - +# sys_version_ge +# +# Returns: +# 0 if current >=3D required, else 1. +#-------------------------------------------------------------------------= - +sys_version_ge() { + local current=3D"$1" + local required=3D"$2" + + if [ "$(printf '%s\n' "$current"X "$required" | sort -V | head -n 1)" = !=3D "$current"X ]; then + return 0 + fi + return 1 +} + +#-------------------------------------------------------------------------= - +# sys_bmap_options_for_image +# +# Returns: +# bmaptool options string ("--nobmap" when no sidecar bmap is present). +#-------------------------------------------------------------------------= - +sys_bmap_options_for_image() { + local image_path=3D"$1" + local disk_bmap + + disk_bmap=3D"${image_path%.wic*}.wic.bmap" + if [ -f "$disk_bmap" ]; then + # If a .wic.bmap sidecar exists, return an empty option string so + # bmaptool uses the bundled map automatically. + echo "" + else + echo "--nobmap" + fi +} + +#-------------------------------------------------------------------------= - +# sys_install_image_with_lock +# +# Performs the actual bmaptool copy, serializing concurrent installer +# consoles via flock. When UI hook functions are available, this API +# uses them to present a progress gauge in attended mode. +# +# Optional UI hooks (if defined): +# ui_start_progress_gauge +# ui_stop_progress_gauge +#-------------------------------------------------------------------------= - +sys_install_image_with_lock() { + local image_path=3D"$1" + local target_device=3D"$2" + local lockfile=3D"/run/installer.lock" + local progress_pipe=3D"/run/installer.fifo" + local bmap_options + local bmap_version + local quiet_flag=3D"" + + bmap_options=3D$(sys_bmap_options_for_image "$image_path") + + exec 9>"$lockfile" + if flock -n 9; then + bmap_version=3D$(bmaptool --version | awk '{ print $NF }') + + if sys_version_ge "$bmap_version" "3.6"; then + if [ -p "$progress_pipe" ]; then + rm -f "$progress_pipe" + fi + + if ! mkfifo "$progress_pipe"; then + echo "Error: Failed to create named pipe $progress_pipe" + return 1 + fi + + bmap_options=3D"$bmap_options --psplash-pipe=3D$progress_pipe" + quiet_flag=3D"-q" + + if declare -F ui_start_progress_gauge >/dev/null; then + ui_start_progress_gauge "$progress_pipe" + fi + fi + + # Run the actual copying step under the lock to avoid concurrent w= rites + # from multiple installer consoles or sessions. + if ! bmaptool $quiet_flag copy $bmap_options "$image_path" "$targe= t_device"; then + if declare -F ui_stop_progress_gauge >/dev/null; then + ui_stop_progress_gauge + fi + return 1 + fi + + if declare -F ui_stop_progress_gauge >/dev/null; then + ui_stop_progress_gauge + fi + else + echo "Installation already running in another console." + sleep 5 + + if [ -e "$progress_pipe" ]; then + echo "Installation progress..." + tail -f "$progress_pipe" | while read -r line; do + printf "\r%s%%" "$line" + done + else + echo "Waiting for installation to finish..." + while pgrep -x "bmaptool" >/dev/null; do + sleep 5 + done + fi + fi + + return 0 +} --=20 2.47.3 --=20 You received this message because you are subscribed to the Google Groups "= isar-users" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to isar-users+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/isar-users/= 20260608051737.946413-2-kasturi.shekar%40siemens.com.