forked from pgadmin-org/pgadmin4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-web.sh
More file actions
executable file
·173 lines (152 loc) · 5.09 KB
/
setup-web.sh
File metadata and controls
executable file
·173 lines (152 loc) · 5.09 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
#
# Setup pgadmin4 in server mode
#
if [ "$EUID" -ne 0 ]
then echo "This script must be run as root"
exit 1
fi
if [[ "$#" -gt 1 ]] || { [[ "$#" -eq 1 ]] && [[ "$1" != "--yes" ]]; }; then
echo "Usage: $0 [--yes]"
exit 1
fi
IS_REDHAT=0
IS_DEBIAN=0
IS_SUSE=0
UNAME=$(uname -a)
# Get the distro from the environment
if [ "${PGADMIN_PLATFORM_TYPE}" == "" ]; then
if [ -f /etc/redhat-release ]; then
PLATFORM_TYPE=redhat
elif [[ ${UNAME} =~ "Ubuntu" ]] || [[ ${UNAME} =~ "Debian" ]] || [ -f /etc/apt/sources.list ]; then
PLATFORM_TYPE=debian
elif [ -f /etc/os-release ]; then
if grep suse /etc/os-release > /dev/null
then
PLATFORM_TYPE=suse
fi
else
echo "Failed to detect the platform. This may mean you're running on a Linux distribution that isn't supported by pgAdmin."
echo "Please set the PGADMIN_PLATFORM_TYPE environment variable to one of 'redhat' or 'debian' and try again."
exit 1
fi
else
PLATFORM_TYPE=${PGADMIN_PLATFORM_TYPE}
fi
case ${PLATFORM_TYPE} in
redhat)
echo "Setting up pgAdmin 4 in web mode on a Redhat based platform..."
IS_REDHAT=1
APACHE=httpd
;;
debian)
echo "Setting up pgAdmin 4 in web mode on a Debian based platform..."
IS_DEBIAN=1
APACHE=apache2
;;
suse)
echo "Setting up pgAdmin 4 in web mode on a SUSE based platform..."
IS_SUSE=1
APACHE=apache2
;;
*)
echo "Invalid value for the PGADMIN_PLATFORM_TYPE environment variable. Please set it to one of 'redhat' or 'debian' and try again."
exit 1
;;
esac
# Is this an automated install?
AUTOMATED=0
if [ "$#" -eq 1 ]; then
AUTOMATED=1
echo "Running in non-interactive mode..."
fi
# Run setup script first:
echo "Creating configuration database..."
if ! /usr/pgadmin4/venv/bin/python3 /usr/pgadmin4/web/setup.py setup-db;
then
echo "Error setting up server mode. Please examine the output above."
exit 1
fi
# Create and own directories:
echo "Creating storage and log directories..."
mkdir -p /var/log/pgadmin /var/lib/pgadmin
if [ ${IS_REDHAT} == 1 ]; then
chown apache: /var/log/pgadmin /var/lib/pgadmin -R
elif [ ${IS_SUSE} == 1 ]; then
chown wwwrun: /var/log/pgadmin /var/lib/pgadmin -R
else
chown www-data: /var/log/pgadmin /var/lib/pgadmin -R
fi
# Set SELinux up:
if [ ${IS_REDHAT} == 1 ]; then
echo "Configuring SELinux..."
setsebool -P httpd_tmp_exec 1 1> /dev/null
setsebool -P httpd_can_network_connect 1 1> /dev/null
setsebool -P httpd_can_network_connect_db 1 1> /dev/null
semanage fcontext -a -t httpd_var_lib_t '/var/lib/pgadmin(/.*)?' 1> /dev/null
restorecon -R -v /var/lib/pgadmin 1> /dev/null
semanage fcontext -a -t httpd_log_t '/var/log/pgadmin(/.*)?' 1> /dev/null
restorecon -R -v /var/log/pgadmin 1> /dev/null
fi
# Setup Apache on Debian/Ubuntu
if [ ${IS_DEBIAN} == 1 ]; then
if [ ${AUTOMATED} == 1 ]; then
RESPONSE=Y
else
read -r -p "We can now configure the Apache Web server for you. This involves enabling the wsgi module and configuring the pgAdmin 4 application to mount at /pgadmin4. Do you wish to continue (y/n)? " RESPONSE
fi
case ${RESPONSE} in
y|Y )
/usr/sbin/a2enmod wsgi 1> /dev/null
/usr/sbin/a2enconf pgadmin4 1> /dev/null
;;
* )
exit 1;;
esac
fi
if pgrep ${APACHE} > /dev/null; then
if [ ${AUTOMATED} == 1 ]; then
RESPONSE=Y
else
read -r -p "The Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y/n)? " RESPONSE
fi
case ${RESPONSE} in
y|Y )
COMMAND=""
if [ -x "$(command -v systemctl)" ]; then
COMMAND="systemctl restart ${APACHE}"
elif [ -x "$(command -v service)" ]; then
COMMAND="service ${APACHE} restart"
fi
if ! ${COMMAND}; then
echo "Error restarting ${APACHE}. Please check the systemd logs"
else
echo "Apache successfully restarted. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4"
fi;;
* )
exit 1;;
esac
else
if [ ${AUTOMATED} == 1 ]; then
RESPONSE=Y
else
read -r -p "The Apache web server is not running. We can enable and start the web server for you to finish pgAdmin 4 installation. Continue (y/n)? " RESPONSE
fi
case ${RESPONSE} in
y|Y )
if ! systemctl enable ${APACHE}; then
echo "Error enabling ${APACHE}. Please check the systemd logs"
else
echo "Apache successfully enabled."
fi
if ! systemctl start ${APACHE}; then
echo "Error starting ${APACHE}. Please check the systemd logs"
else
echo "Apache successfully started."
echo "You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4"
fi;;
* )
exit 1;;
esac
fi
exit 0