diff options
author | Ron Yorston <rmy@pobox.com> | 2020-01-13 10:33:46 +0000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-04-30 17:23:08 +0200 |
commit | 981b2eff814bd186188ad66a32990a6d17b37a3e (patch) | |
tree | 9d66d4de595eac03a479de13ea8a66daf69c87cd | |
parent | da7a6dbfa5d78e3d5cec5906b402908505d0fcf9 (diff) | |
download | busybox-w32-981b2eff814bd186188ad66a32990a6d17b37a3e.tar.gz busybox-w32-981b2eff814bd186188ad66a32990a6d17b37a3e.tar.bz2 busybox-w32-981b2eff814bd186188ad66a32990a6d17b37a3e.zip |
mim: run scripts from a specification file
mim runs scripts from a specification file which can be thought
of as an extremely limited Makefile. Neither make variables nor
dependencies are supported. By default the file 'Mimfile' is read.
An example:
hello:
echo hello $1
clean:
rm -rf *
The command 'mim' or 'mim hello' will echo 'hello'. Unlike 'make'
arguments after the first are available to the script; they don't
specify additional targets.
mim isn't enabled by default. Enabling it increases the size of the
binary by about 500 bytes.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rwxr-xr-x | applets_sh/mim | 39 | ||||
-rw-r--r-- | miscutils/mim.c | 15 |
2 files changed, 54 insertions, 0 deletions
diff --git a/applets_sh/mim b/applets_sh/mim new file mode 100755 index 000000000..2a65c35bb --- /dev/null +++ b/applets_sh/mim | |||
@@ -0,0 +1,39 @@ | |||
1 | #!/bin/sh | ||
2 | MIMFILE="Mimfile" | ||
3 | if [ $# -ge 2 ] && [ "$1" = "-f" ] | ||
4 | then | ||
5 | MIMFILE="$2" | ||
6 | shift 2 | ||
7 | fi | ||
8 | exec <"$MIMFILE" || exit 1 | ||
9 | { | ||
10 | INCASE=false | ||
11 | while read -r REPLY | ||
12 | do | ||
13 | case $REPLY in | ||
14 | *:) | ||
15 | if ! $INCASE | ||
16 | then | ||
17 | printf '[ $# -eq 0 ] && set -- "%s" | ||
18 | TARGET="$1" | ||
19 | shift | ||
20 | case "$TARGET" in | ||
21 | ' "${REPLY%:}" | ||
22 | else | ||
23 | printf ';;\n' | ||
24 | fi | ||
25 | printf '%s)\n' "${REPLY%:}" | ||
26 | INCASE=true | ||
27 | ;; | ||
28 | "") ;; | ||
29 | *) printf '%s\n' "${REPLY##[ ]}";; | ||
30 | esac | ||
31 | done | ||
32 | $INCASE && printf ';;\n' | ||
33 | printf '*) | ||
34 | echo "Unknown command $TARGET" | ||
35 | exit 1 | ||
36 | ;; | ||
37 | esac | ||
38 | ' | ||
39 | } | sh -s "$@" | ||
diff --git a/miscutils/mim.c b/miscutils/mim.c new file mode 100644 index 000000000..d9b4694cb --- /dev/null +++ b/miscutils/mim.c | |||
@@ -0,0 +1,15 @@ | |||
1 | //config:config MIM | ||
2 | //config: bool "mim (0.5 kb)" | ||
3 | //config: default y | ||
4 | //config: depends on FEATURE_SH_EMBEDDED_SCRIPTS | ||
5 | //config: help | ||
6 | //config: Run a script from a Makefile-like specification file. | ||
7 | //config: Unlike 'make' dependencies aren't supported. | ||
8 | |||
9 | //applet:IF_MIM(APPLET_SCRIPTED(mim, scripted, BB_DIR_USR_SBIN, BB_SUID_DROP, mim)) | ||
10 | |||
11 | //usage:#define mim_trivial_usage | ||
12 | //usage: "[-f FILE] [SHELL_OPTIONS] [TARGET] ..." | ||
13 | //usage:#define mim_full_usage "\n\n" | ||
14 | //usage: "Run a script from a Makefile-like specification file\n" | ||
15 | //usage: "\n -f FILE Spec file (default Mimfile)" | ||