Skip to content

Commit ad4c687

Browse files
committed
makeservices: easywp delete tables option
Helpful if the user has an old instance of wordpress that they aren't interested in.
1 parent 13ff417 commit ad4c687

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

makeservices/easywp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ if [[ -z "$sqlpass" ]]; then
6464
fi
6565
echo "SQL set up and the password can be found in wp-config.php ..."
6666

67+
tables=$(mysql --user="$USER" --password="$sqlpass" --execute="show tables" "$USER" | grep -E "^wp_" || echo "")
68+
if ! [[ -z "$tables" ]]; then
69+
echo
70+
echo -e "\033[33mThere appears to be an existing WordPress installation. Would you like to clean the database?\033[00m\n"
71+
read -rp "Do you want to continue? [y/N] " wordpresskiller
72+
wordpresskiller=${wordpresskiller,,}
73+
if ! [[ "$wordpresskiller" =~ ^(yes|y) ]]; then
74+
echo "If you want to run this script and keep the tables intact, rename the existing tables from wp_* to something else."
75+
exit 0
76+
fi
77+
78+
echo "$tables" | tr ' ' '\n' | while read -r table; do
79+
mysql --user="$USER" --password="$sqlpass" --execute="DROP TABLE $table" "$USER"
80+
done
81+
fi
82+
6783
# Install WordPress and create config file
6884
wp core download
6985
wp config create --dbname="$user" --dbuser="$user" --dbpass="$sqlpass" --dbhost=mysql --dbcharset=utf8mb4

0 commit comments

Comments
 (0)