From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <a.lauterer@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 43A9F9A21
 for <pve-devel@lists.proxmox.com>; Tue,  5 Sep 2023 15:29:04 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 2380719EB3
 for <pve-devel@lists.proxmox.com>; Tue,  5 Sep 2023 15:28:34 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Tue,  5 Sep 2023 15:28:33 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 401B542295
 for <pve-devel@lists.proxmox.com>; Tue,  5 Sep 2023 15:28:33 +0200 (CEST)
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue,  5 Sep 2023 15:28:29 +0200
Message-Id: <20230905132832.3179097-4-a.lauterer@proxmox.com>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20230905132832.3179097-1-a.lauterer@proxmox.com>
References: <20230905132832.3179097-1-a.lauterer@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.083 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
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [RFC installer 3/6] add answer file fetch script
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>
X-List-Received-Date: Tue, 05 Sep 2023 13:29:04 -0000

With the auto installer present, the crucial question is how we get the
answer file. This script implements the way of a local disk/partition
present, labelled 'proxmoxinst', lower or upper case, with the
'answer.toml' file in the root directory.

We either want to use it directly and call it from 'unconfigured.sh' or
see it as a first approach to showcase how it could be done.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
 start_autoinstall.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100755 start_autoinstall.sh

diff --git a/start_autoinstall.sh b/start_autoinstall.sh
new file mode 100755
index 0000000..081b865
--- /dev/null
+++ b/start_autoinstall.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+answer_file=answer.toml;
+answer_mp=/tmp/answer;
+answer_location="";
+mount_source="";
+label="proxmoxinst";
+
+mount_answer() {
+    echo "mounting answer filesystem"
+    mkdir -p $answer_mp
+    mount "$mount_source" "$answer_mp"
+}
+
+find_fs() {
+    search_path="/dev/disk/by-label/";
+    if [[ -e ${search_path}/${label,,} ]]; then
+	mount_source="${search_path}/${label,,}";
+    elif [[ -e ${search_path}/${label^^} ]]; then
+	mount_source="${search_path}/${label^^}";
+    else
+	echo "No partition for answer file found!";
+	return 1;
+    fi
+    mount_answer;
+}
+
+find_answer_file() {
+    if [ -e $answer_mp/$answer_file ]; then
+	cp $answer_mp/$answer_file /run/proxmox-installer/answer.toml
+	answer_location=/run/proxmox-installer/answer.toml
+	umount $answer_mp;
+    else
+	return 1;
+    fi
+}
+
+start_installation() {
+    echo "calling 'proxmox-auto-installer'";
+    proxmox-auto-installer < $answer_location;
+}
+
+
+if find_fs && find_answer_file; then
+    echo "found answer file on local device";
+    start_installation;
+else
+    echo "Could not retrieve answer file. Aborting installation!"
+    exit 1;
+fi
-- 
2.39.2