Refactor: ESPHome to uv based install (#5413)
* Refactor: ESPHome to uv based install * fix curl
This commit is contained in:
parent
daad486c5e
commit
66ab254fb2
@ -25,22 +25,57 @@ function update_script() {
|
|||||||
check_container_resources
|
check_container_resources
|
||||||
if [[ ! -f /etc/systemd/system/esphomeDashboard.service ]]; then
|
if [[ ! -f /etc/systemd/system/esphomeDashboard.service ]]; then
|
||||||
msg_error "No ${APP} Installation Found!"
|
msg_error "No ${APP} Installation Found!"
|
||||||
exit
|
exit 1
|
||||||
fi
|
fi
|
||||||
msg_info "Stopping ESPHome"
|
|
||||||
|
msg_info "Stopping ${APP}"
|
||||||
systemctl stop esphomeDashboard
|
systemctl stop esphomeDashboard
|
||||||
msg_ok "Stopped ESPHome"
|
msg_ok "Stopped ${APP}"
|
||||||
|
|
||||||
|
VENV_PATH="/opt/esphome/.venv"
|
||||||
|
ESPHOME_BIN="${VENV_PATH}/bin/esphome"
|
||||||
|
export PYTHON_VERSION="3.12"
|
||||||
|
|
||||||
|
if [[ ! -d "$VENV_PATH" || ! -x "$ESPHOME_BIN" ]]; then
|
||||||
|
PYTHON_VERSION="3.12" setup_uv
|
||||||
|
msg_info "Migrating to uv/venv"
|
||||||
|
rm -rf "$VENV_PATH"
|
||||||
|
mkdir -p /opt/esphome
|
||||||
|
cd /opt/esphome
|
||||||
|
$STD uv venv "$VENV_PATH"
|
||||||
|
$STD "$VENV_PATH/bin/python" -m ensurepip --upgrade
|
||||||
|
$STD "$VENV_PATH/bin/python" -m pip install --upgrade pip
|
||||||
|
$STD "$VENV_PATH/bin/python" -m pip install esphome tornado esptool
|
||||||
|
msg_ok "Migrated to uv/venv"
|
||||||
|
else
|
||||||
msg_info "Updating ESPHome"
|
msg_info "Updating ESPHome"
|
||||||
if [[ -d /srv/esphome ]]; then
|
PYTHON_VERSION="3.12" setup_uv
|
||||||
$STD source /srv/esphome/bin/activate
|
$STD "$VENV_PATH/bin/python" -m pip install --upgrade esphome tornado esptool
|
||||||
fi
|
|
||||||
$STD pip3 install -U esphome
|
|
||||||
msg_ok "Updated ESPHome"
|
msg_ok "Updated ESPHome"
|
||||||
|
fi
|
||||||
|
SERVICE_FILE="/etc/systemd/system/esphomeDashboard.service"
|
||||||
|
if ! grep -q "${VENV_PATH}/bin/esphome" "$SERVICE_FILE"; then
|
||||||
|
msg_info "Updating systemd service"
|
||||||
|
cat <<EOF >"$SERVICE_FILE"
|
||||||
|
[Unit]
|
||||||
|
Description=ESPHome Dashboard
|
||||||
|
After=network.target
|
||||||
|
|
||||||
msg_info "Starting ESPHome"
|
[Service]
|
||||||
|
ExecStart=${VENV_PATH}/bin/esphome dashboard /root/config/
|
||||||
|
Restart=always
|
||||||
|
User=root
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
$STD systemctl daemon-reload
|
||||||
|
msg_ok "Updated systemd service"
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg_info "Starting ${APP}"
|
||||||
systemctl start esphomeDashboard
|
systemctl start esphomeDashboard
|
||||||
msg_ok "Started ESPHome"
|
msg_ok "Started ${APP}"
|
||||||
msg_ok "Updated Successfully"
|
msg_ok "Updated Successfully"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
@ -17,34 +17,34 @@ msg_info "Installing Dependencies"
|
|||||||
$STD apt-get install -y git
|
$STD apt-get install -y git
|
||||||
msg_ok "Installed Dependencies"
|
msg_ok "Installed Dependencies"
|
||||||
|
|
||||||
msg_info "Setup Python3"
|
PYTHON_VERSION="3.12" setup_uv
|
||||||
$STD apt-get install -y \
|
|
||||||
python3 \
|
|
||||||
python3-dev \
|
|
||||||
python3-pip \
|
|
||||||
python3-venv
|
|
||||||
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
|
|
||||||
msg_ok "Setup Python3"
|
|
||||||
|
|
||||||
msg_info "Installing ESPHome"
|
msg_info "Setting up Virtual Environment"
|
||||||
mkdir /root/config
|
mkdir -p /opt/esphome
|
||||||
$STD pip install esphome tornado esptool
|
mkdir -p /root/config
|
||||||
msg_ok "Installed ESPHome"
|
cd /opt/esphome
|
||||||
|
$STD uv venv /opt/esphome/.venv
|
||||||
|
$STD /opt/esphome/.venv/bin/python -m ensurepip --upgrade
|
||||||
|
$STD /opt/esphome/.venv/bin/python -m pip install --upgrade pip
|
||||||
|
$STD /opt/esphome/.venv/bin/python -m pip install esphome tornado esptool
|
||||||
|
msg_ok "Setup and Installed ESPHome"
|
||||||
|
|
||||||
msg_info "Creating Service"
|
msg_info "Creating Service"
|
||||||
|
mkdir -p /root/config
|
||||||
cat <<EOF >/etc/systemd/system/esphomeDashboard.service
|
cat <<EOF >/etc/systemd/system/esphomeDashboard.service
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=ESPHome Dashboard
|
Description=ESPHome Dashboard
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/local/bin/esphome dashboard /root/config/
|
ExecStart=/opt/esphome/.venv/bin/esphome dashboard /root/config/
|
||||||
Restart=always
|
Restart=always
|
||||||
User=root
|
User=root
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
systemctl enable -q --now esphomeDashboard
|
systemctl enable -q --now esphomeDashboard
|
||||||
msg_ok "Created Service"
|
msg_ok "Created Service"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user