From 3eb814765976ce0e4ea6c9155b2bbe701a70cd31 Mon Sep 17 00:00:00 2001 From: Tom Frenzel Date: Sun, 16 Feb 2025 14:42:00 +0100 Subject: [PATCH 1/3] sparkyfitness: add initial files --- ct/sparkyfitness.sh | 74 +++++++++++++ frontend/public/json/sparkyfitness.json | 40 ++++++++ install/sparkyfitness-install.sh | 131 ++++++++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 ct/sparkyfitness.sh create mode 100644 frontend/public/json/sparkyfitness.json create mode 100644 install/sparkyfitness-install.sh diff --git a/ct/sparkyfitness.sh b/ct/sparkyfitness.sh new file mode 100644 index 000000000..95f9dafdf --- /dev/null +++ b/ct/sparkyfitness.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://raw.githubusercontent.com/tomfrenzel/ProxmoxVED/main/misc/build.func) +# Copyright (c) 2021-2026 community-scripts ORG +# Author: Tom Frenzel +# License: MIT | https://github.com/tomfrenzel/ProxmoxVED/raw/main/LICENSE +# Source: https://github.com/CodeWithCJ/SparkyFitness + +APP="SparkyFitness" +var_tags="${var_tags:-health;fitness}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-2048}" +var_disk="${var_disk:-4}" +var_os="${var_os:-debian}" +var_version="${var_version:-13}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + + if [[ ! -d /opt/sparkyfitness ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + + NODE_VERSION="20" setup_nodejs + + if check_for_gh_release "sparkyfitness" "CodeWithCJ/SparkyFitness"; then + msg_info "Stopping Services" + systemctl stop sparkyfitness-server + msg_ok "Stopped Services" + + CLEAN_INSTALL=1 fetch_and_deploy_gh_release "sparkyfitness" "CodeWithCJ/SparkyFitness" "tarball" + + msg_info "Updating Sparky Fitness Backend" + cd /opt/sparkyfitness/SparkyFitnessServer + $STD npm install + msg_ok "Updated Sparky Fitness Backend" + + msg_info "Updating Sparky Fitness Frontend" + cd /opt/sparkyfitness/SparkyFitnessFrontend + $STD npm install + $STD npm run build + rm -rf /var/www/sparkyfitness/* + cp -a /opt/sparkyfitness/SparkyFitnessFrontend/dist/. /var/www/sparkyfitness/ + msg_ok "Updated Sparky Fitness Frontend" + + chown -R sparkyfitness:sparkyfitness /opt/sparkyfitness + + msg_info "Starting Services" + $STD systemctl daemon-reload + $STD systemctl restart sparkyfitness-server + $STD systemctl restart nginx + msg_ok "Started Services" + msg_ok "Updated successfully!" + fi + + exit +} + +start +build_container +description + +msg_ok "Completed successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3004${CL}" diff --git a/frontend/public/json/sparkyfitness.json b/frontend/public/json/sparkyfitness.json new file mode 100644 index 000000000..385b4cc56 --- /dev/null +++ b/frontend/public/json/sparkyfitness.json @@ -0,0 +1,40 @@ +{ + "name": "SparkyFitness", + "slug": "sparkyfitness", + "categories": [ + 9 + ], + "date_created": "2026-02-16", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": 80, + "documentation": "https://codewithcj.github.io/SparkyFitness/", + "website": "https://github.com/CodeWithCJ/SparkyFitness", + "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/workout-cool.webp", + "config_path": "/etc/sparkyfitness/.env", + "description": "SparkyFitness is a self-hosted, privacy-first fitness tracking platform for nutrition, workouts, body metrics, and health integrations.", + "install_methods": [ + { + "type": "default", + "script": "ct/sparkyfitness.sh", + "resources": { + "cpu": 1, + "ram": 1028, + "hdd": 4, + "os": "Debian", + "version": "13" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [ + { + "text": "Optional Garmin connector can be enabled during installation.", + "type": "info" + } + ] +} diff --git a/install/sparkyfitness-install.sh b/install/sparkyfitness-install.sh new file mode 100644 index 000000000..1d4b33bca --- /dev/null +++ b/install/sparkyfitness-install.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2026 community-scripts ORG +# Author: tomfrenzel +# License: MIT | https://github.com/tomfrenzel/ProxmoxVED/raw/main/LICENSE +# Source: https://github.com/CodeWithCJ/SparkyFitness + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +APP_SLUG="sparkyfitness" +APP_DIR="/opt/${APP_SLUG}" +CONFIG_DIR="/etc/${APP_SLUG}" +DATA_DIR="/var/lib/${APP_SLUG}" +WEB_DIR="/var/www/${APP_SLUG}" +APP_USER="${APP_SLUG}" +APP_GROUP="${APP_SLUG}" + +DB_NAME="sparkyfitness_db" +DB_USER="sparky" +DB_PASS="$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c20)" +APP_DB_USER="sparky_app" +APP_DB_PASS="$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c20)" +API_ENCRYPTION_KEY="$(openssl rand -hex 32)" +BETTER_AUTH_SECRET="$(openssl rand -hex 32)" + +msg_info "Installing Dependencies" +$STD apt install -y nginx +msg_ok "Installed Dependencies" + +NODE_VERSION="20" setup_nodejs +PG_VERSION="15" setup_postgresql +PG_DB_NAME="${DB_NAME}" PG_DB_USER="${DB_USER}" PG_DB_PASS="${DB_PASS}" PG_DB_GRANT_SUPERUSER="true" setup_postgresql_db + +fetch_and_deploy_gh_release "${APP_SLUG}" "CodeWithCJ/SparkyFitness" "tarball" "latest" "${APP_DIR}" + +msg_info "Configuring Sparky Fitness" +$STD useradd -r -m -d "${DATA_DIR}" -s /usr/sbin/nologin "${APP_USER}" +mkdir -p "${CONFIG_DIR}" "${DATA_DIR}" "${DATA_DIR}/uploads" "${DATA_DIR}/backup" "${WEB_DIR}" +cp "${APP_DIR}/docker/.env.example" "${CONFIG_DIR}/.env" + +sed -i "s|^SPARKY_FITNESS_DB_NAME=.*|SPARKY_FITNESS_DB_NAME=${DB_NAME}|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_DB_USER=.*|SPARKY_FITNESS_DB_USER=${DB_USER}|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_DB_PASSWORD=.*|SPARKY_FITNESS_DB_PASSWORD=${DB_PASS}|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_APP_DB_USER=.*|SPARKY_FITNESS_APP_DB_USER=${APP_DB_USER}|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_APP_DB_PASSWORD=.*|SPARKY_FITNESS_APP_DB_PASSWORD=${APP_DB_PASS}|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_DB_HOST=.*|SPARKY_FITNESS_DB_HOST=localhost|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_SERVER_HOST=.*|SPARKY_FITNESS_SERVER_HOST=localhost|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_SERVER_PORT=.*|SPARKY_FITNESS_SERVER_PORT=3010|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_FRONTEND_URL=.*|SPARKY_FITNESS_FRONTEND_URL=http://${LOCAL_IP}:80|" "${CONFIG_DIR}/.env" +sed -i "s|^SPARKY_FITNESS_API_ENCRYPTION_KEY=.*|SPARKY_FITNESS_API_ENCRYPTION_KEY=${API_ENCRYPTION_KEY}|" "${CONFIG_DIR}/.env" +sed -i "s|^BETTER_AUTH_SECRET=.*|BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}|" "${CONFIG_DIR}/.env" +sed -i "s|^# SERVER_BACKUP_PATH=.*|SERVER_BACKUP_PATH=${DATA_DIR}/backup|" "${CONFIG_DIR}/.env" +sed -i "s|^# SERVER_UPLOADS_PATH=.*|SERVER_UPLOADS_PATH=${DATA_DIR}/uploads|" "${CONFIG_DIR}/.env" + +cp "${CONFIG_DIR}/.env" "${APP_DIR}/.env" +mkdir -p "${DATA_DIR}/uploads" "${DATA_DIR}/backup" +chmod 640 "${CONFIG_DIR}/.env" +msg_ok "Configured Sparky Fitness" + +msg_info "Building Backend" +cd "${APP_DIR}/SparkyFitnessServer" +$STD npm install +msg_ok "Built Backend" + +msg_info "Building Frontend" +cd "${APP_DIR}/SparkyFitnessFrontend" +$STD npm install +$STD npm run build +rm -rf "${WEB_DIR:?}"/* +cp -a "${APP_DIR}/SparkyFitnessFrontend/dist/." "${WEB_DIR}/" +msg_ok "Built Frontend" + +msg_info "Configuring Nginx" +sed \ + -e 's|${SPARKY_FITNESS_SERVER_HOST}|127.0.0.1|g' \ + -e 's|${SPARKY_FITNESS_SERVER_PORT}|3010|g' \ + -e 's|root /usr/share/nginx/html;|root /var/www/sparkyfitness;|g' \ + -e 's|server_name localhost;|server_name _;|g' \ + "${APP_DIR}/docker/nginx.conf" >/etc/nginx/sites-available/${APP_SLUG} +ln -sf /etc/nginx/sites-available/${APP_SLUG} /etc/nginx/sites-enabled/${APP_SLUG} +rm -f /etc/nginx/sites-enabled/default +$STD nginx -t +msg_ok "Configured Nginx" + +msg_info "Creating Services" +cat </etc/systemd/system/sparkyfitness-server.service +[Unit] +Description=SparkyFitness Backend Service +After=network.target postgresql.service +Requires=postgresql.service + +[Service] +Type=simple +User=${APP_USER} +Group=${APP_GROUP} +WorkingDirectory=${APP_DIR}/SparkyFitnessServer +EnvironmentFile=${CONFIG_DIR}/.env +ExecStart=/usr/bin/node SparkyFitnessServer.js +Restart=always +RestartSec=5 + +[Install] +WantedBy=multi-user.target +EOF + +chown -R ${APP_USER}:${APP_GROUP} "${APP_DIR}" "${DATA_DIR}" "${CONFIG_DIR}" +chmod -R 755 "${WEB_DIR}" + +$STD systemctl daemon-reload +$STD systemctl enable --now sparkyfitness-server +$STD systemctl enable --now nginx +msg_ok "Created Services" + +cat <~/sparkyfitness.creds +SparkyFitness Database Credentials +Database Name: ${DB_NAME} +Database User: ${DB_USER} +Database Password: ${DB_PASS} +App Database User: ${APP_DB_USER} +App Database Password: ${APP_DB_PASS} +EOF + +motd_ssh +customize +cleanup_lxc From 7421d98513ab133b4e199b44fa56acd172b3d862 Mon Sep 17 00:00:00 2001 From: Tom Frenzel Date: Wed, 19 Feb 2025 16:40:00 +0100 Subject: [PATCH 2/3] sparkyfitness: cleanup --- ct/sparkyfitness.sh | 18 +++++++++++------- install/sparkyfitness-install.sh | 3 +-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ct/sparkyfitness.sh b/ct/sparkyfitness.sh index 95f9dafdf..a7d517c90 100644 --- a/ct/sparkyfitness.sh +++ b/ct/sparkyfitness.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -source <(curl -fsSL https://raw.githubusercontent.com/tomfrenzel/ProxmoxVED/main/misc/build.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) # Copyright (c) 2021-2026 community-scripts ORG # Author: Tom Frenzel -# License: MIT | https://github.com/tomfrenzel/ProxmoxVED/raw/main/LICENSE +# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # Source: https://github.com/CodeWithCJ/SparkyFitness APP="SparkyFitness" @@ -29,6 +29,10 @@ function update_script() { exit fi + APP_SLUG="sparkyfitness" + APP_DIR="/opt/${APP_SLUG}" + WEB_DIR="/var/www/${APP_SLUG}" + NODE_VERSION="20" setup_nodejs if check_for_gh_release "sparkyfitness" "CodeWithCJ/SparkyFitness"; then @@ -39,19 +43,19 @@ function update_script() { CLEAN_INSTALL=1 fetch_and_deploy_gh_release "sparkyfitness" "CodeWithCJ/SparkyFitness" "tarball" msg_info "Updating Sparky Fitness Backend" - cd /opt/sparkyfitness/SparkyFitnessServer + cd "${APP_DIR}/SparkyFitnessServer" $STD npm install msg_ok "Updated Sparky Fitness Backend" msg_info "Updating Sparky Fitness Frontend" - cd /opt/sparkyfitness/SparkyFitnessFrontend + cd "${APP_DIR}/SparkyFitnessFrontend" $STD npm install $STD npm run build - rm -rf /var/www/sparkyfitness/* - cp -a /opt/sparkyfitness/SparkyFitnessFrontend/dist/. /var/www/sparkyfitness/ + rm -rf "${WEB_DIR:?}"/* + cp -a "${APP_DIR}/SparkyFitnessFrontend/dist/." "${WEB_DIR}/" msg_ok "Updated Sparky Fitness Frontend" - chown -R sparkyfitness:sparkyfitness /opt/sparkyfitness + chown -R sparkyfitness:sparkyfitness "${APP_DIR}" msg_info "Starting Services" $STD systemctl daemon-reload diff --git a/install/sparkyfitness-install.sh b/install/sparkyfitness-install.sh index 1d4b33bca..81e1aabd2 100644 --- a/install/sparkyfitness-install.sh +++ b/install/sparkyfitness-install.sh @@ -2,7 +2,7 @@ # Copyright (c) 2021-2026 community-scripts ORG # Author: tomfrenzel -# License: MIT | https://github.com/tomfrenzel/ProxmoxVED/raw/main/LICENSE +# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # Source: https://github.com/CodeWithCJ/SparkyFitness source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" @@ -72,7 +72,6 @@ msg_info "Building Frontend" cd "${APP_DIR}/SparkyFitnessFrontend" $STD npm install $STD npm run build -rm -rf "${WEB_DIR:?}"/* cp -a "${APP_DIR}/SparkyFitnessFrontend/dist/." "${WEB_DIR}/" msg_ok "Built Frontend" From bf7b3fb9e8fac7cd32743efa12e6bda8bf917569 Mon Sep 17 00:00:00 2001 From: Tom Frenzel Date: Thu, 19 Feb 2026 21:49:02 +0100 Subject: [PATCH 3/3] sparkyfitness: refactor --- ct/sparkyfitness.sh | 25 ++--- frontend/public/json/sparkyfitness.json | 17 ++-- install/sparkyfitness-install.sh | 120 +++++++++--------------- 3 files changed, 57 insertions(+), 105 deletions(-) diff --git a/ct/sparkyfitness.sh b/ct/sparkyfitness.sh index a7d517c90..011cf1697 100644 --- a/ct/sparkyfitness.sh +++ b/ct/sparkyfitness.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) # Copyright (c) 2021-2026 community-scripts ORG -# Author: Tom Frenzel +# Author: Tom Frenzel (tomfrenzel) # License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # Source: https://github.com/CodeWithCJ/SparkyFitness @@ -29,38 +29,29 @@ function update_script() { exit fi - APP_SLUG="sparkyfitness" - APP_DIR="/opt/${APP_SLUG}" - WEB_DIR="/var/www/${APP_SLUG}" - NODE_VERSION="20" setup_nodejs if check_for_gh_release "sparkyfitness" "CodeWithCJ/SparkyFitness"; then msg_info "Stopping Services" - systemctl stop sparkyfitness-server + systemctl stop sparkyfitness-server nginx msg_ok "Stopped Services" CLEAN_INSTALL=1 fetch_and_deploy_gh_release "sparkyfitness" "CodeWithCJ/SparkyFitness" "tarball" msg_info "Updating Sparky Fitness Backend" - cd "${APP_DIR}/SparkyFitnessServer" + cd "/opt/sparkyfitness/SparkyFitnessServer" $STD npm install msg_ok "Updated Sparky Fitness Backend" - msg_info "Updating Sparky Fitness Frontend" - cd "${APP_DIR}/SparkyFitnessFrontend" + msg_info "Updating Sparky Fitness Frontend (Patience)" + cd "/opt/sparkyfitness/SparkyFitnessFrontend" $STD npm install $STD npm run build - rm -rf "${WEB_DIR:?}"/* - cp -a "${APP_DIR}/SparkyFitnessFrontend/dist/." "${WEB_DIR}/" + cp -a "/opt/sparkyfitness/SparkyFitnessFrontend/dist/." "/var/www/sparkyfitness/" msg_ok "Updated Sparky Fitness Frontend" - chown -R sparkyfitness:sparkyfitness "${APP_DIR}" - msg_info "Starting Services" - $STD systemctl daemon-reload - $STD systemctl restart sparkyfitness-server - $STD systemctl restart nginx + $STD systemctl start sparkyfitness-server nginx msg_ok "Started Services" msg_ok "Updated successfully!" fi @@ -75,4 +66,4 @@ description msg_ok "Completed successfully!\n" echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" echo -e "${INFO}${YW} Access it using the following URL:${CL}" -echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3004${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}${CL}" diff --git a/frontend/public/json/sparkyfitness.json b/frontend/public/json/sparkyfitness.json index 385b4cc56..48dc5f2a0 100644 --- a/frontend/public/json/sparkyfitness.json +++ b/frontend/public/json/sparkyfitness.json @@ -9,18 +9,18 @@ "updateable": true, "privileged": false, "interface_port": 80, - "documentation": "https://codewithcj.github.io/SparkyFitness/", + "documentation": "https://codewithcj.github.io/SparkyFitness", "website": "https://github.com/CodeWithCJ/SparkyFitness", - "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/workout-cool.webp", + "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/sparkyfitness.webp", "config_path": "/etc/sparkyfitness/.env", - "description": "SparkyFitness is a self-hosted, privacy-first fitness tracking platform for nutrition, workouts, body metrics, and health integrations.", + "description": "A self-hosted, privacy-first alternative to MyFitnessPal. Track nutrition, exercise, body metrics, and health data while keeping full control of your data.", "install_methods": [ { "type": "default", "script": "ct/sparkyfitness.sh", "resources": { - "cpu": 1, - "ram": 1028, + "cpu": 2, + "ram": 2048, "hdd": 4, "os": "Debian", "version": "13" @@ -31,10 +31,5 @@ "username": null, "password": null }, - "notes": [ - { - "text": "Optional Garmin connector can be enabled during installation.", - "type": "info" - } - ] + "notes": [] } diff --git a/install/sparkyfitness-install.sh b/install/sparkyfitness-install.sh index 81e1aabd2..865dee432 100644 --- a/install/sparkyfitness-install.sh +++ b/install/sparkyfitness-install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Copyright (c) 2021-2026 community-scripts ORG -# Author: tomfrenzel +# Author: Tom Frenzel (tomfrenzel) # License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # Source: https://github.com/CodeWithCJ/SparkyFitness @@ -13,81 +13,50 @@ setting_up_container network_check update_os -APP_SLUG="sparkyfitness" -APP_DIR="/opt/${APP_SLUG}" -CONFIG_DIR="/etc/${APP_SLUG}" -DATA_DIR="/var/lib/${APP_SLUG}" -WEB_DIR="/var/www/${APP_SLUG}" -APP_USER="${APP_SLUG}" -APP_GROUP="${APP_SLUG}" - -DB_NAME="sparkyfitness_db" -DB_USER="sparky" -DB_PASS="$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c20)" -APP_DB_USER="sparky_app" -APP_DB_PASS="$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c20)" -API_ENCRYPTION_KEY="$(openssl rand -hex 32)" -BETTER_AUTH_SECRET="$(openssl rand -hex 32)" - msg_info "Installing Dependencies" $STD apt install -y nginx msg_ok "Installed Dependencies" NODE_VERSION="20" setup_nodejs PG_VERSION="15" setup_postgresql -PG_DB_NAME="${DB_NAME}" PG_DB_USER="${DB_USER}" PG_DB_PASS="${DB_PASS}" PG_DB_GRANT_SUPERUSER="true" setup_postgresql_db +PG_DB_NAME="sparkyfitness" PG_DB_USER="sparky" PG_DB_GRANT_SUPERUSER="true" setup_postgresql_db -fetch_and_deploy_gh_release "${APP_SLUG}" "CodeWithCJ/SparkyFitness" "tarball" "latest" "${APP_DIR}" +fetch_and_deploy_gh_release sparkyfitness "CodeWithCJ/SparkyFitness" "tarball" "latest" msg_info "Configuring Sparky Fitness" -$STD useradd -r -m -d "${DATA_DIR}" -s /usr/sbin/nologin "${APP_USER}" -mkdir -p "${CONFIG_DIR}" "${DATA_DIR}" "${DATA_DIR}/uploads" "${DATA_DIR}/backup" "${WEB_DIR}" -cp "${APP_DIR}/docker/.env.example" "${CONFIG_DIR}/.env" - -sed -i "s|^SPARKY_FITNESS_DB_NAME=.*|SPARKY_FITNESS_DB_NAME=${DB_NAME}|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_DB_USER=.*|SPARKY_FITNESS_DB_USER=${DB_USER}|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_DB_PASSWORD=.*|SPARKY_FITNESS_DB_PASSWORD=${DB_PASS}|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_APP_DB_USER=.*|SPARKY_FITNESS_APP_DB_USER=${APP_DB_USER}|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_APP_DB_PASSWORD=.*|SPARKY_FITNESS_APP_DB_PASSWORD=${APP_DB_PASS}|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_DB_HOST=.*|SPARKY_FITNESS_DB_HOST=localhost|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_SERVER_HOST=.*|SPARKY_FITNESS_SERVER_HOST=localhost|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_SERVER_PORT=.*|SPARKY_FITNESS_SERVER_PORT=3010|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_FRONTEND_URL=.*|SPARKY_FITNESS_FRONTEND_URL=http://${LOCAL_IP}:80|" "${CONFIG_DIR}/.env" -sed -i "s|^SPARKY_FITNESS_API_ENCRYPTION_KEY=.*|SPARKY_FITNESS_API_ENCRYPTION_KEY=${API_ENCRYPTION_KEY}|" "${CONFIG_DIR}/.env" -sed -i "s|^BETTER_AUTH_SECRET=.*|BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}|" "${CONFIG_DIR}/.env" -sed -i "s|^# SERVER_BACKUP_PATH=.*|SERVER_BACKUP_PATH=${DATA_DIR}/backup|" "${CONFIG_DIR}/.env" -sed -i "s|^# SERVER_UPLOADS_PATH=.*|SERVER_UPLOADS_PATH=${DATA_DIR}/uploads|" "${CONFIG_DIR}/.env" - -cp "${CONFIG_DIR}/.env" "${APP_DIR}/.env" -mkdir -p "${DATA_DIR}/uploads" "${DATA_DIR}/backup" -chmod 640 "${CONFIG_DIR}/.env" +mkdir -p "/etc/sparkyfitness" "/var/lib/sparkyfitness/uploads" "/var/lib/sparkyfitness/backup" "/var/www/sparkyfitness" +cp "/opt/sparkyfitness/docker/.env.example" "/etc/sparkyfitness/.env" +sed \ + -i \ + -e "s|^SPARKY_FITNESS_DB_NAME=.*|SPARKY_FITNESS_DB_NAME=sparkyfitness|" \ + -e "s|^SPARKY_FITNESS_DB_USER=.*|SPARKY_FITNESS_DB_USER=sparky|" \ + -e "s|^SPARKY_FITNESS_DB_PASSWORD=.*|SPARKY_FITNESS_DB_PASSWORD=${PG_DB_PASS}|" \ + -e "s|^SPARKY_FITNESS_APP_DB_USER=.*|SPARKY_FITNESS_APP_DB_USER=sparky_app|" \ + -e "s|^SPARKY_FITNESS_APP_DB_PASSWORD=.*|SPARKY_FITNESS_APP_DB_PASSWORD=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c20)|" \ + -e "s|^SPARKY_FITNESS_DB_HOST=.*|SPARKY_FITNESS_DB_HOST=localhost|" \ + -e "s|^SPARKY_FITNESS_SERVER_HOST=.*|SPARKY_FITNESS_SERVER_HOST=localhost|" \ + -e "s|^SPARKY_FITNESS_SERVER_PORT=.*|SPARKY_FITNESS_SERVER_PORT=3010|" \ + -e "s|^SPARKY_FITNESS_FRONTEND_URL=.*|SPARKY_FITNESS_FRONTEND_URL=http://${LOCAL_IP}:80|" \ + -e "s|^SPARKY_FITNESS_API_ENCRYPTION_KEY=.*|SPARKY_FITNESS_API_ENCRYPTION_KEY=$(openssl rand -hex 32)|" \ + -e "s|^BETTER_AUTH_SECRET=.*|BETTER_AUTH_SECRET=$(openssl rand -hex 32)|" \ + -e "s|^# SERVER_BACKUP_PATH=.*|SERVER_BACKUP_PATH=/var/lib/sparkyfitness/backup|" \ + -e "s|^# SERVER_UPLOADS_PATH=.*|SERVER_UPLOADS_PATH=/var/lib/sparkyfitness/uploads|" \ + "/etc/sparkyfitness/.env" msg_ok "Configured Sparky Fitness" msg_info "Building Backend" -cd "${APP_DIR}/SparkyFitnessServer" +cd "/opt/sparkyfitness/SparkyFitnessServer" $STD npm install msg_ok "Built Backend" -msg_info "Building Frontend" -cd "${APP_DIR}/SparkyFitnessFrontend" +msg_info "Building Frontend (Patience)" +cd "/opt/sparkyfitness/SparkyFitnessFrontend" $STD npm install $STD npm run build -cp -a "${APP_DIR}/SparkyFitnessFrontend/dist/." "${WEB_DIR}/" +cp -a "/opt/sparkyfitness/SparkyFitnessFrontend/dist/." "/var/www/sparkyfitness/" msg_ok "Built Frontend" -msg_info "Configuring Nginx" -sed \ - -e 's|${SPARKY_FITNESS_SERVER_HOST}|127.0.0.1|g' \ - -e 's|${SPARKY_FITNESS_SERVER_PORT}|3010|g' \ - -e 's|root /usr/share/nginx/html;|root /var/www/sparkyfitness;|g' \ - -e 's|server_name localhost;|server_name _;|g' \ - "${APP_DIR}/docker/nginx.conf" >/etc/nginx/sites-available/${APP_SLUG} -ln -sf /etc/nginx/sites-available/${APP_SLUG} /etc/nginx/sites-enabled/${APP_SLUG} -rm -f /etc/nginx/sites-enabled/default -$STD nginx -t -msg_ok "Configured Nginx" - -msg_info "Creating Services" +msg_info "Creating SparkyFitness Service" cat </etc/systemd/system/sparkyfitness-server.service [Unit] Description=SparkyFitness Backend Service @@ -96,10 +65,8 @@ Requires=postgresql.service [Service] Type=simple -User=${APP_USER} -Group=${APP_GROUP} -WorkingDirectory=${APP_DIR}/SparkyFitnessServer -EnvironmentFile=${CONFIG_DIR}/.env +WorkingDirectory=/opt/sparkyfitness/SparkyFitnessServer +EnvironmentFile=/etc/sparkyfitness/.env ExecStart=/usr/bin/node SparkyFitnessServer.js Restart=always RestartSec=5 @@ -107,23 +74,22 @@ RestartSec=5 [Install] WantedBy=multi-user.target EOF +systemctl enable -q --now sparkyfitness-server +msg_ok "Created SparkyFitness Service" -chown -R ${APP_USER}:${APP_GROUP} "${APP_DIR}" "${DATA_DIR}" "${CONFIG_DIR}" -chmod -R 755 "${WEB_DIR}" - -$STD systemctl daemon-reload -$STD systemctl enable --now sparkyfitness-server -$STD systemctl enable --now nginx -msg_ok "Created Services" - -cat <~/sparkyfitness.creds -SparkyFitness Database Credentials -Database Name: ${DB_NAME} -Database User: ${DB_USER} -Database Password: ${DB_PASS} -App Database User: ${APP_DB_USER} -App Database Password: ${APP_DB_PASS} -EOF +msg_info "Configuring Nginx" +sed \ + -e 's|${SPARKY_FITNESS_SERVER_HOST}|127.0.0.1|g' \ + -e 's|${SPARKY_FITNESS_SERVER_PORT}|3010|g' \ + -e 's|root /usr/share/nginx/html;|root /var/www/sparkyfitness;|g' \ + -e 's|server_name localhost;|server_name _;|g' \ + "/opt/sparkyfitness/docker/nginx.conf" >/etc/nginx/sites-available/sparkyfitness +ln -sf /etc/nginx/sites-available/sparkyfitness /etc/nginx/sites-enabled/sparkyfitness +rm -f /etc/nginx/sites-enabled/default +$STD nginx -t +$STD systemctl enable -q --now nginx +$STD systemctl reload nginx +msg_ok "Configured Nginx" motd_ssh customize