|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: johanngrobe |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/joaovitoriasilva/endurain |
| 7 | + |
| 8 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt install -y \ |
| 18 | + default-libmysqlclient-dev \ |
| 19 | + build-essential \ |
| 20 | + pkg-config |
| 21 | +msg_ok "Installed Dependencies" |
| 22 | + |
| 23 | +PYTHON_VERSION="3.13" setup_uv |
| 24 | +NODE_VERSION="24" setup_nodejs |
| 25 | +PG_VERSION="17" PG_MODULES="postgis" setup_postgresql |
| 26 | +PG_DB_NAME="enduraindb" PG_DB_USER="endurain" setup_postgresql_db |
| 27 | + |
| 28 | +fetch_and_deploy_gh_release "endurain" "joaovitoriasilva/endurain" "tarball" "latest" "/opt/endurain" |
| 29 | + |
| 30 | +msg_info "Setting up Endurain" |
| 31 | +cd /opt/endurain |
| 32 | +rm -rf \ |
| 33 | + /opt/endurain/{docs,example.env,screenshot_01.png} \ |
| 34 | + /opt/endurain/docker* \ |
| 35 | + /opt/endurain/*.yml |
| 36 | +mkdir -p /opt/endurain_data/{data,logs} |
| 37 | +SECRET_KEY=$(openssl rand -hex 32) |
| 38 | +FERNET_KEY=$(openssl rand -base64 32) |
| 39 | +IP=$(hostname -I | awk '{print $1}') |
| 40 | +ENDURAIN_HOST=http://${IP}:8080 |
| 41 | +cat <<EOF >/opt/endurain/.env |
| 42 | +DB_PASSWORD=${PG_DB_PASS} |
| 43 | +
|
| 44 | +SECRET_KEY=${SECRET_KEY} |
| 45 | +FERNET_KEY=${FERNET_KEY} |
| 46 | +
|
| 47 | +TZ=Europe/Berlin |
| 48 | +ENDURAIN_HOST=${ENDURAIN_HOST} |
| 49 | +BEHIND_PROXY=false |
| 50 | +
|
| 51 | +POSTGRES_DB=${PG_DB_NAME} |
| 52 | +POSTGRES_USER=${PG_DB_USER} |
| 53 | +PGDATA=/var/lib/postgresql/${PG_DB_NAME} |
| 54 | +
|
| 55 | +DB_DATABASE=${PG_DB_NAME} |
| 56 | +DB_USER=${PG_DB_USER} |
| 57 | +DB_PORT=5432 |
| 58 | +DB_HOST=localhost |
| 59 | +
|
| 60 | +DATABASE_URL=postgresql+psycopg://${PG_DB_USER}:${PG_DB_PASS}@localhost:5432/${PG_DB_NAME} |
| 61 | +
|
| 62 | +BACKEND_DIR="/opt/endurain/backend/app" |
| 63 | +FRONTEND_DIR="/opt/endurain/frontend/app/dist" |
| 64 | +DATA_DIR="/opt/endurain_data/data" |
| 65 | +LOGS_DIR="/opt/endurain_data/logs" |
| 66 | +
|
| 67 | +#SMTP_HOST=smtp.protonmail.ch |
| 68 | +#SMTP_PORT=587 |
| 69 | + |
| 70 | +#SMTP_PASSWORD=your-app-password |
| 71 | +#SMTP_SECURE=true |
| 72 | +#SMTP_SECURE_TYPE=starttls |
| 73 | +EOF |
| 74 | +msg_ok "Setup Endurain" |
| 75 | + |
| 76 | +msg_info "Building Frontend" |
| 77 | +cd /opt/endurain/frontend/app |
| 78 | +$STD npm ci --prefer-offline |
| 79 | +$STD npm run build |
| 80 | +cat <<EOF >/opt/endurain/frontend/app/dist/env.js |
| 81 | +window.env = { |
| 82 | + ENDURAIN_HOST: "${ENDURAIN_HOST}" |
| 83 | +} |
| 84 | +EOF |
| 85 | +msg_ok "Built Frontend" |
| 86 | + |
| 87 | +msg_info "Setting up Backend" |
| 88 | +cd /opt/endurain/backend |
| 89 | +$STD uv tool install poetry |
| 90 | +$STD uv tool update-shell |
| 91 | +export PATH="/root/.local/bin:$PATH" |
| 92 | +$STD poetry self add poetry-plugin-export |
| 93 | +$STD poetry export -f requirements.txt --output requirements.txt --without-hashes |
| 94 | +$STD uv venv |
| 95 | +$STD uv pip install -r requirements.txt |
| 96 | +msg_ok "Setup Backend" |
| 97 | + |
| 98 | +msg_info "Creating Service" |
| 99 | +cat <<EOF >/etc/systemd/system/endurain.service |
| 100 | +[Unit] |
| 101 | +Description=Endurain FastAPI Backend |
| 102 | +After=network.target postgresql.service |
| 103 | +
|
| 104 | +[Service] |
| 105 | +WorkingDirectory=/opt/endurain/backend/app |
| 106 | +EnvironmentFile=/opt/endurain/.env |
| 107 | +ExecStart=/opt/endurain/backend/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 8080 |
| 108 | +Restart=always |
| 109 | +RestartSec=5 |
| 110 | +User=root |
| 111 | +StandardOutput=journal |
| 112 | +StandardError=journal |
| 113 | +
|
| 114 | +[Install] |
| 115 | +WantedBy=multi-user.target |
| 116 | +EOF |
| 117 | +systemctl enable -q --now endurain |
| 118 | +msg_ok "Created Service" |
| 119 | + |
| 120 | +motd_ssh |
| 121 | +customize |
| 122 | +cleanup_lxc |
0 commit comments