[openwrt/openwrt] base-files: add function to remove devicename from LED labels
LEDE Commits
lede-commits at lists.infradead.org
Fri Oct 2 07:55:59 EDT 2020
adrian pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/365a639f916b4e9a3771cbaa1271153e111ebde6
commit 365a639f916b4e9a3771cbaa1271153e111ebde6
Author: Adrian Schmutzler <freifunk at adrianschmutzler.de>
AuthorDate: Sun Sep 27 17:25:15 2020 +0200
base-files: add function to remove devicename from LED labels
Currently, we request LED labels in OpenWrt to follow the scheme
modelname:color:function
However, specifying the modelname at the beginning is actually
entirely useless for the devices we support in OpenWrt. In patches
subsequent to this one, we will thus remove the modelname from
the label definitions on various targets.
To migrate the existing definitions from older installations,
a migration script needs to be deployed that does
modelname:color:function -> color:function
e.g.
dir-789:green:status -> green:status
This patch introduces two functions that do exactly that:
For each entry in /etc/config/system, the routine will check whether
two (or more) colons are present, and then remove everything up to
(and including) the first colon.
For now, this will be applied unconditionally, i.e. if the function
is called for a device, all labels will be cut like this.
However, for a future case of mixed three-part and two-part labels,
it should not be too hard to provide a function argument with
exceptions to the removal.
Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
package/base-files/Makefile | 2 +-
.../base-files/files/lib/functions/migrations.sh | 23 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index db9be216e6..3cb3d2034a 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
include $(INCLUDE_DIR)/feeds.mk
PKG_NAME:=base-files
-PKG_RELEASE:=230
+PKG_RELEASE:=231
PKG_FLAGS:=nonshared
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions/migrations.sh b/package/base-files/files/lib/functions/migrations.sh
index b180a0242f..da10d2be5a 100644
--- a/package/base-files/files/lib/functions/migrations.sh
+++ b/package/base-files/files/lib/functions/migrations.sh
@@ -28,11 +28,34 @@ migrate_led_sysfs() {
done;
}
+remove_devicename_led_sysfs() {
+ local cfg="$1"
+ local sysfs
+ local name
+ local new_sysfs
+
+ config_get sysfs ${cfg} sysfs
+ config_get name ${cfg} name
+
+ echo "${sysfs}" | grep -q ":.*:" || return
+
+ new_sysfs=$(echo ${sysfs} | sed "s/^[^:]*://")
+
+ uci set system.${cfg}.sysfs="${new_sysfs}"
+
+ logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
+}
+
migrate_leds() {
config_load system
config_foreach migrate_led_sysfs led "$@"
}
+remove_devicename_leds() {
+ config_load system
+ config_foreach remove_devicename_led_sysfs led
+}
+
migrations_apply() {
local realm="$1"
[ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
More information about the lede-commits
mailing list