From ba7d862475d0c64d87fb0ba5f37b05813052148d Mon Sep 17 00:00:00 2001 From: ray Date: Sun, 1 Mar 2020 22:21:31 +0000 Subject: [PATCH] add development deploy script --- .gitignore | 2 ++ config-example | 16 +++++++++ dev-container-deploy.sh | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 config-example create mode 100755 dev-container-deploy.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10940cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config +dev-setup-notes.txt diff --git a/config-example b/config-example new file mode 100644 index 0000000..08160f0 --- /dev/null +++ b/config-example @@ -0,0 +1,16 @@ +# rename to `config` and assign suitable values. + +_user_www='www-data' +_passwd_www='www-data' + +_wp_title="WP Test" +_wp_admin_user="admin" +_wp_password="admin" +_wp_email="admin@$_host" +_wp_db_passwd="wordpress" + +_wp_theme_active="twentytwenty" +_wp_themes_additional="twentynineteen twentyseventeen" + +_wp_plugins="better-wp-security wp-fastest-cache autodescription google-analytics-for-wordpress" +_wp_plugins_active="elementor wp-mail-smtp gdpr-cookie-compliance regenerate-thumbnails" diff --git a/dev-container-deploy.sh b/dev-container-deploy.sh new file mode 100755 index 0000000..135d626 --- /dev/null +++ b/dev-container-deploy.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +if [ -z "$1" ] ; then + echo "Must supply container name as argument" + exit 1 +fi + +. ./config + +_host="$1.home" +_user_root='root' +_ssh_cmd_root="ssh $_user_root@$_host" + +_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 ..." +$_ssh_cmd_root 'sed -i '\''s+DocumentRoot /var/www/html$+DocumentRoot /var/www/html/wordpress+'\'' /etc/apache2/sites-enabled/000-default.conf && systemctl restart apache2' + +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. +$_ssh_cmd_root 'echo "create database wordpress;" | mysql' +_mysql_cmd='GRANT ALL PRIVILEGES ON wordpress.* TO \"wordpress\"@\"localhost\" IDENTIFIED BY \"wordpress\";' +$_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" + +$_ssh_cmd_www_cd "wp config create --dbname=wordpress --dbuser=wordpress --dbpass=$_wp_db_passwd" +$_ssh_cmd_www 'sed -i "s/