in preparation of adding another file for custom kernels with the same semantics

Signed-off-by: Fabian Grünbichler <f.gruenbich...@proxmox.com>
---
 bin/pve-efiboot-tool | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/bin/pve-efiboot-tool b/bin/pve-efiboot-tool
index abaaf00..31ba9c1 100755
--- a/bin/pve-efiboot-tool
+++ b/bin/pve-efiboot-tool
@@ -4,6 +4,35 @@ set -e
 
 . /usr/share/pve-kernel-helper/scripts/functions
 
+_add_entry_to_list_file() {
+       file="$1"
+       entry="$2"
+
+       if [ -e "$file" ]; then
+               cp "$file" "$file.new"
+       fi
+       echo "$entry" >> "$file.new"
+       sort -uo "$file.new" "$file.new"
+       mv "$file.new" "$file"
+}
+
+_remove_entry_from_list_file() {
+       file="$1"
+       entry="$2"
+
+       # guard against removing whole file by accident!
+       if [ -z "$entry" ]; then
+               echo "cannot remove empty entry from '$file'."
+               return
+       fi
+
+       if [ -e "$file" ]; then
+               grep -vFx "$entry" "$file" > "$file.new" || true
+               mv "$file.new" "$file"
+       else
+               echo "'$file' does not exist.."
+       fi
+}
 
 _get_partition_info() {
        if [ ! -e "$1" ]; then
@@ -130,12 +159,7 @@ init() {
        umount "$part"
 
        echo "Adding '$part' to list of synced ESPs.."
-       if [ -e "$ESP_LIST" ]; then
-               cp "$ESP_LIST" "$ESP_LIST.new"
-       fi
-       echo "$UUID" >> "$ESP_LIST.new"
-       sort -uo "$ESP_LIST.new" "$ESP_LIST.new"
-       mv "$ESP_LIST.new" "$ESP_LIST"
+       _add_entry_to_list_file "$ESP_LIST" "$UUID"
 
        echo "Refreshing kernels and initrds.."
        refresh
-- 
2.20.1


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

Reply via email to