From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5A1A076606 for ; Fri, 23 Apr 2021 11:05:09 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8C0CA259E8 for ; Fri, 23 Apr 2021 11:05:08 +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 id 91A7525920 for ; Fri, 23 Apr 2021 11:05:04 +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 600BA44F81 for ; Fri, 23 Apr 2021 11:05:04 +0200 (CEST) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Fri, 23 Apr 2021 11:04:44 +0200 Message-Id: <20210423090451.2279-3-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210423090451.2279-1-s.ivanov@proxmox.com> References: <20210423090451.2279-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 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] [PATCH pve-kernel-meta v2 2/8] proxmox-boot-tool: add status command X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2021 09:05:09 -0000 currently simply checking if $ESP_LIST exists, and indicating via the exit status if proxmox-boot-tool is used for booting the system. Signed-off-by: Stoiko Ivanov --- v1->v2: * add sensible output * replace verbose by quiet (with inverted meaning) bin/proxmox-boot-tool | 71 ++++++++++++++++++++++++++++++++++++ proxmox-boot/functions | 1 + proxmox-boot/zz-proxmox-boot | 1 - 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/bin/proxmox-boot-tool b/bin/proxmox-boot-tool index 2d625a6..a60fc0c 100755 --- a/bin/proxmox-boot-tool +++ b/bin/proxmox-boot-tool @@ -283,6 +283,7 @@ usage() { warn " $0 refresh [--hook ]" warn " $0 kernel " warn " $0 kernel list" + warn " $0 status [--quiet]" warn " $0 help" } @@ -312,6 +313,62 @@ help() { echo "" echo " list kernel versions currently selected for inclusion on ESPs." echo "" + echo "USAGE: $0 status [--quiet]" + echo "" + echo " Print details about the ESPs configuration. Exits with 0 if any ESP is configured, else with 2." + echo "" +} + +_status_detail() { + if ! (echo "${curr_uuid}" | grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}'); then + warn "WARN: ${curr_uuid} read from ${ESP_LIST} does not look like a VFAT-UUID - skipping" + return + fi + + path="/dev/disk/by-uuid/$curr_uuid" + if [ ! -e "${path}" ]; then + warn "WARN: ${path} does not exist - clean '${ESP_LIST}'! - skipping" + return + fi + + mountpoint="${MOUNTROOT}/${curr_uuid}" + mkdir -p "${mountpoint}" || \ + { warn "creation of mountpoint ${mountpoint} failed - skipping"; return; } + mount "${path}" "${mountpoint}" || \ + { warn "mount of ${path} failed - skipping"; return; } + + result="" + if [ -f "${mountpoint}/$PMX_LOADER_CONF" ]; then + result="uefi" + if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then + warn "${path}/$PMX_ESP_DIR does not exist" + fi + fi + if [ -d "${mountpoint}/grub" ]; then + if [ -n "$result" ]; then + result="${result},grub" + else + result="grub" + fi + fi + echo "$curr_uuid is configured with: $result" + umount "${mountpoint}" || \ + { warn "umount of ${path} failed - failure"; exit 0; } + + rmdir "${mountpoint}" || true +} + +status() { + quiet="$1" + if [ ! -e "${ESP_LIST}" ]; then + if [ -z "$quiet" ]; then + warn "E: $ESP_LIST does not exist." + fi + exit 2 + fi + if [ -z "$quiet" ]; then + loop_esp_list _status_detail + fi } if [ -z "$1" ]; then @@ -390,6 +447,20 @@ case "$1" in ;; esac ;; + 'status') + if [ "$#" -eq 2 ] && [ "$2" = '--quiet' ]; then + shift + status "$1" + elif [ "$#" -eq 1 ]; then + reexec_in_mountns "$@" + shift + status + else + usage + exit 1 + fi + exit 0 + ;; 'help') shift help diff --git a/proxmox-boot/functions b/proxmox-boot/functions index 72fe15d..4b0b9c2 100755 --- a/proxmox-boot/functions +++ b/proxmox-boot/functions @@ -6,6 +6,7 @@ ESPTYPE='c12a7328-f81f-11d2-ba4b-00a0c93ec93b' MANUAL_KERNEL_LIST="/etc/kernel/pve-efiboot-manual-kernels" +MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts" # relative to the ESP mountpoint PMX_ESP_DIR="EFI/proxmox" PMX_LOADER_CONF="loader/loader.conf" diff --git a/proxmox-boot/zz-proxmox-boot b/proxmox-boot/zz-proxmox-boot index 1c4ad73..b2469d2 100755 --- a/proxmox-boot/zz-proxmox-boot +++ b/proxmox-boot/zz-proxmox-boot @@ -6,7 +6,6 @@ set -e # https://kernel-team.pages.debian.net/kernel-handbook/ch-update-hooks.html -MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts" # - cleanup - gently delete all kernels not in kernel-keep-list -- 2.20.1