Skip to content

Commit

Permalink
ffac-ssid-changer: replace string indexing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grische authored and maurerle committed Nov 20, 2023
1 parent 810703f commit 43c4e6b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ffac-ssid-changer/shsrc/ssid-changer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down

0 comments on commit 43c4e6b

Please sign in to comment.