561fbd22e0
Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.7 KiB
Bash
80 lines
2.7 KiB
Bash
#!/bin/bash
|
|
# Быстрое развёртывание / обновление на Ubuntu (без Docker)
|
|
# sudo bash scripts/quick-deploy-ubuntu.sh
|
|
#
|
|
# Каталог: SHOP_INSTALL_DIR (по умолчанию /opt/shop)
|
|
# URL репозитория: SHOP_GIT_URL (обязателен при первом clone)
|
|
set -euo pipefail
|
|
|
|
INSTALL_DIR="${SHOP_INSTALL_DIR:-/opt/shop}"
|
|
GIT_URL="${SHOP_GIT_URL:-}"
|
|
|
|
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
|
|
if [ -z "$GIT_URL" ]; then
|
|
echo "Задайте URL репозитория:"
|
|
echo " export SHOP_GIT_URL='https://ваш-forge/user/shop.git'"
|
|
echo " sudo SHOP_GIT_URL=\"\$SHOP_GIT_URL\" bash scripts/quick-deploy-ubuntu.sh"
|
|
exit 1
|
|
fi
|
|
echo "Клонирование: $GIT_URL -> $INSTALL_DIR"
|
|
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"
|