From patchwork Tue Dec 16 10:19:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rakesh Kumar X-Patchwork-Id: 4729 Return-Path: Received: from shymkent.ilbers.de ([unix socket]) by shymkent (Cyrus 2.5.10-Debian-2.5.10-3+deb9u2) with LMTPA; Tue, 16 Dec 2025 11:20:14 +0100 X-Sieve: CMU Sieve 2.4 Received: from mail-wm1-f58.google.com (mail-wm1-f58.google.com [209.85.128.58]) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPS id 5BGAKDVt026606 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 16 Dec 2025 11:20:13 +0100 Received: by mail-wm1-f58.google.com with SMTP id 5b1f17b1804b1-477cf25ceccsf46459345e9.0 for ; Tue, 16 Dec 2025 02:20:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1765880408; cv=pass; d=google.com; s=arc-20240605; b=cUFP0Bfk83S3YcSm0Vg1bOvwjh1CK3AflPOOdqDzZKNj9gYdHXM2JZ18ZD8wXW4Zcb t93dUQ2WMim2h+wIjz1CCtn883omqwxignIJyYeQytjnp4Jono3tP23iEuVjeMcq67jw HrI/v4fn+CIMcCX9gG5Z7iOQLX1SrHKjqILZ+vp31zd7A3uNw5NEZTQ8diRo/9kUYXje fEh8x1fJVKn+NHwt2VyP1IE7XHH15FvgL1XTTfD/7YMQAjvBkmtAA6w4qrQOLch+yXnt 8wUQsxRVOnftorqu/N9vvOhqsol1CCG6DQ6MhTZ1El99aycf4AzXFmyynaq2nQpc+Dqp b5LQ== 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:message-id:date:subject:cc :to:from:dkim-signature; bh=ODNwW7rWAkEDqJpiXtguKvVuc5d17phX2M0Djq03IbI=; fh=CbTwLICnqzPgU5YatdlSeBxg7PQ7CzhxVLuLVl5mSMA=; b=NsQAsmrTIRZ9NyNNWPZQVHWeTlMfa6e5HunS7ad884Uu2iWbZ+/KOWA9noMeCVIKwW dn+5GlxVeAMekvr0VkNko36afqqkvIeCAJAOWrSZcSCK65tlgMqu0fkAvIMf89llX9WY N1I0dlsghA+7BP0clSbJKwT2JFyZIdxiIIqUNysINxA/qGU8BosKHxB8BPqujPAhO8QY hv8mYa5qVfDzluPQ/L92hF4QvElZtwbuDknFQ+mR7fTXJxIj1C6uricCEZULR4BhEKFC VwVoih1DQzYVwNC0OjMSb1cUBb54M6K6g1bEixoe1P1HizLKPmz43tT5W83MUyXHIY9c YLUA==; darn=isar-build.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=b7dKyC58; spf=pass (google.com: domain of fm-1333420-20251216102004fe25b9a080000207d5-ba7tbo@rts-flowmailer.siemens.com designates 185.136.65.225 as permitted sender) smtp.mailfrom=fm-1333420-20251216102004fe25b9a080000207d5-Ba7TBO@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=20230601; t=1765880408; x=1766485208; darn=isar-build.org; 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:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ODNwW7rWAkEDqJpiXtguKvVuc5d17phX2M0Djq03IbI=; b=xsZBXfiQ+CoAzoLZRZwjGz1NBSjodogxSgALU+9HKvI3KovTOFx4uZHAnqVI60V74s RiwDjYFaMUffkTM3r1/1/GKejcDvYGp7AqzO7yMWfz64htWIS2w8YVQ55GG29ahM3jdQ j/7SjXiKtSE70xaWFVBMA4A8KSQgy/VGxKo1msHB7RbBrI6jWklh7opqCMPMsjF4WP/K Kcym1DtK+nm+rfX0U+cl0eaYWRTODz+3Din6uCQ4/17IW6i/koOenlSgs+0Fk++eCSqM tNIgIplJ9rC48Zcc1M88H4cDC+twT+OUIQY31ecLVf33AHekj8WtSyornzuOKYWRb6QX e5BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765880408; x=1766485208; 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:message-id:date:subject:cc :to:from:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ODNwW7rWAkEDqJpiXtguKvVuc5d17phX2M0Djq03IbI=; b=AF4KM3lmNT9UXPs0y2FNSDez05PQ9mqkA6H5vk1Sa7UCd0sEYKDHzoAhjjjRQ38NPT Avy5cm+j2eO8322nFsNWKiQ6i+x1meh/JqmqQi0HB408qXe8U2/paZ8vf3RUjYdJZGBC /qClbKQ2aA1872+KGvYEK5JeOMS8zVivQHraFXp1gG+bkMQAeosnu/BDVx2L08/FaGFX aDGOGdvrk3XhDiAjRjwMIxucowJqRRj7LN+Mlw+GV7LjLCWVa51x7f/CYNa+NnliOzXs Kv59kCSRbcl1nQAxn3xJg3rIYfdtYYmXT1EnUhfpvJqPilG80km/Zb/xhRcNlz701WjX EWeA== X-Forwarded-Encrypted: i=2; AJvYcCVww91dyBozMpOAYbGBivMgUXPLf0EkWeqrF79108zFh5sk84RrhcSgjf+P+hBNZDphghRhobs=@isar-build.org X-Gm-Message-State: AOJu0YxrQqByJewooH0K6GeFn7dn2hUfhYuUaYmw61NnNh+8PylZxxkS n3c9McbZsHZrZohtWSI7yDKlx7gcIzcgcszT90/CtmRe/jINHFYqFe6c X-Google-Smtp-Source: AGHT+IH9x3N6eJEj1dceVAtEu6gACLWVJkBZkj0cb68vKBX2214rp+qb+uvKAjKOPPs8Efw/cAOvMA== X-Received: by 2002:a05:600c:4e56:b0:477:569c:34e9 with SMTP id 5b1f17b1804b1-47a8f906ddemr134221245e9.23.1765880407802; Tue, 16 Dec 2025 02:20:07 -0800 (PST) X-BeenThere: isar-users@googlegroups.com; h="AWVwgWbr8NaEnXkzN+YnKDB/U6V9ubzMiOTNjeIS9iUSAuUWMg==" Received: by 2002:a05:600c:19ca:b0:477:a036:8e80 with SMTP id 5b1f17b1804b1-47a8ea2a054ls22244515e9.0.-pod-prod-07-eu; Tue, 16 Dec 2025 02:20:04 -0800 (PST) X-Received: by 2002:a05:600c:3104:b0:477:fcb:2256 with SMTP id 5b1f17b1804b1-47a8f906dd3mr144985855e9.17.1765880404502; Tue, 16 Dec 2025 02:20:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1765880404; cv=none; d=google.com; s=arc-20240605; b=iZ9sNe2PU8RZ3nHk3YJ5EWWZG5IyXdalk82sTtdEfew+iDECtVdBf5ecMP7D8Vt1+O qu7GeyBnim7dP2Lp3eBqdLAKpa3kQYQHc4cmLeyNw7EHq37Z/+bNiLPBUPpFb3lv6/wT V5oy2Z0/ALdvhdPRiKAQoARlqQbJ5X0OaLRD8rNcr5whQAhBNMntF98b9z9vVYJpnS67 HlkqOQ6GhIO7kIeOk13zMH/w9NQ63xb6sbiqXETj6ckdmKhDg0AC84Q7GfMqkfxTd2TZ twHR+t51cQDDebruvNjIvrJ3G3M87TZOOgzMxK2uXlNcwsvQUTIZR+3q/wY1jijbLzOe Y0XA== 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:message-id:date :subject:cc:to:from:dkim-signature; bh=5O8kTry5Z0E50Jm77GxTRB5cyjMKgaL3I5RUYYDV1lg=; fh=dwnf3PiLoNuxEmlEQqfoWYSFcsr4isZMqOMz5uUNloE=; b=aMsKCjXf0am+5JbdaRHckFgkVb8uHhjDzWOC6kBxpipONnIXSLofFlLlM4ngRwLK8F lpMIqq+GDw84vyHDL4tV0APEnlgf1kEnvEqa218+scbLxTVKN8mKGr/gV0zBl/REN3xH 5APuJcmIEjcYGrR84WIyU5LKoKp3xMCBORJ/7pzeSa1fYEIv2hIXSuxW2+bd3SRlAp9M F430DuSz7ptxoklc3FLUivuYugF8KmSSc1r5OzvaNlvNfU8qYOnjT9l57KnXMNXEnvXH mjS/XjopzexLv45fAnmqx9ueyKn+HyxKARoh/PRiTb3JolCxqMNcUmbpZqkbBj3SyOOq OZKg==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=b7dKyC58; spf=pass (google.com: domain of fm-1333420-20251216102004fe25b9a080000207d5-ba7tbo@rts-flowmailer.siemens.com designates 185.136.65.225 as permitted sender) smtp.mailfrom=fm-1333420-20251216102004fe25b9a080000207d5-Ba7TBO@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 ffacd0b85a97d-42fa8a69635si283921f8f.3.2025.12.16.02.20.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Dec 2025 02:20:04 -0800 (PST) Received-SPF: pass (google.com: domain of fm-1333420-20251216102004fe25b9a080000207d5-ba7tbo@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 20251216102004fe25b9a080000207d5 for ; Tue, 16 Dec 2025 11:20:04 +0100 X-Patchwork-Original-From: "'Rakesh Kumar' via isar-users" From: Rakesh Kumar To: isar-users@googlegroups.com Cc: jan.kiszka@siemens.com, cedric.hombourger@siemens.com, Rakesh Kumar Subject: [PATCH] fix: preserve indentation in dracut module-setup.sh Date: Tue, 16 Dec 2025 15:49:36 +0530 Message-Id: <20251216101936.3259099-1-kumar.rakesh@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-1333420:519-21489:flowmailer X-Original-Sender: kumar.rakesh@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=b7dKyC58; spf=pass (google.com: domain of fm-1333420-20251216102004fe25b9a080000207d5-ba7tbo@rts-flowmailer.siemens.com designates 185.136.65.225 as permitted sender) smtp.mailfrom=fm-1333420-20251216102004fe25b9a080000207d5-Ba7TBO@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com X-Original-From: Rakesh Kumar Reply-To: Rakesh Kumar 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_H2,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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= The marker replacement logic treated the inserted file content as plain text, which caused indentation to be lost in generated scripts (e.g. module-setup.sh). Update the replacement logic to detect the marker line’s indentation and apply the same indentation to all non-empty lines of the inserted content. This preserves the original formatting and avoids syntax and readability issues in the generated files. Signed-off-by: Rakesh Kumar --- doc/user_manual.md | 19 +++++++++++++--- meta/classes-recipe/dracut-module.bbclass | 27 +++++++++++++++++------ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/doc/user_manual.md b/doc/user_manual.md index e7955c12..731e84f1 100644 --- a/doc/user_manual.md +++ b/doc/user_manual.md @@ -1763,9 +1763,22 @@ module in the initrd or as a dependency to other modules. It defaults to `${PN}` without the prefix `dracut-`. - `DRACUT_MODULE_PATH` contains the path to the installed module. It is set to `${D}/usr/lib/dracut/modules.d/${DRACUT_MODULE_NO}${DRACUT_MODULE_NAME}/` - -The `install()` function is added by storing the file `install.sh` in the -files directory of the dracut module. +- `DRACUT_CHECK_CONTENT_FILE_NAME` contents for check() function +- `DRACUT_DEPENDS_CONTENT_FILE_NAME` contents for depends() function +- `DRACUT_CMDLINE_CONTENT_FILE_NAME` contents for cmdline() function +- `DRACUT_INSTALL_CONTENT_FILE_NAME` contents for install() function +- `DRACUT_INSTALLKERNEL_CONTENT_FILE_NAME` contents for installkernel() function + +Hook functions such as check(), depends(), cmdline(), install(), and +installkernel() are provided by replacing placeholders in dracut module +module-setup.sh template with content from individual files, selected via +the corresponding `DRACUT__CONTENT_FILE_NAME` variables. + +Example: + +The `install()` function can be provided by placing a file (for example, +`install.sh`) in the dracut module’s files directory and assigning it to +`DRACUT_INSTALL_CONTENT_FILE_NAME`. Other files can by added to the module by coping them to the Module folder with: diff --git a/meta/classes-recipe/dracut-module.bbclass b/meta/classes-recipe/dracut-module.bbclass index 364fb5b4..eb1e4fb6 100644 --- a/meta/classes-recipe/dracut-module.bbclass +++ b/meta/classes-recipe/dracut-module.bbclass @@ -37,15 +37,28 @@ def add_file_if_variable_is_set(d, variable_name, prefix): return '' def replace_marker_with_file_content(template_file, content_file, marker): - with open(template_file, 'r') as template_fd: - tmpl_content = template_fd.read() + import re, bb - with open(content_file, 'r') as content_fd: - content = content_fd.read() + tmpl = open(template_file).read() + content = open(content_file).read().rstrip('\n') - new_tpml_content = tmpl_content.replace(marker, content) - with open(template_file, 'w') as tmpl_fd: - tmpl_fd.write(new_tpml_content) + # locate marker and its indentation + m = re.search(rf'^(?P\s*){re.escape(marker)}\s*$', tmpl, re.MULTILINE) + if not m: + bb.fatal(f"Marker '{marker}' not found in {template_file}") + + indent = m.group('indent') + + # indent all non-blank lines + indented = '\n'.join( + (indent + line) if line.strip() else '' + for line in content.splitlines() + ) + + # replace the exact marker line + new_tmpl = tmpl[:m.start()] + indented + tmpl[m.end():] + + open(template_file, 'w').write(new_tmpl) SRC_URI:append = " ${@ add_file_if_variable_is_set(d, 'DRACUT_CHECK_CONTENT_FILE_NAME', 'file://')} \ ${@ add_file_if_variable_is_set(d, 'DRACUT_DEPENDS_CONTENT_FILE_NAME', 'file://')} \