forked from databasus/databasus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-postgresus.sh
More file actions
85 lines (73 loc) · 2.57 KB
/
install-postgresus.sh
File metadata and controls
85 lines (73 loc) · 2.57 KB
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
#!/bin/bash
# Check if script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "Error: This script must be run as root (sudo ./install-postgresus.sh)" >&2
exit 1
fi
# Set up logging
LOG_FILE="/var/log/postgresus-install.log"
INSTALL_DIR="/opt/postgresus"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
# Create log file if doesn't exist
touch "$LOG_FILE"
log "Starting PostgresUS installation..."
# Create installation directory
log "Creating installation directory..."
if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR"
log "Created directory: $INSTALL_DIR"
else
log "Directory already exists: $INSTALL_DIR"
fi
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
log "Docker not found. Installing Docker..."
# Install Docker
apt-get update
apt-get remove -y docker docker-engine docker.io containerd runc
apt-get install -y ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
log "Docker installed successfully"
else
log "Docker already installed"
fi
# Check if docker-compose is installed
if ! command -v docker-compose &> /dev/null && ! command -v docker compose &> /dev/null; then
log "Docker Compose not found. Installing Docker Compose..."
apt-get update
apt-get install -y docker-compose-plugin
log "Docker Compose installed successfully"
else
log "Docker Compose already installed"
fi
# Write docker-compose.yml
log "Writing docker-compose.yml to $INSTALL_DIR"
cat > "$INSTALL_DIR/docker-compose.yml" << 'EOF'
version: "3"
services:
postgresus:
container_name: postgresus
image: rostislavdugin/postgresus:latest
ports:
- "4005:4005"
volumes:
- ./postgresus-data:/postgresus-data
restart: unless-stopped
EOF
log "docker-compose.yml created successfully"
# Start PostgresUS
log "Starting PostgresUS..."
cd "$INSTALL_DIR"
docker compose up -d
log "PostgresUS started successfully"
log "Postgresus installation completed successfully!"
log "-------------------------------------------"
log "To launch:"
log "> cd $INSTALL_DIR && docker compose up -d"
log "Access Postgresus at: http://localhost:4005"