homeassistant.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. EOF
  16. }
  17. header_info
  18. echo -e "Loading..."
  19. APP="Home Assistant"
  20. var_disk="16"
  21. var_cpu="2"
  22. var_ram="2048"
  23. var_os="debian"
  24. var_version="12"
  25. variables
  26. color
  27. catch_errors
  28. function default_settings() {
  29. CT_TYPE="1"
  30. PW=""
  31. CT_ID=$NEXTID
  32. HN=$NSAPP
  33. DISK_SIZE="$var_disk"
  34. CORE_COUNT="$var_cpu"
  35. RAM_SIZE="$var_ram"
  36. BRG="vmbr0"
  37. NET="dhcp"
  38. GATE=""
  39. DISABLEIP6="no"
  40. MTU=""
  41. SD=""
  42. NS=""
  43. MAC=""
  44. VLAN=""
  45. SSH="no"
  46. FUSE="no"
  47. VERB="no"
  48. echo_default
  49. }
  50. function update_script() {
  51. if [[ ! -d /var/lib/docker/volumes/hass_config/_data ]]; then
  52. msg_error "No ${APP} Installation Found!"
  53. exit
  54. fi
  55. UPD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UPDATE" --radiolist --cancel-button Exit-Script "Spacebar = Select" 11 58 4 \
  56. "1" "Update ALL Containers" ON \
  57. "2" "Remove ALL Unused Images" OFF \
  58. "3" "Install HACS" OFF \
  59. "4" "Install FileBrowser" OFF \
  60. 3>&1 1>&2 2>&3)
  61. header_info
  62. if [ "$UPD" == "1" ]; then
  63. msg_info "Updating All Containers"
  64. CONTAINER_LIST="${1:-$(docker ps -q)}"
  65. for container in ${CONTAINER_LIST}; do
  66. CONTAINER_IMAGE="$(docker inspect --format "{{.Config.Image}}" --type container ${container})"
  67. RUNNING_IMAGE="$(docker inspect --format "{{.Image}}" --type container "${container}")"
  68. docker pull "${CONTAINER_IMAGE}"
  69. LATEST_IMAGE="$(docker inspect --format "{{.Id}}" --type image "${CONTAINER_IMAGE}")"
  70. if [[ "${RUNNING_IMAGE}" != "${LATEST_IMAGE}" ]]; then
  71. echo "Updating ${container} image ${CONTAINER_IMAGE}"
  72. DOCKER_COMMAND="$(runlike "${container}")"
  73. docker rm --force "${container}"
  74. eval ${DOCKER_COMMAND}
  75. fi
  76. done
  77. msg_ok "Updated All Containers"
  78. exit
  79. fi
  80. if [ "$UPD" == "2" ]; then
  81. msg_info "Removing ALL Unused Images"
  82. docker image prune -af
  83. msg_ok "Removed ALL Unused Images"
  84. exit
  85. fi
  86. if [ "$UPD" == "3" ]; then
  87. msg_info "Installing Home Assistant Comunity Store (HACS)"
  88. apt update &>/dev/null
  89. apt install unzip &>/dev/null
  90. cd /var/lib/docker/volumes/hass_config/_data
  91. bash <(curl -fsSL https://get.hacs.xyz) &>/dev/null
  92. msg_ok "Installed Home Assistant Comunity Store (HACS)"
  93. echo -e "\n Reboot Home Assistant and clear browser cache then Add HACS integration.\n"
  94. exit
  95. fi
  96. if [ "$UPD" == "4" ]; then
  97. IP=$(hostname -I | awk '{print $1}')
  98. msg_info "Installing FileBrowser"
  99. RELEASE=$(curl -fsSL https://api.github.com/repos/filebrowser/filebrowser/releases/latest | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g')
  100. curl -fsSL https://github.com/filebrowser/filebrowser/releases/download/v2.23.0/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null
  101. filebrowser config init -a '0.0.0.0' &>/dev/null
  102. filebrowser config set -a '0.0.0.0' &>/dev/null
  103. filebrowser users add admin changeme --perm.admin &>/dev/null
  104. msg_ok "Installed FileBrowser"
  105. msg_info "Creating Service"
  106. service_path="/etc/systemd/system/filebrowser.service"
  107. echo "[Unit]
  108. Description=Filebrowser
  109. After=network-online.target
  110. [Service]
  111. User=root
  112. WorkingDirectory=/root/
  113. ExecStart=/usr/local/bin/filebrowser -r /
  114. [Install]
  115. WantedBy=default.target" >$service_path
  116. systemctl enable --now filebrowser.service &>/dev/null
  117. msg_ok "Created Service"
  118. msg_ok "Completed Successfully!\n"
  119. echo -e "FileBrowser should be reachable by going to the following URL.
  120. ${BL}http://$IP:8080${CL} admin|changeme\n"
  121. exit
  122. fi
  123. }
  124. start
  125. build_container
  126. description
  127. msg_ok "Completed Successfully!\n"
  128. echo -e "${APP} should be reachable by going to the following URL.
  129. ${BL}http://${IP}:8123${CL}
  130. Portainer should be reachable by going to the following URL.
  131. ${BL}http://${IP}:9000${CL}\n"