From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id B99DC1FF15C
	for <inbox@lore.proxmox.com>; Wed, 11 Dec 2024 17:14:08 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id A2E64DD6D;
	Wed, 11 Dec 2024 17:14:12 +0100 (CET)
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 11 Dec 2024 17:14:02 +0100
Message-Id: <20241211161402.236144-1-d.kral@proxmox.com>
X-Mailer: git-send-email 2.39.5
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.005 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [unconfigured.sh]
Subject: [pve-devel] [PATCH installer] fix #5984: unconfigured: do not
 reboot if auto-installer fails by default
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

A unintended side effect was introduced in 21ef304, which caused the
auto-installer to reboot on error, even though the answer file option
`general.reboot_on_error` has been set to `false`.

When an error signal is received inside `unconfigured.sh` (after the
trap statement `trap 'err_reboot' ERR`), it causes any failing command
to execute the `err_reboot` function and therefore dropping the user in
the debug shell. One exception, as described under `trap` in bash(1), is
for a command being part of the test in an if statement.

Therefore, simply simulate a trap by calling `err_reboot` directly.

Fixes: 21ef304 ("unconfigured.sh: run proxmox-post-hook after successful auto-install")
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
I've tested this by booting into debug mode with a auto-installer
prepared ISO that has an invalid configuration (in this case, the
first-boot executable is not available in FromIso mode), patching the
`/usr/sbin/unconfigured.sh` script, forcing `start_auto_installer=1` and
skipping any statements in `unconfigured.sh`, which have already been
run to be in the debug shell (mounting procfs, sysfs, dhcp, ...).

When running `unconfigured.sh`, I have been dropped in another debug
shell with the output:

```sh
root@proxmox:/# unconfigured.sh
Caching device info from udev
Fetching answers for automatic installation
Starting automatic installation
INFO: Starting auto installer
ERROR: Installer setup error: Failed to retrieve setup info: No such
file or directory (os error 2)

Installation aborted - unable to continue (type exit or CTRL-D to reboot)
root@proxmox:/$ _
```

 unconfigured.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/unconfigured.sh b/unconfigured.sh
index 070cf33..f9cc9de 100755
--- a/unconfigured.sh
+++ b/unconfigured.sh
@@ -260,6 +260,9 @@ elif [ $start_auto_installer -ne 0 ]; then
             echo "waiting 30s to allow gathering the error before reboot."
             sleep 30
         fi
+    else
+	# simulate a trap to `err_reboot` if the auto-installer fails
+	err_reboot
     fi
 else
     echo "Starting the installer GUI - see tty2 (CTRL+ALT+F2) for any errors..."
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel