diff --git a/.build/Dockerfile b/.build/Dockerfile index 88321dba5..86bf7f541 100644 --- a/.build/Dockerfile +++ b/.build/Dockerfile @@ -14,7 +14,7 @@ RUN chmod +x ./select.sh && \ # ============================ Actual image from here ==================== FROM debian:stable-slim -WORKDIR /opt/hue-emulator +WORKDIR /diyhue ARG TARGETPLATFORM COPY requirements.txt ./ diff --git a/.travis.yml b/.build/archive/.travis.yml similarity index 100% rename from .travis.yml rename to .build/archive/.travis.yml diff --git a/.build/startup.sh b/.build/archive/startup.sh similarity index 100% rename from .build/startup.sh rename to .build/archive/startup.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index f449b2520..a3fcea7fa 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,5 @@ FROM debian:stable-slim as prod -WORKDIR /opt/hue-emulator +WORKDIR /diyhue COPY requirements.txt /tmp/pip-tmp/ diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index be689d66a..ac2986100 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -28,7 +28,7 @@ services: volumes: # Update this to wherever you want VS Code to mount the folder of your project - ..:/workspace - - ../BridgeEmulator:/opt/hue-emulator + - ../../src/core:/diyhue # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details. # - /var/run/docker.sock:/var/run/docker.sock diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index a002bfbcc..26c7b9f2d 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -71,7 +71,7 @@ jobs: - name: Run docker image if: success() run: | - docker run -d --name diyhue --network=host -v /mnt/hue-emulator/config:/opt/hue-emulator/config -e MAC=b8:27:eb:d4:dc:11 -e IP=192.168.1.123 -e DECONZ=192.168.1.111 -e IP_RANGE=5,6 -e DEBUG=true diyhue/diyhue:ci + docker run -d --name diyhue --network=host -v /mnt/hue-emulator/config:/config -e MAC=b8:27:eb:d4:dc:11 -e IP=192.168.1.123 -e DECONZ=192.168.1.111 -e IP_RANGE=5,6 -e DEBUG=true diyhue/diyhue:ci sleep 15 docker logs diyhue diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 188788782..af1f59c82 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -24,7 +24,7 @@ jobs: - name: Run docker image run: | - docker run -d --name diyHue --network=host -v /mnt/hue-emulator/config:/opt/hue-emulator/config -e MAC=b8:27:eb:d4:dc:11 -e IP=192.168.1.123 -e DECONZ=192.168.1.111 -e IP_RANGE=5,6 -e DEBUG=true diyhue/core:ci + docker run -d --name diyHue --network=host -v /mnt/hue-emulator/config:/config -e MAC=b8:27:eb:d4:dc:11 -e IP=192.168.1.123 -e DECONZ=192.168.1.111 -e IP_RANGE=5,6 -e DEBUG=true diyhue/core:ci sleep 15 docker logs diyHue diff --git a/.idea/docker/Dockerfile b/.idea/docker/Dockerfile index bb7eaeee9..1aaeed507 100644 --- a/.idea/docker/Dockerfile +++ b/.idea/docker/Dockerfile @@ -1,5 +1,5 @@ FROM debian:stable-slim as prod -WORKDIR /opt/hue-emulator +WORKDIR /diyhue COPY requirements.txt /tmp/pip-tmp/ diff --git a/.idea/docker/docker-compose.yml b/.idea/docker/docker-compose.yml index ff3ae1ba7..ead68793a 100644 --- a/.idea/docker/docker-compose.yml +++ b/.idea/docker/docker-compose.yml @@ -11,7 +11,7 @@ services: - disableonlinediscover=true - DEBUG=true - MAC=00:00:00:00:00:00 - - IP=192.168.1.1 + - IP=192.168.1.106 volumes: - ../../src/core:/diyhue - ../../config:/config diff --git a/.vscode/launch.json b/.vscode/launch.json index 12bcfe450..087e2dfff 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Launch diyHue", "type": "python", "request": "launch", - "program": "/opt/hue-emulator/HueEmulator3.py", + "program": "/diyhue/main.py", "args" : [], "pythonPath": "/usr/bin/python3", "console": "integratedTerminal" diff --git a/Installers/OpenWrt/Readme_OpenWrt.md b/Installers/OpenWrt/Readme_OpenWrt.md deleted file mode 100644 index c3465a055..000000000 --- a/Installers/OpenWrt/Readme_OpenWrt.md +++ /dev/null @@ -1,4 +0,0 @@ -opkg update -opkg install wget ca-bundle -cd /tmp && wget --no-check-certificate https://raw.githubusercontent.com/diyhue/diyHue/master/BridgeEmulator/easy_openwrt.sh -sh easy_openwrt.sh diff --git a/Installers/OpenWrt/compiler-entertainment-openwrt.sh b/Installers/OpenWrt/compiler-entertainment-openwrt.sh deleted file mode 100755 index 7b7e09b58..000000000 --- a/Installers/OpenWrt/compiler-entertainment-openwrt.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -arch=`uname -m` -export LC_ALL=C -export CC=gcc -echo -e "\033[32m Updating repository.\033[0m" -opkg update -wait -echo -e "\033[32m Installing dependencies.\033[0m" -opkg install gcc make automake ca-bundle git git-http nano nmap openssl-util curl unzip libustream-mbedtls -wait -echo -e "\033[32m Creating directories.\033[0m" -mkdir /opt -mkdir /opt/tmp -mkdir /opt/hue-emulator -wait -echo -e "\033[32m Download mbedtls to compile binary entertainment.\033[0m" -wait -cd /opt/hue-emulator -wget --no-check-certificate https://github.com/ARMmbed/mbedtls/archive/1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482.zip -wait -unzip 1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482 -wait -mv mbedtls-1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482 mbedtls -rm -Rf 1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482.zip -cd /opt/hue-emulator/mbedtls -echo -e "\033[32m Download entertainment source file to compile binary.\033[0m" -wget --no-check-certificate https://raw.githubusercontent.com/diyhue/diyHue/master/BridgeEmulator/ssl_server2_diyhue.c -wait -echo -e "\033[32m Compiling.\033[0m" -make no_test -wait -gcc -I../mbedtls/include ssl_server2_diyhue.c -o ssl_server2_diyhue -L../mbedtls/library -lmbedtls -lmbedx509 -lmbedcrypto -wait -cp /opt/hue-emulator/mbedtls/ssl_server2_diyhue /opt/hue-emulator/entertain-srv-$arch -wait -cd /opt/hue-emulator -rm -Rf /opt/hue-emulator/mbedtls -wait -echo -e "\033[32m Compiled binary for: $arch.\033[0m" -echo -e "\033[32m Uploading binary $arch to remote server.\033[0m" -curl --upload-file /opt/hue-emulator/entertain-srv-$arch https://transfer.sh/entertain-srv-$arch -rm -Rf /opt/hue-emulator/ -rm -Rf /opt/tmp -rm -Rf /opt/ -wait -exit 0 diff --git a/Installers/OpenWrt/easy_openwrt.sh b/Installers/OpenWrt/easy_openwrt.sh deleted file mode 100644 index d7c377a37..000000000 --- a/Installers/OpenWrt/easy_openwrt.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash - -echo -e "\033[32m Deleting folders.\033[0m" -rm -Rf /opt/hue-emulator -echo -e "\033[32m Updating repository.\033[0m" -opkg update -wait -echo -e "\033[32m Installing dependencies.\033[0m" -opkg install ca-bundle git git-http nano nmap python3 python3-pip python3-setuptools -wait -opkg install curl coap-client unzip coreutils-nohup openssl-util -wait -opkg install python3-requests python3-astral python3-pytz python3-paho-mqtt -wait -echo -e "\033[32m Updating python3-pip.\033[0m" -python3 -m pip install --upgrade pip -wait -echo -e "\033[32m Installing pip dependencies.\033[0m" -python3 -m pip install ws4py -wait -echo -e "\033[32m Creating directories.\033[0m" -mkdir /opt -mkdir /opt/tmp -mkdir /opt/hue-emulator -cd /opt/tmp -echo -e "\033[32m Downloading diyHue.\033[0m" -wget -q https://github.com/diyhue/diyHue/archive/master.zip -O diyHue.zip -echo -e "\033[32m Unzip diyHue.\033[0m" -unzip -q -o diyHue.zip -wait -echo -e "\033[32m Copying unzip files to directories.\033[0m" -cd /opt/tmp/diyHue-master/BridgeEmulator -cp HueEmulator3.py updater /opt/hue-emulator/ -cp default-config.json /opt/hue-emulator/config.json -cp default-config.json /opt/hue-emulator/default-config.json -cp -r configManager debug devices functions logManager protocols responseBuilder web-ui webServer /opt/hue-emulator/ -echo -e "\033[32m Detecting processor architecture.\033[0m" -wait -arch=`uname -m` -wait -echo -e "\033[32m Architecture detected: $arch\033[0m" -echo -e "\033[32m Copying binary $arch for Openwrt.\033[0m" -cp ../Installers/OpenWrt/entertainment-openwrt-$arch /opt/hue-emulator/entertain-srv -echo -e "\033[32m Copying custom network function for openwrt.\033[0m" -rm -Rf /opt/hue-emulator/functions/network.py -mv ../Installers/OpenWrt/network_OpenWrt.py /opt/hue-emulator/functions/network.py -wait -echo -e "\033[32m Copying startup service.\033[0m" -cp ../Installers/OpenWrt/hueemulatorWrt-service /etc/init.d/ -echo -e "\033[32m Generating certificate.\033[0m" -#mac=`cat /sys/class/net/$(ip route get 8.8.8.8 | sed -n 's/.* dev \([^ ]*\).*/\1/p')/address` -mac=`cat /sys/class/net/br-lan/address` -curl "http://mariusmotea.go.ro:9002/gencert?mac=$mac" > /opt/hue-emulator/cert.pem -echo -e "\033[32m Changing permissions.\033[0m" -chmod +x /etc/init.d/hueemulatorWrt-service -chmod +x /opt/hue-emulator/HueEmulator3.py -chmod +x /opt/hue-emulator/debug -chmod +x /opt/hue-emulator/devics -chmod +x /opt/hue-emulator/functions -chmod +x /opt/hue-emulator/logManager -chmod +x /opt/hue-emulator/protocols -chmod +x /opt/hue-emulator/responseBuilder -chmod +x /opt/hue-emulator/webServer -chmod +x /opt/hue-emulator/updater -chmod +x /opt/hue-emulator/web-ui -chmod +x /opt/hue-emulator/config.json -chmod +x /opt/hue-emulator/default-config.json -chmod +x /opt/hue-emulator/entertain-srv -chmod +x /opt/hue-emulator/functions/network.py -chmod +x /opt/hue-emulator -echo -e "\033[32m Enable startup service.\033[0m" -/etc/init.d/hueemulatorWrt-service enable -wait -echo -e "\033[32m modify http port 80 to 82: list listen_http 0.0.0.0:82, list listen_http [::]: 82 and server.port = 82.\033[0m" -echo -e "\033[32m To save the changes you've made, press CTRL + O. To exit nano, press CTRL + X.\033[0m" -sleep 20s -nano /etc/config/uhttpd -wait -nano /etc/lighttpd/lighttpd.conf -echo -e "\033[32m Installation completed.\033[0m" -rm -Rf /opt/tmp -echo -e "\033[32m Restarting...\033[0m" -wait -reboot 10 -exit 0 diff --git a/Installers/OpenWrt/entertainment-openwrt-aarch64 b/Installers/OpenWrt/entertainment-openwrt-aarch64 deleted file mode 100755 index 6ed309a38..000000000 Binary files a/Installers/OpenWrt/entertainment-openwrt-aarch64 and /dev/null differ diff --git a/Installers/OpenWrt/entertainment-openwrt-armv7l b/Installers/OpenWrt/entertainment-openwrt-armv7l deleted file mode 100755 index cda44d1b9..000000000 Binary files a/Installers/OpenWrt/entertainment-openwrt-armv7l and /dev/null differ diff --git a/Installers/OpenWrt/entertainment-openwrt-i686 b/Installers/OpenWrt/entertainment-openwrt-i686 deleted file mode 100755 index 4416cdb3f..000000000 Binary files a/Installers/OpenWrt/entertainment-openwrt-i686 and /dev/null differ diff --git a/Installers/OpenWrt/entertainment-openwrt-mips b/Installers/OpenWrt/entertainment-openwrt-mips deleted file mode 100755 index 3d6478a56..000000000 Binary files a/Installers/OpenWrt/entertainment-openwrt-mips and /dev/null differ diff --git a/Installers/OpenWrt/entertainment-openwrt-x86_64 b/Installers/OpenWrt/entertainment-openwrt-x86_64 deleted file mode 100755 index 44d44643a..000000000 Binary files a/Installers/OpenWrt/entertainment-openwrt-x86_64 and /dev/null differ diff --git a/Installers/OpenWrt/hueemulatorWrt-service b/Installers/OpenWrt/hueemulatorWrt-service deleted file mode 100644 index 0aec5dbb7..000000000 --- a/Installers/OpenWrt/hueemulatorWrt-service +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh /etc/rc.common - -SCRIPT_NAME="HueEmulator3.py" -SCRIPT_PATH="/opt/hue-emulator" -SCRIPT_PARAMS="" -PID_FILE="/tmp/hue-emulator.pid" - -START=98 - -start() { - if [ -f "$PID_FILE" ] && kill -0 $(cat "$PID_FILE"); then - echo "$SCRIPT_NAME already running" - return 1 - fi - sleep 5 - . /etc/profile > /dev/null - nohup python3 $SCRIPT_PATH/$SCRIPT_NAME $SCRIPT_PARAMS >/dev/null 2>&1 & - echo $! > $PID_FILE - echo "Started $SCRIPT_NAME." -} - -stop() { - if [ ! -f "$PID_FILE" ] && ! kill -0 $(cat "$PID_FILE"); then - echo "$SCRIPT_NAME not running" - return 1 - fi - kill -2 $(cat $PID_FILE) - rm -f "$PID_FILE" - echo "Stopped $SCRIPT_NAME." -} - -restart() { - stop - start -} diff --git a/Installers/OpenWrt/install_openwrt.sh b/Installers/OpenWrt/install_openwrt.sh deleted file mode 100644 index 51f2b0db0..000000000 --- a/Installers/OpenWrt/install_openwrt.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash - -echo -e "\033[32m Updating repository.\033[0m" -opkg update -wait -echo -e "\033[32m Installing dependencies.\033[0m" -opkg install gcc make automake ca-bundle git git-http nano nmap python3 python3-pip python3-setuptools openssl-util curl unzip coap-client -wait -export LC_ALL=C -echo -e "\033[32m Creating directories.\033[0m" -mkdir /opt -mkdir /opt/tmp -mkdir /opt/hue-emulator -echo -e "\033[32m Updating python3-pip.\033[0m" -python3 -m pip install --upgrade pip -wait -echo -e "\033[32m Installing pip dependencies.\033[0m" -python3 -m pip install requests ws4py paho-mqtt -wait -cd /opt/tmp -echo -e "\033[32m Downloading diyHue.\033[0m" -git clone https://github.com/diyHue/diyHue.git -wait -echo -e "\033[32m Copying files to directories.\033[0m" -cd /opt/tmp/diyHue/BridgeEmulator -cp HueEmulator3.py ssl_server2_diyhue.c default-config.json updater /opt/hue-emulator/ -cp -r configManager debug devices functions logManager protocols responseBuilder web-ui webServer /opt/hue-emulator/ -cp -r default-config.json /opt/hue-emulator/config.json -echo -e "\033[32m Detecting processor architecture.\033[0m" -wait -arch=`uname -m` -wait -echo -e "\033[32m Architecture detected: $arch\033[0m" -echo -e "\033[32m Copying binary $arch for Openwrt.\033[0m" -cp ../Installers/OpenWrt/entertainment-openwrt-$arch /opt/hue-emulator/entertain-srv -echo -e "\033[32m Copying custom network function for openwrt.\033[0m" -rm -Rf /opt/hue-emulator/functions/network.py -mv ../Installers/OpenWrt/network_OpenWrt.py /opt/hue-emulator/functions/network.py -wait -cp ../Installers/OpenWrt/hueemulatorWrt-service /etc/init.d/ -echo -e "\033[32m Download mbedtls to compile binary entertainment.\033[0m" -wait -cd /opt/hue-emulator -export CC=gcc -wget https://github.com/ARMmbed/mbedtls/archive/1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482.zip -wait -unzip 1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482.zip -wait -cd mbedtls-1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482/ -wget https://raw.githubusercontent.com/diyhue/diyHue/master/BridgeEmulator/ssl_server2_diyhue.c -wait -make no_test -wait -gcc -I../mbedtls/include ssl_server2_diyhue.c -o ssl_server2_diyhue -L../mbedtls/library -lmbedtls -lmbedx509 -lmbedcrypto -wait -cp /opt/hue-emulator/mbedtls/ssl_server2_diyhue /opt/hue-emulator/entertain-srv -wait -cd /opt/hue-emulator -rm -Rf /opt/hue-emulator/mbedtls-1ab9b5714852c6810c0a0bfd8c3b5c60a9a15482 -wait -echo -e "\033[32m Creating certificate.\033[0m" -#mac=`cat /sys/class/net/$(ip route get 8.8.8.8 | sed -n 's/.* dev \([^ ]*\).*/\1/p')/address` -mac=`cat /sys/class/net/br-lan/address` -curl https://raw.githubusercontent.com/mariusmotea/diyHue/9ceed19b4211aa85a90fac9ea6d45cfeb746c9dd/BridgeEmulator/openssl.conf -o openssl.conf -wait -serial="${mac:0:2}${mac:3:2}${mac:6:2}fffe${mac:9:2}${mac:12:2}${mac:15:2}" -dec_serial=`python3 -c "print(int(\"$serial\", 16))"` -openssl req -new -days 3650 -config openssl.conf -nodes -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -pkeyopt ec_param_enc:named_curve -subj "/C=NL/O=Philips Hue/CN=$serial" -keyout private.key -out public.crt -set_serial $dec_serial -wait -touch /opt/hue-emulator/cert.pem -cat private.key > /opt/hue-emulator/cert.pem -cat public.crt >> /opt/hue-emulator/cert.pem -rm private.key public.crt -echo -e "\033[32m Changing permissions.\033[0m" -chmod +x /etc/init.d/hueemulatorWrt-service -chmod +x /opt/hue-emulator/HueEmulator3.py -chmod +x /opt/hue-emulator/debug -chmod +x /opt/hue-emulator/devics -chmod +x /opt/hue-emulator/functions -chmod +x /opt/hue-emulator/logManager -chmod +x /opt/hue-emulator/protocols -chmod +x /opt/hue-emulator/responseBuilder -chmod +x /opt/hue-emulator/webServer -chmod +x /opt/hue-emulator/updater -chmod +x /opt/hue-emulator/web-ui -chmod +x /opt/hue-emulator/config.json -chmod +x /opt/hue-emulator/default-config.json -chmod +x /opt/hue-emulator/entertain-srv -chmod +x /opt/hue-emulator/functions/network.py -chmod +x /opt/hue-emulator -echo -e "\033[32m Enable startup service.\033[0m" -/etc/init.d/hueemulatorWrt-service enable -wait -echo -e "\033[32m Installation completed. run: nano /etc/config/uhttpd and mod htpp port 80 for 82, run: nano /etc/lighttpd/lighttpd.conf and mod server.port = 80 for 82. For save changes ctrl +x, y, and enter..\033[0m" -sleep 15s -nano /etc/config/uhttpd -wait -nano /etc/lighttpd/lighttpd.conf -echo -e "\033[32m Installation completed.\033[0m" -wait -reboot 10 -exit 0 diff --git a/Installers/OpenWrt/network_OpenWrt.py b/Installers/OpenWrt/network_OpenWrt.py deleted file mode 100644 index 749280a85..000000000 --- a/Installers/OpenWrt/network_OpenWrt.py +++ /dev/null @@ -1,41 +0,0 @@ -import os -import socket - -if os.name != "nt": - import fcntl - import struct - - def get_interface_ip(ifname): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', - bytes(ifname[:15], 'utf-8')))[20:24]) - -def getIpAddress(): - ip = None - - try: - ip = socket.gethostbyname(socket.gethostname()) - except: - pass - - if (not ip or ip.startswith("127.")) and os.name != "nt": - interfaces = [ - "br0", - "br-lan", - "eth0", - "eth1", - "eth2", - "wlan0", - "wlan1", - "wifi0", - "ath0", - "ath1", - "ppp0", - ] - for ifname in interfaces: - try: - ip = get_interface_ip(ifname) - break - except IOError: - pass - return ip diff --git a/Installers/OpenWrt/update_openwrt.sh b/Installers/OpenWrt/update_openwrt.sh deleted file mode 100644 index 279e5de27..000000000 --- a/Installers/OpenWrt/update_openwrt.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -echo -e "\033[32m Disable startup service.\033[0m" -/etc/init.d/hueemulatorWrt-service disable -echo -e "\033[32m Create directory for backup configuration.\033[0m" -mkdir /tmp/diyHue-config -echo -e "\033[32m Copying configuration file.\033[0m" -cp /opt/hue-emulator/config.json /tmp/diyHue-config/config.json.bak -cp /opt/hue-emulator/cert.pem /tmp/diyHue-config/cert.pem.bak -echo -e "\033[32m Deleting directories.\033[0m" -rm -Rf /opt/hue-emulator -rm -Rf /etc/init.d/hueemulatorWrt-service -echo -e "\033[32m Updating python3-pip.\033[0m" -python3 -m pip install --upgrade pip -wait -echo -e "\033[32m Updating pip dependencies.\033[0m" -python3 -m pip install --upgrade requests -wait -python3 -m pip install --upgrade astral -wait -python3 -m pip install --upgrade pytz -wait -python3 -m pip install --upgrade ws4py -wait -python3 -m pip install --upgrade paho-mqtt -wait -echo -e "\033[32m Creating directories.\033[0m" -mkdir /opt -mkdir /opt/tmp -mkdir /opt/hue-emulator -cd /opt/tmp -echo -e "\033[32m Downloading diyHue.\033[0m" -wget -q https://github.com/diyhue/diyHue/archive/master.zip -O diyHue.zip -echo -e "\033[32m Unzip diyHue.\033[0m" -unzip -q -o diyHue.zip -wait -echo -e "\033[32m Copying unzip files to directories.\033[0m" -cd /opt/tmp/diyHue-master/BridgeEmulator -cp HueEmulator3.py updater /opt/hue-emulator/ -cp /tmp/diyHue-config/config.json.bak /opt/hue-emulator/config.json -cp /tmp/diyHue-config/cert.pem.bak /opt/hue-emulator/cert.pem -cp default-config.json /opt/hue-emulator/default-config.json -cp -r configManager debug devices functions logManager protocols responseBuilder web-ui webServer /opt/hue-emulator/ -echo -e "\033[32m Detecting processor architecture.\033[0m" -arch=`uname -m` -echo -e "\033[32m Architecture detected: $arch\033[0m" -echo -e "\033[32m Copying binary $arch for Openwrt.\033[0m" -cp ../Installers/OpenWrt/entertainment-openwrt-$arch /opt/hue-emulator/entertain-srv -echo -e "\033[32m Copying custom network function for openwrt.\033[0m" -rm -Rf /opt/hue-emulator/functions/network.py -mv ../Installers/OpenWrt/network_OpenWrt.py /opt/hue-emulator/functions/network.py -wait -echo -e "\033[32m Copying startup service.\033[0m" -cp /opt/tmp/diyHue-master/Installers/OpenWrt/hueemulatorWrt-service /etc/init.d/ -echo -e "\033[32m Changing permissions.\033[0m" -chmod +x /etc/init.d/hueemulatorWrt-service -chmod +x /opt/hue-emulator/HueEmulator3.py -chmod +x /opt/hue-emulator/debug -chmod +x /opt/hue-emulator/devics -chmod +x /opt/hue-emulator/functions -chmod +x /opt/hue-emulator/logManager -chmod +x /opt/hue-emulator/protocols -chmod +x /opt/hue-emulator/responseBuilder -chmod +x /opt/hue-emulator/webServer -chmod +x /opt/hue-emulator/updater -chmod +x /opt/hue-emulator/web-ui -chmod +x /opt/hue-emulator/config.json -chmod +x /opt/hue-emulator/default-config.json -chmod +x /opt/hue-emulator/entertain-srv -chmod +x /opt/hue-emulator/functions/network.py -chmod +x /opt/hue-emulator -echo -e "\033[32m Enable startup service.\033[0m" -/etc/init.d/hueemulatorWrt-service enable -wait -echo -e "\033[32m Update completed.\033[0m" -rm -Rf /opt/tmp -echo -e "\033[32m Restarting...\033[0m" -wait -reboot 10 -exit 0 diff --git a/Installers/check_updates.sh b/Installers/check_updates.sh deleted file mode 100755 index dea9d96b3..000000000 --- a/Installers/check_updates.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Checking for Updates" -curl -s https://raw.githubusercontent.com/diyhue/diyHue/master/BridgeEmulator/easy_install.sh | sudo bash /dev/stdin diff --git a/Installers/easy_install.sh b/Installers/easy_install.sh deleted file mode 100755 index 022b356e9..000000000 --- a/Installers/easy_install.sh +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env bash -mac=`cat /sys/class/net/$(ip route get 8.8.8.8 | sed -n 's/.* dev \([^ ]*\).*/\1/p')/address` -arch=`uname -m` - -cd /tmp - -### installing dependencies -echo -e "\033[36m Installing dependencies.\033[0m" -if type apt &> /dev/null; then - # Debian-based distro - apt-get install -y unzip nmap python3 python3-requests python3-setuptools -elif type pacman &> /dev/null; then - # Arch linux - pacman -Syq --noconfirm || exit 1 - pacman -Sq --noconfirm unzip nmap python3 python-pip gnu-netcat || exit 1 -else - # Or assume that packages are already installed (possibly with user confirmation)? - # Or check them? - echo -e "\033[31mUnable to detect package manager, aborting\033[0m" - exit 1 -fi - -### installing astral library for sunrise/sunset routines -echo -e "\033[36m Installing Python Astral.\033[0m" -curl -sL https://codeload.github.com/sffjunkie/astral/zip/2.2 -o astral.zip -unzip -qo astral.zip -cd astral-2.2/ -python3 setup.py install -cd ../ -rm -rf astral.zip astral-2.2/ - - -### installing paho-mqtt library -echo -e "\033[36m Installing Python MQTT.\033[0m" -curl -sL https://files.pythonhosted.org/packages/59/11/1dd5c70f0f27a88a3a05772cd95f6087ac479fac66d9c7752ee5e16ddbbc/paho-mqtt-1.5.0.tar.gz -o paho-mqtt-1.5.0.tar.gz -tar zxvf paho-mqtt-1.5.0.tar.gz -cd paho-mqtt-1.5.0/ -python3 setup.py install -cd ../ -rm -rf paho-mqtt-1.5.0.tar.gz paho-mqtt-1.5.0/ - -### installing WebSocket for Python -echo -e "\033[36m Installing WebSocket for Python.\033[0m" -curl -sL https://github.com/Lawouach/WebSocket-for-Python/archive/v0.3.4.zip -o ws4py.zip -unzip -qo ws4py.zip -cd WebSocket-for-Python-0.3.4/ -python3 setup.py install -cd ../ -rm -rf ws4py.zip WebSocket-for-Python-0.3.4/ - -### installing hue emulator -echo -e "\033[36m Installing Hue Emulator.\033[0m" -curl -sL https://github.com/diyhue/diyHue/archive/master.zip -o diyHue.zip -unzip -qo diyHue.zip -cd diyHue-master/BridgeEmulator/ - -if [ -d "/opt/hue-emulator" ]; then - if [ -f "/opt/hue-emulator/public.crt" ]; then - echo -e "\033[31m WARNING!! Nginx is not necessary anymore, it will be stopped.\033[0m" - systemctl stop nginx - systemctl disable nginx - cp /opt/hue-emulator/private.key /tmp/cert.pem - cat /opt/hue-emulator/public.crt >> /tmp/cert.pem - elif [ -f "/opt/hue-emulator/cert.pem" ]; then - cp /opt/hue-emulator/cert.pem /tmp/cert.pem - else - curl https://raw.githubusercontent.com/diyhue/diyHue/9ceed19b4211aa85a90fac9ea6d45cfeb746c9dd/BridgeEmulator/openssl.conf -o openssl.conf - serial="${mac:0:2}${mac:3:2}${mac:6:2}fffe${mac:9:2}${mac:12:2}${mac:15:2}" - dec_serial=`python3 -c "print(int(\"$serial\", 16))"` - openssl req -new -days 3650 -config openssl.conf -nodes -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -pkeyopt ec_param_enc:named_curve -subj "/C=NL/O=Philips Hue/CN=$serial" -keyout private.key -out public.crt -set_serial $dec_serial - if [ $? -ne 0 ] ; then - echo -e "\033[31m ERROR!! Local certificate generation failed! Attempting remote server generation\033[0m" - ### test is server for certificate generation is reachable - if ! nc -z mariusmotea.go.ro 9002 2>/dev/null; then - echo -e "\033[31m ERROR!! Certificate generation service is down. Please try again later.\033[0m" - exit 1 - fi - curl "http://mariusmotea.go.ro:9002/gencert?mac=$mac" > /tmp/cert.pem - else - touch /tmp/cert.pem - cat private.key > /tmp/cert.pem - cat public.crt >> /tmp/cert.pem - rm private.key public.crt - fi - fi - - systemctl stop hue-emulator.service - echo -e "\033[33m Existing installation found, performing upgrade.\033[0m" - cp /opt/hue-emulator/config.json /tmp - rm -rf /opt/hue-emulator - mkdir /opt/hue-emulator - mv /tmp/config.json /opt/hue-emulator - mv /tmp/cert.pem /opt/hue-emulator - -else - if nc -z 127.0.0.1 80 2>/dev/null; then - echo -e "\033[31m ERROR!! Port 80 already in use. Close the application that use this port and try again.\033[0m" - exit 1 - fi - if nc -z 127.0.0.1 443 2>/dev/null; then - echo -e "\033[31m ERROR!! Port 443 already in use. Close the application that use this port and try again.\033[0m" - exit 1 - fi - mkdir /opt/hue-emulator - cp default-config.json /opt/hue-emulator/ - - curl https://raw.githubusercontent.com/diyhue/diyHue/9ceed19b4211aa85a90fac9ea6d45cfeb746c9dd/BridgeEmulator/openssl.conf -o openssl.conf - serial="${mac:0:2}${mac:3:2}${mac:6:2}fffe${mac:9:2}${mac:12:2}${mac:15:2}" - dec_serial=`python3 -c "print(int(\"$serial\", 16))"` - openssl req -new -config openssl.conf -nodes -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -pkeyopt ec_param_enc:named_curve -subj "/C=NL/O=Philips Hue/CN=$serial" -keyout private.key -out public.crt -set_serial $dec_serial -days 3650 - if [ $? -ne 0 ] ; then - echo -e "\033[31m ERROR!! Local certificate generation failed! Attempting remote server generation\033[0m" - ### test is server for certificate generation is reachable - if ! nc -z mariusmotea.go.ro 9002 2>/dev/null; then - echo -e "\033[31m ERROR!! Certificate generation service is down. Please try again later.\033[0m" - exit 1 - fi - curl "http://mariusmotea.go.ro:9002/gencert?mac=$mac" > /opt/hue-emulator/cert.pem - else - touch /opt/hue-emulator/cert.pem - cat private.key > /opt/hue-emulator/cert.pem - cat public.crt >> /opt/hue-emulator/cert.pem - rm private.key public.crt - fi -fi -cp -r web-ui functions protocols HueEmulator3.py check_updates.sh debug /opt/hue-emulator/ - -# Install correct binaries -case $arch in - x86_64|i686|aarch64) - cp entertainment-$arch /opt/hue-emulator/entertain-srv - cp coap-client-$arch /opt/hue-emulator/coap-client-linux - ;; - arm64) - cp entertainment-aarch64 /opt/hue-emulator/entertain-srv - cp coap-client-aarch64 /opt/hue-emulator/coap-client-linux - ;; - armv*) - cp entertainment-arm /opt/hue-emulator/entertain-srv - cp coap-client-arm /opt/hue-emulator/coap-client-linux - ;; - *) - echo -e "\033[0;31m-------------------------------------------------------------------------------" - echo -e "ERROR: Unsupported architecture $arch!" - echo -e "You will need to manually compile the entertain-srv binary, " - echo -e "and install your own coap-client\033[0m" - echo -e "Please visit https://diyhue.readthedocs.io/en/latest/AddFuncts/entertainment.html" - echo -e "Once installed, open this script and manually run the last 10 lines." - exit 1 -esac - -chmod +x /opt/hue-emulator/entertain-srv -chmod +x /opt/hue-emulator/coap-client-linux -chmod +x /opt/hue-emulator/check_updates.sh -cp hue-emulator.service /lib/systemd/system/ -cd ../../ -rm -rf diyHue.zip diyHue-master -chmod 644 /lib/systemd/system/hue-emulator.service -systemctl daemon-reload -systemctl enable hue-emulator.service -systemctl start hue-emulator.service - -echo -e "\033[32m Installation completed. Open Hue app and search for bridges.\033[0m" diff --git a/Installers/easy_uninstall.sh b/Installers/easy_uninstall.sh deleted file mode 100755 index 86a7eb7c1..000000000 --- a/Installers/easy_uninstall.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -cd /tmp - -echo -e "\033[36m Stopping diyHue.\033[0m" -systemctl stop hue-emulator.service - -### Uninstalling astral library for sunrise/sunset routines -echo -e "\033[36m Uninstalling Python Astral.\033[0m" -wget -q https://github.com/sffjunkie/astral/archive/master.zip -O astral.zip -unzip -q -o astral.zip -cd astral-master/ -python3 setup.py install --record files.txt -# inspect files.txt to make sure it looks ok. Then: -tr '\n' '\0' < files.txt | xargs -0 sudo rm -f -- -cd ../ -rm -rf astral.zip astral-master/ - -### Uninstalling hue emulator -echo -e "\033[36m Uninstalling Hue Emulator.\033[0m" - -rm -rf /opt/hue-emulator/ - -systemctl disable hue-emulator.service -rm /lib/systemd/system/hue-emulator.service -systemctl daemon-reload - -### Uninstalling dependencies -echo -e "\033[36m Upon setup, diyHue installs some packages.\033[0m" -echo -e "\033[36m These are unzip, nmap, python3, python3-requests, python3-ws4py and python3-setuptools along with their dependencies.\033[0m" -echo -e "\033[36m Uninstalling these may break other services that may use them!\033[0m" -echo -e "\033[36m Uninstall these manually at your own discretion?\033[0m" - -echo -e "\033[32m Uninstal complete!\033[0m" diff --git a/Installers/hue-emulator.service b/Installers/hue-emulator.service deleted file mode 100644 index ea918cb83..000000000 --- a/Installers/hue-emulator.service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Hue Emulator Service -After=multi-user.target - -[Service] -Type=idle -Restart=always -RestartSec=30 -StartLimitInterval=200 -StartLimitBurst=5 - -WorkingDirectory=/opt/hue-emulator -ExecStart=/opt/hue-emulator/HueEmulator3.py -ExecStop=/usr/bin/curl http://127.0.0.1/save -ExecStop=/bin/sleep 1 - -[Install] -WantedBy=multi-user.target diff --git a/src/core/configManager/configStorage.py b/src/core/configManager/configStorage.py index a09b63adf..ea16bda16 100644 --- a/src/core/configManager/configStorage.py +++ b/src/core/configManager/configStorage.py @@ -39,9 +39,9 @@ def _write_json(path, contents): def get_path(self, file, project=False, config=False): #defaulting to config for now... if project: - return Path(self.projectDir, file) + return Path(self.projectDir, file).as_posix() else: - return Path(self.configDir, file) + return Path(self.configDir, file).as_posix() def _generate_new_config(self): self.bridge_config = {}