From ad4c687f7f2c87020f1c83fad622042d61e2fe5b Mon Sep 17 00:00:00 2001 From: Kevin Kuehler Date: Wed, 28 Aug 2019 16:14:56 -0700 Subject: [PATCH] makeservices: easywp delete tables option Helpful if the user has an old instance of wordpress that they aren't interested in. --- makeservices/easywp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/makeservices/easywp b/makeservices/easywp index 22cea20..660d499 100755 --- a/makeservices/easywp +++ b/makeservices/easywp @@ -64,6 +64,22 @@ if [[ -z "$sqlpass" ]]; then fi echo "SQL set up and the password can be found in wp-config.php ..." +tables=$(mysql --user="$USER" --password="$sqlpass" --execute="show tables" "$USER" | grep -E "^wp_" || echo "") +if ! [[ -z "$tables" ]]; then + echo + echo -e "\033[33mThere appears to be an existing WordPress installation. Would you like to clean the database?\033[00m\n" + read -rp "Do you want to continue? [y/N] " wordpresskiller + wordpresskiller=${wordpresskiller,,} + if ! [[ "$wordpresskiller" =~ ^(yes|y) ]]; then + echo "If you want to run this script and keep the tables intact, rename the existing tables from wp_* to something else." + exit 0 + fi + + echo "$tables" | tr ' ' '\n' | while read -r table; do + mysql --user="$USER" --password="$sqlpass" --execute="DROP TABLE $table" "$USER" + done +fi + # Install WordPress and create config file wp core download wp config create --dbname="$user" --dbuser="$user" --dbpass="$sqlpass" --dbhost=mysql --dbcharset=utf8mb4