zigbee2mqtt.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "Checking if any changes were made to package-lock.json..."
  87. git checkout package-lock.json || {
  88. echo "Failed to check package-lock.json."
  89. exit 1
  90. }
  91. echo "Initiating update..."
  92. if ! git pull; then
  93. echo "Update failed, temporarily storing changes and trying again."
  94. git stash && git pull || (
  95. echo "Update failed even after storing changes. Aborting."
  96. exit 1
  97. )
  98. fi
  99. echo "Acquiring necessary components..."
  100. npm ci || {
  101. echo "Failed to install necessary components."
  102. exit 1
  103. }
  104. echo "Building..."
  105. npm run build || {
  106. echo "Failed to build new version."
  107. exit 1
  108. }
  109. echo "Restoring configuration..."
  110. cp -R data-backup/* data || {
  111. echo "Failed to restore configuration."
  112. exit 1
  113. }
  114. rm -rf data-backup || {
  115. echo "Failed to remove backup directory."
  116. exit 1
  117. }
  118. start_zigbee2mqtt
  119. echo "Done!"
  120. exit
  121. }
  122. start
  123. build_container
  124. description
  125. msg_ok "Completed Successfully!\n"