2020-09-03 22:06:42 +00:00
|
|
|
echo "Installing WordPress .."
|
|
|
|
|
|
|
|
_mysql_cmd="mysql -uroot -p$db_root_pass -e "
|
|
|
|
|
|
|
|
ssh -T $ssh << EOSSH
|
|
|
|
|
|
|
|
# install wp-cli first
|
|
|
|
if [ ! -f /usr/local/bin/wp ] ; then
|
|
|
|
wget -nv -O /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
|
|
|
|
&& chmod +x /usr/local/bin/wp
|
|
|
|
fi
|
|
|
|
|
|
|
|
su "$user"
|
|
|
|
|
|
|
|
if wp core is-installed --quiet --path="$wp_path" ; then
|
|
|
|
echo "WordPress already installed"
|
|
|
|
else
|
|
|
|
# first create database and user
|
|
|
|
if command -v mysql ; then
|
|
|
|
$_mysql_cmd "CREATE DATABASE $wp_db_name;"
|
|
|
|
$_mysql_cmd "GRANT ALL PRIVILEGES ON $wp_db_name.* TO '$wp_db_user'@'localhost' IDENTIFIED BY '$wp_db_pass';"
|
|
|
|
$_mysql_cmd "FLUSH PRIVILEGES;"
|
|
|
|
else
|
|
|
|
echo "ERROR: no installed database found - aborting WordPress install"
|
|
|
|
exit 40
|
|
|
|
fi
|
|
|
|
wp core download \
|
|
|
|
--version="$wp_version" \
|
|
|
|
--path="$wp_path" \
|
|
|
|
--skip-content \
|
|
|
|
--locale="$wp_locale"
|
|
|
|
wp config create \
|
|
|
|
--path="$wp_path" \
|
|
|
|
--dbname="$wp_db_name" \
|
|
|
|
--dbuser="$wp_db_user" \
|
|
|
|
--dbpass="$wp_db_pass" \
|
|
|
|
--locale="$wp_locale" \
|
|
|
|
--extra-php <<PHP
|
|
|
|
define( 'WP_DEBUG', true );
|
|
|
|
define( 'WP_DEBUG_LOG', true );
|
|
|
|
PHP
|
|
|
|
wp core install \
|
|
|
|
--path="$wp_path" \
|
2020-09-04 12:34:57 +00:00
|
|
|
--url="$domain" \
|
2020-09-03 22:06:42 +00:00
|
|
|
--title="$wp_title" \
|
|
|
|
--admin_user="$wp_user" \
|
|
|
|
--admin_password="$wp_pass" \
|
|
|
|
--admin_email="$wp_email"
|
|
|
|
fi
|
2020-09-04 13:23:11 +00:00
|
|
|
EOSSH
|
2020-09-03 22:06:42 +00:00
|
|
|
|
|
|
|
if [ -n "$wp_themes" ] ; then
|
|
|
|
printf "\nInstalling themes ..."
|
|
|
|
option='--activate'
|
|
|
|
for theme in $wp_themes ; do
|
|
|
|
echo " installing $theme ..."
|
2020-09-04 13:23:11 +00:00
|
|
|
ssh -T $ssh << EOSSH
|
|
|
|
su "$user"
|
2020-09-04 12:34:57 +00:00
|
|
|
wp theme install $theme "$option" --path="$wp_path"
|
2020-09-04 13:23:11 +00:00
|
|
|
EOSSH
|
2020-09-03 22:06:42 +00:00
|
|
|
option=''
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$wp_plugins" ] ; then
|
|
|
|
printf "\nInstalling plugins ..."
|
|
|
|
for plugin in $wp_plugins ; do
|
|
|
|
echo " installing $plugin ..."
|
2020-09-04 13:23:11 +00:00
|
|
|
ssh -T $ssh << EOSSH
|
|
|
|
su "$user"
|
2020-09-04 12:34:57 +00:00
|
|
|
wp plugin install $plugin --path="$wp_path"
|
2020-09-04 13:23:11 +00:00
|
|
|
EOSSH
|
2020-09-03 22:06:42 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$wp_plugins_active" ] ; then
|
|
|
|
printf "\nInstalling plugins to activate ..."
|
|
|
|
for plugin in $wp_plugins_active ; do
|
|
|
|
echo " installing $plugin ..."
|
2020-09-04 13:23:11 +00:00
|
|
|
ssh -T $ssh << EOSSH
|
|
|
|
su "$user"
|
2020-09-04 12:34:57 +00:00
|
|
|
wp plugin install $plugin --activate --path="$wp_path"
|
2020-09-04 13:23:11 +00:00
|
|
|
EOSSH
|
2020-09-03 22:06:42 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$wp_plugins_active" ] ; then
|
|
|
|
printf "\nUninstalling plugins ..."
|
|
|
|
for plugin in $wp_plugins_uninstall ; do
|
|
|
|
echo " installing $plugin ..."
|
2020-09-04 13:23:11 +00:00
|
|
|
ssh -T $ssh << EOSSH
|
|
|
|
su "$user"
|
2020-09-04 12:34:57 +00:00
|
|
|
wp plugin deactivate $plugin --path="$wp_path"
|
|
|
|
wp plugin uninstall $plugin --path="$wp_path"
|
2020-09-04 13:23:11 +00:00
|
|
|
EOSSH
|
2020-09-03 22:06:42 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
config_path='/etc/apache2/sites-available/wordpress.conf'
|
|
|
|
ssh -T $ssh << EOSSH
|
|
|
|
if [ -n "$apache2_version" ] ; then
|
|
|
|
mkdir -p /var/log/wordpress/
|
|
|
|
cat << EOF > $config_path
|
|
|
|
<VirtualHost *:80>
|
|
|
|
ServerName $domain
|
|
|
|
DocumentRoot $wp_path
|
|
|
|
ErrorLog /var/log/wordpress/error.log
|
|
|
|
CustomLog /var/log/wordpress/access.log combined
|
|
|
|
<Directory $wp_path/>
|
|
|
|
AllowOverride All
|
|
|
|
<IfModule mod_rewrite.c>
|
|
|
|
RewriteEngine On
|
|
|
|
RewriteBase /
|
|
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
|
|
RewriteRule . /index.php [L]
|
|
|
|
</IfModule>
|
|
|
|
</Directory>
|
|
|
|
</VirtualHost>
|
|
|
|
EOF
|
|
|
|
a2enmod rewrite
|
|
|
|
a2ensite wordpress
|
|
|
|
a2dissite 000-default
|
|
|
|
systemctl reload apache2
|
|
|
|
fi
|
|
|
|
EOSSH
|