forked from GreatDevelopers/ofau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install.sh
executable file
·362 lines (298 loc) · 10.4 KB
/
Install.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
########################################################################
# Description: This script checks the internet connectivity and starts #
# the installation. #
# #
# #
# Please read AutoInstall.txt file before you run this script #
# #
# Author : Jasvir Singh Grewal, [email protected] #
# License : GNU General Public License #
# Copyright: Copyright (c) 2013, Great Developers #
# #
# created : 11-July-2013 #
# last update : 12-July-2013 #
# VERSION : 1.5.2 #
# #
########################################################################
read -p "Please enter password provided in Manual:" read_pass
if [ $read_pass = 007700 ]; then
check=0
dir_path=$(pwd)
clear
echo ""
echo "######################################################"
echo "# #"
echo "# CHECKING---Internet Connection--- #"
echo "# #"
echo "######################################################"
echo ""
packet_loss=$(ping -c 5 -q 74.125.236.52 | \
grep -oP '\d+(?=% packet loss)')
if [ $packet_loss -le 50 ]
then
echo "::::::::::::INTERNET IS WORKING PROPERLY::::::::::::"
Thanks() #Thanks for Installation
{
banner "Thanks for"
banner "Installing"
banner "Automation Software"
exit
}
Media() #copies media folder into (~/contrib/admin/)
{
dir_tar=/usr/local/lib/python2.7/dist-packages/django/contrib/admin/
cp -r other_files/media/ $dir_tar
cp other_files/base.html $dir_tar/templates/admin/
chmod -R 777 $dir_tar/media
}
Restart() #restarts apache
{
/etc/init.d/apache2 restart
chmod -R 777 ofau
bash ofau/exim.sh
}
Backup() #backs up important files
{
cp /etc/apache2/httpd.conf $dir_path/other_files/
cp /etc/apache2/sites-available/default $dir_path/other_files/
}
Browser() #open firefox browser at localhost/automation
{
rm -rf Django-1.5.2.tar.gz
rm -rf Django-1.5.2
rm -rf other_files
firefox http://localhost/automation/
Thanks
}
Database()
{
id=1
echo ""
echo "######################################################"
echo "# #"
echo "# INSTALLING---Automation software--- #"
echo "# #"
echo "######################################################"
echo ""
#################################################################
#
# asking user to input the mysql username
#
#################################################################
a=1
while [ $a -ne 2 ]
do
# inputs database name from the user
read -p "enter mysql username :" db_user
read -sp "enter mysql password :" db_password
RESULT=`mysql --user="$db_user" --password="$db_password" \
--skip-column-names -e "SHOW DATABASES LIKE 'mysql'"` 2> \
/dev/null
if [ $RESULT ]; then
echo ""
echo "Username and password match"
echo ""
a=+1
break
else
echo ""
echo "Username and password doesn't match"
echo "re-enter the details"
echo ""
fi
done
sed -i "16 s/db_user/$db_user/" settings.py
sed -i "17 s/db_password/$db_password/" settings.py
# this part checks if database name entered is created before or not.
a=1
while [ $a -ne 2 ]
do
# inputs database name from the user
read -p "enter database name you want to create :" db_name
#checks the existance of database
RESULT=`mysql --user="$db_user" --password="$db_password" \
--skip-column-names -e "SHOW DATABASES LIKE '$db_name'"`
if [ $RESULT ]; then
echo "The Database exist, choose another name for database."
else
a=2
break
fi
done
sed -i "15 s/db_name/$db_name/" settings.py
#################################################################
#
# Determining the path of the script and making necessary changes
#
#################################################################
cd ../
path=$PWD #this passes PWD value in path
echo "Successfully downloading the software at-$path"
echo ""
sed -i "s#mpath#"$path"#g" ofau/other_files/hhtp_cont
sed -i "s#mpath#"$path"#g" ofau/apache/django.wsgi
sed -i "s#mpath#"$path"#g" ofau/settings.py
#################################################################
#
# changes in httpd.conf file
#
#################################################################
#this appends the text from the file to the httpd.conf
etc_path=/etc/apache2
cat ofau/other_files/hhtp_cont >> $etc_path/httpd.conf
cat ofau/other_files/hhtp_cont >> $etc_path/sites-available/default
a2ensite default
####################################################################
#
# creating the database and the further changes required by the user
#
####################################################################
#mysql path address
mysqlbash_path='/usr/bin/mysql'
#declaring a variable
mysqlbash="$mysqlbash_path --user=$db_user --password=$db_password -e"
#creates databases with the name defined by the user
$mysqlbash "create database $db_name "
# a new database is created
echo ""
echo ""
echo "enter 'Y' for the demo database & 'N' for new database "
read -p "Note:Prefer to use demo database:" db_yesno
if [ $db_yesno = y ] || [ $db_yesno = Y ]; then
clear
echo -e "\v\v\v\v\v\t\t\t\t\t::::::::::WELCOME TO " \
"AUTOMATION WORLD:::::::::::"
# this imports demo.sql to the database defined by the user
mysql --user=$db_user --password=$db_password $db_name < \
ofau/other_files/demo.sql
# this creates a new superuser
python ofau/manage.py createsuperuser
elif [ $db_yesno = n ] || [ $db_yesno = N ]; then
echo ""
echo "now you get a new database"
echo "enjoy your experience"
#creates a blank database for use, using django commands
python ofau/manage.py syncdb
clear
echo -e "\v\v\v\v\v\t\t\t\t\t::::::::::WELCOME TO" \
"AUTOMATION WORLD:::::::::::"
# scelect count(*) , counts the number of enteries in the table
result1=`mysql --user=$db_user --password=$db_password \
--skip-column-names -e "use $db_name;" \
-e "select count(*) from auth_user;"`
if [ $result1 = 0 ]; then
echo ""
echo "you need to create a superuser"
#creates a superuser
python ofau/manage.py createsuperuser
else
echo ""
fi
# there is a need to enter Organisation details in the database.
echo ""
echo "Now get ready to ADD Organisation details to your software."
echo ""
read -p "enter organisation name :" name
read -p "enter organisation address :" address
read -p "phone/contact number :" phone
read -p "Director of the Organisation :" director
# this Inserts into the table the input values.
mysql --user=$db_user --password=$db_password $db_name << EOF
Insert into tcc_organisation (name, address, phone, director, status, logo_upload)
values("$name", "$address", "$phone", "$director", "Autonomous", "Logo.jpg");
EOF
# There is a need to enter Department details in the database.
echo ""
echo "Now get ready to ADD Departmant details to your software."
echo ""
read -p "enter Department name :" name
read -p "enter Department address :" address
read -p "phone/contact number :" phone
read -p "Dean of the Department:" dean
read -p "enter the fax number :" faxno
# this inserts values into database
mysql --user=$db_user --password=$db_password $db_name << EOF
Insert into tcc_department (organisation_id, name, address,
phone, dean, faxno) values(1, "$name", "$address", "$phone",
"$dean", "$faxno");
EOF
fi
}
Install() #Calls other functions
{
Backup
Media
Database
Restart
Browser
}
Install_django() #Installs django 1.5.2 if it is not installed.
{
result=$(python -c "import django; print(django.get_version())")
if [ $result = 1.5.2 ]; then
echo "Django 1.5.2 is already installed"
Install
else
echo "Django 1.5.2 is currently not installed"
echo "You want to install it now: (y for yes, " \
"continue otherwise):"
read Y
if [ $Y = y ] || [ $Y = Y ]
then
wget https://www.djangoproject.com/m/releases/1.5/Django-1.5.2.tar.gz
tar xzvf Django-1.5.2.tar.gz
cd Django-1.5.2
python setup.py install
pip install django-registration
pip install django-tagging
pip install python-mysql
check=+1
cd ../
Install
else
echo "You have not installed Django 1.5.2"
pip install django-registration
pip install django-tagging
pip install python-mysql
Install
fi
fi
}
Package()
{
result=$(dpkg-query -W -f='${package}\n' "$1")
if [ $result = $1 ]; then
echo "$1 already installed"
else
echo "$1 is not installed in your system"
echo "You want to install it now: (y for yes, " \
"otherwise aborted):"
read Y
if [ $Y = y ] || [ $Y = Y ]; then
apt-get install $1
else
echo "Aborted"
exit
fi
fi
}
Dependencies()
{
dep=(mysql-server python2.7 python-pip python-imaging python-setuptools \
python-mysqldb apache2 libapache2-mod-wsgi sysvbanner)
for i in "${dep[@]}"
do
Package $i
done
Install_django
}
Dependencies
else
echo "::::::::::::SLOW or NO INTERNET CONNECTION:::::::::::::"
echo "Please check your connectivity and try again later."
exit
fi
else
banner "Read"
banner "Manual"
fi