homeassistant-core.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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="11"
  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 --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 --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.9" ]]; then echo -e "⚠️ Python 3.9 is deprecated and will be removed in Home Assistant 2023.2"; 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. curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash &>/dev/null
  104. filebrowser config init -a '0.0.0.0' &>/dev/null
  105. filebrowser config set -a '0.0.0.0' &>/dev/null
  106. filebrowser users add admin changeme --perm.admin &>/dev/null
  107. msg_ok "Installed FileBrowser"
  108. msg_info "Creating Service"
  109. service_path="/etc/systemd/system/filebrowser.service"
  110. echo "[Unit]
  111. Description=Filebrowser
  112. After=network-online.target
  113. [Service]
  114. User=root
  115. WorkingDirectory=/root/
  116. ExecStart=/usr/local/bin/filebrowser -r /root/.homeassistant
  117. [Install]
  118. WantedBy=default.target" >$service_path
  119. systemctl enable --now -q filebrowser.service
  120. msg_ok "Created Service"
  121. msg_ok "Completed Successfully!\n"
  122. echo -e "FileBrowser should be reachable by going to the following URL.
  123. ${BL}http://$IP:8080${CL} admin|changeme\n"
  124. exit
  125. fi
  126. if [ "$UPD" == "4" ]; then
  127. clear
  128. header_info
  129. if [[ ! -d /srv/appdaemon ]]; then
  130. msg_info "Installing AppDaemon"
  131. mkdir /srv/appdaemon
  132. cd /srv/appdaemon
  133. python3 -m venv .
  134. source bin/activate
  135. pip install appdaemon &>/dev/null
  136. mkdir -p /root/.homeassistant/appdaemon/apps
  137. cat >/root/.homeassistant/appdaemon/appdaemon.yaml <<EOF
  138. # Sample appdaemon.yml file
  139. # For configuration, please visit: https://appdaemon.readthedocs.io/en/latest/CONFIGURE.html
  140. appdaemon:
  141. time_zone: CET
  142. latitude: 51.725
  143. longitude: 14.3434
  144. elevation: 0
  145. plugins:
  146. HASS:
  147. type: hass
  148. ha_url: <home_assistant_base_url>
  149. token: <some_long_lived_access_token>
  150. http:
  151. url: http://127.0.0.1:5050
  152. admin:
  153. api:
  154. EOF
  155. msg_ok "Installed AppDaemon"
  156. msg_info "Creating Service"
  157. cat >/etc/systemd/system/appdaemon.service <<EOF
  158. [Unit]
  159. Description=AppDaemon
  160. After=homeassistant.service
  161. Requires=homeassistant.service
  162. [Service]
  163. Type=simple
  164. WorkingDirectory=/root/.homeassistant/appdaemon
  165. ExecStart=/srv/appdaemon/bin/appdaemon -c "/root/.homeassistant/appdaemon"
  166. RestartForceExitStatus=100
  167. [Install]
  168. WantedBy=multi-user.target
  169. EOF
  170. systemctl enable --now appdaemon &>/dev/null
  171. msg_ok "Created Service"
  172. msg_ok "Completed Successfully!\n"
  173. echo -e "AppDaemon should be reachable by going to the following URL.
  174. ${BL}http://$IP:5050${CL}\n"
  175. exit
  176. else
  177. msg_info "Upgrading AppDaemon"
  178. msg_info "Stopping AppDaemon"
  179. systemctl stop appdaemon
  180. msg_ok "Stopped AppDaemon"
  181. msg_info "Updating AppDaemon"
  182. source /srv/appdaemon/bin/activate
  183. pip install --upgrade appdaemon &>/dev/null
  184. msg_ok "Updated AppDaemon"
  185. msg_info "Starting AppDaemon"
  186. systemctl start appdaemon
  187. sleep 2
  188. msg_ok "Started AppDaemon"
  189. msg_ok "Update Successful"
  190. echo -e "\n Go to http://${IP}:5050 \n"
  191. exit
  192. fi
  193. fi
  194. }
  195. start
  196. build_container
  197. description
  198. msg_ok "Completed Successfully!\n"
  199. echo -e "${APP} should be reachable by going to the following URL.
  200. ${BL}http://${IP}:8123${CL}"