bug fix: remote mysql install

This commit is contained in:
Usman Nasir
2020-07-05 13:26:46 +05:00
parent 575551d1fa
commit 758273dbc6
3 changed files with 35 additions and 10 deletions

View File

@@ -1,4 +1,6 @@
import subprocess, shlex
import install
import time
class mysqlUtilities:
@@ -6,14 +8,16 @@ class mysqlUtilities:
def createDatabase(dbname, dbuser, dbpassword):
try:
createDB = "CREATE DATABASE " + dbname
try:
from json import loads
mysqlData = loads(open("/etc/cyberpanel/mysqlPassword", 'r').read())
createDB = "CREATE DATABASE " + dbname
initCommand = 'mysql -h %s --port %s -u %s -p%s -e "' % (mysqlData['mysqlhost'], mysqlData['mysqlport'], mysqlData['mysqluser'], mysqlData['mysqlpassword'])
except:
passFile = "/etc/cyberpanel/mysqlPassword"
@@ -21,11 +25,14 @@ class mysqlUtilities:
data = f.read()
password = data.split('\n', 1)[0]
createDB = "CREATE DATABASE " + dbname
initCommand = 'mysql -u root -p' + password + ' -e "'
command = initCommand + createDB + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command)
res = subprocess.call(cmd)
@@ -36,6 +43,10 @@ class mysqlUtilities:
command = initCommand + createUser + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command)
res = subprocess.call(cmd)
@@ -44,6 +55,11 @@ class mysqlUtilities:
else:
dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'"
command = initCommand + dropDB + '"'
if install.preFlightsChecks.debug:
print(command)
time.sleep(10)
cmd = shlex.split(command)
res = subprocess.call(cmd)