File: pgsql-allowip.sh

package info (click to toggle)
wwwconfig-common 0.3.0
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 488 kB
  • sloc: sh: 952; makefile: 5
file content (87 lines) | stat: -rwxr-xr-x 3,116 bytes parent folder | download | duplicates (6)
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
86
87
#!/bin/sh
# File:		pgsql-allowip.sh
# Changes:
#	20010225 Ola Lundqvist <opal@debian.org>
#	20011022 Luca De Vitis <luca@debian.org>
#      		Changed the sed script on line 18.
#		Need only one regular expression.
# Needs:
#		/etc/postgresql/postmaster.init or
#		/etc/postgresql/postmaster.conf
# Description:	Allows ip connections to database.
# Sets:		$status = {error, nothing, restart, start}
#		$error = error message (if $status = error)

status=error

if [ -f /etc/postgresql/postmaster.conf ] ; then
    # Allowed by default so not change should be needed, but it will be
    # done anyway, to make sure that it works.
    status=nothing
    if grep -e 'tcpip_socket' /etc/postgresql/postmaster.conf > /dev/null 2>&1 ; then
	if ! grep -e '^[[:space:]]*tcpip_socket[[:space:]]*=[[:space:]]*1' \
	    /etc/postgresql/postmaster.conf > /dev/null 2>&1 ; then
	    sed -e 's/#[[:space:]]*tcpip_socket[[:space:]]*=.*/tcpip_socket=1/;' \
		/etc/postgresql/postmaster.conf \
		> /etc/postgresql/postmaster.conf.tmp
	    if grep 'tcpip_socket=1' \
		/etc/postgresql/postmaster.conf.tmp \
		> /dev/null 2>&1; then
		cp /etc/postgresql/postmaster.conf \
		    /etc/postgresql/postmaster.conf.back > /dev/null 2>&1
		mv /etc/postgresql/postmaster.conf.tmp \
		    /etc/postgresql/postmaster.conf > /dev/null 2>&1;
		log="${log}Now restarting postgres to make this take effect."
		status=restart
		/etc/init.d/postgresql restart || true
		log="${log}Waiting for the database to really start."
		sleep 5
	    else
		error="Local database configuration was not successful, trying anyway."
		status=error
		rm -f /etc/postgresql/postmaster.conf.tmp
	    fi
	fi
    fi
    if ! ps xa | grep "postgresql/bin/postmaster" > /dev/null 2>&1 ; then
	/etc/init.d/postgresql start || true
	echo "Waiting for the database to really start."
	status=start
	sleep 5
    fi
elif [ -f /etc/postgresql/postmaster.init ] ; then
    if grep -e 'PGALLOWTCPIP' /etc/postgresql/postmaster.init \
	> /dev/null 2>&1 ; then
	if ! grep -e '^[[:space:]]*PGALLOWTCPIP=yes' \
	    /etc/postgresql/postmaster.init > /dev/null 2>&1 ; then
	    /bin/sed -e \
		's#\# PGALLOWTCPIP=no#PGALLOWTCPIP=yes#;
	s#\# PGALLOWTCPIP=yes#PGALLOWTCPIP=yes#' \
	    /etc/postgresql/postmaster.init \
		> /etc/postgresql/postmaster.init.tmp
	    if grep 'PGALLOWTCPIP=yes' \
		/etc/postgresql/postmaster.init.tmp \
		>/dev/null 2>&1; then
		cp /etc/postgresql/postmaster.init \
		    /etc/postgresql/postmaster.init.back > /dev/null 2>&1
		mv /etc/postgresql/postmaster.init.tmp \
		    /etc/postgresql/postmaster.init >/dev/null 2>&1;
		echo "Now restarting postgres to make this take effect."
		status=restart
		/etc/init.d/postgresql restart || true
		echo "Waiting for the database to really start."
		sleep 5
	    else
		echo "Local database configuration was not successful, trying anyway."
		status=error
		rm -f /etc/postgresql/postmaster.init.tmp
	    fi
	fi
    fi
    if ! ps xa | grep "postgresql/bin/postmaster" > /dev/null 2>&1 ; then
	/etc/init.d/postgresql start || true
	echo "Waiting for the database to really start."
	status=start
	sleep 5
    fi
fi