Skip to content

Commit

Permalink
Merge pull request #27 from volkmarnissen/hassio-addon
Browse files Browse the repository at this point in the history
Fixes: standalone container: register user was not allowed
  • Loading branch information
volkmarnissen authored Oct 26, 2024
2 parents eb8ee4a + 49be0d9 commit e01a682
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 87 deletions.
23 changes: 18 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@
"<node_internals>/**"
],
"sourceMaps": true,
"sourceMapPathOverrides": {
"../specification.shared/cjs/*.js": "${workspaceFolder}../specification.shared/src/*.ts",
"../server.shared/*/*": "${workspaceFolder}../server.shared/*/*",
"../specification/dist/*/*.js": "${workspaceFolder}../specification/src/*.ts",
},
"type": "node"
},
{
"name": "Run TestServer TCP",
"preLaunchTask": "npm: build.dev",
"timeout": 10000,
"program": "${workspaceFolder}/dist/modbus2mqtt.js",
"args": [ "-s", "${workspaceFolder}/e2e/temp/ssl", "-y" ,"${workspaceFolder}/e2e/temp/yaml-dir", "--busid", "${workspaceFolder}/e2e/temp/yaml-dir-tcp:0"],
"console": "integratedTerminal",
"env": {
"DEBUG": "config",
"NODE_OPTIONS": "--experimental-vm-modules npx jest"
},
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"sourceMaps": true,
"type": "node"
},

Expand Down
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
temp/**/*
96 changes: 96 additions & 0 deletions e2e/localdev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/sh
BASEDIR=$(dirname "$0")
# .../server/e2e
cd $BASEDIR
sudo apt-get install -y nginx mosquitto mosquitto-clients
sudo rm /etc/nginx/sites-enabled/default
WWWROOT=temp/www-root
sudo mkdir -p $WWWROOT/services/mqtt
echo configure nginx
sudo bash -c 'cat >'$WWWROOT'/services/mqtt/mqtt.json <<EOF
"mqttconnect": {
"host" : "localhost",
"port" : 3001,
"username" : "homeassistant",
"password" : "homeassistant"
}
EOF'
if ! grep supervisor /etc/hosts >/dev/null
then
sudo echo "127.0.0.1 supervisor" >>/etc/hosts
fi
sudo bash -c ' cat >/etc/nginx/conf.d/modbus2mqtt-addon-e2e.conf <<EOF2
server {
listen 80 default_server;
listen [::]:80 default_server;
location /services/mqtt {
root temp/www-root;
index mqtt.json;
}
location /modbus2mqtt/ {
proxy_pass http://localhost:3000;
}
}
EOF2'
sudo systemctl restart nginx.service
YAMLDIR=temp/yaml-dir-tcp
BUSSES=$YAMLDIR/local/busses/bus.0
mkdir -p $BUSSES
mkdir -p temp/yaml-dir
mkdir -p temp/ssl
cat >$BUSSES/bus.yaml <<EOF3
host: localhost
port: 502
timeout: 500
EOF3
cat >$BUSSES/s3.yaml <<EOF4
slaveid: 3
specificationid: dimplexpco5
EOF4
cat >$BUSSES/s4.yaml <<EOF5
slaveid: 4
specificationid: eastronsdm720-m
EOF5

sudo bash -c 'cat >/etc/mosquitto/conf.d/homeassistant.conf <<EOF6
listener 3001
allow_anonymous false
password_file /etc/mosquitto/password.txt
EOF6'
sudo chmod 700 /etc/mosquitto/password.txt
sudo chown mosquitto /etc/mosquitto/password.txt
sudo mosquitto_passwd -b /etc/mosquitto/password.txt homeassistant homeassistant

sudo systemctl restart mosquitto.service
export CWD=`pwd`
bash -c '
cat <<EOF7
[Unit]
Description=Modbus <=> MQTT e2e test server
After=network.target
StartLimitIntervalSec=1
[Service]
Type=simple
User=|user|
ExecStart=/usr/bin/env sh -c "|script|"
[Install]
WantedBy=multi-user.target
EOF7' | sed -e "s:|script|:${CWD}/modbus2mqtt-server.sh:g" | sed -e "s/|user|/${USER}/g"| sudo bash -c 'cat >/etc/systemd/system/modbus2mqtt-e2e.service'
bash -c '
cat <<EOF8
[Unit]
Description=Modbus <=> MQTT e2e test server
After=network.target
StartLimitIntervalSec=1
[Service]
Type=simple
User=root
ExecStart=/usr/bin/env sh -c "|script|"
[Install]
WantedBy=multi-user.target
EOF8' | sed -e "s:|script|:${CWD}/modbus2mqtt-tcp-server.sh:g" | sudo bash -c 'cat >/etc/systemd/system/modbus2mqtt-tcp-server.service'

sudo systemctl restart modbus2mqtt-tcp-server.service
sudo systemctl restart modbus2mqtt-e2e.service

5 changes: 5 additions & 0 deletions e2e/modbus2mqtt-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
BASEDIR=$(dirname "$0")
# .../server/e2e
cd $BASEDIR/..
node dist/modbus2mqtt.js -y e2e/temp/yaml-dir -s e2e/temp/ssl --busid e2e/temp/yaml-dir-tcp:0
9 changes: 9 additions & 0 deletions e2e/modbus2mqtt-tcp-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
BASEDIR=$(dirname "$0")
# .../server/e2e
cd $BASEDIR/..
echo starting tcp server
# git is not happy when a repository was checked out by another user
rm -rf e2e/temp/yaml-dir-tcp/public
# --inspect-brk=9229 for debugging
node ./dist/runModbusTCPserver.js -y e2e/temp/yaml-dir-tcp --busid 0 --port 3002
Loading

0 comments on commit e01a682

Please sign in to comment.