]> git.proxmox.com Git - pve-kernel-meta.git/commitdiff
pve-efiboot-tool: add and use list file helpers
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 12 Jul 2019 13:16:44 +0000 (15:16 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 15 Jul 2019 12:28:21 +0000 (14:28 +0200)
in preparation of adding another file for custom kernels with the same semantics

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
bin/pve-efiboot-tool

index abaaf00b038d50537ce8828d278342c1976d2e09..31ba9c18e3341895e013ea6ca75f2f80b9de4533 100755 (executable)
@@ -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