2019-01-16 19:32:16 +00:00
#!/bin/bash
2019-01-21 16:39:30 +00:00
bold = $( tput bold)
normal = $( tput sgr0)
2019-01-27 21:09:43 +00:00
screen_minor = ` screen --version | cut -d . -f 2`
if [ $screen_minor -gt 5 ] ; then
2019-01-27 14:28:16 +00:00
screen_with_log = "sudo screen -L -Logfile"
2019-01-27 21:09:43 +00:00
elif [ $screen_minor -eq 5 ] ; then
2019-01-27 14:28:16 +00:00
screen_with_log = "sudo screen -L"
2019-01-27 21:09:43 +00:00
else
screen_with_log = "sudo screen -L -t"
2019-01-27 14:28:16 +00:00
fi
2019-01-16 19:32:16 +00:00
. ./config.txt
./stop_flash.sh >/dev/null
2019-08-07 17:14:47 +00:00
pushd scripts >/dev/null
2019-01-16 19:32:16 +00:00
2019-08-07 17:10:08 +00:00
if [ ! -f eula_accepted ] ; then
echo "======================================================"
echo " ${ bold } TUYA-CONVERT ${ normal } "
echo
echo "https://github.com/ct-Open-Source/tuya-convert"
echo "TUYA-CONVERT was developed by Michael Steigerwald from the IT security company VTRUST (https://www.vtrust.de/) in collaboration with the techjournalists Merlin Schumacher, Pina Merkert, Andrijan Moecker and Jan Mahn at c't Magazine. (https://www.ct.de/)"
echo
echo
echo "======================================================"
echo " ${ bold } PLEASE READ THIS CAREFULLY! ${ normal } "
echo "======================================================"
echo "TUYA-CONVERT creates a fake update server environment for ESP8266/85 based tuya devices. It enables you to backup your devices firmware and upload an alternative one (e.g. ESPEasy, Tasmota, Espurna) without the need to open the device and solder a serial connection (OTA, Over-the-air)."
echo "Please make sure that you understand the consequences of flashing an alternative firmware, since you might lose functionality!"
echo
echo " Flashing an alternative firmware can cause unexpected device behavior and/or render the device unusable. Be aware that you do use this software at YOUR OWN RISK! Please acknowledge that VTRUST and c't Magazine (or Heise Medien GmbH & Co. KG) CAN NOT be held accountable for ANY DAMAGE or LOSS OF FUNCTIONALITY by typing ${ bold } yes + Enter ${ normal } "
echo
read
if [ " $REPLY " != "yes" ] ; then
exit
fi
touch eula_accepted
2019-01-18 16:26:16 +00:00
fi
2019-01-16 19:32:16 +00:00
echo "======================================================"
2019-10-02 19:13:44 +00:00
echo -n " Starting AP in a screen"
2019-01-27 14:28:16 +00:00
$screen_with_log smarthack-wifi.log -S smarthack-wifi -m -d ./setup_ap.sh
2019-10-03 18:43:31 +00:00
while ! ping -c 1 -W 1 -n $GATEWAY & > /dev/null; do
2019-10-02 19:13:44 +00:00
printf .
done
2019-10-02 19:26:15 +00:00
echo
2019-01-27 20:41:25 +00:00
echo " Stopping any apache web server"
2019-01-16 19:32:16 +00:00
sudo service apache2 stop >/dev/null 2>& 1
2019-01-27 20:41:25 +00:00
echo " Starting web server in a screen"
2019-01-27 14:28:16 +00:00
$screen_with_log smarthack-web.log -S smarthack-web -m -d ./fake-registration-server.py
2019-01-16 19:32:16 +00:00
echo " Starting Mosquitto in a screen"
2019-01-21 16:39:30 +00:00
sudo service mosquitto stop >/dev/null 2>& 1
2019-10-03 17:23:44 +00:00
sudo pkill mosquitto
2019-01-27 14:28:16 +00:00
$screen_with_log smarthack-mqtt.log -S smarthack-mqtt -m -d mosquitto -v
2019-09-18 19:38:11 +00:00
echo " Starting PSK frontend in a screen"
$screen_with_log smarthack-psk.log -S smarthack-psk -m -d ./psk-frontend.py -v
2019-01-16 19:32:16 +00:00
echo
2019-08-07 17:14:47 +00:00
REPLY = y
while [ [ $REPLY = ~ ^[ Yy] $ ] ] ; do
2019-01-16 19:32:16 +00:00
echo "======================================================"
echo
echo "IMPORTANT"
2019-01-27 20:41:25 +00:00
echo " 1. Connect any other device (a smartphone or something) to the WIFI $AP "
2019-01-16 19:32:16 +00:00
echo " This step is IMPORTANT otherwise the smartconfig will not work!"
2019-01-26 23:25:16 +00:00
echo "2. Put your IoT device in autoconfig/smartconfig/pairing mode (LED will blink fast). This is usually done by pressing and holding the primary button of the device"
2019-01-21 16:39:30 +00:00
echo " 3. Press ${ bold } ENTER ${ normal } to continue "
2019-01-16 19:32:16 +00:00
read x
2019-01-21 16:39:30 +00:00
echo ""
2019-01-16 19:32:16 +00:00
echo "======================================================"
2019-03-22 21:09:26 +00:00
2019-08-07 17:20:49 +00:00
echo "Starting smart config pairing procedure"
./smartconfig/main.py &
2019-03-22 21:09:26 +00:00
2019-10-02 19:13:44 +00:00
echo "Waiting for the device to install the intermediate firmware"
2019-01-16 19:32:16 +00:00
2019-08-07 21:10:30 +00:00
i = 60
2019-10-02 19:13:44 +00:00
while ! ping -c 1 -W 1 -n 10.42.42.42 & > /dev/null; do
printf .
2019-08-07 17:14:47 +00:00
if ( ( --i = = 0 ) ) ; then
echo
echo "Device did not appear with the intermediate firmware"
2019-10-03 17:17:46 +00:00
echo "Check the *.log files in the scripts folder"
2019-10-02 19:22:57 +00:00
pkill -f smartconfig/main.py && echo "Stopping smart config"
2019-08-07 19:34:23 +00:00
read -p "Do you want to flash another device? [y/N] " -n 1 -r
echo
2019-08-07 17:14:47 +00:00
continue 2
fi
2019-01-16 19:32:16 +00:00
done
echo
echo "IoT-device is online with ip 10.42.42.42"
2019-08-07 17:20:49 +00:00
2019-10-02 19:22:57 +00:00
pkill -f smartconfig/main.py && echo "Stopping smart config"
2019-08-07 17:20:49 +00:00
2019-01-16 19:32:16 +00:00
echo "Fetching firmware backup"
sleep 2
2019-08-07 20:54:35 +00:00
timestamp = ` date +%Y%m%d_%H%M%S`
mkdir -p " ../backups/ $timestamp "
pushd " ../backups/ $timestamp " >/dev/null
2019-03-22 21:09:26 +00:00
curl -JO http://10.42.42.42/backup
2019-01-16 19:32:16 +00:00
echo "======================================================"
echo "Getting Info from IoT-device"
2019-10-03 17:05:38 +00:00
curl -s http://10.42.42.42 | tee device-info.txt
2019-08-07 20:54:35 +00:00
popd >/dev/null
2019-01-16 19:32:16 +00:00
echo "======================================================"
2019-01-18 16:26:16 +00:00
echo "Please make sure to note the correct SPI flash mode!"
2019-01-21 13:00:17 +00:00
echo "Installing an alternative firmware with the wrong flash mode will leave the ESP unable to boot!"
2019-01-16 19:32:16 +00:00
echo
echo "Next steps:"
echo "1. To go back to the orginal software"
echo " # curl http://10.42.42.42/undo"
echo
echo "2. Be sure the conversion software runs in user2"
echo " # curl http://10.42.42.42/flash2"
echo
echo "3. Flash a third party firmware to the device"
2019-01-21 13:00:17 +00:00
echo "BE SURE THE FIRMWARE FITS THE DEVICE AND USES THE CORRECT FLASH MODE!"
2019-01-16 19:32:16 +00:00
echo "MAXIMUM SIZE IS 512KB"
echo "put or link it to ./files/thirdparty.bin"
2019-03-20 23:37:03 +00:00
echo "A basic build of Sonoff-Tasmota v6.5.0 is already included in this repository."
2019-01-16 19:32:16 +00:00
echo " # curl http://10.42.42.42/flash3"
2019-10-10 14:01:25 +00:00
echo "If you want to flash the included ESPurna 1.13.5 image use this command:"
echo " # curl http://10.42.42.42/flash3?url=http://10.42.42.1/files/espurna-base.bin"
2019-01-22 13:26:52 +00:00
echo "Alternatively let the device download and flash a file via HTTP:"
2019-03-31 19:40:29 +00:00
echo " # curl http://10.42.42.42/flash3?url=http://10.42.42.1/files/thirdparty.bin"
2019-01-16 19:32:16 +00:00
echo
echo "HAVE FUN!"
2019-08-07 17:14:47 +00:00
echo "======================================================"
read -p "Do you want to flash another device? [y/N] " -n 1 -r
echo
done
echo "Exiting..."
2019-01-16 19:32:16 +00:00
2019-08-07 17:14:47 +00:00
popd >/dev/null
2019-01-16 19:32:16 +00:00