podman-homeassistant.sh 4.3 KB

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