zigbee2mqtt.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env bash
  2. source <(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/build.func)
  3. # Copyright (c) 2021-2023 tteck
  4. # Author: tteck (tteckster)
  5. # License: MIT
  6. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  7. function header_info {
  8. clear
  9. cat <<"EOF"
  10. _____ _ __ ___ __ _______ ____________
  11. /__ / (_)___ _/ /_ ___ ___ |__ \ / |/ / __ \/_ __/_ __/
  12. / / / / __ / __ \/ _ \/ _ \__/ // /|_/ / / / / / / / /
  13. / /__/ / /_/ / /_/ / __/ __/ __// / / / /_/ / / / / /
  14. /____/_/\__, /_.___/\___/\___/____/_/ /_/\___\_\/_/ /_/
  15. /____/ 🐝
  16. EOF
  17. }
  18. header_info
  19. echo -e "Loading..."
  20. APP="Zigbee2MQTT"
  21. var_disk="4"
  22. var_cpu="2"
  23. var_ram="1024"
  24. var_os="debian"
  25. var_version="12"
  26. variables
  27. color
  28. catch_errors
  29. function default_settings() {
  30. CT_TYPE="0"
  31. PW=""
  32. CT_ID=$NEXTID
  33. HN=$NSAPP
  34. DISK_SIZE="$var_disk"
  35. CORE_COUNT="$var_cpu"
  36. RAM_SIZE="$var_ram"
  37. BRG="vmbr0"
  38. NET="dhcp"
  39. GATE=""
  40. DISABLEIP6="no"
  41. MTU=""
  42. SD=""
  43. NS=""
  44. MAC=""
  45. VLAN=""
  46. SSH="no"
  47. VERB="no"
  48. echo_default
  49. }
  50. function update_script() {
  51. header_info
  52. if [[ ! -d /opt/zigbee2mqtt ]]; then
  53. msg_error "No ${APP} Installation Found!"
  54. exit
  55. fi
  56. cd /opt/zigbee2mqtt
  57. stop_zigbee2mqtt() {
  58. if which systemctl 2>/dev/null >/dev/null; then
  59. echo "Shutting down Zigbee2MQTT..."
  60. sudo systemctl stop zigbee2mqtt
  61. else
  62. echo "Skipped stopping Zigbee2MQTT, no systemctl found"
  63. fi
  64. }
  65. start_zigbee2mqtt() {
  66. if which systemctl 2>/dev/null >/dev/null; then
  67. echo "Starting Zigbee2MQTT..."
  68. sudo systemctl start zigbee2mqtt
  69. else
  70. echo "Skipped starting Zigbee2MQTT, no systemctl found"
  71. fi
  72. }
  73. set -e
  74. if [ -d data-backup ]; then
  75. echo "ERROR: Backup directory exists. May be previous restoring was failed?"
  76. echo "1. Save 'data-backup' and 'data' dirs to safe location to make possibility to restore config later."
  77. echo "2. Manually delete 'data-backup' dir and try again."
  78. exit 1
  79. fi
  80. stop_zigbee2mqtt
  81. echo "Generating a backup of the configuration..."
  82. cp -R data data-backup || {
  83. echo "Failed to create backup."
  84. exit 1
  85. }
  86. echo "Initiating update"
  87. if ! git pull; then
  88. echo "Update failed, temporarily storing changes and trying again."
  89. git stash && git pull || (
  90. echo "Update failed even after storing changes. Aborting."
  91. exit 1
  92. )
  93. fi
  94. echo "Acquiring necessary components..."
  95. npm ci || {
  96. echo "Failed to install necessary components."
  97. exit 1
  98. }
  99. echo "Restoring configuration..."
  100. cp -R data-backup/* data || {
  101. echo "Failed to restore configuration."
  102. exit 1
  103. }
  104. rm -rf data-backup || {
  105. echo "Failed to remove backup directory."
  106. exit 1
  107. }
  108. start_zigbee2mqtt
  109. echo "Done!"
  110. exit
  111. }
  112. start
  113. build_container
  114. description
  115. msg_ok "Completed Successfully!\n"