-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.sh
executable file
·220 lines (201 loc) · 8.46 KB
/
check.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
#!/bin/bash
# ./check.sh -f
# This is the Cloudrexx check script
# It checks if the operating system passes the requirements for Cloudrexx, if not, we try to help the user
# install the missing component
# if force fix is true, we try to install the missing components without asking the user
FORCE_FIX=0
SHOW_HELLO_MESSAGE=1
for i in "$@"
do
case $i in
-f|--force)
FORCE_FIX=1
shift # past argument=value
;;
-nhm|--no-hello-message)
SHOW_HELLO_MESSAGE=0
shift # past argument=value
;;
-h|--help)
echo "This scripts checks the system requirements for Cloudrexx and tries to fix them"
echo "(-f|--force) force installation of missing components and do not ask for it"
echo "(-nhm|--no-hello-message) do not show hello message at the beginning of the script"
exit
shift # past argument=value
;;
*)# unknown option
;;
esac
done
if [[ $SHOW_HELLO_MESSAGE == 1 ]]; then
echo -e "\033[1mWelcome to Cloudrexx Development Environment check\033[0m"
echo "This script will check if everything needed for Cloudrexx coding is available"
echo "on the current system."
echo ""
echo -n "Press CTRL+c to quit, press ENTER to proceed: "
read -r
fi
# the required versions of php and mysql can be changed here. Please use syntak [1-9].[1-9].[1-9]
REQUIRED_PHP_VERSION="5.4.0"
REQUIRED_MYSQL_VERSION="5.0.0"
# outputs a message that a component is not installed
# first parameter must be the name component which is not installed
function outputNotInstalledMessage () {
echo "$1 is not installed"
echo "1 - Install and configure $1 (recommended)"
echo "Enter - Ignore error and continue"
}
function writeReport () {
REPORT="$REPORT \n$1: $2"
}
function checkVersion () {
writeReport "$3" "installed"
writeReport "$3 Version" $1
if [[ ${1//.} < ${2//.} ]]; then
# we will never install a second version of a component, because this often causes problems
writeReport "ERROR" "You need to install at least $3 $2 to install Cloudrexx"
exit
fi
}
function checkApache () {
echo "Checking apache..."
type apache2 >/dev/null 2>&1 && APACHE_INSTALLED=1 || APACHE_INSTALLED=0
if [[ $APACHE_INSTALLED != 1 ]]; then
# if force fix is true, we save the information that we want to install apache, otherwise we ask the user if we should install it
[[ $FORCE_FIX == 1 ]] && INSTALL_APACHE=1 || { outputNotInstalledMessage "Apache"; read INSTALL_APACHE; }
else
writeReport "APACHE" "installed"
checkFolder
fi
# if apache is not installed, but we tried to install it, we inform the user, that the installation failed
[[ $INSTALL_APACHE = 1 && $1 == 1 ]] && { writeReport "APACHE" "could not be installed, please do it manually"; exit; }
[[ $INSTALL_APACHE == 1 ]] && installApache
}
function installApache () {
echo "Installing Apache2..."
sudo apt-get update
sudo apt-get install apache2
INSTALL_APACHE=0
checkApache 1
}
function checkFolder () {
APACHE_ROOT=$(apache2ctl -S | grep "DocumentRoot" | cut -d "\"" -f 2)
if [[ ${PWD##$APACHE_ROOT} == $PWD ]]; then
writeReport "NOTE" "Your installing folder is not inside apache root. You need to create a vhost that it works"
fi
}
function checkPHP () {
type php >/dev/null 2>&1 && PHP_INSTALLED=1 || PHP_INSTALLED=0
echo "Checking php..."
if [[ $PHP_INSTALLED != 1 ]]; then
# if force fix is true, we save the information that we want to install php, otherwise we ask the user if we should install it
[[ $FORCE_FIX == 1 ]] && INSTALL_PHP=1 || { outputNotInstalledMessage "PHP"; read INSTALL_PHP; }
else
PHP_VERSION=$(php -r \@phpinfo\(\)\; | grep 'PHP Version' -m 1 | grep -o [[:digit:]]\.[[:digit:]]\.[[:digit:]] -m 1)
checkVersion $PHP_VERSION $REQUIRED_PHP_VERSION "PHP"
checkPDO
checkAPC
fi
# if PHP is not installed, but we tried to install it, we inform the user, that the installation failed
[[ $INSTALL_PHP = 1 && $1 == 1 ]] && { writeReport "PHP" "could not be installed, please do it manually"; exit; }
[[ $INSTALL_PHP == 1 ]] && installPHP
}
function installPHP () {
echo "Installing PHP..."
sudo apt-get update
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
INSTALL_PHP=0
checkPHP 1
}
function checkMySQL () {
type mysql >/dev/null 2>&1 && MYSQL_INSTALLED=1 || MYSQL_INSTALLED=0
echo "Checking mysql..."
if [[ $MYSQL_INSTALLED != 1 ]]; then
# if force fix is true, we save the information that we want to install mysql, otherwise we ask the user if we should install it
[[ $FORCE_FIX == 1 ]] && INSTALL_MYSQL=1 || { outputNotInstalledMessage "MYSQL"; read INSTALL_MYSQL; }
else
MYSQL_VERSION=$(apt-cache show mysql-server | grep -o [[:digit:]]\.[[:digit:]]\.[[:digit:]][[:digit:]] -m 1)
checkVersion $MYSQL_VERSION $REQUIRED_MYSQL_VERSION "MySQL"
fi
# if MySQL is not installed, but we tried to install it, we inform the user, that the installation failed
[[ $INSTALL_MYSQL == 1 && $1 == 1 ]] && { writeReport "MySQL" "could not be installed, please do it manually"; exit; }
[[ $INSTALL_MYSQL == 1 ]] && installMySQL
}
function installMySQL () {
echo "Installing MySQL..."
sudo apt-get update
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
sudo mysql_install_db
sudo /usr/bin/mysql_secure_installation
INSTALL_MYSQL=0
checkMySQL 1
}
function checkPDO () {
if [[ $(php -m | grep "PDO") != "" ]]; then
writeReport "PDO" "installed"
else
# installing pdo is not that easy. it is standard with PHP and if it was deleted by the user, we can not install
# it for him that easy. This case should not exist very often
writeReport "PDO" "not installed"
writeReport "ERROR" "We can not install PDO for you, you need to do it manually"
exit
fi
}
function checkAPC () {
echo "Checking apc..."
[[ $(php -m | grep "apc") != "" ]] && APC_INSTALLED=1 || APC_INSTALLED=0
if [[ $APC_INSTALLED != 1 ]]; then
writeReport "Note" "APC is not installed (optional)"
# if force fix is true, we save the information that we want to install apc, otherwise we ask the user if we should install it
[[ $FORCE_FIX == 1 ]] && INSTALL_APC=1 || { outputNotInstalledMessage "apc"; read INSTALL_APC; }
else
writeReport "APC" "installed (optional)"
fi
# if APC is not installed, but we tried to install it, we inform the user, that the installation failed
# we do not exit because apc is optional
[[ $INSTALL_APC == 1 && $1 == 1 ]] && writeReport "APC" "could not be installed, please do it manually";
[[ $INSTALL_APC == 1 && $1 != 1 ]] && installAPC
}
function installAPC () {
echo "Installing apc..."
sudo apt-get update
sudo apt-get install php-apc
service apache2 restart
INSTALL_APC=0
checkAPC 1
}
function checkPostfix () {
type postfix >/dev/null 2>&1 && POSTFIX_INSTALLED=1 || POSTFIX_INSTALLED=0
echo "Checking postfix..."
if [[ $POSTFIX_INSTALLED != 1 ]]; then
# if force fix is true, we save the information that we want to install postfix, otherwise we ask the user if we should install it
[[ $FORCE_FIX == 1 ]] && INSTALL_POSTFIX=1 || { outputNotInstalledMessage "POSTFIX"; read INSTALL_POSTFIX; }
else
writeReport "POSTFIX" "installed (optional)"
fi
# if Postfix is not installed, but we tried to install it, we inform the user, that the installation failed
# we do not exit because apc is optional
[[ $INSTALL_POSTFIX == 1 && $1 == 1 ]] && writeReport "Postfix" "could not be installed, please do it manually";
[[ $INSTALL_POSTFIX == 1 && $1 != 1 ]] && installPostfix
}
function installPostfix () {
echo "Installing postfix..."
sudo apt-get update
sudo apt-get install postfix
INSTALL_POSTFIX=0
checkPostfix 1
}
### Get information what is installed and what not
echo "Getting system information..."
# REPORT is used to save the information of the components, so we can output them all together - this is more user-friendly
REPORT="\033[1m----------------------------------------------------"
checkApache
checkPHP
checkMySQL
checkPostfix
writeReport "NOTE" "We didn't check if apache and mysql are running. Please check this by your own, otherwise the installation won't work"
writeReport "\n----------------------------------------------------" "\033[0m"
echo ""
echo "Check finished. Got the following to report:"
echo -e $REPORT