2019-03-21 17:03:38 +00:00
|
|
|
. /lib/functions.sh
|
|
|
|
|
|
|
|
migrate_led_sysfs() {
|
|
|
|
local cfg="$1"; shift
|
|
|
|
local tuples="$@"
|
|
|
|
local sysfs
|
|
|
|
local name
|
|
|
|
|
|
|
|
config_get sysfs ${cfg} sysfs
|
|
|
|
config_get name ${cfg} name
|
|
|
|
|
|
|
|
[ -z "${sysfs}" ] && return
|
|
|
|
|
|
|
|
for tuple in ${tuples}; do
|
|
|
|
local old=${tuple%=*}
|
|
|
|
local new=${tuple#*=}
|
|
|
|
local new_sysfs
|
|
|
|
|
|
|
|
new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
|
|
|
|
|
|
|
|
[ "${new_sysfs}" = "${sysfs}" ] && continue
|
|
|
|
|
|
|
|
uci set system.${cfg}.sysfs="${new_sysfs}"
|
|
|
|
|
|
|
|
logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
|
|
|
|
done;
|
|
|
|
}
|
|
|
|
|
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@adrianschmutzler.de>
2020-09-27 15:25:15 +00:00
|
|
|
remove_devicename_led_sysfs() {
|
2020-10-02 12:23:59 +00:00
|
|
|
local cfg="$1"; shift
|
|
|
|
local exceptions="$@"
|
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@adrianschmutzler.de>
2020-09-27 15:25:15 +00:00
|
|
|
local sysfs
|
|
|
|
local name
|
|
|
|
local new_sysfs
|
|
|
|
|
|
|
|
config_get sysfs ${cfg} sysfs
|
|
|
|
config_get name ${cfg} name
|
|
|
|
|
2020-10-02 12:23:59 +00:00
|
|
|
# only continue if two or more colons are present
|
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@adrianschmutzler.de>
2020-09-27 15:25:15 +00:00
|
|
|
echo "${sysfs}" | grep -q ":.*:" || return
|
|
|
|
|
2020-10-02 12:23:59 +00:00
|
|
|
for exception in ${exceptions}; do
|
|
|
|
# no change if exceptions provided as argument are found for devicename
|
|
|
|
echo "${sysfs}" | grep -q "^${exception}:" && return
|
|
|
|
done
|
|
|
|
|
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@adrianschmutzler.de>
2020-09-27 15:25:15 +00:00
|
|
|
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}"
|
|
|
|
}
|
|
|
|
|
2019-03-21 17:03:38 +00:00
|
|
|
migrate_leds() {
|
|
|
|
config_load system
|
|
|
|
config_foreach migrate_led_sysfs led "$@"
|
|
|
|
}
|
|
|
|
|
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@adrianschmutzler.de>
2020-09-27 15:25:15 +00:00
|
|
|
remove_devicename_leds() {
|
|
|
|
config_load system
|
2020-10-02 12:23:59 +00:00
|
|
|
config_foreach remove_devicename_led_sysfs led "$@"
|
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@adrianschmutzler.de>
2020-09-27 15:25:15 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 17:03:38 +00:00
|
|
|
migrations_apply() {
|
|
|
|
local realm="$1"
|
|
|
|
[ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
|
|
|
|
}
|