aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-11-27 10:45:30 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2018-11-27 12:33:28 +0100
commit31a04d91c24f6ee180de45e1508dc03dea9f9c11 (patch)
treea4e4d4251fd91c937243d2edfa78fe4ef9a1284f /docs
parent403d2574be8f8c41aa46f73dec5f998b2cbf2790 (diff)
downloadbusybox-w32-31a04d91c24f6ee180de45e1508dc03dea9f9c11.tar.gz
busybox-w32-31a04d91c24f6ee180de45e1508dc03dea9f9c11.tar.bz2
busybox-w32-31a04d91c24f6ee180de45e1508dc03dea9f9c11.zip
docs: add embedded-scripts.txt
Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/embedded-scripts.txt116
1 files changed, 116 insertions, 0 deletions
diff --git a/docs/embedded-scripts.txt b/docs/embedded-scripts.txt
new file mode 100644
index 000000000..1b0c5b591
--- /dev/null
+++ b/docs/embedded-scripts.txt
@@ -0,0 +1,116 @@
1Embedded Shell Scripts in BusyBox
2=================================
3
4BusyBox allows applets to be implemented as shell scripts. Since
5this obviously requires a shell to interpret the scripts the feature
6depends on having a shell (specifically, ash) built into the binary.
7Support for embedded scripts also has to be enabled.
8
9To embed scripts in BusyBox you must enable these configuration options:
10
11 ASH
12 ASH_EMBEDDED_SCRIPTS
13
14It's unlikely that your applet will be implemented as a pure shell
15script: it will probably need some external commands. If these are
16to be provided by BusyBox you'll need to ensure they're enabled too.
17
18There are two ways to include scripts in BusyBox: the quick-and-dirty
19custom script and the full-featured scripted applet.
20
21Custom Scripts
22--------------
23
24When embedded script support is enabled the BusyBox build process
25assumes that any files in the directory 'embed' at the top level of
26the source tree are scripts to be embedded.
27
28The embed directory isn't present in the BusyBox source tree and
29BusyBox itself will never put anything there: it's entirely for the
30use of third parties.
31
32Adding a custom script is as simple as running the following sequence
33of commands in the BusyBox source directory:
34
35 mkdir embed
36 echo 'echo foo' >embed/foo
37 make defconfig
38 make
39
40The resulting binary includes the new applet foo!
41
42Custom scripts have limited opportunities for configuration: the only
43control developers have is to put them in the embed directory, or not.
44Everything else takes default values. For more control you need the
45additional features provided by scripted applets.
46
47Scripted Applets
48----------------
49
50Suppose we want to make a shell script version of the sample applet
51from the New Applet HOWTO. First we'd have to write a script (vaguely)
52equivalent to the C code:
53
54 return $(($RANDOM%256))
55
56This should be placed in the file applets_sh/mu in the source tree.
57
58Next we need the configuration data. This is very similar to the example
59code for the native applet:
60
61//config:config MU
62//config: bool "MU"
63//config: default y
64//config: help
65//config: Returns an indeterminate value.
66
67//applet:IF_MU(APPLET_SCRIPTED(mu, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, mu))
68
69//usage:#define mu_trivial_usage
70//usage: "[-abcde] FILE..."
71//usage:#define mu_full_usage
72//usage: "Returns an indeterminate value\n"
73//usage: "\n -a First function"
74//usage: "\n -b Second function"
75
76The only difference is that the applet is specified as being of type
77APPLET_SCRIPTED. It would also be useful to include details of any
78dependencies the script has. We can assume that ash is available.
79No external commands are used by our mu script, but it does depend on
80optional shell features. We can ensure these are selected by adding
81this to the configuration:
82
83//config:config MU_DEPENDENCIES
84//config: bool "Enable dependencies for mu"
85//config: default y
86//config: depends on MU
87//config: select ASH_RANDOM_SUPPORT
88//config: select FEATURE_SH_MATH
89//config: help
90//config: mu is implemented as a shell script. It requires ash
91//config: support for $RANDOM and arithmetic.
92
93The configuration data should be placed in a C file in an appropriate
94subdirectory. There isn't any C code, though! In this case the file
95could be miscutils/mu.c.
96
97Scripted applets are just as configurable as applets written in C.
98They can be enabled or disabled using the configuration menu; their
99install directory can be specified and their usage messages are stored
100along with those of all other applets.
101
102Additional Notes
103----------------
104
105The source for embedded scripts can be displayed by running:
106
107 busybox --show SCRIPT
108
109This can be disabled by turning off FEATURE_SHOW_SCRIPT in the
110configuration, though it won't prevent a determined user from
111extracting the source code.
112
113It can be argued that embedded scripts are linked into the BusyBox
114binary and are therefore not subject to the 'mere aggregation'
115exception in the GPL. If this is the case embedded scripts should
116have a licence compatible with BusyBox's GPL v2-only licence.