zigbee2mqtt-install.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. msg_ok "Installed Dependencies"
  22. msg_info "Setting up Node.js Repository"
  23. $STD bash <(curl -fsSL https://deb.nodesource.com/setup_18.x)
  24. msg_ok "Set up Node.js Repository"
  25. msg_info "Installing Node.js"
  26. $STD apt-get install -y nodejs
  27. msg_ok "Installed Node.js"
  28. msg_info "Setting up Zigbee2MQTT Repository"
  29. $STD git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
  30. msg_ok "Set up Zigbee2MQTT Repository"
  31. read -r -p "Switch to Edge/dev branch? (y/N) " prompt
  32. if [[ $prompt == "y" ]]; then
  33. DEV="y"
  34. else
  35. DEV="n"
  36. fi
  37. msg_info "Installing Zigbee2MQTT"
  38. cd /opt/zigbee2mqtt
  39. if [[ $DEV == "y" ]]; then
  40. $STD git checkout dev
  41. fi
  42. $STD npm ci
  43. msg_ok "Installed Zigbee2MQTT"
  44. msg_info "Creating Service"
  45. service_path="/etc/systemd/system/zigbee2mqtt.service"
  46. echo "[Unit]
  47. Description=zigbee2mqtt
  48. After=network.target
  49. [Service]
  50. Environment=NODE_ENV=production
  51. ExecStart=/usr/bin/npm start
  52. WorkingDirectory=/opt/zigbee2mqtt
  53. StandardOutput=inherit
  54. StandardError=inherit
  55. Restart=always
  56. User=root
  57. [Install]
  58. WantedBy=multi-user.target" >$service_path
  59. $STD systemctl enable zigbee2mqtt.service
  60. msg_ok "Created Service"
  61. motd_ssh
  62. root
  63. msg_info "Cleaning up"
  64. $STD apt-get autoremove
  65. $STD apt-get autoclean
  66. msg_ok "Cleaned"