From 8c867fc82942611178da7d5ca30446756ea2a5ee Mon Sep 17 00:00:00 2001 From: Roman Azarenko Date: Tue, 19 Apr 2022 15:52:50 +0200 Subject: [PATCH] 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. --- obuspa/Makefile | 2 +- obuspa/files/etc/init.d/obuspa | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/obuspa/Makefile b/obuspa/Makefile index 5613dae6f..cd684e834 100644 --- a/obuspa/Makefile +++ b/obuspa/Makefile @@ -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) diff --git a/obuspa/files/etc/init.d/obuspa b/obuspa/files/etc/init.d/obuspa index 9adde316b..63b67d137 100755 --- a/obuspa/files/etc/init.d/obuspa +++ b/obuspa/files/etc/init.d/obuspa @@ -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