pve-efiboot-tool: add and use list file helpers

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

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2019-07-12 15:16:44 +02:00 committed by Thomas Lamprecht
parent 4bd56b83e1
commit 2955b2b7fe

View File

@ -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