@@ -25,22 +25,57 @@ function update_script() {
2525 check_container_resources
2626 if [[ ! -f /etc/systemd/system/esphomeDashboard.service ]]; then
2727 msg_error " No ${APP} Installation Found!"
28- exit
28+ exit 1
2929 fi
30- msg_info " Stopping ESPHome"
30+
31+ msg_info " Stopping ${APP} "
3132 systemctl stop esphomeDashboard
32- msg_ok " Stopped ESPHome"
33+ msg_ok " Stopped ${APP} "
34+
35+ VENV_PATH=" /opt/esphome/.venv"
36+ ESPHOME_BIN=" ${VENV_PATH} /bin/esphome"
37+ export PYTHON_VERSION=" 3.12"
38+
39+ if [[ ! -d " $VENV_PATH " || ! -x " $ESPHOME_BIN " ]]; then
40+ PYTHON_VERSION=" 3.12" setup_uv
41+ msg_info " Migrating to uv/venv"
42+ rm -rf " $VENV_PATH "
43+ mkdir -p /opt/esphome
44+ cd /opt/esphome
45+ $STD uv venv " $VENV_PATH "
46+ $STD " $VENV_PATH /bin/python" -m ensurepip --upgrade
47+ $STD " $VENV_PATH /bin/python" -m pip install --upgrade pip
48+ $STD " $VENV_PATH /bin/python" -m pip install esphome tornado esptool
49+ msg_ok " Migrated to uv/venv"
50+ else
51+ msg_info " Updating ESPHome"
52+ PYTHON_VERSION=" 3.12" setup_uv
53+ $STD " $VENV_PATH /bin/python" -m pip install --upgrade esphome tornado esptool
54+ msg_ok " Updated ESPHome"
55+ fi
56+ SERVICE_FILE=" /etc/systemd/system/esphomeDashboard.service"
57+ if ! grep -q " ${VENV_PATH} /bin/esphome" " $SERVICE_FILE " ; then
58+ msg_info " Updating systemd service"
59+ cat << EOF >"$SERVICE_FILE "
60+ [Unit]
61+ Description=ESPHome Dashboard
62+ After=network.target
63+
64+ [Service]
65+ ExecStart=${VENV_PATH} /bin/esphome dashboard /root/config/
66+ Restart=always
67+ User=root
3368
34- msg_info " Updating ESPHome"
35- if [[ -d /srv/esphome ]]; then
36- $STD source /srv/esphome/bin/activate
69+ [Install]
70+ WantedBy=multi-user.target
71+ EOF
72+ $STD systemctl daemon-reload
73+ msg_ok " Updated systemd service"
3774 fi
38- $STD pip3 install -U esphome
39- msg_ok " Updated ESPHome"
4075
41- msg_info " Starting ESPHome "
76+ msg_info " Starting ${APP} "
4277 systemctl start esphomeDashboard
43- msg_ok " Started ESPHome "
78+ msg_ok " Started ${APP} "
4479 msg_ok " Updated Successfully"
4580 exit
4681}
@@ -52,4 +87,4 @@ description
5287msg_ok " Completed Successfully!\n"
5388echo -e " ${CREATING}${GN}${APP} setup has been successfully initialized!${CL} "
5489echo -e " ${INFO}${YW} Access it using the following URL:${CL} "
55- echo -e " ${TAB}${GATEWAY}${BGN} http://${IP} :6052${CL} "
90+ echo -e " ${TAB}${GATEWAY}${BGN} http://${IP} :6052${CL} "
0 commit comments