[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [RFC PATCH 0/1] ash: allow shell scripts to be embedded in the binary
From:       Ron Yorston <rmy () pobox ! com>
Date:       2018-10-25 11:27:28
Message-ID: 5bd1a8a0.GggAi/Vz+Sm0+oHz%rmy () pobox ! com
[Download RAW message or body]

The patch in the following message allows shell scripts to be embedded
in the BusyBox binary.  I'm issuing it as an RFC because I'm sure I
haven't thought this through properly and would appreciate input from
the community.

The idea is to allow users ship application scripts as part of the
binary so there's less chance of them getting lost.  It also allows
them to extend BusyBox without having to write full-blown applets.

The process is something like:

   $ make defconfig
   $ : add some scripts
   $ mkdir embed
   $ echo 'echo foo $1 $2' >embed/foo
   $ echo 'echo bar $1 $2' >embed/bar
   $ : enable embedding
   $ sed -i \
   > -e 's/# \(CONFIG_ASH_EMBEDDED_SCRIPTS\) is not set/\1=y/' \
   > -e 's/# \(CONFIG_ASH_LIST_EMBEDDED_SCRIPTS\) is not set/\1=y/' \
   > .config
   $ make
   $ : list the names of the embedded scripts
   $ ./busybox sh -L
   bar
   foo
   $ : list the contents of a script
   $ ./busybox sh -L foo
   echo foo $1 $2
   $ : run an embedded script from the shell
   $ ./busybox sh foo hello shell
   foo hello shell
   $ : like applets scripts can be given as arguments to BusyBox
   $ ./busybox foo hello busybox
   foo hello busybox
   $ : running the binary with the name of a script also works
   $ ln -s busybox bar
   $ ./bar 'Woo!' 'A script and shell in one!'
   bar Woo! A script and shell in one!

If standalone shell mode is enabled you also get to run the scripts
directly from the shell (without having to say 'sh name') and tab
completion works.

The method used is fairly simplistic.  The script names and contents
are scanned linearly.  All the scripts are compressed as one lump
and have to be decompressed into memory as one lump.  The scripts
are compressed unconditionally, even it it doesn't make them smaller.

They really have to be shell scripts:  you can't stick '#!/bin/awk -f'
at the top and expect good things to happen.

I've assumed that users will only want to embed a small number of
scripts.  If it turns out they want to build entire application
suites consisting of hundreds of scripts some refinement will be
required.

I'm aware that the 'applets_sh' directory in the source tree has some
applets implemented as scripts.  Though as the README says, they aren't
hooked up to the build system.

I consider what I've done here orthogonal to the idea of implementing
actual applets as scripts.  I'd expect the latter to set much higher
standards in terms of usage documentation and integration.  I'd expect
script applets to be separately configured at build time and to ensure
that any other applets required by the script were included.  It'd be
a whole lot more work to implement.

There may be licensing implications.  Shipping the BusyBox binary and
some shell scripts as separate files is clearly 'mere aggregation';
embedding the scripts in the binary isn't.  I don't know what the status
of the scripts would be in that case.

Have fun,

Ron
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic