dbdelete improved

- Errors when MySQL is not installed or not found and try to delete a DB.
- Purge nginx now remove SSL Cronjobs.
This commit is contained in:
Cristhian Martínez Ochoa 2018-10-27 17:19:26 -06:00
parent 14e19177af
commit e63a9dc1d9
4 changed files with 32 additions and 28 deletions

View file

@ -10,13 +10,6 @@ end=`tput sgr0`
db_delete() {
local domain="$1"
if [[ $(conf_read mysql-client) != "true" ]]; then
echo "${gre}MySQL Client is not installed and we need it to stablish a connection with your Database."
echo "Wait while we install MySQL Client... installing!!!${end}"
mysql_client_install > /dev/null 2>&1 &
echo "${gre}MySQL Client has been successfully installed!${end}"
fi
# Get dbname and dbuser of a WP site
if [[ -a /var/www/$domain/wp-config.php ]]; then
wpconfpath="/var/www/$domain/wp-config.php"
@ -39,8 +32,10 @@ db_delete() {
done="1"
if [[ $host == "localhost" ]]; then
# Check if MySQL installed
if [[ ! -d /etc/mysql || $(conf_read mysql) != "true" ]]; then
echo "${red}[ERROR] Seems like MySQL is not installed or Webinoly can not detect it! ( $domain ) ${end}"
if [[ ! -d /etc/mysql || $(conf_read mysql) != "true" || $(conf_read mysql-client) != "true" ]]; then
echo "${red}[ERROR] Seems like MySQL is not installed or Webinoly can not detect it!"
echo " - Database can not be deleted -${blu} $domain ${end}"
exit 1
fi
local ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "$dbsetup"
@ -52,14 +47,10 @@ db_delete() {
echo ""
echo "${blu} Retry [Y/n]? "
while read -r -n 1 -s answer; do
answer=${answer:-y}
if [[ $answer = [YyNn] ]]; then
break
fi
answer=${answer:-y}
[[ $answer = [YyNn] ]] && break
done
if [[ $answer == [Nn] ]]; then
done="1"
fi
[[ $answer == [Nn] ]] && done="1"
else
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
fi
@ -79,6 +70,13 @@ db_delete() {
echo "${red} Action aborted, database not deleted!"
continue 1;
else
if [[ $(conf_read mysql-client) != "true" ]]; then
echo "${gre}MySQL Client is not installed and we need it to stablish a connection with your Database."
echo "Wait while we install MySQL Client... installing!!!${end}"
mysql_client_install > /dev/null 2>&1 &
echo "${gre}MySQL Client has been successfully installed!${end}"
fi
sudo mysql --connect-timeout=10 -h "$url" -P "$port" -u"$uroot" -p"$proot" -e "$dbsetup"
if [ $? != "0" ]; then
done="0"
@ -88,14 +86,10 @@ db_delete() {
echo ""
echo "${blu} Retry [Y/n]? "
while read -r -n 1 -s answer; do
answer=${answer:-y}
if [[ $answer = [YyNn] ]]; then
break
fi
answer=${answer:-y}
[[ $answer = [YyNn] ]] && break
done
if [[ $answer == [Nn] ]]; then
done="1"
fi
[[ $answer == [Nn] ]] && done="1"
else
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
fi

View file

@ -168,7 +168,7 @@ wpinstall() {
if [[ $dbhost == "localhost" && $setupmysql == [yY] && $(conf_read mysql) != "true" ]]; then
echo "${red} [ERROR] MySQL is not installed or localhost was not found!${blu}"
done="0"
continue 1;
[[ $wp == 1 ]] && continue 1 || exit 1
fi
# Check if localhost or external DB
if [[ $dbhost != "localhost" && $setupmysql == [yY] ]]; then
@ -467,7 +467,7 @@ deletesite() {
fi
fi
[[ $dbdel == [yY] ]] && db_delete $domain
[[ $dbdel == [yY] ]] && db_delete $domain &
# Delete site files
sudo rm /etc/nginx/sites-available/$domain

View file

@ -141,11 +141,14 @@ elif [[ "$domain" == "-delete-all" && -z "$type" && -z "$cache" ]]; then
domi=$(echo $site | cut -f 4 -d "/")
# List sites then will be deleted
if [[ $domi != "html" && $domi != $(conf_read tools-port) ]]; then
# Determina if site is WP (so has DB to delete)
[[ -a $site/wp-config.php || -a $site/htdocs/wp-config.php ]] && db_delete $domi &
sudo rm -rf /etc/nginx/sites-available/$domi
sudo rm -rf /etc/nginx/sites-enabled/$domi
sudo rm -rf /var/www/$domi
echo "${gre}Your site ${blu}${domi}${gre} has been successfully deleted! ${end}"
fi
# Determina if site is WP (so has DB to delete)
[[ -a $site/wp-config.php || -a $site/htdocs/wp-config.php ]] && db_delete $domi
done
# List all remaining sites (parked and proxy)
@ -153,11 +156,13 @@ elif [[ "$domain" == "-delete-all" && -z "$type" && -z "$cache" ]]; then
do
domi=$(echo $site | cut -f 5 -d "/")
if [[ $domi != "html" && $domi != "default" && $domi != $(conf_read tools-port) ]]; then
sudo rm -rf /etc/nginx/sites-available/$domi
sudo rm -rf /etc/nginx/sites-enabled/$domi
echo "${gre}Your site ${blu}${domi}${gre} has been successfully deleted! ${end}"
fi
done
# Delete all files
# Delete all files - double check!
# -rf is necessary to not generate an error when is empty.
sudo rm -rf /etc/nginx/sites-available/!(default|$(conf_read tools-port))
sudo rm -rf /etc/nginx/sites-enabled/!(default|$(conf_read tools-port))

View file

@ -100,6 +100,11 @@ elif [[ $arg == "-purge" && ( $opt == "-html" || $opt == "-nginx" ) ]]; then
api-events_update pn5
sudo apt-get -y purge certbot python-boto duplicity duply
echo | sudo add-apt-repository --remove 'ppa:certbot/certbot'
# Remove SSL Cron
if [[ -a /var/spool/cron/crontabs/root ]]; then
sudo sed -i '/MAILTO=/d' /var/spool/cron/crontabs/root
sudo sed -i '/certbot renew/d' /var/spool/cron/crontabs/root
fi
sudo apt-get -y autoremove
sudo rm $HOME/www
sudo rm $HOME/sites-available