55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
#!/usr/bin/python3 -u
|
|
|
|
import argparse
|
|
import os
|
|
#from pastafariutils.unix import add_user, del_user
|
|
from pathlib import Path
|
|
from subprocess import call, DEVNULL
|
|
import json
|
|
import time
|
|
import shutil
|
|
import pwd
|
|
import distro
|
|
import subprocess
|
|
import re
|
|
import sys
|
|
|
|
|
|
parser=argparse.ArgumentParser(prog='delete_wordpress.py', description='A tool for delete wordpress')
|
|
|
|
parser.add_argument('--home_user', help='Home where wordpress resides', required=True)
|
|
parser.add_argument('--user', help='The user', required=True)
|
|
parser.add_argument('--mysql_host', help='The host of mysql', required=True)
|
|
parser.add_argument('--mysql_db', help='The db to clean', required=True)
|
|
|
|
print('Deleting Wordpress..')
|
|
|
|
args=parser.parse_args()
|
|
|
|
home_user=args.home_user
|
|
|
|
if home_user.find('/htdocs/', -8)!=-1:
|
|
|
|
if subprocess.call("sudo su %s -s /bin/bash -c 'rm -f -r %s && mkdir %s'" % (args.user, args.home_user, args.home_user), shell=True) > 0:
|
|
print('Error: cannot delete %s' % args.home_user)
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
if subprocess.call("sudo su %s -s /bin/bash -c 'rm -f -r %s'" % (args.user, args.home_user), shell=True) > 0:
|
|
print('Error: cannot delete %s' % args.home_user)
|
|
sys.exit(1)
|
|
|
|
print('Deleting Database if in localhost..')
|
|
|
|
if args.mysql_host=='127.0.0.1' or args.mysql_host=='localhost':
|
|
|
|
if subprocess.call("sudo mysql --execute=\"drop database %s\"" % (args.mysql_db), shell=True) > 0:
|
|
print('Error: cannot delete database %s' % args.mysql_db)
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print('I cannot delete db because are not in the same server, please, delete manually the db.')
|
|
|
|
print('Deleted Wordpress successfully..')
|