homeassistant-core.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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-Core"
  20. var_disk="8"
  21. var_cpu="2"
  22. var_ram="1024"
  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. VERB="no"
  47. echo_default
  48. }
  49. function update_script() {
  50. if [[ ! -d /srv/homeassistant ]]; then
  51. msg_error "No ${APP} Installation Found!"
  52. exit
  53. fi
  54. PY=$(ls /srv/homeassistant/lib/)
  55. IP=$(hostname -I | awk '{print $1}')
  56. UPD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UPDATE" --radiolist --cancel-button Exit-Script "Spacebar = Select" 11 58 4 \
  57. "1" "Update Core" ON \
  58. "2" "Install HACS" OFF \
  59. "3" "Install FileBrowser" OFF \
  60. "4" "Install/Update AppDaemon" OFF \
  61. 3>&1 1>&2 2>&3)
  62. header_info
  63. if [ "$UPD" == "1" ]; then
  64. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SELECT BRANCH" --yesno "Use Beta Branch?" 10 58); then
  65. clear
  66. header_info
  67. echo -e "${GN}Updating to Beta Version${CL}"
  68. BR="--pre "
  69. else
  70. clear
  71. header_info
  72. echo -e "${GN}Updating to Stable Version${CL}"
  73. BR=""
  74. fi
  75. if [[ "$PY" == "python3.10" ]]; then echo -e "⚠️ Home Assistant now requires Python 3.11 to run."; fi
  76. msg_info "Stopping Home Assistant"
  77. systemctl stop homeassistant
  78. msg_ok "Stopped Home Assistant"
  79. msg_info "Updating Home Assistant"
  80. source /srv/homeassistant/bin/activate
  81. pip install ${BR}--upgrade homeassistant &>/dev/null
  82. msg_ok "Updated Home Assistant"
  83. msg_info "Starting Home Assistant"
  84. systemctl start homeassistant
  85. sleep 2
  86. msg_ok "Started Home Assistant"
  87. msg_ok "Update Successful"
  88. echo -e "\n Go to http://${IP}:8123 \n"
  89. exit
  90. fi
  91. if [ "$UPD" == "2" ]; then
  92. msg_info "Installing Home Assistant Comunity Store (HACS)"
  93. apt update &>/dev/null
  94. apt install unzip &>/dev/null
  95. cd .homeassistant
  96. bash <(curl -fsSL https://get.hacs.xyz) &>/dev/null
  97. msg_ok "Installed Home Assistant Comunity Store (HACS)"
  98. echo -e "\n Reboot Home Assistant and clear browser cache then Add HACS integration.\n"
  99. exit
  100. fi
  101. if [ "$UPD" == "3" ]; then
  102. msg_info "Installing FileBrowser"
  103. RELEASE=$(curl -fsSL https://api.github.com/repos/filebrowser/filebrowser/releases/latest | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g')
  104. 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
  105. filebrowser config init -a '0.0.0.0' &>/dev/null
  106. filebrowser config set -a '0.0.0.0' &>/dev/null
  107. filebrowser users add admin changeme --perm.admin &>/dev/null
  108. msg_ok "Installed FileBrowser"
  109. msg_info "Creating Service"
  110. service_path="/etc/systemd/system/filebrowser.service"
  111. echo "[Unit]
  112. Description=Filebrowser
  113. After=network-online.target
  114. [Service]
  115. User=root
  116. WorkingDirectory=/root/
  117. ExecStart=/usr/local/bin/filebrowser -r /root/.homeassistant
  118. [Install]
  119. WantedBy=default.target" >$service_path
  120. systemctl enable --now -q filebrowser.service
  121. msg_ok "Created Service"
  122. msg_ok "Completed Successfully!\n"
  123. echo -e "FileBrowser should be reachable by going to the following URL.
  124. ${BL}http://$IP:8080${CL} admin|changeme\n"
  125. exit
  126. fi
  127. if [ "$UPD" == "4" ]; then
  128. clear
  129. header_info
  130. if [[ ! -d /srv/appdaemon ]]; then
  131. msg_info "Installing AppDaemon"
  132. mkdir /srv/appdaemon
  133. cd /srv/appdaemon
  134. python3 -m venv .
  135. source bin/activate
  136. pip install appdaemon &>/dev/null
  137. mkdir -p /root/.homeassistant/appdaemon/apps
  138. cat >/root/.homeassistant/appdaemon/appdaemon.yaml <<EOF
  139. # Sample appdaemon.yml file
  140. # For configuration, please visit: https://appdaemon.readthedocs.io/en/latest/CONFIGURE.html
  141. appdaemon:
  142. time_zone: CET
  143. latitude: 51.725
  144. longitude: 14.3434
  145. elevation: 0
  146. plugins:
  147. HASS:
  148. type: hass
  149. ha_url: <home_assistant_base_url>
  150. token: <some_long_lived_access_token>
  151. http:
  152. url: http://127.0.0.1:5050
  153. admin:
  154. api:
  155. EOF
  156. msg_ok "Installed AppDaemon"
  157. msg_info "Creating Service"
  158. cat >/etc/systemd/system/appdaemon.service <<EOF
  159. [Unit]
  160. Description=AppDaemon
  161. After=homeassistant.service
  162. Requires=homeassistant.service
  163. [Service]
  164. Type=simple
  165. WorkingDirectory=/root/.homeassistant/appdaemon
  166. ExecStart=/srv/appdaemon/bin/appdaemon -c "/root/.homeassistant/appdaemon"
  167. RestartForceExitStatus=100
  168. [Install]
  169. WantedBy=multi-user.target
  170. EOF
  171. systemctl enable --now appdaemon &>/dev/null
  172. msg_ok "Created Service"
  173. msg_ok "Completed Successfully!\n"
  174. echo -e "AppDaemon should be reachable by going to the following URL.
  175. ${BL}http://$IP:5050${CL}\n"
  176. exit
  177. else
  178. msg_info "Upgrading AppDaemon"
  179. msg_info "Stopping AppDaemon"
  180. systemctl stop appdaemon
  181. msg_ok "Stopped AppDaemon"
  182. msg_info "Updating AppDaemon"
  183. source /srv/appdaemon/bin/activate
  184. pip install --upgrade appdaemon &>/dev/null
  185. msg_ok "Updated AppDaemon"
  186. msg_info "Starting AppDaemon"
  187. systemctl start appdaemon
  188. sleep 2
  189. msg_ok "Started AppDaemon"
  190. msg_ok "Update Successful"
  191. echo -e "\n Go to http://${IP}:5050 \n"
  192. exit
  193. fi
  194. fi
  195. }
  196. start
  197. build_container
  198. description
  199. msg_ok "Completed Successfully!\n"
  200. echo -e "${APP} should be reachable by going to the following URL.
  201. ${BL}http://${IP}:8123${CL}"