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:
parent
14e19177af
commit
e63a9dc1d9
40
lib/general
40
lib/general
|
@ -10,13 +10,6 @@ end=`tput sgr0`
|
||||||
db_delete() {
|
db_delete() {
|
||||||
local domain="$1"
|
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
|
# Get dbname and dbuser of a WP site
|
||||||
if [[ -a /var/www/$domain/wp-config.php ]]; then
|
if [[ -a /var/www/$domain/wp-config.php ]]; then
|
||||||
wpconfpath="/var/www/$domain/wp-config.php"
|
wpconfpath="/var/www/$domain/wp-config.php"
|
||||||
|
@ -39,8 +32,10 @@ db_delete() {
|
||||||
done="1"
|
done="1"
|
||||||
if [[ $host == "localhost" ]]; then
|
if [[ $host == "localhost" ]]; then
|
||||||
# Check if MySQL installed
|
# Check if MySQL installed
|
||||||
if [[ ! -d /etc/mysql || $(conf_read mysql) != "true" ]]; then
|
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! ( $domain ) ${end}"
|
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
|
fi
|
||||||
local ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
|
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"
|
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "$dbsetup"
|
||||||
|
@ -52,14 +47,10 @@ db_delete() {
|
||||||
echo ""
|
echo ""
|
||||||
echo "${blu} Retry [Y/n]? "
|
echo "${blu} Retry [Y/n]? "
|
||||||
while read -r -n 1 -s answer; do
|
while read -r -n 1 -s answer; do
|
||||||
answer=${answer:-y}
|
answer=${answer:-y}
|
||||||
if [[ $answer = [YyNn] ]]; then
|
[[ $answer = [YyNn] ]] && break
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
if [[ $answer == [Nn] ]]; then
|
[[ $answer == [Nn] ]] && done="1"
|
||||||
done="1"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
|
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
|
||||||
fi
|
fi
|
||||||
|
@ -79,6 +70,13 @@ db_delete() {
|
||||||
echo "${red} Action aborted, database not deleted!"
|
echo "${red} Action aborted, database not deleted!"
|
||||||
continue 1;
|
continue 1;
|
||||||
else
|
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"
|
sudo mysql --connect-timeout=10 -h "$url" -P "$port" -u"$uroot" -p"$proot" -e "$dbsetup"
|
||||||
if [ $? != "0" ]; then
|
if [ $? != "0" ]; then
|
||||||
done="0"
|
done="0"
|
||||||
|
@ -88,14 +86,10 @@ db_delete() {
|
||||||
echo ""
|
echo ""
|
||||||
echo "${blu} Retry [Y/n]? "
|
echo "${blu} Retry [Y/n]? "
|
||||||
while read -r -n 1 -s answer; do
|
while read -r -n 1 -s answer; do
|
||||||
answer=${answer:-y}
|
answer=${answer:-y}
|
||||||
if [[ $answer = [YyNn] ]]; then
|
[[ $answer = [YyNn] ]] && break
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
if [[ $answer == [Nn] ]]; then
|
[[ $answer == [Nn] ]] && done="1"
|
||||||
done="1"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
|
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -168,7 +168,7 @@ wpinstall() {
|
||||||
if [[ $dbhost == "localhost" && $setupmysql == [yY] && $(conf_read mysql) != "true" ]]; then
|
if [[ $dbhost == "localhost" && $setupmysql == [yY] && $(conf_read mysql) != "true" ]]; then
|
||||||
echo "${red} [ERROR] MySQL is not installed or localhost was not found!${blu}"
|
echo "${red} [ERROR] MySQL is not installed or localhost was not found!${blu}"
|
||||||
done="0"
|
done="0"
|
||||||
continue 1;
|
[[ $wp == 1 ]] && continue 1 || exit 1
|
||||||
fi
|
fi
|
||||||
# Check if localhost or external DB
|
# Check if localhost or external DB
|
||||||
if [[ $dbhost != "localhost" && $setupmysql == [yY] ]]; then
|
if [[ $dbhost != "localhost" && $setupmysql == [yY] ]]; then
|
||||||
|
@ -467,7 +467,7 @@ deletesite() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ $dbdel == [yY] ]] && db_delete $domain
|
[[ $dbdel == [yY] ]] && db_delete $domain &
|
||||||
|
|
||||||
# Delete site files
|
# Delete site files
|
||||||
sudo rm /etc/nginx/sites-available/$domain
|
sudo rm /etc/nginx/sites-available/$domain
|
||||||
|
|
11
plugins/site
11
plugins/site
|
@ -141,11 +141,14 @@ elif [[ "$domain" == "-delete-all" && -z "$type" && -z "$cache" ]]; then
|
||||||
domi=$(echo $site | cut -f 4 -d "/")
|
domi=$(echo $site | cut -f 4 -d "/")
|
||||||
# List sites then will be deleted
|
# List sites then will be deleted
|
||||||
if [[ $domi != "html" && $domi != $(conf_read tools-port) ]]; then
|
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-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}"
|
echo "${gre}Your site ${blu}${domi}${gre} has been successfully deleted! ${end}"
|
||||||
fi
|
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
|
done
|
||||||
|
|
||||||
# List all remaining sites (parked and proxy)
|
# List all remaining sites (parked and proxy)
|
||||||
|
@ -153,11 +156,13 @@ elif [[ "$domain" == "-delete-all" && -z "$type" && -z "$cache" ]]; then
|
||||||
do
|
do
|
||||||
domi=$(echo $site | cut -f 5 -d "/")
|
domi=$(echo $site | cut -f 5 -d "/")
|
||||||
if [[ $domi != "html" && $domi != "default" && $domi != $(conf_read tools-port) ]]; then
|
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}"
|
echo "${gre}Your site ${blu}${domi}${gre} has been successfully deleted! ${end}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Delete all files
|
# Delete all files - double check!
|
||||||
# -rf is necessary to not generate an error when is empty.
|
# -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-available/!(default|$(conf_read tools-port))
|
||||||
sudo rm -rf /etc/nginx/sites-enabled/!(default|$(conf_read tools-port))
|
sudo rm -rf /etc/nginx/sites-enabled/!(default|$(conf_read tools-port))
|
||||||
|
|
|
@ -100,6 +100,11 @@ elif [[ $arg == "-purge" && ( $opt == "-html" || $opt == "-nginx" ) ]]; then
|
||||||
api-events_update pn5
|
api-events_update pn5
|
||||||
sudo apt-get -y purge certbot python-boto duplicity duply
|
sudo apt-get -y purge certbot python-boto duplicity duply
|
||||||
echo | sudo add-apt-repository --remove 'ppa:certbot/certbot'
|
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 apt-get -y autoremove
|
||||||
sudo rm $HOME/www
|
sudo rm $HOME/www
|
||||||
sudo rm $HOME/sites-available
|
sudo rm $HOME/sites-available
|
||||||
|
|
Loading…
Reference in a new issue