Bug#803115: flash-kernel: please provide an option to disable creation of backup files
Package: flash-kernel
Version: 3.48
Followup-For: Bug #803115
Here's a patch, tested on my Seagate Dockstar.
Default behavior:
$ sudo flash-kernel
DTB: kirkwood-dockstar.dtb
Installing kirkwood-dockstar.dtb into /boot/dtbs/4.2.0-0.bpo.1-kirkwood/kirkwood-dockstar.dtb
Taking backup of kirkwood-dockstar.dtb.
Installing new kirkwood-dockstar.dtb.
flash-kernel: installing version 4.2.0-0.bpo.1-kirkwood
flash-kernel: appending /usr/lib/linux-image-4.2.0-0.bpo.1-kirkwood/kirkwood-dockstar.dtb to kernel
Generating kernel u-boot image... done.
Taking backup of uImage.
Installing new uImage.
Generating initramfs u-boot image... done.
Taking backup of uInitrd.
Installing new uInitrd.
Taking backup of dtb.
Installing new dtb.
New behavior with NO_BACKUP_FILES=true set in /etc/default/flash-kernel:
$ sudo flash-kernel
DTB: kirkwood-dockstar.dtb
Installing kirkwood-dockstar.dtb into /boot/dtbs/4.2.0-0.bpo.1-kirkwood/kirkwood-dockstar.dtb
Skipping backup of kirkwood-dockstar.dtb.
Installing new kirkwood-dockstar.dtb.
flash-kernel: installing version 4.2.0-0.bpo.1-kirkwood
flash-kernel: appending /usr/lib/linux-image-4.2.0-0.bpo.1-kirkwood/kirkwood-dockstar.dtb to kernel
Generating kernel u-boot image... done.
Skipping backup of uImage.
Installing new uImage.
Generating initramfs u-boot image... done.
Skipping backup of uInitrd.
Installing new uInitrd.
Skipping backup of dtb.
Installing new dtb.
>From e111d107a0e9453d0af0eb0ed4708a1aea1f901e Mon Sep 17 00:00:00 2001
From: Eric Cooper <ecc@cmu.edu>
Date: Sat, 7 Nov 2015 13:15:39 -0500
Subject: [PATCH] Add NO_BACKUP_FILES option to /etc/default/flash-kernel.
If set, no backups of kernel, initrd, and dtb files will be created,
to save space on systems with limited storage.
Signed-off-by: Eric Cooper <ecc@cmu.edu>
---
README | 9 ++++++---
functions | 18 ++++++++++++++++--
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/README b/README
index 4ca5a22..bc7493c 100644
--- a/README
+++ b/README
@@ -191,9 +191,12 @@ Configuration files currently supported:
script snippets. See "Adding U-Boot Commands for Pre-Boot Execution"
below for more details.
-* /etc/default/flash-kernel currently contains a single variable,
- LINUX_KERNEL_CMDLINE, which should be used by bootscripts to set kernel
- options.
+* /etc/default/flash-kernel currently contains the following variables:
+ - LINUX_KERNEL_CMDLINE, which should be used by bootscripts to set kernel
+ options.
+ - NO_BACKUP_FILES, which if set to "true" or "yes" will prevent
+ flash-kernel from creating backup versions of kernel, initrd,
+ and dtb files.
Adding U-Boot Commands for Pre-Boot Execution
diff --git a/functions b/functions
index 35d872b..9bbef2c 100644
--- a/functions
+++ b/functions
@@ -404,13 +404,27 @@ mkimage_multi() {
echo "done." >&2
}
+# Return a nonempty string *unless* NO_BACKUP_FILES is set.
+get_backup_preference() {
+ . /etc/default/flash-kernel
+ case $(echo "$NO_BACKUP_FILES" | tr '[:upper:]' '[:lower:]') in
+ true|yes|1) ;;
+ *) echo yes ;;
+ esac
+}
+
backup_and_install() {
local source="$1"
local dest="$2"
+ local do_backups=$(get_backup_preference)
if [ -e "$dest" ]; then
- echo "Taking backup of $(basename "$dest")." >&2
- mv "$dest" "$dest.bak"
+ if [ -n "$do_backups" ]; then
+ echo "Taking backup of $(basename "$dest")." >&2
+ mv "$dest" "$dest.bak"
+ else
+ echo "Skipping backup of $(basename "$dest")." >&2
+ fi
fi
echo "Installing new $(basename "$dest")." >&2
mv "$source" "$dest"
--
2.6.2
Reply to: