Files
balikci/scripts/cleanup-manual-install.sh
2025-11-11 05:42:16 +03:00

205 lines
7.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ═══════════════════════════════════════════════════════════════
# Oltalama - Manuel Kurulum Temizleme Scripti
# ═══════════════════════════════════════════════════════════════
# Bu script eski manuel kurulumdan (PM2, systemd) kalan dosyaları temizler
# Docker kullanıyorsanız bu dosyalar gereksizdir
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
print_info() {
echo -e "${GREEN}${NC} $1"
}
print_warning() {
echo -e "${YELLOW}${NC} $1"
}
print_error() {
echo -e "${RED}${NC} $1"
}
print_success() {
echo -e "${GREEN}${NC} $1"
}
echo ""
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ Oltalama - Manuel Kurulum Temizleme Scripti ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
print_error "Bu script root olarak çalıştırılmalıdır (sudo)"
exit 1
fi
INSTALL_DIR="/opt/oltalama"
LOG_DIR="/var/log/oltalama"
SERVICE_USER="oltalama"
print_warning "Bu script şunları temizleyecek:"
echo " • PM2 process'leri ve konfigürasyonları"
echo " • Systemd servisleri (oltalama-backend, oltalama-frontend)"
echo " • /opt/oltalama dizini (opsiyonel)"
echo " • /var/log/oltalama dizini (opsiyonel)"
echo " • oltalama kullanıcısı (opsiyonel)"
echo ""
read -p "Devam etmek istiyor musunuz? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "İşlem iptal edildi."
exit 0
fi
# 1. Stop and remove PM2 processes
print_info "PM2 process'leri durduruluyor..."
if command -v pm2 &> /dev/null; then
pm2 delete all 2>/dev/null || print_warning "PM2 process bulunamadı"
pm2 kill 2>/dev/null || true
pm2 unstartup systemd 2>/dev/null || true
print_success "PM2 temizlendi"
else
print_info "PM2 bulunamadı, atlanıyor"
fi
# 2. Stop and disable systemd services
print_info "Systemd servisleri durduruluyor..."
if systemctl list-units --type=service | grep -q "oltalama-backend.service"; then
systemctl stop oltalama-backend 2>/dev/null || true
systemctl disable oltalama-backend 2>/dev/null || true
print_success "oltalama-backend servisi durduruldu ve devre dışı bırakıldı"
else
print_info "oltalama-backend servisi bulunamadı"
fi
if systemctl list-units --type=service | grep -q "oltalama-frontend.service"; then
systemctl stop oltalama-frontend 2>/dev/null || true
systemctl disable oltalama-frontend 2>/dev/null || true
print_success "oltalama-frontend servisi durduruldu ve devre dışı bırakıldı"
else
print_info "oltalama-frontend servisi bulunamadı"
fi
# Remove systemd service files
if [ -f "/etc/systemd/system/oltalama-backend.service" ]; then
rm -f /etc/systemd/system/oltalama-backend.service
print_success "oltalama-backend.service dosyası silindi"
fi
if [ -f "/etc/systemd/system/oltalama-frontend.service" ]; then
rm -f /etc/systemd/system/oltalama-frontend.service
print_success "oltalama-frontend.service dosyası silindi"
fi
# Reload systemd
systemctl daemon-reload 2>/dev/null || true
# 3. Remove PM2 service file
if [ -f "/etc/systemd/system/pm2-root.service" ]; then
print_warning "PM2 systemd servisi bulundu. Silmek istiyor musunuz? (y/N): "
read -p "" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
systemctl stop pm2-root 2>/dev/null || true
systemctl disable pm2-root 2>/dev/null || true
rm -f /etc/systemd/system/pm2-root.service
systemctl daemon-reload 2>/dev/null || true
print_success "PM2 systemd servisi silindi"
fi
fi
# 4. Remove installation directory (optional)
if [ -d "$INSTALL_DIR" ]; then
echo ""
print_warning "$INSTALL_DIR dizini bulundu."
read -p "Silmek istiyor musunuz? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$INSTALL_DIR"
print_success "$INSTALL_DIR dizini silindi"
else
print_info "$INSTALL_DIR dizini korundu"
fi
fi
# 5. Remove log directory (optional)
if [ -d "$LOG_DIR" ]; then
echo ""
print_warning "$LOG_DIR dizini bulundu."
read -p "Silmek istiyor musunuz? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$LOG_DIR"
print_success "$LOG_DIR dizini silindi"
else
print_info "$LOG_DIR dizini korundu"
fi
fi
# 6. Remove system user (optional)
if id "$SERVICE_USER" &>/dev/null; then
echo ""
print_warning "Sistem kullanıcısı '$SERVICE_USER' bulundu."
read -p "Silmek istiyor musunuz? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Check if user has home directory
USER_HOME=$(getent passwd "$SERVICE_USER" | cut -d: -f6)
if [ -d "$USER_HOME" ] && [ "$USER_HOME" != "/" ]; then
read -p "Kullanıcı home dizini ($USER_HOME) de silinsin mi? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
userdel -r "$SERVICE_USER" 2>/dev/null || userdel "$SERVICE_USER" 2>/dev/null || true
print_success "Kullanıcı '$SERVICE_USER' ve home dizini silindi"
else
userdel "$SERVICE_USER" 2>/dev/null || true
print_success "Kullanıcı '$SERVICE_USER' silindi (home dizini korundu)"
fi
else
userdel "$SERVICE_USER" 2>/dev/null || true
print_success "Kullanıcı '$SERVICE_USER' silindi"
fi
else
print_info "Kullanıcı '$SERVICE_USER' korundu"
fi
fi
# 7. Remove PM2 data directories (optional)
if [ -d "/root/.pm2" ]; then
echo ""
print_warning "PM2 data dizini (/root/.pm2) bulundu."
read -p "Silmek istiyor musunuz? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf /root/.pm2
print_success "PM2 data dizini silindi"
fi
fi
echo ""
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ ✅ Temizleme Tamamlandı! ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo ""
print_info "Manuel kurulum dosyaları temizlendi."
print_info "Artık Docker ile çalıştırabilirsiniz:"
echo ""
echo " docker compose -f docker-compose.single.yml up -d --build"
echo ""