telem-seq.sh: Make compatible to busybox sh

busybox's sh-implementation is differnt from the normal sh:

In busybox-expr an empty string does not evaluate to int(0).
Calling `expr ($SEQ +1)` with `SEQ=""` fails.

This patch works around this behavior by making sure the file
exists.

I left the pipe for stderr around the `cat` in place to make
sure I do not break any other error cases.

Signed-off-by: Chris Fiege <chris@tinyhost.de>
This commit is contained in:
Chris Fiege 2018-11-20 22:06:51 +01:00
parent c0abb4b216
commit 5eb7ae6a19
1 changed files with 5 additions and 1 deletions

View File

@ -2,6 +2,10 @@
# Generate sequence number as described here:
# https://github.com/wb2osz/direwolf/issues/9
#
if [ ! -f /tmp/seq ]; then
echo 0 > /tmp/seq
fi
SEQ=`cat /tmp/seq 2>/dev/null`
SEQ=$(expr \( $SEQ + 1 \) % 1000)
echo $SEQ | tee /tmp/seq
echo $SEQ | tee /tmp/seq