Update zigbee2mqtt-install.sh

This commit is contained in:
CanbiZ 2025-01-04 10:08:45 +01:00 committed by Duncan Hill
parent 23f89faf0f
commit a4e2f373ea
No known key found for this signature in database

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2021-2024 tteck # Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster) # Author: tteck (tteckster)
# License: MIT # License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
@ -14,15 +14,15 @@ network_check
update_os update_os
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt-get install -y curl $STD apt-get install -y \
$STD apt-get install -y sudo curl \
$STD apt-get install -y mc sudo \
$STD apt-get install -y git mc \
$STD apt-get install -y make make \
$STD apt-get install -y g++ g++ \
$STD apt-get install -y gcc gcc \
$STD apt-get install -y ca-certificates ca-certificates \
$STD apt-get install -y gnupg gnupg
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
msg_info "Setting up Node.js Repository" msg_info "Setting up Node.js Repository"
@ -36,49 +36,46 @@ $STD apt-get update
$STD apt-get install -y nodejs $STD apt-get install -y nodejs
msg_ok "Installed Node.js" msg_ok "Installed Node.js"
msg_info "Setting up Zigbee2MQTT Repository" msg_info "Installing pnpm"
$STD git clone --depth 1 https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt $STD npm install -g pnpm
msg_ok "Set up Zigbee2MQTT Repository" msg_ok "Installed pnpm"
read -r -p "Switch to Edge/dev branch? (y/N) " prompt msg_info "Setting up Zigbee2MQTT"
if [[ $prompt == "y" ]]; then cd /opt
DEV="y" corepack enable
else RELEASE=$(curl -s https://api.github.com/repos/Koenkk/zigbee2mqtt/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
DEV="n" wget -q "https://github.com/Koenkk/zigbee2mqtt/archive/refs/tags/${RELEASE}.zip"
fi unzip -q ${RELEASE}.zip
mv zigbee2mqtt-${RELEASE} /opt/zigbee2mqtt
msg_info "Installing Zigbee2MQTT" cd /opt/zigbee2mqtt/data
mv configuration.example.yaml configuration.yaml
cd /opt/zigbee2mqtt cd /opt/zigbee2mqtt
if [[ $DEV == "y" ]]; then pnpm install
$STD git fetch origin dev:dev
$STD git checkout dev
$STD git pull
fi
$STD npm ci
msg_ok "Installed Zigbee2MQTT" msg_ok "Installed Zigbee2MQTT"
msg_info "Creating Service" msg_info "Creating Service"
service_path="/etc/systemd/system/zigbee2mqtt.service" cat <<EOF >/etc/systemd/system/zigbee2mqtt.service
echo "[Unit] echo "[Unit]
Description=zigbee2mqtt Description=zigbee2mqtt
After=network.target After=network.target
[Service] [Service]
Environment=NODE_ENV=production Environment=NODE_ENV=production
ExecStart=/usr/bin/npm start ExecStart=/usr/bin/pnpm start
WorkingDirectory=/opt/zigbee2mqtt WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit StandardOutput=inherit
StandardError=inherit StandardError=inherit
Restart=always Restart=always
User=root User=root
[Install] [Install]
WantedBy=multi-user.target" >$service_path EOF
$STD systemctl enable zigbee2mqtt.service systemctl enable -q --now zigbee2mqtt.service
msg_ok "Created Service" msg_ok "Created Service"
motd_ssh motd_ssh
customize customize
msg_info "Cleaning up" msg_info "Cleaning up"
rm -rf /opt/${RELEASE}.zip
$STD apt-get -y autoremove $STD apt-get -y autoremove
$STD apt-get -y autoclean $STD apt-get -y autoclean
msg_ok "Cleaned" msg_ok "Cleaned"