From 43c4e6b6766cce8dce56282692a6a5e4a26123df Mon Sep 17 00:00:00 2001 From: Grische <10663446-grische@users.noreply.gitlab.com> Date: Fri, 17 Nov 2023 22:30:25 +0100 Subject: [PATCH] ffac-ssid-changer: replace string indexing In POSIX sh, string indexing is not defined. This only works in ksh, bash or busybox's modified version of ash. Does not work in dash, ash, etc. Fixes: SC3057 (warning): In POSIX sh, string indexing is undefined. --- ffac-ssid-changer/shsrc/ssid-changer.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ffac-ssid-changer/shsrc/ssid-changer.sh b/ffac-ssid-changer/shsrc/ssid-changer.sh index a08d0fba..0f86a9f5 100755 --- a/ffac-ssid-changer/shsrc/ssid-changer.sh +++ b/ffac-ssid-changer/shsrc/ssid-changer.sh @@ -55,11 +55,11 @@ if [ "$SETTINGS_SUFFIX" = 'nodename' ]; then # 32 would be possible as well if [ ${#SUFFIX} -gt $((30 - ${#PREFIX})) ]; then # calculate the length of the first part of the node identifier in the offline-ssid - HALF=$(( (28 - ${#PREFIX} ) / 2 )) - # jump to this charakter for the last part of the name - SKIP=$(( ${#SUFFIX} - HALF )) + max_suffix_length=$(( (28 - ${#PREFIX} ) / 2 )) # use the first and last part of the nodename for nodes with long name - SUFFIX=${SUFFIX:0:$HALF}...${SUFFIX:$SKIP:${#SUFFIX}} + suffix_first_chars="$(printf '%s' "$SUFFIX" | head -c ${max_suffix_length})" + suffix_last_chars="$(printf '%s' "$SUFFIX" | tail -c ${max_suffix_length})" + SUFFIX="${suffix_first_chars}...${suffix_last_chars}" fi elif [ "$SETTINGS_SUFFIX" = 'mac' ]; then SUFFIX="$(uci -q get network.bat0.macaddr | /bin/sed 's/://g')"