2021-02-08 19:47:35 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
TOOLDIR=tools/
|
|
|
|
LUATOOL=${TOOLDIR}luatool.py
|
|
|
|
|
2021-02-13 15:12:11 +01:00
|
|
|
#DIET=bin/luasrcdiet --maximum
|
2021-02-08 19:47:35 +01:00
|
|
|
DIET=bin/luasrcdiet
|
|
|
|
|
|
|
|
DEVICE=$1
|
|
|
|
BAUD=115200
|
|
|
|
|
2021-02-10 23:05:54 +01:00
|
|
|
LUASCRIPT_STOP=${TOOLDIR}/stopController.lua
|
|
|
|
|
2021-02-08 19:47:35 +01:00
|
|
|
# check environment
|
|
|
|
if [ ! -f $LUATOOL ]; then
|
|
|
|
echo "$LUATOOL not found"
|
|
|
|
echo "is the command prompt at the same level as the tools folder ?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check the serial connection
|
|
|
|
|
|
|
|
if [ ! -c $DEVICE ]; then
|
2021-02-09 19:58:59 +01:00
|
|
|
echo "Serial target: $DEVICE does not exist"
|
2021-02-08 19:47:35 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo ""
|
|
|
|
echo "e.g. usage $0 <device> [<files to upoad>]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
FILES="displayword.lua main.lua timecore.lua webpage.html webserver.lua telnet.lua wordclock.lua init.lua"
|
|
|
|
else
|
|
|
|
FILES=$2
|
|
|
|
fi
|
|
|
|
|
2021-03-21 16:06:26 +01:00
|
|
|
# Convert files, if necessary
|
|
|
|
if [ "$FILES" != "config.lua" ]; then
|
|
|
|
echo "Generate DIET version of the files"
|
|
|
|
OUTFILES=""
|
|
|
|
ROOTDIR=$PWD
|
|
|
|
cd $TOOLDIR
|
|
|
|
for f in $FILES; do
|
|
|
|
if [[ "$f" == *.lua ]] && [[ "$f" != init.lua ]]; then
|
|
|
|
echo "Compress $f ..."
|
|
|
|
out=$(echo "$f" | sed 's/.lua/_diet.lua/g')
|
|
|
|
$DIET ../$f -o ../diet/$out
|
2023-03-04 19:20:41 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Failed to generate file"
|
|
|
|
exit $?
|
|
|
|
fi
|
2021-03-21 16:06:26 +01:00
|
|
|
OUTFILES="$OUTFILES diet/$out"
|
|
|
|
else
|
|
|
|
OUTFILES="$OUTFILES $f"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
FILES=$OUTFILES
|
|
|
|
cd $ROOTDIR
|
|
|
|
fi
|
|
|
|
echo "Reboot ESP and stop init timer"
|
|
|
|
if [ ! -f $LUASCRIPT_STOP ]; then
|
|
|
|
echo "Cannot find $LUASCRIPT_STOP"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
python3 $LUATOOL -p $DEVICE -f $LUASCRIPT_STOP -b $BAUD --volatile --delay 2
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Could not reboot"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-02-08 19:47:35 +01:00
|
|
|
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
# Format filesystem first
|
|
|
|
echo "Format the complete ESP"
|
|
|
|
python3 $LUATOOL -p $DEVICE -w -b $BAUD
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "STOOOOP"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Start Flasing ..."
|
|
|
|
for f in $FILES; do
|
|
|
|
if [ ! -f $f ]; then
|
|
|
|
echo "Cannot find $f"
|
|
|
|
echo "place the terminal into the folder where the lua files are present"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-02-08 19:51:54 +01:00
|
|
|
|
|
|
|
espFile=$(echo "$f" | sed 's;diet/;;g')
|
|
|
|
echo "------------- $espFile ------------"
|
|
|
|
python3 $LUATOOL -p $DEVICE -f $f -b $BAUD -t $espFile
|
2021-02-08 19:47:35 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "STOOOOP"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-02-10 23:05:54 +01:00
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
echo "Reboot the ESP"
|
|
|
|
echo "node.restart()" >> $DEVICE
|
|
|
|
fi
|
2021-02-08 19:47:35 +01:00
|
|
|
|
|
|
|
exit 0
|