Skip to content

Instantly share code, notes, and snippets.

@TomMannson
Last active April 27, 2024 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomMannson/b03e9c8a1b98b309606098c3e9f2b20d to your computer and use it in GitHub Desktop.
Save TomMannson/b03e9c8a1b98b309606098c3e9f2b20d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Set up script with error handling
# set -euo pipefail
set -e
# Update the package index
sudo apt-get update
#### POSTGRESS INSTALL
# Install necessary packages for adding repository and installing PostgreSQL
sudo apt-get install -y wget ca-certificates gnupg lsb-release locales
# Set up PostgreSQL user and group
sudo groupadd -r postgres --gid=990
sudo useradd -r -g postgres --uid=990 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres
sudo mkdir -p /var/lib/postgresql
sudo chown -R postgres:postgres /var/lib/postgresql
echo "Linux user and group configured correctly"
# Configure locales to support UTF-8
sudo apt-get install locales-all
sudo sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen
sudo locale-gen
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
echo "Locale on system configured"
#### Veryfikacja podpisu ODPALIĆ RĘCZNIE
# Add PostgreSQL's official apt repository
echo "deb [signed-by=/usr/share/keyrings/postgres.gpg.asc] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
echo "PostgreSQL's official apt added"
# Import the repository signing key
# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgres.gpg.asc
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "PostgreSQL's signing key imported"
#### Postgress Installing
# Install PostgreSQL
# sudo apt-get update
# sudo apt-get install -y postgresql-15
sudo apt-get install -y postgresql-15-postgis-3
# Modify the PostgreSQL configuration to listen on all interfaces
sudo sed -ri "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/15/main/postgresql.conf
# Allow remote connections (modify pg_hba.conf as needed)
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /etc/postgresql/15/main/pg_hba.conf
echo "PostgreSQL's Database with Postgist installed"
#### POSTGRESS EXTENSIONS
# Installing extensions pg
sudo apt-get install -y postgresql-contrib
echo "PostgreSQL postgresql-contrib extensions installed"
#### ENABLING SERVICE
# Restart PostgreSQL to apply changes
sudo systemctl restart postgresql
# Enable PostgreSQL to start on boot
sudo systemctl enable postgresql
echo "PostgreSQL Server is UP and RUNNING"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment