#!/bin/bash # Быстрое развёртывание / обновление на Ubuntu (без Docker) # sudo bash scripts/quick-deploy-ubuntu.sh # # Каталог по умолчанию: /opt/shop/shop10 # Переопределение: SHOP_INSTALL_DIR=/opt/shop/shop10 SHOP_GIT_URL=https://... set -euo pipefail INSTALL_DIR="${SHOP_INSTALL_DIR:-/opt/shop/shop10}" GIT_URL="${SHOP_GIT_URL:-https://git.evilfox.cc/test/shop10.git}" if [ "$(id -u)" -ne 0 ]; then echo "Запустите от root: sudo bash scripts/quick-deploy-ubuntu.sh" exit 1 fi echo "=== Shop: быстрое развёртывание ===" echo "Каталог: $INSTALL_DIR" if ! command -v node >/dev/null; then echo "Установка Node.js 20..." apt update apt install -y git curl ca-certificates curl -fsSL https://deb.nodesource.com/setup_20.x | bash - apt install -y nodejs fi if [ ! -f "$INSTALL_DIR/package.json" ]; then echo "Клонирование репозитория..." mkdir -p "$(dirname "$INSTALL_DIR")" git clone "$GIT_URL" "$INSTALL_DIR" fi export SHOP_ROOT="$INSTALL_DIR" cd "$INSTALL_DIR" git config --global --add safe.directory "$INSTALL_DIR" 2>/dev/null || true git pull bash scripts/install-postgresql-ubuntu.sh bash scripts/setup-postgres-ubuntu.sh if [ ! -f .env ]; then cp .env.example .env if command -v openssl >/dev/null; then SECRET=$(openssl rand -hex 32) sed -i "s/change-me-to-a-long-random-string/${SECRET}/" .env fi if ! grep -q '^DATABASE_URL=' .env; then echo 'DATABASE_URL=postgresql://shop:shop@127.0.0.1:5432/shop' >> .env fi echo "Создан .env — проверьте SITE_URL и SMTP" fi npm install --omit=dev if [ -f deploy/shop.service ]; then cp -f deploy/shop.service /etc/systemd/system/shop.service # Подставить фактический путь в unit sed -i "s|WorkingDirectory=.*|WorkingDirectory=${INSTALL_DIR}|" /etc/systemd/system/shop.service sed -i "s|EnvironmentFile=.*|EnvironmentFile=${INSTALL_DIR}/.env|" /etc/systemd/system/shop.service systemctl daemon-reload systemctl enable shop 2>/dev/null || true systemctl restart shop sleep 2 curl -sf http://127.0.0.1:3000/health && echo && echo "OK — shop запущен (systemd)" systemctl reload caddy 2>/dev/null || true else echo "deploy/shop.service не найден — запустите: npm start" fi echo "" echo "Обновления в будущем:" echo " bash ${INSTALL_DIR}/scripts/server-update.sh"