From bbc106c0187943d6e71f9d85f7e5ce1d6b825f5b Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 8 Sep 2020 18:59:02 +0100 Subject: [PATCH] use user and root ssh where appropriate --- config/local/local | 13 +++++++++++-- config/local/ssh | 5 ----- config/local/user | 6 ------ config/remote/remote | 11 ++++++++++- config/remote/ssh | 5 ----- config/remote/user | 6 ------ install.sh | 4 ++-- old/server-install-litespeed.sh | 5 ++++- pull-from.sh | 2 +- reset.sh | 3 --- scripts/debian10/install-apache2.sh | 5 ++++- scripts/debian10/install-base.sh | 5 ++++- scripts/debian10/install-dev-base.sh | 13 +++++++------ scripts/debian10/install-mariadb.sh | 5 ++++- scripts/debian10/install-mysql.sh | 5 ++++- scripts/debian10/install-php.sh | 7 +++++-- scripts/debian10/install-user.sh | 17 ++++++++++------- scripts/debian10/install-wordpress.sh | 23 +++++++++++------------ scripts/debian10/reset-wordpress.sh | 7 +++++-- scripts/export-wp.sh | 11 +++++++---- scripts/reset-wordpress.sh | 9 ++++++--- 21 files changed, 95 insertions(+), 72 deletions(-) delete mode 100644 config/local/ssh delete mode 100644 config/local/user delete mode 100644 config/remote/ssh delete mode 100644 config/remote/user diff --git a/config/local/local b/config/local/local index a31e3f5..cb157b6 100644 --- a/config/local/local +++ b/config/local/local @@ -1,9 +1,18 @@ # local specific options ## export if using local development environment -export domain='test123.home' -export url='http://test123.home' +export domain='thecampsitebible.home' +export url='http://thecampsitebible.home' # set to anything other than the empty string to set up a dev environment export dev_env='true' +## user configuration +export user='ray' +export user_pass='ray' +export group='ray' + +## ssh configuration +export ssh_root='root@thecampsitebible.home' +export ssh_user='ray@thecampsitebible.home' + diff --git a/config/local/ssh b/config/local/ssh deleted file mode 100644 index 17f32db..0000000 --- a/config/local/ssh +++ /dev/null @@ -1,5 +0,0 @@ -## ssh configuration - -## uncomment if connecting via ssh -export ssh='root@test123.home' - diff --git a/config/local/user b/config/local/user deleted file mode 100644 index ccf2832..0000000 --- a/config/local/user +++ /dev/null @@ -1,6 +0,0 @@ -## user configuration -## uncomment to set user - -export user='ray' -export user_pass='ray' -export group='ray' diff --git a/config/remote/remote b/config/remote/remote index 9b8d807..b7a39d9 100644 --- a/config/remote/remote +++ b/config/remote/remote @@ -1,6 +1,15 @@ # remote specific options -## export if using local development environment #export domain='test123.example.com' #export url='http://test123.example.com' +## user configuration +## uncomment to set user +# export user='ray' +# export user_pass='ray' +# export group='ray' + +## ssh configuration +# export ssh_root='root@wordpress-453075-1468300.cloudwaysapps.com' # we do not have root access +export ssh_user='test123@wordpress-453075-1468300.cloudwaysapps.com' + diff --git a/config/remote/ssh b/config/remote/ssh deleted file mode 100644 index 2659daf..0000000 --- a/config/remote/ssh +++ /dev/null @@ -1,5 +0,0 @@ -## ssh configuration - -## uncomment if connecting via ssh -# export ssh='root@test123.isnet.uk' - diff --git a/config/remote/user b/config/remote/user deleted file mode 100644 index 8b33702..0000000 --- a/config/remote/user +++ /dev/null @@ -1,6 +0,0 @@ -## user configuration -## uncomment to set user - -# export user='ray' -# export user_pass='ray' -# export group='ray' diff --git a/install.sh b/install.sh index 6824b4d..b22ed35 100755 --- a/install.sh +++ b/install.sh @@ -30,11 +30,11 @@ fi echo "Using Scripts in: $_script_dir" # check we have ssh access -[ -z "$ssh" ] && echo "Error: no ssh configuration specified" && exit 5 +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 # update echo "Updating .." -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH export DEBIAN_FRONTEND=noninteractive apt-get -qq -y update && apt-get -qq -y upgrade EOSSH diff --git a/old/server-install-litespeed.sh b/old/server-install-litespeed.sh index 53a3655..5bd88ea 100755 --- a/old/server-install-litespeed.sh +++ b/old/server-install-litespeed.sh @@ -7,7 +7,10 @@ fi . ./"$1" -ssh -T $ssh << EOSSH +# check we have ssh access +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 + +ssh -T $ssh_root << EOSSH ufw allow http && ufw allow https diff --git a/pull-from.sh b/pull-from.sh index acf3593..3278b50 100755 --- a/pull-from.sh +++ b/pull-from.sh @@ -16,7 +16,7 @@ for _file in ./config/$_target/* ; do done # check we have ssh access -[ -z "$ssh" ] && echo "Error: no ssh configuration specified" && exit 5 +[ -z "$ssh_user" ] && echo "Error: no user ssh configuration specified" && exit 5 if [ -n "$wp_user" ] ; then . ./scripts/export-wp.sh diff --git a/reset.sh b/reset.sh index 9dcc984..f82e720 100755 --- a/reset.sh +++ b/reset.sh @@ -29,9 +29,6 @@ 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" diff --git a/scripts/debian10/install-apache2.sh b/scripts/debian10/install-apache2.sh index dd69e9c..d2a0c05 100755 --- a/scripts/debian10/install-apache2.sh +++ b/scripts/debian10/install-apache2.sh @@ -5,7 +5,10 @@ if [ "$apache2_version" != 'latest' ] ; then exit 30 fi -ssh -T $ssh << EOSSH +# check we have ssh access +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 + +ssh -T $ssh_root << EOSSH echo "Installing Apache2" export DEBIAN_FRONTEND=noninteractive echo "Installing packages .." diff --git a/scripts/debian10/install-base.sh b/scripts/debian10/install-base.sh index c7c35b3..1bd86e9 100755 --- a/scripts/debian10/install-base.sh +++ b/scripts/debian10/install-base.sh @@ -1,6 +1,9 @@ #!/bin/sh -ssh -T $ssh << EOSSH +# check we have ssh access +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 + +ssh -T $ssh_root << EOSSH sed -i '/PubkeyAuthentication/c\PubkeyAuthentication yes' /etc/ssh/sshd_config sed -i '/PasswordAuthentication/c\PasswordAuthentication no' /etc/ssh/sshd_config diff --git a/scripts/debian10/install-dev-base.sh b/scripts/debian10/install-dev-base.sh index 9ac51ab..76620ea 100755 --- a/scripts/debian10/install-dev-base.sh +++ b/scripts/debian10/install-dev-base.sh @@ -2,7 +2,10 @@ _home_dir="/home/$user" -ssh -T $ssh << EOSSH +# check we have ssh access +[ -z "$ssh_user" ] || [ -z "$ssh_root" ] && echo "Error: user and root ssh configuration must be specified" && exit 5 + +ssh -T $ssh_root << EOSSH echo "Installing packages .." export DEBIAN_FRONTEND=noninteractive @@ -36,7 +39,7 @@ if command -v php ; then fi EOSSH -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH su "$user" @@ -46,16 +49,14 @@ echo 'export NVM_DIR="\$HOME/.nvm"' >> "$_home_dir/.profile" echo '[ -s "\$NVM_DIR/nvm.sh" ] && \. "\$NVM_DIR/nvm.sh"' >> "$_home_dir/.profile" EOSSH -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH su --login "$user" . ./.profile nvm install --lts --latest-npm EOSSH -ssh -T $ssh << EOSSH - -su --login "$user" +ssh -T $ssh_user << EOSSH . ./.profile echo "Configuring neovim ..." npm install -g neovim diff --git a/scripts/debian10/install-mariadb.sh b/scripts/debian10/install-mariadb.sh index 77f69c2..5abb0b9 100755 --- a/scripts/debian10/install-mariadb.sh +++ b/scripts/debian10/install-mariadb.sh @@ -5,9 +5,12 @@ if [ "$mariadb_version" != 'latest' ] ; then exit 30 fi +# check we have ssh access +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 + _mysql_cmd="mysql -uroot -e " -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH if mysql --version ; then echo "ERROR: unable to install MariaDb, 'mysql' already installed - aborting install" exit 35 diff --git a/scripts/debian10/install-mysql.sh b/scripts/debian10/install-mysql.sh index 2f08c59..d0f4880 100755 --- a/scripts/debian10/install-mysql.sh +++ b/scripts/debian10/install-mysql.sh @@ -5,9 +5,12 @@ if [ "$mysql_version" != 'latest' ] ; then exit 30 fi +# check we have ssh access +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 + _mysql_cmd="mysql -uroot -e " -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH if mysql --version ; then echo "ERROR: unable to install MySQL, 'mysql' already installed - aborting install" exit 35 diff --git a/scripts/debian10/install-php.sh b/scripts/debian10/install-php.sh index 20f1a3a..4671165 100755 --- a/scripts/debian10/install-php.sh +++ b/scripts/debian10/install-php.sh @@ -5,10 +5,13 @@ if [ "$php_version" != 'latest' ] ; then exit 30 fi +# check we have ssh access +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 + if [ -n "$wp_user" ] ; then echo 'Installing PHP for WordPress ...' -ssh -T $ssh << 'EOSSH' +ssh -T $ssh_root << 'EOSSH' export DEBIAN_FRONTEND=noninteractive echo "Installing packages .." apt-get install -qq -y php libapache2-mod-php php-fpm php-bcmath php-curl php-gd php-imagick php-mbstring \ @@ -25,7 +28,7 @@ EOSSH else echo 'Installing default PHP ...' -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH export DEBIAN_FRONTEND=noninteractive echo "Installing packages .." apt-get install -qq -y php libapache2-mod-php php-mysql diff --git a/scripts/debian10/install-user.sh b/scripts/debian10/install-user.sh index 070c353..3eb4dcc 100755 --- a/scripts/debian10/install-user.sh +++ b/scripts/debian10/install-user.sh @@ -1,8 +1,11 @@ #!/bin/sh +# check we have ssh access +[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5 + _home_dir="/home/$user" -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH echo "Creating user .." useradd -m -d "$_home_dir" "$user" echo "$user:$user_pass" | chpasswd @@ -11,12 +14,12 @@ EOSSH echo "Configuring ssh .." -ssh $ssh mkdir -v -p "$_home_dir/.ssh" -scp files/private/id_rsa "$ssh:$_home_dir/.ssh/" -scp files/id_rsa.pub "$ssh:$_home_dir/.ssh/" -scp files/known_hosts "$ssh:$_home_dir/.ssh/" +ssh $ssh_root mkdir -v -p "$_home_dir/.ssh" +scp files/private/id_rsa "$ssh_root:$_home_dir/.ssh/" +scp files/id_rsa.pub "$ssh_root:$_home_dir/.ssh/" +scp files/known_hosts "$ssh_root:$_home_dir/.ssh/" -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH cp -v /root/.ssh/authorized_keys "$_home_dir/.ssh/authorized_keys" chown -v -R "$user:$group" "$_home_dir/.ssh" @@ -61,7 +64,7 @@ ssh -T $ssh << EOSSH "$_home_dir/.config/zsh/install.sh" EOSSH -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH chsh -s /usr/bin/zsh "$user" EOSSH diff --git a/scripts/debian10/install-wordpress.sh b/scripts/debian10/install-wordpress.sh index 604acb4..49db490 100755 --- a/scripts/debian10/install-wordpress.sh +++ b/scripts/debian10/install-wordpress.sh @@ -1,15 +1,18 @@ echo "Installing WordPress .." -ssh -T $ssh << EOSSH +# check we have ssh access +[ -z "$ssh_user" ] || [ -z "$ssh_root" ] && echo "Error: user and root ssh configuration must be specified" && exit 5 + +ssh -T $ssh_root << EOSSH # install wp-cli first if [ ! -f /usr/local/bin/wp ] ; then 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 fi +EOSSH -su "$user" - +ssh -T $ssh_user << EOSSH if wp core is-installed --quiet --path="$wp_path" ; then echo "WordPress already installed" else @@ -43,8 +46,7 @@ printf "\nInstalling themes ..." option='--activate' for theme in $wp_themes ; do echo " installing $theme ..." -ssh -T $ssh << EOSSH - su "$user" +ssh -T $ssh_user << EOSSH wp theme install $theme "$option" --path="$wp_path" EOSSH option='' @@ -55,8 +57,7 @@ if [ -n "$wp_plugins" ] ; then printf "\nInstalling plugins ..." for plugin in $wp_plugins ; do echo " installing $plugin ..." -ssh -T $ssh << EOSSH - su "$user" +ssh -T $ssh_user << EOSSH wp plugin install $plugin --path="$wp_path" EOSSH done @@ -66,8 +67,7 @@ if [ -n "$wp_plugins_active" ] ; then printf "\nInstalling plugins to activate ..." for plugin in $wp_plugins_active ; do echo " installing $plugin ..." -ssh -T $ssh << EOSSH - su "$user" +ssh -T $ssh_user << EOSSH wp plugin install $plugin --activate --path="$wp_path" EOSSH done @@ -77,8 +77,7 @@ if [ -n "$wp_plugins_active" ] ; then printf "\nUninstalling plugins ..." for plugin in $wp_plugins_uninstall ; do echo " installing $plugin ..." -ssh -T $ssh << EOSSH - su "$user" +ssh -T $ssh_user << EOSSH wp plugin deactivate $plugin --path="$wp_path" wp plugin uninstall $plugin --path="$wp_path" EOSSH @@ -86,7 +85,7 @@ EOSSH fi config_path='/etc/apache2/sites-available/wordpress.conf' -ssh -T $ssh << EOSSH +ssh -T $ssh_root << EOSSH if [ -n "$apache2_version" ] ; then mkdir -p /var/log/wordpress/ cat << EOF > $config_path diff --git a/scripts/debian10/reset-wordpress.sh b/scripts/debian10/reset-wordpress.sh index 7316702..e8fdbc2 100644 --- a/scripts/debian10/reset-wordpress.sh +++ b/scripts/debian10/reset-wordpress.sh @@ -1,8 +1,11 @@ echo "Removing WordPress .." -_mysql_cmd="mysql -uroot -p$db_root_pass -e " +# check we have ssh access +[ -z "$ssh_user" ] && echo "Error: no user ssh configuration specified" && exit 5 -ssh -T $ssh << EOSSH +_mysql_cmd="mysql -u$db_user -p$db_pass -e " + +ssh -T $ssh_user << EOSSH # remove database if command -v mysql ; then $_mysql_cmd "DROP DATABASE $db_name;" diff --git a/scripts/export-wp.sh b/scripts/export-wp.sh index 7813013..408e1a3 100755 --- a/scripts/export-wp.sh +++ b/scripts/export-wp.sh @@ -7,7 +7,10 @@ _db_filename="wordpress-$_timestamp.db" _archive_filename="wordpress-$_timestamp.tar.gz" _local_dest_dir="./data/$_target" -ssh -T $ssh << EOSSH +# check we have ssh access +[ -z "$ssh_user" ] && echo "Error: no user ssh configuration specified" && exit 5 + +ssh -T $ssh_user << EOSSH cd "$wp_path" wp db export \ --path="$wp_path" \ @@ -19,11 +22,11 @@ wp db export \ 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" +scp "$ssh_user:/tmp/$_archive_filename" "$_local_dest_dir/$_archive_filename" +scp "$ssh_user:/tmp/$_db_filename" "$_local_dest_dir/$_db_filename" exit -ssh -T $ssh << EOSSH +ssh -T $ssh_user << EOSSH rm "/tmp/$_db_filename" rm "/tmp/$_archive_filename" EOSSH diff --git a/scripts/reset-wordpress.sh b/scripts/reset-wordpress.sh index 77f682c..e8fdbc2 100755 --- a/scripts/reset-wordpress.sh +++ b/scripts/reset-wordpress.sh @@ -1,14 +1,17 @@ echo "Removing WordPress .." -_mysql_cmd="mysql -uroot -p$db_root_pass -e " +# check we have ssh access +[ -z "$ssh_user" ] && echo "Error: no user ssh configuration specified" && exit 5 -ssh -T $ssh << EOSSH +_mysql_cmd="mysql -u$db_user -p$db_pass -e " + +ssh -T $ssh_user << EOSSH # remove database if command -v mysql ; then $_mysql_cmd "DROP DATABASE $db_name;" $_mysql_cmd "CREATE DATABASE $db_name;" else - echo "ERROR: no installed database found - aborting WordPress removal" + echo "ERROR: mysql not found - aborting WordPress removal" exit 40 fi # remove files