From e1206cf45b3bdde97e166d5c0d55842c864a1c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Sep 2023 12:09:09 +0200 Subject: [PATCH] Let ln and cp remove the destination files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No functional change, but makes the script a bit shorter. Signed-off-by: Zbigniew Jędrzejewski-Szmek --- 20-grub.install | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/20-grub.install b/20-grub.install index 58a998ee..1114cf53 100755 --- a/20-grub.install +++ b/20-grub.install @@ -55,8 +55,7 @@ case "$COMMAND" in add) if [[ "${KERNEL_DIR}" != "/boot" ]]; then # rename to match the name used in the pseudo-BLS snippet above - rm -f "/boot/vmlinuz-${KERNEL_VERSION}" - cp --preserve=timestamps -T "${KERNEL_IMAGE}" "/boot/vmlinuz-${KERNEL_VERSION}" + cp --remove-destination --preserve=timestamps -T "${KERNEL_IMAGE}" "/boot/vmlinuz-${KERNEL_VERSION}" command -v restorecon &>/dev/null && \ restorecon -R "/boot/vmlinuz-${KERNEL_VERSION}" @@ -67,16 +66,14 @@ case "$COMMAND" in "$KERNEL_DIR"/dtb do [[ -e "$i" ]] || continue - rm -f "/boot/${i##*/}-${KERNEL_VERSION}" - cp --preserve=timestamps -T "$i" "/boot/${i##*/}-${KERNEL_VERSION}" + cp --remove-destination --preserve=timestamps -T "$i" "/boot/${i##*/}-${KERNEL_VERSION}" command -v restorecon &>/dev/null && \ restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}" done # hmac is .vmlinuz-.hmac so needs a special treatment i="$KERNEL_DIR/.${KERNEL_IMAGE##*/}.hmac" if [[ -e "$i" ]]; then - rm -f "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" - cp --preserve=timestamps "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" + cp --remove-destination --preserve=timestamps "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" command -v restorecon &>/dev/null && \ restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" fi @@ -84,16 +81,14 @@ case "$COMMAND" in # symvers is symvers-.gz symlink, needs a special treatment i="$KERNEL_DIR/symvers.gz" if [[ -e "$i" ]]; then - rm -f "/boot/symvers-${KERNEL_VERSION}.gz" - ln -s "$i" "/boot/symvers-${KERNEL_VERSION}.gz" + ln -fs "$i" "/boot/symvers-${KERNEL_VERSION}.gz" command -v restorecon &>/dev/null && \ restorecon "/boot/symvers-${KERNEL_VERSION}.gz" fi # symvers is symvers-.bz symlink, needs a special treatment i="$KERNEL_DIR/symvers.bz" if [[ -e "$i" ]]; then - rm -f "/boot/symvers-${KERNEL_VERSION}.bz" - ln -s "$i" "/boot/symvers-${KERNEL_VERSION}.bz" + ln -fs "$i" "/boot/symvers-${KERNEL_VERSION}.bz" command -v restorecon &>/dev/null && \ restorecon "/boot/symvers-${KERNEL_VERSION}.bz" fi