obuspa: init: fix manipulating USP_BOARD_IFNAME env var in .profile

This addresses two problems:

1. `sed 'g/export USP_BOARD_NAME/d'` would erase all the lines in the affected
file, regardless of whether there was a match or not. Replace this with
`sed '/foo/d'`, which correctly deletes just the affected lines.

2. Changing an `interface`/`ifname` in UCI configuration would end up
appending to /root/.profile due to how the control flow was written.
This commit is contained in:
Roman Azarenko 2022-04-19 15:52:50 +02:00
parent c9bc7a3dea
commit 8c867fc829
No known key found for this signature in database
GPG key ID: 621795252915BD63
2 changed files with 9 additions and 13 deletions

View file

@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=obuspa
PKG_VERSION:=5.0.0.8
PKG_VERSION:=5.0.0.9
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)

View file

@ -699,20 +699,16 @@ configure_obuspa() {
if [ -n "${ifname}" ]; then
procd_set_param env USP_BOARD_IFNAME="${ifname}"
# Set this variable for root user and obuspa -c tool
fi
if [ -z "${ifname}" ] || ! grep -F -q "export USP_BOARD_IFNAME=${ifname}" "${PROFILE}"; then
if [ -f "${PROFILE}" ]; then
if grep -q "export USP_BOARD_IFNAME=${ifname}" ${PROFILE}; then
if grep -q "export USP_BOARD_IFNAME" ${PROFILE}; then
sed -i "g/export USP_BOARD_IFNAME/d" ${PROFILE}
fi
fi
sed -i "/export USP_BOARD_IFNAME/d" "${PROFILE}"
fi
echo "export USP_BOARD_IFNAME=${ifname}" >> ${PROFILE}
else
if [ -f "$PROFILE" ]; then
if grep -q "export USP_BOARD_IFNAME" ${PROFILE}; then
sed -i "g/export USP_BOARD_IFNAME/d" ${PROFILE}
fi
if [ -n "${ifname}" ]; then
# Set this variable for root user and obuspa -c tool
echo "export USP_BOARD_IFNAME=${ifname}" >> "${PROFILE}"
fi
fi