wordpress-dev/dev/container-create.sh

76 lines
3.2 KiB
Bash
Raw Normal View History

2020-03-01 22:21:31 +00:00
#!/bin/sh
set -e
_host="$_local_hostname.$_local_domain"
2020-03-01 22:21:31 +00:00
_user_root='root'
_ssh_cmd_root="ssh $_user_root@$_host"
2020-03-19 13:25:29 +00:00
_scp_to="$_user_root@$_host"
2020-03-01 22:21:31 +00:00
_ssh_cmd_www="sshpass -p$_passwd_www ssh $_user_www@$_host"
_ssh_cmd_www_cd="$_ssh_cmd_www cd /var/www/html/wordpress &&"
_wp_url="http://$_host"
printf "\nInstalling requirements ..."
$_ssh_cmd_root 'apt-get update && apt-get -y upgrade && apt-get -y install apache2 mariadb-server php php-common libapache2-mod-php python-mysqldb php-gd php-ssh2 php-mysql php-dom php-simplexml php-xml php-xmlreader php-curl php-ftp php-iconv php-imagick php-mbstring php-posix php-sockets php-tokenizer php-zip'
printf "\nConfiguring Apache ..."
2020-03-19 13:25:29 +00:00
scp ./dev/config/000-default.conf "$_scp_to":/etc/apache2/sites-enabled/000-default.conf
$_ssh_cmd_root 'a2enmod rewrite; systemctl restart apache2'
2020-03-01 22:21:31 +00:00
printf "\nSetting %s permissions ..." "$_user_www"
$_ssh_cmd_root "echo \"$_user_www:$_passwd_www\" | chpasswd"
$_ssh_cmd_root 'sed -i '\''s+www-data:/var/www:/usr/sbin/nologin+www-data:/var/www:/bin/bash+'\'' /etc/passwd'
$_ssh_cmd_root 'chown -R www-data: /var/www/html'
printf "\nCreating database ..."
# database is insecure (no root password, remote root login, etc) - but not
# worried because it's in a trusted dev environment with no remote connections.
# TODO ensure production database is secure TODO
2020-03-01 22:21:31 +00:00
$_ssh_cmd_root 'echo "create database wordpress;" | mysql'
_mysql_cmd='GRANT ALL PRIVILEGES ON wordpress.* TO \"wordpress\"@\"localhost\" IDENTIFIED BY \"'"$_wp_db_passwd"'\";'
2020-03-01 22:21:31 +00:00
$_ssh_cmd_root "echo \"$_mysql_cmd\" | mysql"
$_ssh_cmd_root 'echo "FLUSH PRIVILEGES;" | mysql'
printf "\nInstalling WordPress CLI ...\n"
$_ssh_cmd_root "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"
printf "\nInstalling WordPress ..."
$_ssh_cmd_www "cd /var/www/html && wp core download --path=wordpress --skip-content"
printf "\nConfiguring WordPress ..."
$_ssh_cmd_root 'mkdir -p /var/www/.wp-cli/cache && chown -R www-data: /var/www/.wp-cli'
$_ssh_cmd_www_cd "wp config create --dbname=wordpress --dbuser=wordpress --dbpass='$_wp_db_passwd'"
2020-03-01 22:21:31 +00:00
$_ssh_cmd_www 'sed -i "s/<?php$/<?php\n\ndefine( '\''WP_DEBUG'\'', true );\ndefine( '\''WP_DEBUG_LOG'\'', true );\n/" /var/www/html/wordpress/wp-config.php'
$_ssh_cmd_www_cd "wp core install --url=$_wp_url --title=\"$_wp_title\" --admin_user=$_wp_admin_user --admin_password=\"$_wp_password\" --admin_email=$_wp_email --skip-email"
2020-03-09 20:45:35 +00:00
$_ssh_cmd_www_cd "wp rewrite structure /%postname%/"
2020-03-01 22:21:31 +00:00
printf "\nInstalling themes ..."
2020-03-01 22:21:31 +00:00
if [ -n "$_wp_theme_active" ] ; then
$_ssh_cmd_www_cd "wp theme install $_wp_theme_active --activate"
fi
if [ -n "$_wp_themes_additional" ] ; then
for _theme in $_wp_themes_additional ; do
echo " installing $_theme ..."
$_ssh_cmd_www_cd "wp theme install $_theme"
done
fi
printf "\nInstalling plugins ..."
2020-03-01 22:21:31 +00:00
if [ -n "$_wp_plugins" ] ; then
for _plugin in $_wp_plugins ; do
echo " installing $_plugin ..."
$_ssh_cmd_www_cd "wp plugin install $_plugin"
done
fi
if [ -n "$_wp_plugins_active" ] ; then
for _plugin in $_wp_plugins_active ; do
echo " installing $_plugin ..."
$_ssh_cmd_www_cd "wp plugin install $_plugin --activate"
done
fi