-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsptool_reqd_checks.sh
executable file
·220 lines (192 loc) · 6.94 KB
/
sptool_reqd_checks.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
#
#==================================================================================
# Filename : sptool_reqd_checks.sh
# Author : ENVIRON International Corp.
# Version : 4.5
# Description: Script to check software requirements for Speciation Tool
# Release : 30Sep2017
#
# This script tests the status of PostgreSQL and Perl installations on
# a Linux system to determine it's readiness for the Speciation Tool.
#
# Use: ./sptool_reqd_checks.sh
#
#====================================================================================
#ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
#c Copyright (C) 2013 ENVIRON International Corporation
#c
#c Developed by:
#c
#c Michele Jimenez <[email protected]> 415.899.0700
#c
#c This program is free software; you can redistribute it and/or
#c modify it under the terms of the GNU General Public License
#c as published by the Free Software Foundation; either version 2
#c of the License, or (at your option) any later version.
#c
#c This program is distributed in the hope that it will be useful,
#c but WITHOUT ANY WARRANTY; without even the implied warranty of
#c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#c GNU General Public License for more details.
#c
#c To obtain a copy of the GNU General Public License
#c write to the Free Software Foundation, Inc.,
#c 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
#====================================================================================
echo
echo ===== Speciation Tool Requirements Check =====
echo
#====================================================================================
#
# Check environment variables: If not set assign system defaults
#
if [[ -z "$PERL_BIN" ]]; then
PERL_BIN=$(dirname `which perl`)
echo -e "Perl located in $PERL_BIN"
fi
#
if [[ -z $POSTGRES_BIN ]]; then
if psql --version < /dev/null > /dev/null 2>&1 ; then
POSTGRES_BIN=$(dirname `which psql`)
echo -e "PostgreSQL located in $POSTGRES_BIN"
fi
fi
#====================================================================================
echo
echo Checking the status of software requirements...
echo
echo
echo Status of required software:
echo [x] = Installed
echo [ ] = Not installed
echo [?] = Unable to determine, see notes
echo
#------PERL------#
echo "------PERL------"
perlMods=0
# CHECK IF PERL IS INSTALLED
if $PERL_BIN/perl -v < /dev/null > /dev/null 2>&1 ; then
# PERL IS INSTALLED
echo [x] Perl
# CHECK IF PERL DBI MODULE IS INSTALLED
if $PERL_BIN/perl -MDBI -e 'print "$DBI::VERSION\n";' < /dev/null > /dev/null 2>&1 ; then
echo -e "[x] -DBI"
else
echo -e "[ ] -DBI"
perlMods=$(( $perlMods + 1 ))
fi
# CHECK IF PERL DBD::PgPP or DBD::Pg MODULE IS INSTALLED
if $PERL_BIN/perl -MDBD::PgPP -e 'print "$DBD::PgPP::VERSION\n";' < /dev/null > /dev/null 2>&1 ; then
echo -e "[x] -DBD-PgPP"
else
if $PERL_BIN/perl -MDBD::Pg -e 'print "$DBD::Pg::VERSION\n";' < /dev/null > /dev/null 2>&1 ; then
echo -e "[x] -DBD-Pg"
else
echo -e "[ ] -DBD-Pg or DBD-PgPP"
perlMods=$(( $perlMods + 1 ))
fi
fi
# CHECK IF PERL TEXT::CSV MODULE IS INSTALLED
if $PERL_BIN/perl -MText::CSV -e 'print "$Text::CSV::VERSION\n";' < /dev/null > /dev/null 2>&1 ; then
echo -e "[x] -Text-CSV"
else
echo -e "[ ] -Text-CSV"
perlMods=$(( $perlMods + 1 ))
fi
# LIST MISSING PERL MODULES
if [ "$perlMods" -gt 0 ]; then
echo
echo Warning:
echo "$perlMods missing Perl module(s). Install the missing module(s) before running the Speciation Tool."
echo
echo "Check with your system administrator or refer to Appendix A of the Speciation Tool User Guide."
echo
fi
else
# PERL IS NOT INSTALLED
echo [ ] Perl
echo -e "[ ] -DBI"
echo -e "[ ] -DBD-Pg or DBD-PgPP"
echo -e "[ ] -Text-CSV"
fi
#-------POSTGRESQL-------#
echo
echo "---POSTGRESQL---"
psqlState=0
dateTime=`date +%Y%m%d%H%M`
# CHECK IF POSTGRESQL IS INSTALLED
if $POSTGRES_BIN/psql --version < /dev/null > /dev/null 2>&1 ; then
# POSTGRES IS INSTALLED
psqlState=$(( $psqlState + 1 ))
echo [x] PostgreSQL
# POSTGRES IS INSTALLED, SO LET'S CHECK TO SEE IF THE USER HAS AN ACCOUNT
if $POSTGRES_BIN/psql -l < /dev/null > /dev/null 2>&1 ; then
# USER HAS ACCESS
#echo User $(whoami) has a PostgreSQL user account of the same name.
psqlState=$(( $psqlState + 1 ))
else
# USER DOES NOT HAVE ACCESS TO POSTGRESQL, SO WE CAN'T TEST IF PL/pgSQL IS INSTALLED
# NEED TO CREATE A NEW USER ACCOUNT IN POSTGRESQL
# CREATE USER WITH NO-SUPERUSER, CREATEDB, CREATEROLE
if $POSTGRES_BIN/createuser $(whoami) -U postgres -Sdr < /dev/null > /dev/null 2>&1 ; then
# SUCCESSFULLY CREATED NEW USER
psqlState=$(( $psqlState + 1 ))
fi
fi
# CREATE NEW DB TO TEST CAPABILITIES
if [ "$psqlState" -eq 2 ] ; then
#
if $POSTGRES_BIN/createdb $(whoami)_test_$dateTime < /dev/null > /dev/null 2>&1 ; then
# SUCCESSFULLY CREATED NEW TESTER DATABASE
#echo "created new tester database"
$POSTGRES_BIN/dropdb $(whoami)_test_$dateTime < /dev/null > /dev/null 2>&1
else
#echo "couldn't create new tester database (might already exist?)"
if $POSTGRES_BIN/dropdb $(whoami)_test_$dateTime < /dev/null > /dev/null 2>&1 ; then
# SUCCESSFULLY DROPPED THE TESTER DB, SO NOW WE CAN RECREATE IT
#echo "was able to drop old tester database"
if $POSTGRES_BIN/createdb $(whoami)_test_$dateTime < /dev/null > /dev/null 2>&1 ; then
#echo "and was able to create a new tester database"
# SUCCESSFULLY CREATED NEW TESTER DATABASE
$POSTGRES_BIN/dropdb $(whoami)_test_$dateTime < /dev/null > /dev/null 2>&1
else
echo "was not able to create a new tester database"
fi
else
# COULDN'T CREATE NOR DROP THE TESTER DB, SO USER DOESN'T HAVE PRIVELEDGES
echo
echo Warning:
echo PostgreSQL user $(whoami) does not have the required privileges to CREATEDB
echo or DROPDB. These privileges are required to run the Speciation Tool. Please
echo contact your system administrator to obtain these privileges.
echo
fi
fi
else
if [ "$psqlState" -eq 1 ] ; then
# NO POSTGRES USER AND WAS UNABLE TO CREATE ONE
echo
echo Warning:
echo User $(whoami) does not have a PostgreSQL user account.
echo The attempt to create an account for the user was unsuccessful.
echo Check with your system administrator to create a PostgreSQL account
echo in order to install and run the Speciation Tool.
echo
fi
fi
else
# POSTGRESQL DOES NOT APPEAR TO BE INSTALLED
echo -e "[ ] PostgreSQL"
echo
echo Warning:
echo PostgreSQL and PL/pgSQL were not found. These need to be installed to run the Speciation Tool.
echo Check with your system administrator to have them installed or refer to Appendix A of
echo the Speciation Tool User Guide.
echo
fi
echo
echo Refer to the Speciation Tool User Guide Appendix A for installation procedures of the required software.
echo