androidbashdockerbusybox

Android / busybox / termux test environment


I'm developping some bash scripts that run on Linux/BSD/Mac/Windows. I'd like to port them to the busybox environment, to get them to run in an android terminal emulator, like termux.

What's the best way to get a test environment for busybox / android ? I've tried to go with the docker busybox image. I also need to be able to add tools like an ssh client or rsync, which works in android termux via apt install rsync, but won't work in a docker image for obvious reasons.

Any ideas ? Thanks.


Solution

  • Busybox itself is really just a single multicall binary that can behave like many different tools. In a pure busybox environment, you'd probably end up compiling busybox to include the applets that you need (like rsync).

    In your question, you referenced a command apt install rsync. Busybox doesn't have an apt command, like you mentioned. It may be possible to install a package manager that would in turn be able to install things on demand.

    The Alpine Linux distro has a very small package manager called apk, and it also can use busybox. The alpine official image on the Docker Hub essentially has just busybox and apk. Its packages are based on libmusl instead of glibc. It'd be worth taking a look at alpine for sure.

    Here's how to install rsync on alpine:

    $ docker run --rm -it alpine sh
    / # which busybox
    /bin/busybox
    / # ls -lah `which mv`
    lrwxrwxrwx    1 root     root          12 Jun 23 19:37 /bin/mv -> /bin/busybox
    / # apk --no-cache add rsync
    fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
    fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
    (1/4) Installing libattr (2.4.47-r4)
    (2/4) Installing libacl (2.2.52-r2)
    (3/4) Installing popt (1.16-r6)
    (4/4) Installing rsync (3.1.2-r2)
    Executing busybox-1.24.2-r9.trigger
    OK: 5 MiB in 15 packages
    / # ls -lah `which rsync`
    -rwxr-xr-x    1 root     root      396.0K Apr 29 16:02 /usr/bin/rsync
    / #
    

    Other tiny package managers may work as well, but I'm not aware of how easy they are to install into a stripped down busybox root (like the busybox image). opkg and ipkg come to mind for embedded package managers.