zigbee2mqtt-install.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
  7. color
  8. verb_ip6
  9. catch_errors
  10. setting_up_container
  11. network_check
  12. update_os
  13. msg_info "Installing Dependencies"
  14. $STD apt-get install -y curl
  15. $STD apt-get install -y sudo
  16. $STD apt-get install -y mc
  17. $STD apt-get install -y git
  18. $STD apt-get install -y make
  19. $STD apt-get install -y g++
  20. $STD apt-get install -y gcc
  21. $STD apt-get install -y ca-certificates
  22. $STD apt-get install -y gnupg
  23. msg_ok "Installed Dependencies"
  24. msg_info "Setting up Node.js Repository"
  25. mkdir -p /etc/apt/keyrings
  26. curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
  27. echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
  28. msg_ok "Set up Node.js Repository"
  29. msg_info "Installing Node.js"
  30. $STD apt-get update
  31. $STD apt-get install -y nodejs
  32. msg_ok "Installed Node.js"
  33. msg_info "Setting up Zigbee2MQTT Repository"
  34. $STD git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
  35. msg_ok "Set up Zigbee2MQTT Repository"
  36. read -r -p "Switch to Edge/dev branch? (y/N) " prompt
  37. if [[ $prompt == "y" ]]; then
  38. DEV="y"
  39. else
  40. DEV="n"
  41. fi
  42. msg_info "Installing Zigbee2MQTT"
  43. cd /opt/zigbee2mqtt
  44. if [[ $DEV == "y" ]]; then
  45. $STD git checkout dev
  46. fi
  47. $STD npm ci
  48. msg_ok "Installed Zigbee2MQTT"
  49. msg_info "Creating Service"
  50. service_path="/etc/systemd/system/zigbee2mqtt.service"
  51. echo "[Unit]
  52. Description=zigbee2mqtt
  53. After=network.target
  54. [Service]
  55. Environment=NODE_ENV=production
  56. ExecStart=/usr/bin/npm start
  57. WorkingDirectory=/opt/zigbee2mqtt
  58. StandardOutput=inherit
  59. StandardError=inherit
  60. Restart=always
  61. User=root
  62. [Install]
  63. WantedBy=multi-user.target" >$service_path
  64. $STD systemctl enable zigbee2mqtt.service
  65. msg_ok "Created Service"
  66. motd_ssh
  67. customize
  68. msg_info "Cleaning up"
  69. $STD apt-get autoremove
  70. $STD apt-get autoclean
  71. msg_ok "Cleaned"