summaryrefslogtreecommitdiff
path: root/server-build/QEMU-autobuild/buildWooTalerServer.sh
blob: d53f002d06454cbf7dcfbc4592f4837f772c593d (plain)
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 -e

# This script runs on the Qemu image "WooTaler.img"  to create a WooTaler installation.

# update Debian from repos (not upgrade)
echo
echo '## Updating (not upgrading) Debian repos ...'
apt update

# upgrade system on user input
echo
read -e -r -p "Do you want to upgrade Debian (and do you know what you're doing)? ['y' Upgrades Debian] " -i "y" upgradeDebian
if [[ -z $upgradeDebian ]]
then
    upgradeDebian="y"
fi
if [[ $upgradeDebian == "y" ]]
then
  echo
  echo '## Performing Debian upgrade...'
  apt -y upgrade
else
  echo
  echo '** Good safe choice.  Proceeding with installation without upgrading Debian...'
fi

# install some basic software
echo
read -e -r -p "Do you want to install imagemagick? ['y' Installs imagemagick] " -i "y" installImagemagick
if [[ -z $installImagemagick ]]
then
    installImagemagick="y"
fi
if [[ $installImagemagick == "y" ]]
then
  echo
  echo '## Installing imagemagick...'
  apt install imagemagick -y
else
  echo
  echo '** imagemagick not installed.  You can install it later with "apt install imagemagick php-imagick"'
fi

# install mariaDB
echo
echo '## Installing mariaDB...'
apt install -y mariadb-server

# install software for apache2/php
echo
read -e -p "What minor (x.x) version of PHP are you using? " -i "7.3" phpVersion
if [[ -z $phpVersion ]]
then
    phpVersion="7.3"
fi
echo
echo '## Installing apache2/php'$phpVersion'...'
apt install -y sendmail curl apache2 php${phpVersion} php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php

# apache2 customization
echo
echo "## Customizing apache2 with php ${phpVersion} for WordPress..."
echo
echo '--- installing apache2 modules'
echo
a2enmod rewrite alias proxy_fcgi php${phpVersion} proxy_fcgi setenvif

echo
echo '--- setting up apache2 .conf file'
cp woocommerce-taler/server-build/QEMU-autobuild/wootaler-qemu.conf /etc/apache2/sites-available

# enable wootaler-qemu
a2ensite wootaler-qemu

# remove the default apache2 config
a2dissite 000-default

echo
echo '--- restarting apache2 now: systemctl restart apache2'
systemctl restart apache2

echo
echo '***** WordPress Installation *****'

echo
read -e -p "-- What version of WordPress will you install? " -i "5.5.1" wordpressVersion
if [[ -z $wordpressVersion ]]
then
    wordpressVersion="5.5.1"
fi
echo
echo '-- Downloading and installing WordPress v.' $wordpressVersion' now.'
wget https://wordpress.org/wordpress-$wordpressVersion.tar.gz
tar -xf wordpress-$wordpressVersion.tar.gz -C /var/www
chmod -R 755 /var/www/wordpress
chown -R www-data:www-data /var/www/wordpress

rm wordpress-$wordpressVersion.tar.gz

echo
echo '-- Please set some terms to use for the WordPress database (mariaDB):'
echo
read -e -p "---- What name will you give the WP DATABASE? " -i "wordpress" WPdbName
if [[ -z $WPdbName ]]
then
    WPdbName="wordpress"
fi
echo
read -e -p "---- What should be the WP database USER? " -i "wordpress" WPdbUser
if [[ -z $WPdbUser ]]
then
    WPdbUser="wordpress"
fi
echo
read -e -p "---- What should be the WP database user's PASSWORD? " -i "wordpress-pass" WPdbUserPass
if [[ -z $WPdbUserPass ]]
then
    WPdbUserPass="wordpress-pass"
fi

echo
echo '-- Setting wp-config.php with the parameters set above.'
# borrowed from https://gist.github.com/bgallagh3r/2853221
cd /var/www/wordpress
#create wp config
cp wp-config-sample.php wp-config.php
#set database details with perl find and replace
perl -pi -e "s/database_name_here/$WPdbName/g" wp-config.php
perl -pi -e "s/username_here/$WPdbUser/g" wp-config.php
perl -pi -e "s/password_here/$WPdbUserPass/g" wp-config.php
echo
echo '** wp-config.php has the DB variables'
echo
echo '** WordPress is installed.'

echo
echo '***** mariaDB Configuration *****'
echo
read -e -r -p "Do you want to secure the mariaDB installation? ['y' runs mysql_secure_installation] " -i "n" secureMariaDB
if [[ -z $secureMariaDB ]]
then
    secureMariaDB="n"
fi
if [[ $secureMariaDB == "y" ]]
then
  mysql_secure_installation -p ""
else
  echo
  echo '** Okay.  Your mariaDB installtion is not secure.'
fi

# Create the mariaDB DB

DBEXISTS=$(mysql --batch --skip-column-names -e "SHOW DATABASES LIKE '"$WPdbName"';" | grep "$WPdbName" > /dev/null; echo "$?")
if [ $DBEXISTS -eq 0 ];then
    echo "A database with the name $WPdbName already exists.  Skipping mariaDB database creation."
else
    echo
    echo '-- Creating new mariaDB database '$WPdbName'...'
    mysql -e "CREATE DATABASE $WPdbName /*\!40100 DEFAULT CHARACTER SET utf8 */;"
    echo
    echo '** Database successfully created!'
    echo
    echo '-- Creating new user '$WPdbUser'...'
    mysql -e "CREATE USER $WPdbUser@localhost IDENTIFIED BY '$WPdbUserPass';"
    echo
    echo '** User successfully created!'
      echo
    echo '-- Granting ALL privileges on '$WPdbName' to '$WPdbUser'...'
    mysql -e "GRANT ALL PRIVILEGES ON $WPdbName.* TO '$WPdbUser'@'localhost';"
    mysql -e "FLUSH PRIVILEGES;"
    echo
    echo '** The mariaDB database is created.'
fi

# Stop to test the config so far
echo
echo 'Now is a good time to test your WordPress installation.'
echo '  You should be able to view it at http://127.0.0.1:9999 of your host system.'
echo
read -e -r -p "Press 'y' when you are ready to continue. " -i "y"  doContinue
if [[ -z $doContinue ]]
then
    doContinue="y"
fi
if ! [[ $doContinue == "y" ]]
then
  echo
  echo 'Oh.  I guess something is wrong.  Exiting.  (Re-start the script when ready.)'
  exit 1
fi

# Continuing...
echo
echo 'Continuing with installation...'

echo
read -e -r -p "Ready to build the webstore with buildWebstore.sh? ['y' continues] " -i "n" doBuildWebstore
if [[ -z $doBuildWebstore ]]
then
    doBuildWebstore="n"
fi
if [[ $doBuildWebstore == "y" ]]
then
  woocommerce-taler/server-build/QEMU-autobuild/buildWebstore.sh
fi

echo
read -e -r -p "Ready to setup Re:claim? ['y' continues] " -i "n" doReClaim
if [[ -z $doReClaim ]]
then
    doReClaim="n"
fi
if [[ $doReclaim == "y" ]]
then
  woocommerce-taler/server-build/QEMU-autobuild/buildReclaim.sh
fi

exit 0