[PATCH] mim: run scripts from a specification file

Boris Kotov bk at webdeb.de
Mon Jan 13 12:04:17 UTC 2020


This is amazing!
Totally agree with "Mimfile" and (mim = affectedly shy or modest) I 
think its a good match for it!
I appreciate your work on this Ron, and I hope this will be added!

Am 13.01.20 um 11:33 schrieb Ron Yorston:
> 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 at pobox.com>
> ---
>   applets_sh/mim  | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
>   miscutils/mim.c | 16 +++++++++++++++
>   2 files changed, 69 insertions(+)
>   create mode 100755 applets_sh/mim
>   create mode 100644 miscutils/mim.c
>
> diff --git a/applets_sh/mim b/applets_sh/mim
> new file mode 100755
> index 000000000..fd4152568
> --- /dev/null
> +++ b/applets_sh/mim
> @@ -0,0 +1,53 @@
> +#!/bin/sh
> +
> +MIMFILE="Mimfile"
> +if [ $# -ge 2 ] && [ "$1" = "-f" ]
> +then
> +	MIMFILE="$2"
> +	shift 2
> +fi
> +
> +if [ ! -f "$MIMFILE" ]
> +then
> +	printf "Unable to open '%s'\n" "$MIMFILE"
> +	exit 1
> +fi
> +
> +(
> +	INCASE=0
> +
> +	while read -r REPLY
> +	do
> +		case $REPLY in
> +		*:)
> +			if [ $INCASE -eq 0 ]
> +			then
> +				printf "if [ \$# -eq 0 ]\n"
> +				printf "then\n"
> +				printf "\tTARGET=\"%s\"\n" "${REPLY%:}"
> +				printf "else\n"
> +				printf "\tTARGET=\"\$1\"\n"
> +				printf "\tshift\n"
> +				printf "fi\n"
> +				printf "case \"\$TARGET\" in\n"
> +			else
> +				printf "\t;;\n"
> +			fi
> +			printf "%s)\n" "${REPLY%:}"
> +			INCASE=1
> +			;;
> +		"") ;;
> +		*) printf "\t%s\n" "${REPLY##[ 	]}";;
> +		esac
> +	done <"$MIMFILE"
> +
> +	if [ $INCASE -eq 1 ]
> +	then
> +		printf "\t;;\n"
> +	fi
> +	printf "*)\n"
> +	printf "\techo \"Unknown command '\$TARGET'\"\n"
> +	printf "\texit 1\n"
> +	printf "\t;;\n"
> +	printf "esac\n"
> +) | sh -s "$@"
> diff --git a/miscutils/mim.c b/miscutils/mim.c
> new file mode 100644
> index 000000000..1cf67e1f3
> --- /dev/null
> +++ b/miscutils/mim.c
> @@ -0,0 +1,16 @@
> +//config:config MIM
> +//config:	bool "mim (0.5 kb)"
> +//config:	default n
> +//config:	depends on FEATURE_SH_EMBEDDED_SCRIPTS
> +//config:	depends on ASH_PRINTF || HUSH_PRINTF || PRINTF
> +//config:	help
> +//config:	Run a script from a Makefile-like specification file.
> +//config:	Unlike 'make' dependencies aren't supported.
> +
> +//applet:IF_MIM(APPLET_SCRIPTED(mim, scripted, BB_DIR_USR_SBIN, BB_SUID_DROP, mim))
> +
> +//usage:#define mim_trivial_usage
> +//usage:	"[-f FILE] [SHELL_OPTIONS] [TARGET] ..."
> +//usage:#define mim_full_usage "\n\n"
> +//usage:	"Run a script from a Makefile-like specification file\n"
> +//usage:    "\n -f FILE  Spec file (default Mimfile)"


More information about the busybox mailing list