diff options
author | Ron Yorston <rmy@pobox.com> | 2018-11-27 10:45:30 +0000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-11-27 12:33:28 +0100 |
commit | 31a04d91c24f6ee180de45e1508dc03dea9f9c11 (patch) | |
tree | a4e4d4251fd91c937243d2edfa78fe4ef9a1284f /docs | |
parent | 403d2574be8f8c41aa46f73dec5f998b2cbf2790 (diff) | |
download | busybox-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.txt | 116 |
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 @@ | |||
1 | Embedded Shell Scripts in BusyBox | ||
2 | ================================= | ||
3 | |||
4 | BusyBox allows applets to be implemented as shell scripts. Since | ||
5 | this obviously requires a shell to interpret the scripts the feature | ||
6 | depends on having a shell (specifically, ash) built into the binary. | ||
7 | Support for embedded scripts also has to be enabled. | ||
8 | |||
9 | To embed scripts in BusyBox you must enable these configuration options: | ||
10 | |||
11 | ASH | ||
12 | ASH_EMBEDDED_SCRIPTS | ||
13 | |||
14 | It's unlikely that your applet will be implemented as a pure shell | ||
15 | script: it will probably need some external commands. If these are | ||
16 | to be provided by BusyBox you'll need to ensure they're enabled too. | ||
17 | |||
18 | There are two ways to include scripts in BusyBox: the quick-and-dirty | ||
19 | custom script and the full-featured scripted applet. | ||
20 | |||
21 | Custom Scripts | ||
22 | -------------- | ||
23 | |||
24 | When embedded script support is enabled the BusyBox build process | ||
25 | assumes that any files in the directory 'embed' at the top level of | ||
26 | the source tree are scripts to be embedded. | ||
27 | |||
28 | The embed directory isn't present in the BusyBox source tree and | ||
29 | BusyBox itself will never put anything there: it's entirely for the | ||
30 | use of third parties. | ||
31 | |||
32 | Adding a custom script is as simple as running the following sequence | ||
33 | of commands in the BusyBox source directory: | ||
34 | |||
35 | mkdir embed | ||
36 | echo 'echo foo' >embed/foo | ||
37 | make defconfig | ||
38 | make | ||
39 | |||
40 | The resulting binary includes the new applet foo! | ||
41 | |||
42 | Custom scripts have limited opportunities for configuration: the only | ||
43 | control developers have is to put them in the embed directory, or not. | ||
44 | Everything else takes default values. For more control you need the | ||
45 | additional features provided by scripted applets. | ||
46 | |||
47 | Scripted Applets | ||
48 | ---------------- | ||
49 | |||
50 | Suppose we want to make a shell script version of the sample applet | ||
51 | from the New Applet HOWTO. First we'd have to write a script (vaguely) | ||
52 | equivalent to the C code: | ||
53 | |||
54 | return $(($RANDOM%256)) | ||
55 | |||
56 | This should be placed in the file applets_sh/mu in the source tree. | ||
57 | |||
58 | Next we need the configuration data. This is very similar to the example | ||
59 | code 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 | |||
76 | The only difference is that the applet is specified as being of type | ||
77 | APPLET_SCRIPTED. It would also be useful to include details of any | ||
78 | dependencies the script has. We can assume that ash is available. | ||
79 | No external commands are used by our mu script, but it does depend on | ||
80 | optional shell features. We can ensure these are selected by adding | ||
81 | this 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 | |||
93 | The configuration data should be placed in a C file in an appropriate | ||
94 | subdirectory. There isn't any C code, though! In this case the file | ||
95 | could be miscutils/mu.c. | ||
96 | |||
97 | Scripted applets are just as configurable as applets written in C. | ||
98 | They can be enabled or disabled using the configuration menu; their | ||
99 | install directory can be specified and their usage messages are stored | ||
100 | along with those of all other applets. | ||
101 | |||
102 | Additional Notes | ||
103 | ---------------- | ||
104 | |||
105 | The source for embedded scripts can be displayed by running: | ||
106 | |||
107 | busybox --show SCRIPT | ||
108 | |||
109 | This can be disabled by turning off FEATURE_SHOW_SCRIPT in the | ||
110 | configuration, though it won't prevent a determined user from | ||
111 | extracting the source code. | ||
112 | |||
113 | It can be argued that embedded scripts are linked into the BusyBox | ||
114 | binary and are therefore not subject to the 'mere aggregation' | ||
115 | exception in the GPL. If this is the case embedded scripts should | ||
116 | have a licence compatible with BusyBox's GPL v2-only licence. | ||