-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstallation.sh
More file actions
199 lines (143 loc) · 5.06 KB
/
installation.sh
File metadata and controls
199 lines (143 loc) · 5.06 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
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
#!/bin/bash
set -e
re='^[0-9]+$'
PURPLE='\033[0;35m'
NC='\033[0m'
#CHECK USER ROOT PRIVILEGES
###########################
if [ "$USER" != "root" ]; then
echo "You must run this script with the root privileges (sudo)" >&2; exit 1
fi
#PARSING PARAMETER
##################
if [ ! -f installation.dat ]; then
echo "1" > installation.dat
fi
if [ "$1" = "" ]; then
PARAM=$(head -c 1 installation.dat)
else
if ! [[ $1 =~ $re ]] ; then
echo "Error: Argument '$1' is not a number" >&2; exit 1
fi
PARAM=$1
fi
#01 CONFIGURING MySQL:
######################
if [ "$PARAM" -le "1" ]; then
echo -e "\n${PURPLE}01 CONFIGURING MySQL:"
echo -e "=====================${NC}\n"
read -p "Enter your current MySQL root user: " dbUser
read -s -p "Enter your current MySQL root password: " dbPasswd
echo -e "\n"
read -p "Enter a new Mysql username for this application: " dbNewUser
read -s -p "Enter MySQL password for this application: " dbNewPasswd
echo -e "\n"
read -p "Enter a new name for your application database: " dbName
if [ "$dbPasswd" = "" ]; then
DBCALL="mysql -u$dbUser"
else
DBCALL="mysql -u$dbUser -p$dbPasswd"
fi
$DBCALL -e "CREATE DATABASE IF NOT EXISTS $dbName;"
$DBCALL -e "CREATE USER '$dbNewUser'@'localhost' IDENTIFIED BY '$dbNewPasswd';"
$DBCALL -e "GRANT ALL PRIVILEGES ON $dbName . * TO '$dbNewUser'@'localhost';"
$DBCALL -e "FLUSH PRIVILEGES;"
SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo "# This file is auto-generated during the composer install" > app/config/parameters.yml
echo "parameters:" >> app/config/parameters.yml
echo " database_host: 127.0.0.1" >> app/config/parameters.yml
echo " database_port: null" >> app/config/parameters.yml
echo " database_name: $dbName" >> app/config/parameters.yml
echo " database_user: $dbNewUser" >> app/config/parameters.yml
echo " database_password: $dbNewPasswd" >> app/config/parameters.yml
echo " mailer_transport: smtp" >> app/config/parameters.yml
echo " mailer_host: 127.0.0.1" >> app/config/parameters.yml
echo " mailer_user: sample@sample.com" >> app/config/parameters.yml
echo " mailer_password: sample" >> app/config/parameters.yml
echo " secret: $SECRET" >> app/config/parameters.yml
echo "2" > installation.dat
else
echo -e "\n${PURPLE}IGNORING MySQL CONFIGURATION STEP"
echo -e "==================================${NC}\n"
echo "2" > installation.dat
fi
#02 INSTALLING DEPENDENCIES:
############################
if [ "$PARAM" -le "2" ]; then
echo -e "\n${PURPLE}02 INSTALLING DEPENDENCIES:"
echo -e "========================${NC}\n"
apt-get install php-intl
apt-get install php-mysql
apt-get install php-xml
apt-get install xz-utils
php composer.phar install
echo "3" > installation.dat
else
echo -e "\n${PURPLE}IGNORING DEPENDENCIES INSTALLATION STEP"
echo -e "==================================${NC}\n"
echo "3" > installation.dat
fi
#03 CONFIGURING SYMFONY & DOCTRINE:
###################################
if [ "$PARAM" -le "3" ]; then
echo -e "\n${PURPLE}03 CONFIGURING SYMFONY & DOCTRINE:"
echo -e "===============================${NC}\n"
php bin/console doctrine:schema:update --force
echo "4" > installation.dat
else
echo -e "\n${PURPLE}IGNORING SYMFONY & DOCTRINE CONFIGURATION STEP"
echo -e "==================================${NC}\n"
echo "4" > installation.dat
fi
#04 CONFIGURING APACHE:
#######################
if [ "$PARAM" -le "4" ]; then
echo -e "\n${PURPLE}04 CONFIGURING APACHE:"
echo -e "===================${NC}\n"
a2enmod rewrite
cat vhost1.sample > /etc/apache2/sites-available/factorio-web-view.local.conf
echo " DocumentRoot $PWD/web" >> /etc/apache2/sites-available/factorio-web-view.local.conf
echo " <Directory $PWD/web>" >> /etc/apache2/sites-available/factorio-web-view.local.conf
cat vhost2.sample >> /etc/apache2/sites-available/factorio-web-view.local.conf
a2ensite factorio-web-view.local.conf
/etc/init.d/apache2 restart
echo "127.0.0.1 factorio-web-view.local" >> /etc/hosts
echo "5" > installation.dat
else
echo -e "\n${PURPLE}IGNORING APACHE CONFIGURATION STEP"
echo -e "==================================${NC}\n"
echo "5" > installation.dat
fi
#05 CONFIGURING PERMISSIONS:
############################
if [ "$PARAM" -le "5" ]; then
echo -e "\n${PURPLE}05 CONFIGURING PERMISSIONS:"
echo -e "========================${NC}\n"
echo "rm -rf var/cache/*"
rm -rf var/cache/*
echo "rm -rf var/logs/*"
rm -rf var/logs/*
echo "chown -R www-data:www-data $PWD"
chown -R www-data:www-data $PWD
echo "chmod -R 755 $PWD"
chmod -R 755 $PWD
echo "6" > installation.dat
else
echo -e "\n${PURPLE}IGNORING PERMISSIONS CONFIGURATION STEP"
echo -e "==================================${NC}\n"
echo "6" > installation.dat
fi
#06 CREATING NEW USER:
######################
if [ "$PARAM" -le "6" ]; then
echo -e "\n${PURPLE}06 CREATING NEW USER:"
echo -e "========================${NC}\n"
php bin/console fos:user:create
else
echo -e "\n${PURPLE}IGNORING USER CREATION STEP"
echo -e "==================================${NC}\n"
fi
#DONE
#####
echo -e "\n${PURPLE}DONE"
echo -e "====${NC}\n"