From 20559e5395ea06cd3555d3b373a9c98de17c4640 Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 12 Jun 2020 23:41:13 +0100 Subject: [PATCH] update --- config-example | 5 +++ run.sh | 20 ------------ server-install-base.sh | 18 ++++++++++ server-install-web.sh | 20 +++++++++++- wp-duplicate.sh | 74 ++++++++++++++++++++++++++++++++++++++++++ wp-export.sh | 20 ++++++++++++ wp-install.sh | 21 ++++++++++-- 7 files changed, 154 insertions(+), 24 deletions(-) delete mode 100755 run.sh diff --git a/config-example b/config-example index c412026..c37f539 100755 --- a/config-example +++ b/config-example @@ -1,4 +1,9 @@ #!/bin/sh +export local_url='' +export remote_url='' + +export local_ssh='' +export remote_ssh='' export username='' export webuser='' diff --git a/run.sh b/run.sh deleted file mode 100755 index 763ba3e..0000000 --- a/run.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -. ./config-urls - -if [ "$1" = 'local' ] ; then - ( - echo "export local_url=\"$local_ur\""; \ - echo "export remote_url=\"$remote_url\""; \ - cat config "$2" \ - ) | ssh root@"$local_url" -T /bin/sh -elif [ "$1" = 'remote' ] ; then - ( - echo "export local_url=\"$remote_url\""; \ - echo "export remote_url=\"$local_url\""; \ - cat config "$2" \ - ) | ssh root@"$remote_url" -T /bin/sh -else - echo "error: must specify local or remote" -fi - diff --git a/server-install-base.sh b/server-install-base.sh index bf05a65..bb4abe6 100755 --- a/server-install-base.sh +++ b/server-install-base.sh @@ -1,5 +1,22 @@ #!/bin/sh +. ./config + +if [ "$1" = 'local' ] ; then + src_url="$local_url"; + dest_url="$remote_url"; + src_ssh="$local_ssh" +elif [ "$1" = 'remote' ] ; then + src_url="$remote_url"; + dest_url="$local_url"; + src_ssh="$remote_ssh" +else + echo "error: must specify local or remote" + exit 5 +fi + +ssh -T $src_ssh << EOSSH + apt upgrade -y || exit 10 apt install -y tmux ufw curl || exit 15 @@ -11,3 +28,4 @@ systemctl restart sshd ufw allow ssh || exit 20 yes | ufw enable +EOSSH diff --git a/server-install-web.sh b/server-install-web.sh index 605ba56..5276a47 100755 --- a/server-install-web.sh +++ b/server-install-web.sh @@ -1,5 +1,22 @@ #!/bin/sh +. ./config + +if [ "$1" = 'local' ] ; then + src_url="$local_url"; + dest_url="$remote_url"; + src_ssh="$local_ssh" +elif [ "$1" = 'remote' ] ; then + src_url="$remote_url"; + dest_url="$local_url"; + src_ssh="$remote_ssh" +else + echo "error: must specify local or remote" + exit 5 +fi + +ssh -T $src_ssh << EOSSH + success="0" if [ -n "$apache2_version" ] ; then @@ -21,7 +38,7 @@ elif [ -n "$lightspeed_version" ] ; then wget --no-check-certificate https://raw.githubusercontent.com/litespeedtech/ols1clk/master/ols1clk.sh && bash ols1clk.sh \ --adminpassword "$ls_webadmin_pass" \ --lsphp "$ls_lsphp_version" \ - --wordpressplus "$local_url" \ + --wordpressplus "$src_url" \ --wordpresspath "$wp_path" \ --dbrootpassword "$db_root_pass" \ --dbpassword "$wp_db_pass" \ @@ -46,3 +63,4 @@ if [ "$success" -eq 1 ] ; then && ufw allow https fi +EOSSH diff --git a/wp-duplicate.sh b/wp-duplicate.sh index 1a24852..dc74d41 100755 --- a/wp-duplicate.sh +++ b/wp-duplicate.sh @@ -1 +1,75 @@ #!/bin/sh + +. ./config + +if [ "$1" = 'local' ] ; then + src_url="$local_url"; + dest_url="$remote_url"; + src_ssh="$local_ssh" + dest_ssh="$remote_ssh" +elif [ "$1" = 'remote' ] ; then + src_url="$remote_url"; + dest_url="$local_url"; + src_ssh="$remote_ssh" + dest_ssh="$local_ssh" +else + echo "error: must specify local or remote" + exit 5 +fi + +db_file="$wp_path/data.sql" +tar_file="/tmp/wordpress.tar.gz" + +############## source + +ssh -T $src_ssh << EOSSH +wp db export \ + --path="$wp_path" \ + --dbuser="$wp_db_user" \ + --dbpass="$wp_db_pass" \ + --add-drop-table \ + --allow-root \ + "$db_file" +tar czf "$tar_file" "$wp_path" +EOSSH + +scp "$src_ssh:$tar_file" "$tar_file" + +ssh -T $src_ssh << EOSSH +rm "$db_file" +rm "$tar_file" +EOSSH + +############## destination + +scp "$tar_file" "$dest_ssh:$tar_file" + +ssh -T $dest_ssh << EOSSH +rm -Rf "$wp_path" +cd / +tar xzf "$tar_file" + +wp db import \ + --path="$wp_path" \ + --dbuser="$wp_db_user" \ + --dbpass="$wp_db_pass" \ + --allow-root \ + "$db_file" +rm "$db_file" +rm "$tar_file" +wp search-replace \ + --path="$wp_path" \ + --allow-root \ + --skip-columns=guid \ + "$src_url" \ + "$dest_url" +wp option update home \ + --path="$wp_path" \ + --allow-root +wp option update home \ + --path="$wp_path" \ + --allow-root +EOSSH + + +mv "$tar_file" ./wordpress-"$(date +%s)".tar.gz diff --git a/wp-export.sh b/wp-export.sh index 829303e..efaba7b 100755 --- a/wp-export.sh +++ b/wp-export.sh @@ -1,3 +1,23 @@ #!/bin/sh +. ./config-urls +( + echo "export local_url=\"$local_ur\""; \ + echo "export remote_url=\"$remote_url\""; \ + cat config "$2" \ +) | ssh root@"$local_url" -T /bin/sh + +( + echo "export local_url=\"$remote_url\""; \ + echo "export remote_url=\"$local_url\""; \ + cat config "$2" \ +) | ssh root@"$remote_url" -T /bin/sh + +db_file="$wp_path/data.sql" + +wp db export --dbuser=wordpress --dbpass=$wp_db_pass --add-drop-table --alow-root "$db_file" +tar czf /tmp/wordpress.tar.gz "$wp_path" +# scp +rm "$db_file" +rm /tmp/wordpress.tar.gz diff --git a/wp-install.sh b/wp-install.sh index 76be19a..6e88e10 100755 --- a/wp-install.sh +++ b/wp-install.sh @@ -1,5 +1,22 @@ #!/bin/sh +. ./config + +if [ "$1" = 'local' ] ; then + src_url="$local_url"; + dest_url="$remote_url"; + src_ssh="$local_ssh" +elif [ "$1" = 'remote' ] ; then + src_url="$remote_url"; + dest_url="$local_url"; + src_ssh="$remote_ssh" +else + echo "error: must specify local or remote" + exit 5 +fi + +ssh -T $src_ssh << EOSSH + if [ -n "$php_version" ] ; then echo "TODO - install specific PHP version" exit 1 @@ -26,9 +43,6 @@ else echo "TODO - install WordPress" fi -# check if wordpress already installed in $wp_path -# if not then install - if [ -n "$wp_themes" ] ; then printf "\nInstalling themes ..." option='--activate' @@ -71,3 +85,4 @@ if [ -n "$litespeed_version" ] ; then fi chown -R "$ownergroup" "$wp_path" +EOSSH