On Lu, 16 dec 19, 11:01:09, Jonas Smedegaard wrote:
> Quoting andreimpope...@gmail.com (2019-12-16 09:42:46)
> > 
> > I'll rework the patch accordingly, probably sometimes this week.
> 
> Really, the only change I would want compared to your current proposed 
> patch would be to have the newly line in the conffile uncommented.

That wouldn't be in line with the other variables that are commented out 
by default.

Additionally, if the variable is always set the checks must be changed 
slightly, otherwise the script would always error out.
 
> I am looking forward to see what changes you come up with.

Attached. Comments welcome :)

> > [1] Not sure how common it is, but my motivation for this was to 
> > have an entry with a different root file system that is not 
> > overwritten on every update, hence my example above. I might come up 
> > with a patch implementing U_BOOT_ALT_ROOT as well, if I don't have 
> > anything better to do ;)
> 
> Please make that a separate patch files as a separate bug from this one. 
> What I can imagine, such feature would be more involving and I suspect 
> the usecase is more narrow.  On the other hand, I am really pleased with 
> your proposed patch so it might simply be my imagination being too 
> limited: Please do make a patch and try argue the case for its adoption!

Will do so in a separate bug, if I do ever get around to it.

BTW, U_BOOT_FDT_DIR is not documented in the manpage (there is a pull 
request in the upstream github repo that appears to address this) and 
shellcheck has some recommendations.

Would you take patches for these as well?

Kind regards,
Andrei
-- 
http://wiki.debian.org/FAQsFromDebianUser
From d24f8dd89f73ff5abdfb147a85f339413661f57e Mon Sep 17 00:00:00 2001
From: Andrei POPESCU <andreimpope...@gmail.com>
Date: Sun, 8 Dec 2019 11:53:36 +0200
Subject: [PATCH] Add option to append one or more custom entries from an
 external file

This patch adds a new option U_BOOT_CUSTOM_ENTRIES to specify an
external file to be appended to extlinux.conf.

default:
Add the new option commented out, with the default value.

u-boot-update:
Do some basic checks on the file (exists, regular file, readable,
non-zero length).
Issue a warning in case the file is not owned by root, but don't
error out (the sysadmin may have good reasons for that).

u-boot-update.8:
Document the new option in the manpage, including some safety/security
warnings.

U_BOOT_CUSTOM_ENTRIES is always set
---
 default         |  1 +
 u-boot-update   | 30 ++++++++++++++++++++++++++++++
 u-boot-update.8 |  2 ++
 3 files changed, 33 insertions(+)

diff --git a/default b/default
index 4389a87..7e6804d 100644
--- a/default
+++ b/default
@@ -11,4 +11,5 @@
 #U_BOOT_TIMEOUT="50"
 #U_BOOT_FDT=""
 #U_BOOT_FDT_DIR="/usr/lib/linux-image-"
+#U_BOOT_CUSTOM_ENTRIES="/etc/default/u-boot-custom"
 
diff --git a/u-boot-update b/u-boot-update
index 2bf151b..2cfe3ca 100755
--- a/u-boot-update
+++ b/u-boot-update
@@ -82,6 +82,7 @@ U_BOOT_TIMEOUT="${U_BOOT_TIMEOUT:-50}"
 U_BOOT_MENU_LABEL="Debian GNU/Linux kernel"
 U_BOOT_PARAMETERS="${U_BOOT_PARAMETERS:-ro quiet}"
 U_BOOT_FDT_DIR="${U_BOOT_FDT_DIR:-/usr/lib/linux-image-}"
+U_BOOT_CUSTOM_ENTRIES="${U_BOOT_CUSTOM:-/etc/default/u-boot-custom}"
 
 # Find parameter for root from fstab
 if [ -z "${U_BOOT_ROOT}" ]
@@ -216,5 +217,34 @@ done
 
 _NUMBER=""
 
+# Append custom entries if any
+if [ -f "${U_BOOT_CUSTOM_ENTRIES}" ]
+then
+    if [ ! -r "${U_BOOT_CUSTOM_ENTRIES}" ]
+    then
+        echo 'E: The file '"${U_BOOT_CUSTOM_ENTRIES}"' is unreadable'
+        exit 1
+    fi
+
+    if [ ! -s "${U_BOOT_CUSTOM_ENTRIES}" ]
+    then
+        echo 'E: The file '"${U_BOOT_CUSTOM_ENTRIES}"' is empty'
+        exit 1
+    fi
+
+    if [ ! -O "${U_BOOT_CUSTOM_ENTRIES}" ]
+    then
+        echo 'W: The file '"${U_BOOT_CUSTOM_ENTRIES}"' is NOT owned by root'
+    fi
+
+echo 'P: Appending custom entries from '"${U_BOOT_CUSTOM_ENTRIES}"'...'
+
+# Writing custom entries
+_CONFIG="${_CONFIG}
+
+$(< "${U_BOOT_CUSTOM_ENTRIES}")
+"
+fi
+
 Update "${_U_BOOT_DIRECTORY}/extlinux.conf" "${_CONFIG}"
 
diff --git a/u-boot-update.8 b/u-boot-update.8
index 3397bc8..7e88000 100644
--- a/u-boot-update.8
+++ b/u-boot-update.8
@@ -26,6 +26,8 @@ This variable specifies additional boot parameters that are appended to each ker
 This variable specifies the root partition. It is automatically extracted from /etc/fstab. U\-BOOT supports both devices and UUIDs.
 .IP "U_BOOT_TIMEOUT=""\fB50\fR""" 4
 This variable specifies the time that U\-BOOT should wait for user input during boot. Values are in decisecond greater than 0 (e.g. '10' for a 1 second timeout), 0 specifies to wait forever. The default is 50.
+.IP "U_BOOT_CUSTOM_ENTRIES=""/path/to/file""" 4
+This variable specifies the name of a file containing one or more custom entries. The file is appended \fBas is\fR, without any checks for validity or safety. For security reasons the file should not be writable to untrusted users as it can be used to gain root access to the system (e.g. by adding a boot entry with "init=/bin/sh" as kernel parameter). u\-boot\-update will issue a warning if the file is not owned by root. The default is '/etc/default/u-boot-custom'.
 
 .SH FILES
 /etc/default/u-boot
-- 
2.20.1

Attachment: signature.asc
Description: PGP signature

Reply via email to