Join the community today
Become a Member

Sharing my custom WordPress delete script

Discussion in 'System Administration' started by cim, Dec 22, 2018.

  1. cim

    cim New Member

    9
    0
    1
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    5:10 AM
    nginx/1.15.7 (201218-125755)
    10.1.37-MariaDB MariaDB Server
    Hey guys, I couldn't find an option to delete a domain from centmin so I borrowed up some code from /root/tools/wp_uninstall_domain.sh.

    Removes:
    • Auto generated mysql db and users
    • FTP user
    • Webroot
    • Nginx files (including SSL)
    • Root tools (updater/uninstaller scripts)
    • Cron entries
    And just like with any scripts you find on the internet, USE AT YOUR OWN RISK! So far no issues for me.

    Code:
    #!/bin/bash
    
    read -ep "Enter domain to delete: " domain
    if [[ ! "$domain" ]]; then
        echo "Please re-run and enter domain. Goodbye."
        exit
    fi
    echo
    echo -e "\e[91mThe following will be deleted for this domain:\e[39m"
    echo
    echo "mysql database and user"
    echo "webroot"
    echo "nginx conf files (including ssl)"
    echo "root tools (updater/uninstaller scripts)"
    echo "cron entries"
    echo
    read -ep "Proceed? [y/n]: " check
    if [[ "$check" != [yY] ]]; then
        echo "Please re-run and double check domain. Goodbye."
        exit
    fi
    echo
    read -ep "Enter ftp username to delete for $domain (leave blank to continue): " ftp
    if [[ "$ftp" != "" ]]; then
        pure-pw userdel $ftp
        pure-pw mkdb
    fi
    echo
    echo -e "\e[91mDeleting $domain, please wait...\e[39m"
    echo
    # Yes I know, it's not the most graceful method but it works!
    echo "<?php require_once('wp-load.php'); echo DB_NAME; ?>" > /home/nginx/domains/$domain/public/db.php
    echo "<?php require_once('wp-load.php'); echo DB_USER; ?>" > /home/nginx/domains/$domain/public/user.php
    db=$(php /home/nginx/domains/$domain/public/db.php)
    user=$(php /home/nginx/domains/$domain/public/user.php)
    mysql -e "drop database $db; drop user '$user'@'localhost';"
    rm -rf /usr/local/nginx/conf/conf.d/$domain.conf
    rm -rf /usr/local/nginx/conf/conf.d/$domain.ssl.conf
    rm -rf /home/nginx/domains/$domain
    rm -rf /usr/local/nginx/conf/wpincludes/$domain/wpsecure_$domain.conf
    rm -rf /usr/local/nginx/conf/wpincludes/$domain/wpsupercache_$domain.conf
    rm -rf /root/tools/wp_updater_$domain.sh
    rm -rf /root/tools/wp_uninstall_$domain.sh
    rm -rf /usr/local/nginx/conf/ssl/$domain/$domain.crt
    rm -rf /usr/local/nginx/conf/ssl/$domain/$domain.key
    rm -rf /usr/local/nginx/conf/ssl/$domain/$domain.csr
    rm -rf /usr/local/nginx/conf/ssl/$domain
    rm -rf /usr/local/nginx/conf/wpincludes/$domain/rediscache_$domain.conf
    rm -rf /usr/local/nginx/conf/wpincludes/$domain/wpcacheenabler_$domain.conf
    rm -rf /root/.acme.sh/$domain
    crontab -l > cronjoblist
    sed -i "/wp_updater_$domain.sh/d" cronjoblist
    sed -i "/\/$domain\/wp-cron.php/d" cronjoblist
    sed -i "/$domain cacheenabler cron/d" cronjoblist
    crontab cronjoblist
    rm -rf cronjoblist
    service nginx restart
    echo
    echo -e "\e[92mAll done!"
    echo
    
     
    • Informative Informative x 1
  2. eva2000

    eva2000 Administrator Staff Member

    42,731
    9,666
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,919
    Local Time:
    11:10 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Interesting thanks for sharing

    FYI, to properly remove an Nginx vhost the instructions are on official site at How to delete Nginx vhost account for existing domain/subdomain ? as well as on each Nginx vhost creation's ending output too lists the commands.

    You also get a log file for each Nginx vhost created which also lists the commands in 123.09beta01 and higher example for http2.domain.com remove log at /root/centminlogs/centminmod_140218-021218_nginx_addvhost_nv-remove-cmds-http2.domain.com.log
    Code (Text):
    ls -lahrt /root/centminlogs/ | grep remove
    -rw-r--r--   1 root root 1.3K Feb 14 02:12 centminmod_140218-021218_nginx_addvhost_nv-remove-cmds-http2.domain.com.log
    
     
  3. cim

    cim New Member

    9
    0
    1
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    5:10 AM
    nginx/1.15.7 (201218-125755)
    10.1.37-MariaDB MariaDB Server
    Is the one I'm using bad? Or did I miss out some things? I also noticed there's .acme in the docs. Mine wasn't accounted for Lets Encrypt because self sign certs are good enough to not throw CloudFlare into a panic.
     
  4. eva2000

    eva2000 Administrator Staff Member

    42,731
    9,666
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,919
    Local Time:
    11:10 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    your's isn't bad, just highlighting that the info required to remove and nginx vhost is readily available in centmin logs if needed :)

    one thing though yours missings the deletion of pure-ftpd virtual ftp user which is in the outlined centmin mod logs
     
  5. cim

    cim New Member

    9
    0
    1
    Dec 21, 2018
    Ratings:
    +4
    Local Time:
    5:10 AM
    nginx/1.15.7 (201218-125755)
    10.1.37-MariaDB MariaDB Server
    Sweet. Anyone who uses this script can delete FTP users. Check line 25. This is pretty much your script since most of it is borrowed lol.
     
    • Informative Informative x 1
  6. eva2000

    eva2000 Administrator Staff Member

    42,731
    9,666
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,919
    Local Time:
    11:10 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    oh missed that part :)
     
    • Like Like x 1