forked from PlanningBiblio/PlanningBiblio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·241 lines (191 loc) · 7.08 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
#!/bin/bash
version='21.04.00.000'
# Check PHP version
phpversion=$(php -r "echo version_compare(phpversion(), '7.4');");
if [[ $phpversion -lt 0 ]]; then
echo "You need PHP version 7.4 or greater to install Planning Biblio";
exit
fi
# Check if .env.local exists.
if [[ -f .env.local ]]; then
echo "The file .env.local exists.";
echo "If you want to start a new installation, remove the file .env.local then run ./install.sh";
echo "If you want to update your current installation, open Planning Biblio in your web browser.";
exit
fi
# Prompt user for information
echo "You are about to install Planning Biblio";
echo "You will be asking for information to create the database.";
echo "A database and a user will be created with given information. WARNING: if the database and the user already exist, they will be overwritten";
echo "We strongly recommend that you back up your databases before starting this installation";
echo "Do you want to proceed ? [yes/no]"
read proceed
proceed=$(echo $proceed | tr '[:upper:]' '[:lower:]');
if [[ $proceed != 'yes' && $proceed != 'y' ]]; then
exit;
fi
# Generate default passwords
planningbdbpass_default=$(head /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 10|head -n 1)
planningbadminpass_default=$(head /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 10|head -n 1)
echo "DB Host [localhost] :"
read planningdbhost
echo "DB Port [3306] :"
read planningdbport
echo "DB Admin User [root] :"
read dbroot
echo "DB Admin Pass :"
prompt=''
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]
then
break
fi
prompt='*'
dbpass+="$char"
done
echo ""
echo "DB User [planningbiblio] (will be overwritten if exists) :"
read planningbdbuser
echo "DB Pass [$planningbdbpass_default] (will be overwritten if exists) :"
prompt=''
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]
then
break
fi
prompt='*'
planningbdbpass+="$char"
done
echo ""
echo "DB Name [planningbiblio] (will be overwritten if exists) :"
read planningbdbname
# DB Prefix : does not work by loading the sql file
# echo "DB Prefix [] (optional) :"
# read planningbdbprefix
echo "Planning Biblio admin's lastname [admin] :"
read planningbadminlastname
echo "Planning Biblio admin's firstname [admin] :"
read planningbadminfirstname
echo "Planning Biblio admin's e-mail address [[email protected]] :"
read planningbadminemail
echo "Planning Biblio admin's password [$planningbadminpass_default] :"
prompt=''
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]
then
break
fi
prompt='*'
planningbadminpass+="$char"
done
echo ""
echo "Update composer dependencies [no] :"
read updatecomposer
# Set defaults
if [[ $planningdbhost = '' ]]; then
planningdbhost='localhost'
fi
if [[ $planningdbport = '' ]]; then
planningdbport='3306'
fi
if [[ $dbroot = '' ]]; then
dbroot='root'
fi
if [[ $planningbdbuser = '' ]]; then
planningbdbuser='planningbiblio'
fi
if [[ $planningbdbpass = '' ]]; then
planningbdbpass=$planningbdbpass_default
fi
if [[ $planningbdbname = '' ]]; then
planningbdbname='planningbiblio'
fi
if [[ $planningbadminlastname = '' ]]; then
planningbadminlastname='admin'
fi
if [[ $planningbadminfirstname = '' ]]; then
planningbadminfirstname='admin'
fi
if [[ $planningbadminemail = '' ]]; then
planningbadminemail='[email protected]'
fi
if [[ $planningbadminpass = '' ]]; then
planningbadminpass=$planningbadminpass_default
fi
updatecomposer=$(echo $updatecomposer | tr '[:upper:]' '[:lower:]');
if [[ $updatecomposer = '' ]]; then
updatecomposer='no'
fi
if [[ $planningdbhost = 'localhost' ]] || [[ $planningdbhost = '127.0.0.1' ]]; then
planningdbuserhost='localhost'
else
planningdbuserhost='%'
fi
# Set variables
planningbdatas=data/planningb_2104.sql.gz
planningbsecret=$(head /dev/urandom|tr -dc "a-f0-9"|fold -w 32|head -n 1)
# Create the database
mysql --defaults-file=/dev/null -h $planningdbhost -u $dbroot --password=$dbpass -e "DROP USER IF EXISTS '$planningbdbuser'@'$planningdbuserhost';"
mysql --defaults-file=/dev/null -h $planningdbhost -u $dbroot --password=$dbpass -e "DROP DATABASE IF EXISTS $planningbdbname;"
mysql --defaults-file=/dev/null -h $planningdbhost -u $dbroot --password=$dbpass -e "CREATE DATABASE IF NOT EXISTS $planningbdbname CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
mysql --defaults-file=/dev/null -h $planningdbhost -u $dbroot --password=$dbpass -e "CREATE USER '$planningbdbuser'@'$planningdbuserhost' IDENTIFIED BY '$planningbdbpass';"
mysql --defaults-file=/dev/null -h $planningdbhost -u $dbroot --password=$dbpass -e "GRANT ALL PRIVILEGES ON $planningbdbname.* TO '$planningbdbuser'@'$planningdbuserhost' IDENTIFIED BY '$planningbdbpass'"
mysql --defaults-file=/dev/null -h $planningdbhost -u $dbroot --password=$dbpass -e "FLUSH PRIVILEGES"
zcat $planningbdatas | mysql -h $planningdbhost -u $dbroot --password=$dbpass $planningbdbname
mysql --defaults-file=/dev/null -h $planningdbhost -u $planningbdbuser --password=$planningbdbpass -e "UPDATE $planningbdbname.\`personnel\` SET \`nom\`='$planningbadminlastname', \`prenom\`='$planningbadminfirstname', \`mail\`='$planningbadminemail', \`password\`=MD5('$planningbadminpass') WHERE \`id\` = 1;"
if [[ $? -ne 0 ]]; then
exit;
fi
# Create the .env.local file
cp .env .env.local
sed -i "s/APP_SECRET=.*/APP_DEBUG=0\nAPP_SECRET=${planningbsecret}/" .env.local
sed -i "s/DATABASE_URL=.*/DATABASE_URL=mysql:\/\/$planningbdbuser:$planningbdbpass@$planningdbhost:$planningdbport\/$planningbdbname/" .env.local
sed -i "s/DATABASE_PREFIX=.*/DATABASE_PREFIX=$planningbdbprefix/" .env.local
# Set the light_blue theme
mysql -h $planningdbhost -u $planningbdbuser --password=$planningbdbpass -e "UPDATE $planningbdbname.\`config\` SET \`valeur\` = 'light_blue' WHERE \`nom\` = 'Affichage-theme';"
if [[ ! -d public/themes/light_blue ]]; then
git clone https://github.com/planningbiblio/theme_light_blue public/themes/light_blue
fi
# Download composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# Update dependencies ?
if [[ $updatecomposer = 'yes' && -f composer.lock ]]; then
echo "Removing composer.lock"
rm composer.lock
if [[ -d vendor ]];then
echo "Removing vendor folder"
rm -r vendor
fi
fi
# Run composer install
php composer.phar install
if [[ $? -eq 2 ]]; then
if [[ -d vendor ]];then
echo "Removing vendor folder"
rm -r vendor
fi
if [[ -e composer.lock ]];then
echo "Removing composer.lock"
rm composer.lock
fi
php composer.phar update
fi
if [[ $? > 0 ]]; then
exit;
fi
# Remove composer.phar
php -r "unlink('composer.phar');"
# Run database update
grep "\$version=\"$version\";" init/init.php
if [[ $? != 0 ]]; then
php -f public/index.php
fi
echo ""
echo -e "One more step, run : \e[1m\033[32msudo chmod -R 777 var\e[0m";
echo "Then, the installation will be completed and you will be able to use Planning Biblio in your web browser with these cretentials : admin / $planningbadminpass";
echo ""