File size: 2,666 Bytes
2586f2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

# Gemini Business2API Update Script for Linux/macOS
# This script updates the project to the latest version

set -e  # Exit on error

echo "=========================================="
echo "Gemini Business2API Update Script"
echo "=========================================="
echo ""

# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Function to print colored messages
print_success() {
    echo -e "${GREEN}✓ $1${NC}"
}

print_error() {
    echo -e "${RED}✗ $1${NC}"
}

print_info() {
    echo -e "${YELLOW}→ $1${NC}"
}

# Check if git is installed
if ! command -v git &> /dev/null; then
    print_error "Git is not installed. Please install git first."
    exit 1
fi

# Check if python3 is installed
if ! command -v python3 &> /dev/null; then
    print_error "Python3 is not installed. Please install Python 3.11+ first."
    exit 1
fi

# Step 1: Backup current .env file
print_info "Backing up .env file..."
if [ -f ".env" ]; then
    cp .env .env.backup
    print_success ".env backed up to .env.backup"
else
    print_info "No .env file found, skipping backup"
fi

# Step 2: Pull latest code from git
print_info "Pulling latest code from git..."
git fetch origin
git pull origin main || git pull origin master
print_success "Code updated successfully"

# Step 3: Restore .env file
if [ -f ".env.backup" ]; then
    print_info "Restoring .env file..."
    mv .env.backup .env
    print_success ".env restored"
fi

# Step 4: Update Python dependencies
print_info "Updating Python dependencies..."
if [ -d ".venv" ]; then
    print_info "Virtual environment detected, activating..."
    source .venv/bin/activate
fi

pip install -r requirements.txt --upgrade
print_success "Python dependencies updated"

# Step 5: Update frontend dependencies
if [ -d "frontend" ]; then
    print_info "Updating frontend dependencies..."
    cd frontend

    # Check if npm is installed
    if command -v npm &> /dev/null; then
        npm install
        npm run build
        print_success "Frontend dependencies updated and built"
    else
        print_error "npm is not installed. Skipping frontend update."
    fi

    cd ..
fi

# Step 6: Show completion message
echo ""
echo "=========================================="
print_success "Update completed successfully!"
echo "=========================================="
echo ""
print_info "To restart the service, run:"
echo "  python main.py"
echo ""
print_info "Or if using systemd:"
echo "  sudo systemctl restart gemini-business2api"
echo ""