Skip to content

Commit a34b2c9

Browse files
authored
Merge pull request #1137 from ct-Open-Source/development
Release v2.4.6
2 parents 61ba060 + f2e9942 commit a34b2c9

17 files changed

+127
-57
lines changed

.env-template

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Attention: "host" means your computer where you are running docker on
2+
3+
WLAN=wlan0 #must match the name of your wlan-interface on your host, you may find it with ifconfig
4+
AP=vtrust-flash #the name of the created AP, can be anything you want
5+
GATEWAY=10.42.42.1 #gateway address, leave it here
6+
LOCALBACKUPDIR=./data/backups #location on your host where you want to store backuos of the old firmware & logs

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ node_modules/
109109
device-info.txt
110110
scripts/smartconfig/package-lock.json
111111

112-
# firmware backups directory
112+
# firmware backups directory and data-file
113113
backups/
114+
data
114115

115116
# flag files
116117
eula_accepted

Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
FROM phusion/baseimage:master
1+
FROM alpine:3.13
22

3-
RUN apt-get update && apt-get install -y sudo iproute2 iputils-ping
3+
RUN apk add --update bash git iw dnsmasq hostapd screen curl py3-pip py3-wheel python3-dev mosquitto haveged net-tools openssl openssl-dev gcc musl-dev linux-headers sudo coreutils grep iproute2 ncurses
44

5-
RUN echo '* libraries/restart-without-asking boolean true' | sudo debconf-set-selections
5+
RUN python3 -m pip install --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
66

77
COPY docker/bin /usr/bin/
88

99
COPY . /usr/bin/tuya-convert
1010

11-
RUN cd /usr/bin/tuya-convert && ./install_prereq.sh
11+
WORKDIR "/usr/bin/tuya-convert"
1212

13-
RUN mkdir -p /etc/service/tuya && cd /etc/service/tuya && ln -s /usr/bin/config.sh run
13+
ENTRYPOINT ["tuya-start"]

README.md

+17-18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ These scripts were tested in
3434
* a Raspberry Pi 3B / 3B+ Raspberry Pi OS Buster (previously called Raspbian) and its internal Wifi chip
3535
* a Raspberry Pi 3B+ + USB-WIFI with an image from [here](https://www.offensive-security.com/kali-linux-arm-images/)
3636
* Ubuntu 18.04.3 64Bit in VirtualBox on Win10 with a cheap RTL8188CU Wifi Adapter connected to the VM
37+
* Ubuntu Mate 18.04.5 32bit in VirtualBox on Win 10 with cheap Ralink 802.11n WLAN (MediaTek RT5370) WiFi Adapter connected to VM
3738

3839
Any Linux with a Wifi adapter which can act as an Access Point should also work. Please note that we have tested the Raspberry Pi with clean installations only. If you use your Raspberry Pi for anything else, we recommend using another SD card with a clean installation.
3940

@@ -83,26 +84,24 @@ Requirements:
8384
* docker is installed
8485
* docker-compose is installed
8586

86-
Create docker image:
87+
Preparations:
8788
* git clone https://github.com/ct-Open-Source/tuya-convert
8889
* cd tuya-convert
89-
* docker build -t tuya:latest .
90-
91-
Setup docker-compose:
92-
* copy docker/docker-compose.sample.yml to a new folder you created, the file should be named docker-compose.yml
93-
* you may adjust this docker-compose.yml, if necessary:
94-
* environment-variables may be different, for example network-adapter may be different from wlan0
95-
* adjust the volume folder, where you want your backups stored
96-
97-
Run the image:
98-
* go into the folder you copied docker-compose.yml
99-
* docker-compose up -d
100-
* docker-compose exec tuya start
101-
* tuya-convert now starts within docker
102-
103-
Stop the image:
104-
* docker-compose exec tuya stop
105-
* docker-compose down
90+
* if you have already cloned this repo just cd into the directory and execute `git pull`
91+
* cp .env-template .env
92+
* adjust the created .env-file, it contains usage information as comments
93+
94+
Building and running your container:
95+
* `docker-compose build && docker-compose run --rm tuya`
96+
* This directly starts into tuya. If you press ctrl+break or exit tuya after flashing, your container is closed and deleted
97+
98+
Troubleshooting:
99+
* Q: Where are my logs after flashing? A: The folder can be adjusted in .env with LOCALBACKUPDIR, the path here may be relative or absolute
100+
* Q: I don't want that my container is deleted after running tuya, I need this for troubleshooting! How do I accomplish this? A: Just remove --rm from `docker-compose run --rm tuya`
101+
* Q: I want to start the container, but instead of starting tuya immediately I want to get into bash. Is this possible? A: Yes just start the container with `docker-compose run --entrypoint bash tuya`.
102+
* Q: I want to rebuild my docker-image, even if there are no changes. Is this possible? A: Just start `docker-compose build --no-cache` instead of `docker-compose build`! Don't do this all the time, this is a time consuming process ...
103+
* Q: I can't connect to my USB, PCI, ... network card. How do I get this working? A: You may have an error in your .env-File. The WLAN-variable should reflect the name of your network interface on your host. Execute ifconfig and look through your interfaces.
104+
* Q: I can't get an IP-address and or connection on my phone, what's the problem? A: You may look into smarthack-wifi.log (location is set in .env with LOCALBACKUPDIR) or possible stop your firewall (e.g. NixOS seems to have a problem here). It may be a problem with a wrongly set network interface (see previous question)
106105

107106
## CONTRIBUTING
108107

docker-compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3'
2+
services:
3+
tuya:
4+
build: .
5+
privileged: true
6+
network_mode: "host"
7+
environment:
8+
WLAN: ${WLAN}
9+
AP: ${AP}
10+
GATEWAY: ${GATEWAY}
11+
volumes:
12+
- $LOCALBACKUPDIR:/usr/bin/tuya-convert/backups
File renamed without changes.

docker/bin/stop

-2
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
2-
cd /usr/bin/tuya-convert
2+
config-tuya.sh
33
./start_flash.sh

docker/docker-compose.sample.yml

-12
This file was deleted.

install_prereq.sh

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
set -euo pipefail
23

3-
set -e
4+
debianInstall() {
5+
sudo apt-get update
6+
sudo apt-get install -y git iw dnsmasq rfkill hostapd screen curl build-essential python3-pip python3-setuptools python3-wheel python3-dev mosquitto haveged net-tools libssl-dev iproute2 iputils-ping
7+
sudo python3 -m pip install --user --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
8+
}
49

5-
sudo apt-get update
6-
sudo apt-get install -y git iw dnsmasq rfkill hostapd screen curl build-essential python3-pip python3-setuptools python3-wheel python3-dev mosquitto haveged net-tools libssl-dev
10+
archInstall() {
11+
sudo pacman -S --needed git iw dnsmasq hostapd screen curl python-pip python-wheel python-pycryptodomex python-paho-mqtt python-tornado mosquitto haveged net-tools openssl
12+
sudo python -m pip install --user --upgrade git+https://github.com/drbild/sslpsk.git
13+
}
714

8-
sudo -H python3 -m pip install --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
15+
if [[ -e /etc/os-release ]]; then
16+
source /etc/os-release
17+
else
18+
echo "/etc/os-release not found! Assuming debian-based system, but this will likely fail!"
19+
ID=debian
20+
fi
21+
22+
if [[ ${ID} == 'debian' ]] || [[ ${ID_LIKE-} == 'debian' ]]; then
23+
debianInstall
24+
elif [[ ${ID} == 'arch' ]] || [[ ${ID_LIKE-} == 'arch' ]]; then
25+
archInstall
26+
else
27+
if [[ -n ${ID_LIKE-} ]]; then
28+
printID="${ID}/${ID_LIKE}"
29+
else
30+
printID="${ID}"
31+
fi
32+
echo "/etc/os-release found but distribution ${printID} is not explicitly supported. Assuming debian-based system, but this will likely fail!"
33+
debianInstall
34+
fi
935

1036
echo "Ready to start upgrade"

scripts/mosquitto.conf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
allow_anonymous true
2+
listener 1883

scripts/old_screen_with_log.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Run screen with a custom .screenrc that defines the name of "logfile"
2+
3+
screen_minor=${1}
4+
screen_logfile_name=${2}
5+
screen_other_options=${@:3}
6+
7+
if [ "$screen_minor" -gt 5 ]; then
8+
echo "Info: you have the modern enough version" \
9+
"to use the \"-Logfile\" flag of \"screen\""
10+
elif [ "$screen_minor" -eq 5 ]; then
11+
screen_with_log="sudo screen -L"
12+
else
13+
screen_with_log="sudo screen -L -t"
14+
fi
15+
16+
echo "logfile ${screen_logfile_name}" > ${screen_logfile_name}.screenrc
17+
18+
${screen_with_log} ${screen_logfile_name} \
19+
-c ${screen_logfile_name}.screenrc ${screen_other_options}
20+
21+
rm ${screen_logfile_name}.screenrc

scripts/oui/nonesp.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
D4A651
1616
DC446D
1717
E078A3
18+
CC8CBF

scripts/psk-frontend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def new_client(self, s1):
6969
self.sessions.append((ssl_sock, s2))
7070
except ssl.SSLError as e:
7171
print("could not establish sslpsk socket:", e)
72-
if "NO_SHARED_CIPHER" in e.reason or "WRONG_VERSION_NUMBER" in e.reason or "WRONG_SSL_VERSION" in e.reason:
72+
if e and ("NO_SHARED_CIPHER" in e.reason or "WRONG_VERSION_NUMBER" in e.reason or "WRONG_SSL_VERSION" in e.reason):
7373
print("don't panic this is probably just your phone!")
7474
except Exception as e:
7575
print(e)

scripts/setup_ap.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ setup () {
2626

2727
if test -d /etc/NetworkManager; then
2828
echo "Stopping NetworkManager..."
29-
sudo service network-manager stop
29+
if ! sudo systemctl stop network-manager 2>/dev/null
30+
then
31+
if ! sudo systemctl stop NetworkManager 2>/dev/null
32+
then
33+
echo "** Failed to stop NetworkManager, AP may not work! **"
34+
fi
35+
fi
3036
fi
3137

3238
echo "Configuring AP interface..."
@@ -62,11 +68,16 @@ cleanup () {
6268

6369
if test -d /etc/NetworkManager; then
6470
echo "Restarting NetworkManager..."
65-
sudo service network-manager restart
71+
if ! sudo systemctl restart network-manager 2>/dev/null
72+
then
73+
if ! sudo systemctl restart NetworkManager 2>/dev/null
74+
then
75+
echo "** Failed to restart NetworkManager: network may not be functional! **"
76+
fi
77+
fi
6678
fi
6779
}
6880

6981
version_check
7082
trap cleanup EXIT
7183
setup
72-

scripts/setup_checks.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ check_port () {
6767
port="$2"
6868
reason="$3"
6969
echo -n "Checking ${protocol^^} port $port... "
70-
process_pid=$(sudo ss -lnp -A "$protocol" "sport = :$port" | grep -Po "(?<=pid=)(\d+)" | head -n1)
70+
ss_output=$(sudo ss -lnp -A "$protocol" "sport = :$port")
71+
process_pid=$(echo "$ss_output" | grep -Po "(?<=pid=)(\d+)" | head -n1)
7172
if [ -n "$process_pid" ]; then
7273
process_name=$(ps -p "$process_pid" -o comm=)
7374
echo "Occupied by $process_name with PID $process_pid."
@@ -98,6 +99,12 @@ check_port () {
9899
sleep 1
99100
fi
100101
else
102+
if [ $(echo "$ss_output" | wc -l) -gt 1 ]; then
103+
echo "Occupied by unknown process."
104+
echo "Port $port is needed to $reason"
105+
echo "Aborting due to occupied port"
106+
exit 1
107+
fi
101108
echo "Available."
102109
fi
103110
}

start_flash.sh

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
bold=$(tput bold)
33
normal=$(tput sgr0)
44
. ./config.txt
@@ -10,10 +10,8 @@ setup () {
1010
screen_minor=$(screen --version | cut -d . -f 2)
1111
if [ "$screen_minor" -gt 5 ]; then
1212
screen_with_log="sudo screen -L -Logfile"
13-
elif [ "$screen_minor" -eq 5 ]; then
14-
screen_with_log="sudo screen -L"
1513
else
16-
screen_with_log="sudo screen -L -t"
14+
screen_with_log="./old_screen_with_log.sh ${screen_minor}"
1715
fi
1816
echo "======================================================"
1917
echo -n " Starting AP in a screen"
@@ -26,7 +24,7 @@ setup () {
2624
echo " Starting web server in a screen"
2725
$screen_with_log smarthack-web.log -S smarthack-web -m -d ./fake-registration-server.py
2826
echo " Starting Mosquitto in a screen"
29-
$screen_with_log smarthack-mqtt.log -S smarthack-mqtt -m -d mosquitto -v
27+
$screen_with_log smarthack-mqtt.log -S smarthack-mqtt -m -d mosquitto -v -c $PWD/mosquitto.conf
3028
echo " Starting PSK frontend in a screen"
3129
$screen_with_log smarthack-psk.log -S smarthack-psk -m -d ./psk-frontend.py -v
3230
echo " Starting Tuya Discovery in a screen"
@@ -75,7 +73,7 @@ while true; do
7573
# The intermediate firmware will request 10.42.42.42
7674
# Do NOT change this address!!!
7775
# It will NOT make it install and will break this script
78-
while ! ping -c 1 -W 1 -n 10.42.42.42 &> /dev/null; do
76+
while ! ping -c 1 -W 1 -n 10.42.42.42 -I 10.42.42.1 &> /dev/null; do
7977
printf .
8078
if (( --i == 0 )); then
8179
echo
@@ -121,8 +119,8 @@ while true; do
121119
echo "Ready to flash third party firmware!"
122120
echo
123121
echo "For your convenience, the following firmware images are already included in this repository:"
124-
echo " Tasmota v8.1.0.2 (wifiman)"
125-
echo " ESPurna 1.13.5 (base)"
122+
echo " Tasmota v9.2.0 (wifiman)"
123+
echo " ESPurna 1.5 (base)"
126124
echo
127125
echo "You can also provide your own image by placing it in the /files directory"
128126
echo "Please ensure the firmware fits the device and includes the bootloader"

0 commit comments

Comments
 (0)