Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
71 lines (59 loc) · 2.25 KB
/
Copy pathinstall.sh
File metadata and controls
71 lines (59 loc) · 2.25 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
#!/bin/bash
# ************************************************************************************
# Copyright (C) 2022-2026 rhctl Contributors
#
# SPDX-License-Identifier: Apache-2.0
# ************************************************************************************
# Install PostgreSQL (latest from PGDG) and ensure the service is running.
# Default Port: 5432
#
# If exists, skip — safe to re-run.
#
# Usage:
# ./install.sh
#
# Required Parameters:
# (none)
#
# Optional Parameters:
# (none)
#
# Override Parameters:
# (none)
#
# Since : 1.0.1
# Date : Feb 8, 2026
# ************************************************************************************
# Check if PostgreSQL is already installed
if command -v psql &> /dev/null; then
PG_VERSION=$(psql --version 2>&1 | grep -oP '(?<=psql \(PostgreSQL\) )[\d.]+' | head -1)
echo "[INFO] PostgreSQL is already installed (version: $PG_VERSION)"
echo "[INFO] Skipping reinstallation"
if systemctl is-active --quiet postgresql; then
echo "[INFO] PostgreSQL service is currently running"
else
echo "[WARN] PostgreSQL service is not running. Starting it now..."
sudo systemctl start postgresql
fi
echo "[INFO] To test PostgreSQL, run: sudo -u postgres psql -c 'SELECT version();'"
exit 0
fi
echo "[INFO] PostgreSQL not found. Proceeding with installation..."
echo "[INFO] Install prerequisites"
sudo apt update
sudo apt install -y lsb-release curl gpg ca-certificates
echo "[INFO] Add the PostgreSQL repository key"
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
echo "[INFO] Update package list"
sudo apt update
echo "[INFO] Install PostgreSQL (latest version)"
sudo apt install -y postgresql postgresql-contrib
echo "[INFO] Enable PostgreSQL to start on boot"
sudo systemctl enable postgresql
echo "[INFO] Start PostgreSQL service"
sudo systemctl start postgresql
echo "[INFO] Check PostgreSQL status"
sudo systemctl status postgresql --no-pager
echo "[INFO] PostgreSQL installation completed successfully"
echo "[INFO] Installed PostgreSQL version: $(psql --version)"