Compare commits

...

12 Commits

Author SHA1 Message Date
Ray Elliott f858776a9e move reset-wordpress.sh 2020-09-08 17:35:16 +01:00
Ray Elliott c477713d94 add reset script 2020-09-07 12:24:58 +01:00
Ray Elliott a2e534f552 update error message 2020-09-07 11:46:30 +01:00
Ray Elliott fad8de9d4e add pull-from script 2020-09-05 14:04:37 +01:00
Ray Elliott 4c37540ab5 add export wp script 2020-09-05 14:04:21 +01:00
Ray Elliott 81edc68811 add data directories 2020-09-05 12:33:16 +01:00
Ray Elliott e15ab61d29 WIP 2020-09-05 12:27:45 +01:00
Ray Elliott ce0dc65590 add cloudways config 2020-09-05 12:01:33 +01:00
Ray Elliott 29861e9be2 update 2020-09-05 11:47:08 +01:00
Ray Elliott 40f17c5a8e load configuration based on target 2020-09-05 11:46:59 +01:00
Ray Elliott b624a6e8cb comment out options 2020-09-05 11:46:17 +01:00
Ray Elliott b16fe3f73c combine install-local.sh and install-remote.sh 2020-09-05 11:10:14 +01:00
24 changed files with 241 additions and 86 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
files/private
*.secret

View File

@ -7,6 +7,4 @@ Development environment base packages:
## TODO
* combine install-local.sh and install-remote.sh into one script that takes
an argument of local/remote
* get remote working with cloudways
* make sure to use export in all config files (the newer ones aren't)

View File

@ -1,4 +1,4 @@
## apache configuration
#
## uncomment if using apache
#apache2_version='latest'
# apache2_version='latest'

11
config/remote/cloudways Normal file
View File

@ -0,0 +1,11 @@
# cloudways configuration
. ./config/remote/cloudways.secret
cloudways_user='cloudways@rayelliott.dev'
cloudways_url='https://wordpress-453075-1468300.cloudwaysapps.com'
cloudways_ssh='test123@wordpress-453075-1468300.cloudwaysapps.com'
cloudways_db_name='mhhusspndh'
cloudways_db_user='mhhusspndh'

View File

@ -9,5 +9,5 @@
## https://openlitespeed.org/kb/1-click-install/
## password used to log into litespeed web interface
#export ls_webadmin_pass='x7__+85676--Dd'
#export ls_webadmin_pass='admin'

View File

@ -1,3 +1,4 @@
## uncomment if using mariadb
#mariadb_version='latest'
# mariadb_version='latest'
# db_root_pass='9483ujtej0--=0FFFdl'

View File

@ -1,2 +1,3 @@
## uncomment if using mysql
#mysql_version='latest'
#db_root_pass='9483ujtej0--=0FFFdl'

View File

@ -1,5 +1,5 @@
## php configuration
#
## uncomment if using php
#php_version='latest'
# php_version='latest'

View File

@ -1,5 +1,5 @@
## ssh configuration
## uncomment if connecting via ssh
#export ssh='root@test123.example.com'
# export ssh='root@test123.isnet.uk'

View File

@ -1,7 +1,6 @@
## user configuration
## uncomment to set user
## webuser/webgroup
## leave commented for default
#export webuser='www-data'
#export webgroup='www-data'
# export user='ray'
# export user_pass='ray'
# export group='ray'

View File

@ -1,24 +1,23 @@
## wordpress configuration - uncomment if using wordpress
# export wp_user='admin'
# export wp_pass=''
# export wp_pass='admin'
# export wp_email='myemail@isnet.uk'
## leave commented if using default
# export wp_version='latest'
# export wp_path='/var/www/html/wordpress'
# export wp_locale='en_GB'
# export wp_title='The WordPress'
# export db_root_pass='9dn,s93j_UU9--s889d8dUY'
# export wp_db_name='wordpress'
# export wp_db_user='wordpress'
# export wp_db_pass='__d39fhi3nkjdflk8-ddWEs'
# export wp_db_pass='wordpress'
## list of themes to install - first one will be activate
## list of themes to install - first one will be activated
# export wp_themes="twentytwenty"
## list of plugins to install
# export wp_plugins=""
# export wp_plugins="akismet all-in-one-seo-pack"
## list of plugins to activate
## list of plugins to install and activate
# export wp_plugins_active=""
## list of plugins to uninstall
# export wp_plugins_uninstall="hello aksimet"

0
export-to-remote.sh → data/.gitkeep Executable file → Normal file
View File

0
import-from-remote.sh → data/local/.gitkeep Executable file → Normal file
View File

0
install-remote.sh → data/remote/.gitkeep Executable file → Normal file
View File

View File

@ -1,62 +0,0 @@
#!/bin/sh
# default scripts to use
_script_dir='./scripts/debian10'
if [ -n "$1" ] ; then
_script_dir="./scripts/$1"
if ! [ -d "$_script_dir" ] ; then
echo "Error: script directory not found '$_script_dir'"
exit 1
fi
fi
echo "Using Scripts in: $_script_dir"
# source our config files
for _file in ./config/local/* ; do
. "$_file"
done
# check we have ssh access
[ -z "$ssh" ] && echo "Error: no ssh configuration specified" && exit 5
# update local server
echo "Updating .."
ssh -T $ssh << EOSSH
export DEBIAN_FRONTEND=noninteractive
apt-get -qq -y update && apt-get -qq -y upgrade
EOSSH
echo "Update complete"
. "$_script_dir/install-user.sh"
. "$_script_dir/install-base.sh"
if [ -n "$php_version" ] ; then
. "$_script_dir/install-php.sh"
fi
if [ -n "$mariadb_version" ] ; then
. "$_script_dir/install-mariadb.sh"
elif [ -n "$mysql_version" ] ; then
. "$_script_dir/install-mysql.sh"
fi
if [ -n "$apache2_version" ] ; then
. "$_script_dir/install-apache2.sh"
elif [ -n "$nginx_version" ] ; then
# TODO nginx install script
echo 'TODO - nginx install script'
elif [ -n "$litespeed_version" ] ; then
# TODO
echo 'TODO litespeed install script'
fi
if [ -n "$wp_user" ] ; then
. "$_script_dir/install-wordpress.sh"
fi
if [ -n "$dev_env" ] ; then
. "$_script_dir/install-dev-base.sh"
fi

77
install.sh Executable file
View File

@ -0,0 +1,77 @@
#!/bin/sh
_target="$1"
_target_os="$2"
# default scripts to use
_script_dir='./scripts/debian10'
if ! [ "$_target" = local ] && ! [ "$_target" = remote ] ; then
echo "Error: must specify 'local' or 'remote' target"
exit 1
fi
echo "Loading $_target configuration"
# source our config files
for _file in ./config/$_target/* ; do
[ -e "$_file" ] || continue
. "$_file"
done
if [ "$_target" = remote ] && [ -n "$cloudways_user" ] ; then
echo "Using Cloudways - nothing to install"
exit
fi
# source script files
if [ -n "$_target_os" ] ; then
_script_dir="./scripts/$_target_os"
if ! [ -d "$_script_dir" ] ; then
echo "Error: script directory not found '$_script_dir'"
exit 1
fi
fi
echo "Using Scripts in: $_script_dir"
# check we have ssh access
[ -z "$ssh" ] && echo "Error: no ssh configuration specified" && exit 5
# update
echo "Updating .."
ssh -T $ssh << EOSSH
export DEBIAN_FRONTEND=noninteractive
apt-get -qq -y update && apt-get -qq -y upgrade
EOSSH
echo "Update complete"
. "$_script_dir/install-user.sh"
# . "$_script_dir/install-base.sh"
#
# if [ -n "$php_version" ] ; then
# . "$_script_dir/install-php.sh"
# fi
#
# if [ -n "$mariadb_version" ] ; then
# . "$_script_dir/install-mariadb.sh"
# elif [ -n "$mysql_version" ] ; then
# . "$_script_dir/install-mysql.sh"
# fi
#
# if [ -n "$apache2_version" ] ; then
# . "$_script_dir/install-apache2.sh"
# elif [ -n "$nginx_version" ] ; then
# # TODO nginx install script
# echo 'TODO - nginx install script'
# elif [ -n "$litespeed_version" ] ; then
# # TODO
# echo 'TODO litespeed install script'
# fi
#
# if [ -n "$wp_user" ] ; then
# . "$_script_dir/install-wordpress.sh"
# fi
#
# if [ -n "$dev_env" ] ; then
# . "$_script_dir/install-dev-base.sh"
# fi

23
pull-from.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
_target="$1"
if ! [ "$_target" = local ] && ! [ "$_target" = remote ] ; then
echo "Error: must specify 'local' or 'remote' target"
exit 1
fi
echo "Loading $_target configuration"
# source our config files
for _file in ./config/$_target/* ; do
[ -e "$_file" ] || continue
. "$_file"
done
# check we have ssh access
[ -z "$ssh" ] && echo "Error: no ssh configuration specified" && exit 5
if [ -n "$wp_user" ] ; then
. ./scripts/export-wp.sh
fi

3
push-to.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh

42
reset.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/sh
_target="$1"
_target_os="$2"
# default scripts to use
_script_dir='./scripts/debian10'
if ! [ "$_target" = local ] && ! [ "$_target" = remote ] ; then
echo "Error: must specify 'local' or 'remote' target"
exit 1
fi
echo "Loading $_target configuration"
# source our config files
for _file in ./config/$_target/* ; do
[ -e "$_file" ] || continue
. "$_file"
done
# source script files
if [ -n "$_target_os" ] ; then
_script_dir="./scripts/$_target_os"
if ! [ -d "$_script_dir" ] ; then
echo "Error: script directory not found '$_script_dir'"
exit 1
fi
fi
echo "Using Scripts in: $_script_dir"
# check we have ssh access
[ -z "$ssh" ] && echo "Error: no ssh configuration specified" && exit 5
if [ -n "$wp_user" ] ; then
# TODO - confirmation prompt
echo "IMPORTANT - we need a confirmation prompt here"
echo "You are about to reinstall the $_target WordPress installation"
echo "Reinstall WordPress (y/N): "
. "./scripts/reset-wordpress.sh"
. "$_script_dir/install-wordpress.sh"
fi

View File

@ -21,7 +21,7 @@ else
$_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"
echo "ERROR: mysql not found - aborting WordPress install"
exit 40
fi
wp core download \

View File

@ -0,0 +1,15 @@
echo "Removing WordPress .."
_mysql_cmd="mysql -uroot -p$db_root_pass -e "
ssh -T $ssh << EOSSH
# remove database
if command -v mysql ; then
$_mysql_cmd "DROP DATABASE $wp_db_name;"
else
echo "ERROR: no installed database found - aborting WordPress removal"
exit 40
fi
# remove files
rm -Rf $wp_path
EOSSH

29
scripts/export-wp.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
echo "Exporting from $url .."
_timestamp="$(date +%s)"
_db_filename="wordpress-$_timestamp.db"
_archive_filename="wordpress-$_timestamp.tar.gz"
_local_dest_dir="./data/$_target"
ssh -T $ssh << EOSSH
cd "$wp_path"
wp db export \
--path="$wp_path" \
--dbuser="$wp_db_user" \
--dbpass="$wp_db_pass" \
--add-drop-table \
--allow-root \
"/tmp/$_db_filename"
tar czf "/tmp/$_archive_filename" "$wp_path"
EOSSH
scp "$ssh:/tmp/$_archive_filename" "$_local_dest_dir/$_archive_filename"
scp "$ssh:/tmp/$_db_filename" "$_local_dest_dir/$_db_filename"
exit
ssh -T $ssh << EOSSH
rm "/tmp/$_db_filename"
rm "/tmp/$_archive_filename"
EOSSH

3
scripts/import-wp.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh

15
scripts/reset-wordpress.sh Executable file
View File

@ -0,0 +1,15 @@
echo "Removing WordPress .."
_mysql_cmd="mysql -uroot -p$db_root_pass -e "
ssh -T $ssh << EOSSH
# remove database
if command -v mysql ; then
$_mysql_cmd "DROP DATABASE $wp_db_name;"
else
echo "ERROR: no installed database found - aborting WordPress removal"
exit 40
fi
# remove files
rm -Rf $wp_path
EOSSH