Compare commits

..

No commits in common. "c389c52385c8ab8b4459ba21d193faa8ee5427ef" and "1ee910ab86b425e9168061b970179c817d4ecafa" have entirely different histories.

7 changed files with 23 additions and 66 deletions

View File

@ -4,7 +4,6 @@ TODO
## TODO
* implement option to not have remote url include hostname (i.e., bare domain)
* convert scripts to use ssh pipes/bash here documents.
see [ssh pipes](https://stackoverflow.com/a/4412324), [Bash Here Document](https://stackoverflow.com/a/4412338)
* Script to export database from production database

View File

@ -8,10 +8,10 @@ export _local_domain="home"
export _user_www='www-data'
export _passwd_www='www-data'
export _wp_title="WP Title"
export _wp_title="WP Test"
export _wp_admin_user="admin"
export _wp_password="a_better_password_than_this_bro"
export _wp_email="wp@example.org"
export _wp_password="admin"
export _wp_email="$_local_hostname@isnet.uk"
export _wp_db_passwd="wordpress"
export _wp_theme_active="twentytwenty"
@ -23,10 +23,9 @@ export _wp_plugins_active="elementor wp-mail-smtp gdpr-cookie-compliance regener
# remote configuration
export _remote_host="www"
export _domain="isnet.uk"
_lets_encrypt_email="letsencrypt@example.org"
export _docker_user="ray"
export _remote_host="seven"
export _domain="wptest.isnet.uk"
export _docker_base_dir="/var/docker"
export _mysql_root_passwd="another_password_better_than_this_bruh"
export _mysql_root_passwd="db"

View File

@ -1,7 +1,5 @@
#!/bin/sh
set -e
if [ -z "$1" ] ; then
_target_filename='.'
else
@ -13,9 +11,8 @@ _cmd_wp_export="wp db export --dbuser=wordpress --dbpass=$_wp_db_passwd --add-dr
_ssh_cmd="sshpass -p$_passwd_www ssh $_user_www@$_host"
_scp_cmd="sshpass -p$_passwd_www scp $_user_www@$_host:/tmp/wordpress.tar.gz"
echo "Exporting database ..."
echo "Exporting data ..."
$_ssh_cmd "cd /var/www/html/wordpress &&" $_cmd_wp_export
echo "Exporting files ..."
$_ssh_cmd 'cd /var/www/html/wordpress && tar czf /tmp/wordpress.tar.gz .'
$_ssh_cmd "rm /var/www/html/wordpress/data.sql"
$_scp_cmd "$_target_filename"

View File

@ -1,5 +0,0 @@
#!/bin/sh
set -e

View File

@ -1,7 +1,5 @@
#!/bin/sh
set -e
_docker_dir="$_docker_base_dir/$_remote_host"
_ssh_cmd="ssh root@$_remote_host.$_domain"
@ -51,12 +49,12 @@ echo "Configuring WordPress ..."
# TODO does docker always assign ips in range 172.% ????
# TODO - sort this mess out - use functions or something
_ssh_shell_cmd='echo "GRANT ALL PRIVILEGES ON wordpress."*" TO \"wordpress\"@\"172.%\" IDENTIFIED BY \"'"$_wp_db_passwd"'\";" | mysql -uroot -p'"$_mysql_root_passwd"
_ssh_shell_cmd='echo "GRANT ALL PRIVILEGES ON wordpress."*" TO \"wordpress\"@\"172.%\" IDENTIFIED BY \"wordpress\";" | mysql -uroot -pdb'
_cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-mysql /bin/sh -c '$_ssh_shell_cmd'"
echo "$_ssh_cmd $_cmd_docker_exec"
$_ssh_cmd $_cmd_docker_exec
_cmd_wp="wp db import --dbuser=wordpress --dbpass=$_wp_db_passwd data.sql && rm data.sql"
_cmd_wp="wp db import --dbuser=wordpress --dbpass=$_wp_db_passwd data.sql"
_cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-wordpress /bin/sh -c '$_cmd_wp'"
echo "$_ssh_cmd $_cmd_docker_exec"
$_ssh_cmd "$_cmd_docker_exec"
@ -81,15 +79,9 @@ _cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-wordpress /bin
echo "$_ssh_cmd $_cmd_docker_exec"
$_ssh_cmd "$_cmd_docker_exec"
_remote_url="$_remote_host.$_domain"
_cmd_wp="wp search-replace '$_local_hostname.$_local_domain' '$_remote_url' --skip-columns=guid"
_cmd_wp="wp search-replace '$_local_hostname.$_local_domain' '$_remote_host.$_domain' --skip-columns=guid"
_cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-wordpress /bin/sh -c '$_cmd_wp'"
echo "$_ssh_cmd $_cmd_docker_exec"
$_ssh_cmd "$_cmd_docker_exec"
echo ""
echo "-------------------------------------------------------------------------"
echo "Deploy complete"
echo " URL: https://$_remote_url/wp-login.php"
rm .env

View File

@ -1,30 +1,23 @@
#!/bin/sh
set -e
# TODO basic error checking
# TODO verbosity
# TODO hardening
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
_server_base_url="$_domain"
echo "Provisioning: $_server_base_url$ - (whoami)@$(hostname)"
_lets_encrypt_email="wptest@isnet.uk"
_server_base_url="wptest.isnet.uk"
_docker_container_config_dir="/var/docker"
_docker_compose_version="1.25.4"
# add user
useradd -m -s /bin/bash "$_docker_user"
useradd -m -s /bin/bash ray
groupadd docker
usermod -aG docker "$_docker_user"
mkdir /home/"$_docker_user"/.ssh
cp /root/.ssh/authorized_keys /home/"$_docker_user"/.ssh/
chown "$_docker_user": /home/"$_docker_user"/.ssh/authorized_keys
usermod -aG docker ray
mkdir /home/ray/.ssh
cp /root/.ssh/authorized_keys /home/ray/.ssh/
chown ray: /home/ray/.ssh/authorized_keys
apt-get update
apt-get upgrade --yes
apt-get install \
apt-transport-https \
ca-certificates \
@ -37,9 +30,9 @@ apt-get install \
ufw allow ssh
ufw allow http
ufw allow https
ufw --force enable
ufw enable
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
@ -50,8 +43,8 @@ apt-get install docker-ce docker-ce-cli containerd.io
curl -L "https://github.com/docker/compose/releases/download/$_docker_compose_version/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "Basic HTTP authorisation password for user: $_docker_user"
_HT_PASSWD=$(htpasswd -nB "$_docker_user" | sed -e 's/\$/\$\$/g')
echo "Basic HTTP authorisation password for user: ray"
_HT_PASSWD=$(htpasswd -nB ray | sed -e 's/\$/\$\$/g')
docker network create web
@ -161,14 +154,5 @@ networks:
" >> docker-compose.yml
docker-compose up -d
echo "-------------------------------------------------------------------------"
echo ""
echo "VISIT PORTAINER URL NOW TO SET INITIAL LOGIN:"
echo "VISIT PORTAINER URL NOW TO SET INITIAL LOGIN:" # or see if can set from script
echo " https://$_portainer_url"
echo ""
echo "Traefik URl: https://$_server_base_url"
echo ""
echo "WARNING: May get insecure SSL errors"
echo " this is temporary while certs are in process of being issued"
rm /tmp/setup.sh

View File

@ -1,9 +0,0 @@
#!/bin/sh
. ./config
_ssh_url="root@$_remote_host.$_domain"
# ssh "$_remote_host.$_domain" '/bin/bash -s' < ./production/webserver-setup.sh
cat config ./production/webserver-setup.sh | ssh "$_ssh_url" "cat >/tmp/setup.sh"
ssh $_ssh_url '/bin/bash /tmp/setup.sh'