-
Notifications
You must be signed in to change notification settings - Fork 0
/
INSTALL.sh
executable file
·205 lines (168 loc) · 6.43 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
#!/bin/bash
#---
# System changes before installation
#---
# Getting comand line argument no 1
IFS='.' read -r -a array <<< $1
if [ -z $1 ]; then
printf "
No domain name given\n
Usage: ./INSTALL.sh your.domanin.com\n
For further help type ./INSTALL.sh help
For system info and version type ./INSTALL.sh info
For OS2display management type ./INSTALL.sh display\n\n"
exit
fi
if [ "$1" = "help" ]; then
printf "
Help section\n
For further help type ./INSTALL.sh help
For system info and version type ./INSTALL.sh info
For OS2display management type ./INSTALL.sh display\n\n"
exit
fi
if [ "$1" = "info" ]; then
printf "
Info section\n
For further help type ./INSTALL.sh help
For system info and version type ./INSTALL.sh info
For OS2display management type ./INSTALL.sh display\n\n"
exit
fi
if [ "$1" = "display" ]; then
printf "
Display management\n
For further help type ./INSTALL.sh help
For system info and version type ./INSTALL.sh info
For OS2display management type ./INSTALL.sh display\n\n"
exit
fi
if [ "$1" = "help" ]; then
printf "\n./INSTALL.sh help\n"
exit
fi
# Setting permissions for the template and layout script
chmod a+x /var/www/display/scripts/install_templates.sh
chmod a+x /var/www/display/scripts/install_layouts.sh
chmod a+x /var/www/display/scripts/install_feeds.sh
# Dropping the database if it exists
mysql=$(mysql -u root -e 'show databases;')
check_db=${1//./_}
echo $check_db
echo $mysql;
if [[ $mysql == *"$check_db"* ]]; then
read -p "Database exists - Do you want to drop user and database and continue (y/n) ?" -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then
exit
else
mysql_user_name_max=${check_db:0:15}
mysql -u root -D mysql -e 'DELETE from user where User = "'$mysql_user_name_max'"';
printf "\nUser dropped - continuing\n"
mysql=$(mysql -u root -e 'DROP DATABASE '$check_db';')
printf "\nDatabase dropped - continuing\n"
fi
fi
# Creating DB, docroot and vhost for the site
/usr/bin/php /var/www/display/scripts/create_site_with_db.php $1
# Changing PHP defaults to the needed max MB
sed -i 's/post_max_size = 8M/post_max_size = 200M/g' /etc/php/8.3/cli/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/g' /etc/php/8.3/cli/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 200M/g' /etc/php/8.3/apache2/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/g' /etc/php/8.3/apache2/php.ini
# Implementing OS2display vhost templare from /var/www/display/templates
cp /var/www/display/templates/apache2.vhost.conf /etc/apache2/sites-available/$1.conf
sed -i 's/DOMAIN/'$1'/g' /etc/apache2/sites-available/$1.conf
# Restarting Apache webserver to load new configuration
systemctl restart apache2
# Cleaning up default files that are not needed
rm -rf /etc/apache2/sites-enabled/000-default.conf
rm -rf /var/www/$1/public_html
#---
# OS2display API
#---
# Cloning the OS2display API into ./public
cd /var/www/$1
git clone https://github.com/os2display/display-api-service.git public_html
# Setup of the API setup
cd /var/www/$1/public_html
mapfile -t a < /var/www/$1/db.txt
declare "${a[@]}"
cp .env .env.local
# Writing the DB info and domain changes to the .env.local file.
sed -i 's/db:db/'$DBUSERNAME':db/g' .env.local
sed -i 's/:db@/:'$DBPASS'@/g' .env.local
sed -i 's/mariadb/localhost/g' .env.local
sed -i 's/db?/'$DBNAME'?/g' .env.local
sed -i 's/redis:6379/localhost:6379/g' .env.local
sed -i 's/displayapiservice.local.itkdev.dk/'$1'/g' .env.local
# Moving install scripts
cp /var/www/display/scripts/install_templates.sh /var/www/$1/public_html/
cp /var/www/display/scripts/install_layouts.sh /var/www/$1/public_html/
cp /var/www/display/scripts/install_feeds.sh /var/www/$1/public_html/
#---
# OS2display client
#---
# Cloning the OS2display client into ./public_html/client
cd /var/www/$1/public_html
wget https://github.com/os2display/display-client/releases/download/2.0.3/display-client-2.0.3.tar.gz
tar -xvzf display-client-2.0.3.tar.gz
chown -R www-data: client/
# Setup of the client configuration
cd /var/www/$1/public_html/client
cp example_config.json config.json
chown -R www-data: config.json
sed -i 's/os2display.example.org/'$1'/g' config.json
echo $1 ' Has been added to config.json'
#---
# OS2display sdmin client
#---
# Cloning the OS2display admin client into ./public_html/admin
cd /var/www/$1/public_html
wget https://github.com/os2display/display-admin-client/releases/download/2.0.2/display-admin-client-2.0.2.tar.gz
tar -xvzf display-admin-client-2.0.2.tar.gz
chown -R www-data: admin/
# Setup of the admin client configuration
cd /var/www/$1/public_html/admin
cp example_config.json config.json
cp example-access-config.json access-config.json
chown -R www-data: config.json
chown -R www-data: access-config.json
# File that has been changed and needs a patch - planned
cp /var/www/display/patch/Media.php /var/www/$1/public_html/src/Entity/Tenant/Media.php
# Composer install
composer require predis/predis
composer install --optimize-autoloader
composer install
# To be removed
#/usr/bin/php -q /var/www/$1/public/bin/console doctrine:query:sql "show tables"
# Creating Symfony DB schema via Doctrine / the console
/usr/bin/php -q /var/www/$1/public_html/bin/console doctrine:schema:create
/usr/bin/php -q /var/www/$1/public_html/bin/console cache:clear
# Generating needed JWT keypair
/usr/bin/php -q /var/www/$1/public_html/bin/console lexik:jwt:generate-keypair
ls -la /var/www/$1/public_html/config/jwt/
# Adding Tennant before creating the admin user
/usr/bin/php -q /var/www/$1/public_html/bin/console app:tenant:add
echo "As the last field in the user creation. Ad the tenant. The value from the first field in the tennant creation "
/usr/bin/php -q /var/www/$1/public_html/bin/console app:user:add
# Linking the admin and client folders into the document root.
ln -s /var/www/$1/public_html/admin /var/www/$1/public_html/public/admin
ln -s /var/www/$1/public_html/client /var/www/$1/public_html/public/client
# Running Symfony install commands for templates and layouts.
chown -R www-data: /var/www/$1
cd /var/www/$1/public_html
./install_templates.sh
./install_layouts.sh
# Running Symfony install command for Feeds. This needs a little feedback
read -p "Installing an RSS feeds - this needs a little input
* Feed type needed (use the down arrow): App\Feed\RssFeedType
* Add it to the tenant that was just created (use arrow down)
* Follow the rest of the instructions for naming
Pres y to continue (y/n)" -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then
exit
else
./install_feeds.sh
fi