forked from devopsbc01/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresql-Install-1.sh
More file actions
67 lines (48 loc) · 2.17 KB
/
Postgresql-Install-1.sh
File metadata and controls
67 lines (48 loc) · 2.17 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
#!/bin/bash -ex
# This script is for use with the DevOps Challenge of installing PostgreSQL 9.6 on to a instance running Ubuntu.
# Section 1 - Variable Creation
# $rfolder is the install directory for PostgreSQL
rfolder='/postgres'
# $dfolder is the root directory for various types of read-only data files
dfolder='/postgres/data'
# $sysuser is the system user for running PostgreSQL
sysuser='postgres'
# $scripts directory
scripts="/home/$USER/scripts"
# $sqlscript is the sql script for creating the PSQL user and creating a database.
sqlscript="$scripts/initial-table.sql"
# $logfile is the log file for this installation.
logfile='psqlinstall-log'
# Section 2 - Package Installation
# Ensures the server is up to date before proceeding.
echo "Updating server..."
sudo apt-get update -y >> $logfile
# This for-loop will pull all packages from the package array and install them using apt-get
echo "Installing PostgreSQL dependencies"
sudo apt-get install ${packages[@]} -y >> $logfile
# Section 3 - Create required directories
echo "Creating folders $dfolder..."
sudo mkdir -p $dfolder >> $logfile
sudo mkdir -p $scripts >> $logfile
# Section 4 - Create system user
#echo "Creating system user '$sysuser'"
#sudo adduser --system $sysuser >> $logfile
# Section 5 - Installing PSQL
echo "installing PostgreSQL"
sudo apt-get install postgresql postgresql-contrib
echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/10/main/pg_hba.conf
sed -i 's+localhost+*+gI' /etc/postgresql/10/main/postgresql.conf
sed -i 's+#listen_addresses+listen_addresses+gI' /etc/postgresql/10/main/postgresql.conf
#listen_addresses = 'localhost'
# Section 7 - Start PSQL
echo "Wait for PostgreSQL to finish starting up..."
sleep 5
# Section 8 - initial-table.sql script is ran
# The initial-table.sql script is downloaded and ran to create the user, database, and populate the database.
echo "Downloading SQL script"
wget -P $scripts https://raw.githubusercontent.com/devopsbc01/Scripts/master/initial-table.sql
echo "Running script"
#$rfolder/bin/psql -U postgres -f $sqlscript
sudo -u postgres psql -f $sqlscript
echo "Restarting postgres DB"
sudo /etc/init.d/postgresql restart