From 8a8976f0ad4e66fccb8c8de35cd2093149f8166c Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 29 Jul 2017 21:34:55 -0400 Subject: [PATCH] push* scripts: use luasrcdiet if directed If ${LUADIET} is empty, send files as they are; otherwise, stream them through luasrcdiet. To use the default options, use 'LUADIET=' '" or something to that effect. This can be set per-file, should some module turn out to be broken by dieting. The "dopush" utility macro is split and now called "dopushlua" and "dopushtext" (which skips luasrcdiet even if it is engaged). --- host/pushcommon.sh | 36 +++++++++++++++++++++++++++++------- host/pushinit.sh | 8 ++++---- host/pushvia.expect | 2 +- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/host/pushcommon.sh b/host/pushcommon.sh index d43f145..1fce50a 100644 --- a/host/pushcommon.sh +++ b/host/pushcommon.sh @@ -1,11 +1,33 @@ -if [ -z ${MCUHOST:-} ]; then - # Uses LUATOOL to push init and dependencies to the device; bootstrap! +luafile () { + if [ -z "${LUADIET:-}" ]; then + echo "No diet for lua" >&2 + LUAFILE=$1 + else + DF=$(mktemp -p /tmp esp-pushcommon-XXXXX) + if [ -n "${luafilefd:-}" ]; then exec {luafilefd}<&-; fi + exec {luafilefd}<>${DF} + + echo "Lua diet ${LUADIET}" >&2 + lua5.1 \ + -e 'package.path=package.path..";_external/luasrcdiet/?.lua"' \ + ./_external/luasrcdiet/bin/luasrcdiet $1 -o ${DF} \ + --quiet ${=LUADIET} 2>/dev/null + rm ${DF} + LUAFILE=/dev/fd/${luafilefd} + fi +} + +if [ -z "${MCUHOST:-}" ]; then + if [ -z "${LUATOOL:-}" ]; then echo "Need LUATOOL or MCUHOST"; exit 1; fi + if [ -z "${MCUPORT:-}" ]; then echo "Need MCUPORT or MCUHOST"; exit 1; fi + if [ -z "${MCUBAUD:-}" ]; then echo "Need MCUBAUD or MCUHOST"; exit 1; fi PUSHCMD="${LUATOOL} --delay 0.1 -p ${MCUPORT} -b ${MCUBAUD}" - dopush() { ${=PUSHCMD} -f $1 -t ${2:-`basename $1`}; } - dopushcompile() { ${=PUSHCMD} -f $1 -t ${2:-`basename $1`} -c; } + dopushtext() { ${=PUSHCMD} -f $1 -t ${2:-`basename $1`} ; } + dopushlua() { luafile ${1} ; ${=PUSHCMD} -f ${LUAFILE} -t ${2:-`basename $1`} ; } + dopushcompile() { luafile ${1} ; ${=PUSHCMD} -f ${LUAFILE} -t ${2:-`basename $1`} -c ; } else - # Uses host/pushvia to push everything if MCUHOST is set PUSHCMD="./host/pushvia.expect ${MCUHOST} ${PORT:-23}" - dopush() { ${=PUSHCMD} ${2:-`basename $1`} $1; } - dopushcompile() { ${=PUSHCMD} ${2:-`basename $1`} $1 compile; } + dopushtext() { ${=PUSHCMD} ${2:-`basename $1`} $1 ; } + dopushlua() { luafile ${1} ; ${=PUSHCMD} ${2:-`basename $1`} ${LUAFILE} ; } + dopushcompile() { luafile ${1} ; ${=PUSHCMD} ${2:-`basename $1`} ${LUAFILE} compile ; } fi diff --git a/host/pushinit.sh b/host/pushinit.sh index c3801ad..ffdf999 100755 --- a/host/pushinit.sh +++ b/host/pushinit.sh @@ -12,13 +12,13 @@ dopushcompile net/nwfnet.lua dopushcompile net/nwfnet-sntp.lua dopushcompile net/nwfnet-go.lua dopushcompile net/nwfnet-diag.lua -#dopush net/conf/nwfnet.conf -#dopush net/conf/nwfnet.cert -#dopush net/conf/nwfnet.conf2 +#dopushtext net/conf/nwfnet.conf +#dopushtext net/conf/nwfnet.cert +#dopushtext net/conf/nwfnet.conf2 dopushcompile net/fifosock.lua dopushcompile telnetd/telnetd.lua dopushcompile telnetd/telnetd-file.lua dopushcompile telnetd/telnetd-diag.lua -dopush init.lua +dopushlua init.lua echo "SUCCESS" diff --git a/host/pushvia.expect b/host/pushvia.expect index 1c80c5a..c6f1e8a 100755 --- a/host/pushvia.expect +++ b/host/pushvia.expect @@ -33,7 +33,7 @@ set remote_sid ${spawn_id} set rfn [lindex $argv 2] set lfn [lindex $argv 3] -set lchan [open ${lfn} r+] +set lchan [open ${lfn} r] fconfigure ${lchan} -translation binary -encoding binary set timeout 2 -- 2.50.1