raphaelcohn / bish-bosh

MQTT shell script client, for bash, dash, BusyBox ash and others. Gives you MQTT on anything Unix like, from embedded routers to AIX servers with almost no dependenices.
https://github.com/raphaelcohn/bish-bosh
Other
216 stars 37 forks source link

syntax error: Bad substitution when running on BusyBox v1.11.2 #6

Closed magcode closed 7 years ago

magcode commented 7 years ago

Hello,

I'm trying to run bish bosh on an ubiquiti mpower device.

I'm using latest release BusyBox v1.11.2 (2015-04-06 14:24:36 PDT) built-in shell (ash) MF.v2.1.11# ./bish-bosh_2015.0629.0920-2_all ./bish-bosh_2015.0629.0920-2_all: line 2890: syntax error: Bad substitution

Do you have any advice?

Thanks a lot.

raphaelcohn commented 7 years ago

This is going to be tricky to track down, but there are some things we can try.

First, can you modify the bish-bosh script to put a set -x into it? This will produce an insane amount of information, but should give us a little better idea of what's going wrong. You might be able to get a little context around the error message.

Secondly, we can work with the uncombined sources from git. It should be possible to do a git clone and git submodule update --init --recursive, and use the version of bish-bosh there. This may give us a little more context - or even the file things are blowing up in, if we're lucky. bish-bosh pushes the POSIX shell to the absolute limits. If you're using a version of BusyBox ash that integrates the applets as shell commands, then that frequently goes wrong in very strange ways. When we create a fix, it's highly likely to be in one of the pieces of shell script that bish-bosh depends on.

magcode commented 7 years ago

Thanks for your reply. Very much appreciated. I'll try it later today and post an update here.

magcode commented 7 years ago

I tried -x, but output is not very helpful

...
rm coreutils /bin/rm
rmdir coreutils /bin/rmdir
mkdir coreutils /bin/mkdir

./bish-bosh_2015.0629.0920-2_all: line 2891: syntax error: Bad substitution

Then I tried to copy the uncombined sources to the device but I failed due to too less disk space. I remove .git directory but still 4,3Mb and ~4.600 files. Seems to be too much.

MF.v2.1.11# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.8M      5.8M         0 100% /
/dev/root                 5.8M      5.8M         0 100% /
tmpfs                    10.0M      2.2M      7.8M  22% /var
dev                      14.4M         0     14.4M   0% /dev

Any chance to reduce git sources even more? Like removing all CentOS and Homebrew and ... folders?

magcode commented 7 years ago

finding:

#!/usr/bin/env sh
bishbosh_adjustReadLatencyIfNecessary () 
{ 
    if core_variable_isSet BASH_VERSINFO; then
        if [ ${BASH_VERSINFO[0]} -eq 3 ]; then
            if [ $bishbosh_readLatency -lt 1000 ]; then
                core_message WARN "bash 3 does not support fractional read latency (we're forcing bishbosh_readLatency to 1000 ms) [discovered on Mac OS X when run as default sh]";
                bishbosh_readLatency=1000;
                bishbosh_readLatency_inFractionalSeconds=1;
            fi;
        fi;
    fi;
    if ! core_compatibility_sleepSupportsFractionalSeconds; then
        core_message WARN "sleep does not support fractional seconds for read latency (we're forcing bishbosh_readLatency to 1000 ms) [discovered on AIX]";
        bishbosh_readLatency=1000;
        bishbosh_readLatency_inFractionalSeconds=1;
    fi
}

This script gives me

 line 5: syntax error: Bad substitution

after commenting it out in bishbosh I get another error:

./bish-bosh_2015.0629.0920-2_all: line 4499: syntax error: Bad substitution

so different/next issue.

magcode commented 7 years ago

I think I have all problematic lines now...

if [ ${BASH_VERSINFO[0]} -eq 3 ]; then gives syntax error: Bad substitution

addressKind="${$bishbosh_proxyKind}:${bishbosh_proxyAddress}:${bishbosh_server}:${bishbosh_port}"; gives syntax error: Bad substitution

source () gives syntax error: Bad function name

set +o emacs; gives illegal option +o emacs

after commenting the 4 lines above bb finally starts. 😄 Are they crucial?

Need to set many properties though. Will continue this weekend.

magcode commented 7 years ago

next issue

MF.v2.1.11# ./bish-bosh_2015.0629.0920-2_all  --client-id 12 --verbose 3 -c '/var/tmp/bbclient' --session-path '/var/tmp/bbsession' --lock-path /var/tmp/bblock
/ -s 192.168.155.20
bish-bosh: WARN: sleep does not support fractional seconds for read latency (we're forcing bishbosh_readLatency to 1000 ms) [discovered on AIX]
bish-bosh: INFO: Using backend 'ncBusyBox' (on path '/usr/bin/nc') with port '1883'
bish-bosh: WARN: Disabling UTF-8 validation because 'iconv' isn't available
bish-bosh: TODO: Allow BusyBox builtins to work by calling nc directly
bish-bosh: DEBUG: Passing options to backend 'ncBusyBox' using '/usr/bin/nc' as '-w 30 nc 192.168.155.20 1883' (please note spaces ARE handled correctly)
bish-bosh: DEBUG: bishbosh_connection_clientPid is 14277
bish-bosh: INFO: Using hexdump
bish-bosh: DEBUG: bishbosh_connection_hexConversionPid is 14286
bish-bosh: INFO: Writing CONNECT
bish-bosh: DEBUG: bishbosh_connection_processLoopPid is 14291
BusyBox v1.11.2 (2015-04-06 14:24:36 PDT) multi-call binary

Usage: nc [IPADDR PORTNUM]

Open a pipe to IP:port

bish-bosh: DEBUG: Our Pid is 14165
bish-bosh: NOTICE: Terminate bish-bosh with  kill 14165
bish-bosh: FAIL: Could not connect to '192.168.155.20'
raphaelcohn commented 7 years ago

Ok some ideas.

You can get away without etc/shellfire/path.d

You can get away without lib/shellfire/core/some package managers.

You don't need swaddle or anything in /tools iirc.

Try running on a regular busybox distribution eg Alpine Linux in a VM.

My other half enforces no programming at weekends so I'll be back in action Monday.

On 2 Dec 2016 7:37 p.m., "magcode" notifications@github.com wrote:

I tried -x, but output is not very helpful

... rm coreutils /bin/rm rmdir coreutils /bin/rmdir mkdir coreutils /bin/mkdir

./bish-bosh_2015.0629.0920-2_all: line 2891: syntax error: Bad substitution

Then I tried to copy the uncombined sources to the device but I failed due to too less disk space. I remove .git directory but still 4,3Mb and ~4.600 files. Seems to be too much.

MF.v2.1.11# df -h Filesystem Size Used Available Use% Mounted on rootfs 5.8M 5.8M 0 100% / /dev/root 5.8M 5.8M 0 100% / tmpfs 10.0M 2.2M 7.8M 22% /var dev 14.4M 0 14.4M 0% /dev

Any chance to reduce git sources even more? Like removing all CentOS and Homebrew and ... folders?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/raphaelcohn/bish-bosh/issues/6#issuecomment-264543139, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPx2XpxZ99dRdfLeM-_j-NVaWvY0mOPks5rEHOVgaJpZM4LB2Nm .

magcode commented 7 years ago

I think I have it 👍

I needed to make several changes. New file is here https://github.com/magcode/mpower-mqtt/blob/master/bish-bosh

Github DIFF does not work for some strange reason. This is a better view of the changes:

image

Not sure if you like to include this stuff in your sources.

Thanks again for this neat tool.

raphaelcohn commented 7 years ago

Brilliant stuff. More to follow Monday.

On 4 Dec 2016 2:16 p.m., "magcode" notifications@github.com wrote:

I think I have it 👍

I needed to make several changes. New file is here https://github.com/magcode/mpower-mqtt/blob/master/bish-bosh

Github DIFF does not work for some strange reason. This is a better view of the changes:

[image: image] https://cloud.githubusercontent.com/assets/9279656/20866744/87836c0c-ba34-11e6-9638-589a5d9a7009.png

Not sure if you like to include this stuff in your sources.

Thanks again for this neat tool.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/raphaelcohn/bish-bosh/issues/6#issuecomment-264706437, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPx2b3FckztsJbI1RnprqwySXTRqxiUks5rEstbgaJpZM4LB2Nm .

stormmq commented 7 years ago

Ah ha it's the indirection operator. I thought I'd eliminated it. I'll check the rest of the code base.

On 4 Dec 2016 4:27 p.m., "Raphael Cohn" notifications@github.com wrote:

Brilliant stuff. More to follow Monday.

On 4 Dec 2016 2:16 p.m., "magcode" notifications@github.com wrote:

I think I have it 👍

I needed to make several changes. New file is here https://github.com/magcode/mpower-mqtt/blob/master/bish-bosh

Github DIFF does not work for some strange reason. This is a better view of the changes:

[image: image] https://cloud.githubusercontent.com/assets/9279656/20866744/87836c0c- ba34-11e6-9638-589a5d9a7009.png

Not sure if you like to include this stuff in your sources.

Thanks again for this neat tool.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/raphaelcohn/bish-bosh/issues/ 6#issuecomment-264706437, or mute the thread https://github.com/notifications/unsubscribe-auth/ ABPx2b3FckztsJbI1RnprqwySXTRqxiUks5rEstbgaJpZM4LB2Nm .

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/raphaelcohn/bish-bosh/issues/6#issuecomment-264713632, or mute the thread https://github.com/notifications/unsubscribe-auth/AAaotm0j1f9IyRHyxrviQRDqI-Fns080ks5rEuoAgaJpZM4LB2Nm .