-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.InstallPostgres.sh
executable file
·58 lines (50 loc) · 1.88 KB
/
3.InstallPostgres.sh
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
#!/bin/sh
echo "======================================"
echo " Step 1: Installing PostgreSQL "
echo "======================================"
# Step 1: Check if PostgreSQL is already installed
echo "1. Checking if PostgreSQL is already installed..."
if command -v psql >/dev/null 2>&1; then
echo "✅ PostgreSQL is already installed."
else
# Step 2: Add PostgreSQL repository to apt sources list
echo "2. Adding PostgreSQL repository..."
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
if [ $? -ne 0 ]; then
echo "❌ Failed to add PostgreSQL repository. Exiting."
exit 1
else
echo "✅ PostgreSQL repository added successfully."
fi
# Step 3: Add PostgreSQL GPG key
echo "3. Adding PostgreSQL GPG key..."
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
if [ $? -ne 0 ]; then
echo "❌ Failed to add PostgreSQL GPG key. Exiting."
exit 1
else
echo "✅ PostgreSQL GPG key added successfully."
fi
# Step 4: Install PostgreSQL and PostgreSQL client
echo "4. Installing PostgreSQL and PostgreSQL client..."
sudo apt update
sudo apt install postgresql postgresql-client -y
if [ $? -ne 0 ]; then
echo "❌ Failed to install PostgreSQL. Exiting."
exit 1
else
echo "✅ PostgreSQL and PostgreSQL client installed successfully."
fi
fi
# Step 5: Verify PostgreSQL version
echo "5. Verifying PostgreSQL version..."
psql --version
if [ $? -ne 0 ]; then
echo "❌ PostgreSQL version check failed. Exiting."
exit 1
else
echo "✅ PostgreSQL version verified successfully."
fi
echo "======================================"
echo "✅ PostgreSQL installed and running!"
echo "======================================"