Skip to content

Commit

Permalink
Merge pull request #1137 from ct-Open-Source/development
Browse files Browse the repository at this point in the history
Release v2.4.6
  • Loading branch information
kueblc authored Sep 6, 2024
2 parents 61ba060 + f2e9942 commit a34b2c9
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 57 deletions.
6 changes: 6 additions & 0 deletions .env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Attention: "host" means your computer where you are running docker on

WLAN=wlan0 #must match the name of your wlan-interface on your host, you may find it with ifconfig
AP=vtrust-flash #the name of the created AP, can be anything you want
GATEWAY=10.42.42.1 #gateway address, leave it here
LOCALBACKUPDIR=./data/backups #location on your host where you want to store backuos of the old firmware & logs
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ node_modules/
device-info.txt
scripts/smartconfig/package-lock.json

# firmware backups directory
# firmware backups directory and data-file
backups/
data

# flag files
eula_accepted
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM phusion/baseimage:master
FROM alpine:3.13

RUN apt-get update && apt-get install -y sudo iproute2 iputils-ping
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

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

COPY docker/bin /usr/bin/

COPY . /usr/bin/tuya-convert

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

RUN mkdir -p /etc/service/tuya && cd /etc/service/tuya && ln -s /usr/bin/config.sh run
ENTRYPOINT ["tuya-start"]
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These scripts were tested in
* a Raspberry Pi 3B / 3B+ Raspberry Pi OS Buster (previously called Raspbian) and its internal Wifi chip
* a Raspberry Pi 3B+ + USB-WIFI with an image from [here](https://www.offensive-security.com/kali-linux-arm-images/)
* Ubuntu 18.04.3 64Bit in VirtualBox on Win10 with a cheap RTL8188CU Wifi Adapter connected to the VM
* Ubuntu Mate 18.04.5 32bit in VirtualBox on Win 10 with cheap Ralink 802.11n WLAN (MediaTek RT5370) WiFi Adapter connected to VM

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.

Expand Down Expand Up @@ -83,26 +84,24 @@ Requirements:
* docker is installed
* docker-compose is installed

Create docker image:
Preparations:
* git clone https://github.com/ct-Open-Source/tuya-convert
* cd tuya-convert
* docker build -t tuya:latest .

Setup docker-compose:
* copy docker/docker-compose.sample.yml to a new folder you created, the file should be named docker-compose.yml
* you may adjust this docker-compose.yml, if necessary:
* environment-variables may be different, for example network-adapter may be different from wlan0
* adjust the volume folder, where you want your backups stored

Run the image:
* go into the folder you copied docker-compose.yml
* docker-compose up -d
* docker-compose exec tuya start
* tuya-convert now starts within docker

Stop the image:
* docker-compose exec tuya stop
* docker-compose down
* if you have already cloned this repo just cd into the directory and execute `git pull`
* cp .env-template .env
* adjust the created .env-file, it contains usage information as comments

Building and running your container:
* `docker-compose build && docker-compose run --rm tuya`
* This directly starts into tuya. If you press ctrl+break or exit tuya after flashing, your container is closed and deleted

Troubleshooting:
* 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
* 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`
* 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`.
* 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 ...
* 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.
* 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)

## CONTRIBUTING

Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
services:
tuya:
build: .
privileged: true
network_mode: "host"
environment:
WLAN: ${WLAN}
AP: ${AP}
GATEWAY: ${GATEWAY}
volumes:
- $LOCALBACKUPDIR:/usr/bin/tuya-convert/backups
File renamed without changes.
2 changes: 0 additions & 2 deletions docker/bin/stop

This file was deleted.

2 changes: 1 addition & 1 deletion docker/bin/start → docker/bin/tuya-start
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
cd /usr/bin/tuya-convert
config-tuya.sh
./start_flash.sh
12 changes: 0 additions & 12 deletions docker/docker-compose.sample.yml

This file was deleted.

36 changes: 31 additions & 5 deletions install_prereq.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail

set -e
debianInstall() {
sudo apt-get update
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
sudo python3 -m pip install --user --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
}

sudo apt-get update
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
archInstall() {
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
sudo python -m pip install --user --upgrade git+https://github.com/drbild/sslpsk.git
}

sudo -H python3 -m pip install --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
if [[ -e /etc/os-release ]]; then
source /etc/os-release
else
echo "/etc/os-release not found! Assuming debian-based system, but this will likely fail!"
ID=debian
fi

if [[ ${ID} == 'debian' ]] || [[ ${ID_LIKE-} == 'debian' ]]; then
debianInstall
elif [[ ${ID} == 'arch' ]] || [[ ${ID_LIKE-} == 'arch' ]]; then
archInstall
else
if [[ -n ${ID_LIKE-} ]]; then
printID="${ID}/${ID_LIKE}"
else
printID="${ID}"
fi
echo "/etc/os-release found but distribution ${printID} is not explicitly supported. Assuming debian-based system, but this will likely fail!"
debianInstall
fi

echo "Ready to start upgrade"
2 changes: 2 additions & 0 deletions scripts/mosquitto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allow_anonymous true
listener 1883
21 changes: 21 additions & 0 deletions scripts/old_screen_with_log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Run screen with a custom .screenrc that defines the name of "logfile"

screen_minor=${1}
screen_logfile_name=${2}
screen_other_options=${@:3}

if [ "$screen_minor" -gt 5 ]; then
echo "Info: you have the modern enough version" \
"to use the \"-Logfile\" flag of \"screen\""
elif [ "$screen_minor" -eq 5 ]; then
screen_with_log="sudo screen -L"
else
screen_with_log="sudo screen -L -t"
fi

echo "logfile ${screen_logfile_name}" > ${screen_logfile_name}.screenrc

${screen_with_log} ${screen_logfile_name} \
-c ${screen_logfile_name}.screenrc ${screen_other_options}

rm ${screen_logfile_name}.screenrc
1 change: 1 addition & 0 deletions scripts/oui/nonesp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
D4A651
DC446D
E078A3
CC8CBF
2 changes: 1 addition & 1 deletion scripts/psk-frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def new_client(self, s1):
self.sessions.append((ssl_sock, s2))
except ssl.SSLError as e:
print("could not establish sslpsk socket:", e)
if "NO_SHARED_CIPHER" in e.reason or "WRONG_VERSION_NUMBER" in e.reason or "WRONG_SSL_VERSION" in e.reason:
if e and ("NO_SHARED_CIPHER" in e.reason or "WRONG_VERSION_NUMBER" in e.reason or "WRONG_SSL_VERSION" in e.reason):
print("don't panic this is probably just your phone!")
except Exception as e:
print(e)
Expand Down
17 changes: 14 additions & 3 deletions scripts/setup_ap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ setup () {

if test -d /etc/NetworkManager; then
echo "Stopping NetworkManager..."
sudo service network-manager stop
if ! sudo systemctl stop network-manager 2>/dev/null
then
if ! sudo systemctl stop NetworkManager 2>/dev/null
then
echo "** Failed to stop NetworkManager, AP may not work! **"
fi
fi
fi

echo "Configuring AP interface..."
Expand Down Expand Up @@ -62,11 +68,16 @@ cleanup () {

if test -d /etc/NetworkManager; then
echo "Restarting NetworkManager..."
sudo service network-manager restart
if ! sudo systemctl restart network-manager 2>/dev/null
then
if ! sudo systemctl restart NetworkManager 2>/dev/null
then
echo "** Failed to restart NetworkManager: network may not be functional! **"
fi
fi
fi
}

version_check
trap cleanup EXIT
setup

9 changes: 8 additions & 1 deletion scripts/setup_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ check_port () {
port="$2"
reason="$3"
echo -n "Checking ${protocol^^} port $port... "
process_pid=$(sudo ss -lnp -A "$protocol" "sport = :$port" | grep -Po "(?<=pid=)(\d+)" | head -n1)
ss_output=$(sudo ss -lnp -A "$protocol" "sport = :$port")
process_pid=$(echo "$ss_output" | grep -Po "(?<=pid=)(\d+)" | head -n1)
if [ -n "$process_pid" ]; then
process_name=$(ps -p "$process_pid" -o comm=)
echo "Occupied by $process_name with PID $process_pid."
Expand Down Expand Up @@ -98,6 +99,12 @@ check_port () {
sleep 1
fi
else
if [ $(echo "$ss_output" | wc -l) -gt 1 ]; then
echo "Occupied by unknown process."
echo "Port $port is needed to $reason"
echo "Aborting due to occupied port"
exit 1
fi
echo "Available."
fi
}
Expand Down
14 changes: 6 additions & 8 deletions start_flash.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
bold=$(tput bold)
normal=$(tput sgr0)
. ./config.txt
Expand All @@ -10,10 +10,8 @@ setup () {
screen_minor=$(screen --version | cut -d . -f 2)
if [ "$screen_minor" -gt 5 ]; then
screen_with_log="sudo screen -L -Logfile"
elif [ "$screen_minor" -eq 5 ]; then
screen_with_log="sudo screen -L"
else
screen_with_log="sudo screen -L -t"
screen_with_log="./old_screen_with_log.sh ${screen_minor}"
fi
echo "======================================================"
echo -n " Starting AP in a screen"
Expand All @@ -26,7 +24,7 @@ setup () {
echo " Starting web server in a screen"
$screen_with_log smarthack-web.log -S smarthack-web -m -d ./fake-registration-server.py
echo " Starting Mosquitto in a screen"
$screen_with_log smarthack-mqtt.log -S smarthack-mqtt -m -d mosquitto -v
$screen_with_log smarthack-mqtt.log -S smarthack-mqtt -m -d mosquitto -v -c $PWD/mosquitto.conf
echo " Starting PSK frontend in a screen"
$screen_with_log smarthack-psk.log -S smarthack-psk -m -d ./psk-frontend.py -v
echo " Starting Tuya Discovery in a screen"
Expand Down Expand Up @@ -75,7 +73,7 @@ while true; do
# The intermediate firmware will request 10.42.42.42
# Do NOT change this address!!!
# It will NOT make it install and will break this script
while ! ping -c 1 -W 1 -n 10.42.42.42 &> /dev/null; do
while ! ping -c 1 -W 1 -n 10.42.42.42 -I 10.42.42.1 &> /dev/null; do
printf .
if (( --i == 0 )); then
echo
Expand Down Expand Up @@ -121,8 +119,8 @@ while true; do
echo "Ready to flash third party firmware!"
echo
echo "For your convenience, the following firmware images are already included in this repository:"
echo " Tasmota v8.1.0.2 (wifiman)"
echo " ESPurna 1.13.5 (base)"
echo " Tasmota v9.2.0 (wifiman)"
echo " ESPurna 1.5 (base)"
echo
echo "You can also provide your own image by placing it in the /files directory"
echo "Please ensure the firmware fits the device and includes the bootloader"
Expand Down

0 comments on commit a34b2c9

Please sign in to comment.