Files
ProxmoxVE/install/alpine-mqtt-install.sh
2025-10-20 20:51:43 +02:00

173 lines
4.5 KiB
Bash

#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://www.zigbee2mqtt.io/
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
msg_info "Installing Alpine-Mosquitto_Zigbee2MQTT_haBridge"
# mosquitto -----------------
msg_info "Installing Mosquitto"
$STD apk add mosquitto
mosquitto_config=/etc/mosquitto/mosquitto.conf
sed -i -e "s/^#allow_anonymous.*$/allow_anonymous true/" $mosquitto_config
sed -i -e "s/^#listener.*$/listener 1883/" $mosquitto_config
rc-update add mosquitto
rc-service mosquitto start
# ha-bridge -----------------
msg_info "Installing haBridge"
$STD apk add openjdk11
java --version
mkdir -p /opt/habridge
cd /opt/habridge
release=$( curl -fsSL https://api.github.com/repos/bwssytems/ha-bridge/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
wget -q https://github.com/bwssytems/ha-bridge/releases/download/v${release}/ha-bridge-${release}.jar
ln -s ha-bridge-${release}.jar ha-bridge.jar
initfile=/etc/init.d/habridge
cat > $initfile <<\EOF
#!/sbin/openrc-run
command="/usr/bin/java"
command_args="-jar -Dconfig.file=/opt/habridge/data/habridge.config /opt/habridge/ha-bridge.jar"
name="habridge"
description="HA Bridge Service"
pidfile="/run/habridge.pid"
directory="/opt/habridge"
#user="habridge" # or leave as root if needed
user="root"
depend() {
need net
after firewall
}
start_pre() {
checkpath --directory --owner $user:$user /run
}
start() {
ebegin "Starting ha-bridge $pidfile"
start-stop-daemon --start --background \
--pidfile $pidfile \
--make-pidfile \
--chdir $directory \
--user $user \
--exec $command -- $command_args
eend $?
}
stop() {
ebegin "Stopping ha-bridge"
start-stop-daemon --stop --pidfile $pidfile --retry 10
eend $?
}
EOF
chmod +x $initfile
rc-update add habridge default
rc-service habridge start
rc-service habridge status
# config-file: /opt/habridge/data/habridge.config
# "mqttaddress": {
# "devices": [
# {
# "name": "habridge",
# "ip": "localhost:1883"
# }
# ]
# },
# zigbee2mqtt ----------------
set2net_ip=192.168.178.29
set2net_port=20108
ser2net_baud=115200
#mkdir -p /root/.z2m /etc/zigbee2mqtt
#$STD apk add zigbee2mqtt
#ln -s /etc/zigbee2mqtt/ /root/.z2m
#chown -R root:root /etc/zigbee2mqtt /root/.z2m
#$STD rc-update add zigbee2mqtt
#$STD rc-service zigbee2mqtt restart
#mkdir -p /etc/zigbee2mqtt
$STD apk add zigbee2mqtt
sed -i -e 's/#datadir="\/var\/lib\/zigbee2mqtt"/datadir="\/var\/lib\/zigbee2mqtt"/' -e 's/#command_user="zigbee2mqtt"/command_user="root"/' /etc/conf.d/zigbee2mqtt
cat >>/etc/conf.d/zigbee2mqtt <<EOF
export ZIGBEE2MQTT_CONFIG_MQTT_BASE_TOPIC="zigbee"
export ZIGBEE2MQTT_CONFIG_SERIAL_PORT="tcp://$ser2net_ip:$ser2net_port"
export ZIGBEE2MQTT_CONFIG_SERIAL_RTSCTS="false"
export ZIGBEE2MQTT_CONFIG_SERIAL_BAUDRATE="$ser2net_baud"
export ZIGBEE2MQTT_CONFIG_SERIAL_ADAPTER="ezsp"
export ZIGBEE2MQTT_CONFIG_FRONTEND_PORT="8089"
export ZIGBEE2MQTT_CONFIG_FRONTEND_ENABLED="true"
EOF
$STD rc-update add zigbee2mqtt default
$STD rc-service zigbee2mqtt start
$STD rc-service zigbee2mqtt status
msg_ok "Installed Alpine-Zigbee2MQTT"
# config-file: /var/lib/zigbee2mqtt/configuration.yaml
# tuya-mqtt -------------------------
$STD apk add npm git
cd /opt
git clone https://github.com/lehanspb/tuya-mqtt
cd tuya-mqtt
npm install
npm audit fix --force
# influxdb ---------------------------
# https://github.com/woahbase/alpine-influxdb/blob/master/Dockerfile
INFLUXDB_HOME=/var/lib/influxdb \
INFLUXDB_CONFIG_PATH=/etc/influxdb.conf
$STD apk add -Uu --purge --no-cache ca-certificates
# influxdb unavailable in repos since v3.17
# newer builds will not have armv7l/armhf
{ REPO=v3.17; \
echo "http://dl-cdn.alpinelinux.org/alpine/${REPO}/main"; \
echo "http://dl-cdn.alpinelinux.org/alpine/${REPO}/community"; \
} > /tmp/repo
$STD apk add --no-cache --repositories-file "/tmp/repo" influxdb
update-ca-certificates
mkdir -p defaults ${INFLUXDB_HOME}
mv ${INFLUXDB_CONFIG_PATH} /defaults/influxdb.conf.default
if [ ! -e /etc/nsswitch.conf ]; then
echo 'hosts: files dns' > /etc/nsswitch.conf
fi
# grafana --------------
msg_info "Installing Grafana"
$STD apk add grafana
$STD sed -i '/http_addr/s/127.0.0.1/0.0.0.0/g' /etc/conf.d/grafana
$STD rc-service grafana start
$STD rc-update add grafana default
msg_ok "Installed Grafana"
rm -rf /var/cache/apk/* /tmp/*
motd_ssh
customize