Changeset View
Changeset View
Standalone View
Standalone View
pykolab/setup/setup_mysql.py
Show All 39 Lines | |||||
def cli_options(): | def cli_options(): | ||||
mysql_group = conf.add_cli_parser_option_group(_("MySQL Options")) | mysql_group = conf.add_cli_parser_option_group(_("MySQL Options")) | ||||
mysql_group.add_option( | mysql_group.add_option( | ||||
"--mysqlserver", | "--mysqlserver", | ||||
dest="mysqlserver", | dest="mysqlserver", | ||||
action="store", | action="store", | ||||
help=_("Specify whether to use an (existing) or (new) MySQL server.") | help=_("Specify whether to use an (existing), (unix_socket) or (new) MySQL server.") | ||||
) | ) | ||||
mysql_group.add_option( | mysql_group.add_option( | ||||
"--mysqlhost", | "--mysqlhost", | ||||
dest="mysqlhost", | dest="mysqlhost", | ||||
action="store", | action="store", | ||||
default='127.0.0.1', | default='127.0.0.1', | ||||
help=_("The MySQL host address.") | help=_("The MySQL host address.") | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if conf.mysqlserver != 'existing': | ||||
max_wait = 0 | max_wait = 0 | ||||
if max_wait > 0: | if max_wait > 0: | ||||
max_wait = max_wait - 1 | max_wait = max_wait - 1 | ||||
time.sleep(1) | time.sleep(1) | ||||
options = { | options = { | ||||
1: "Existing MySQL server (with root password already set).", | 1: "Existing MySQL server (with root password already set).", | ||||
2: "New MySQL server (needs to be initialized)." | 2: "Existing MySQL server (with unix_socket authentication plugin).", | ||||
3: "New MySQL server (needs to be initialized)." | |||||
} | } | ||||
answer = 0 | answer = 0 | ||||
if conf.mysqlserver != 'existing': | if conf.mysqlserver != 'existing': | ||||
if len([x for x in socket_paths if os.path.exists(x)]) > 0: | if len([x for x in socket_paths if os.path.exists(x)]) > 0: | ||||
if conf.mysqlserver: | if conf.mysqlserver: | ||||
if conf.mysqlserver == 'existing': | if conf.mysqlserver == 'existing': | ||||
answer = 1 | answer = 1 | ||||
elif conf.mysqlserver == 'new': | elif conf.mysqlserver == 'unix_socket': | ||||
answer = 2 | answer = 2 | ||||
elif conf.mysqlserver == 'new': | |||||
answer = 3 | |||||
if answer == 0: | if answer == 0: | ||||
answer = utils.ask_menu(_("What MySQL server are we setting up?"), options) | answer = utils.ask_menu(_("What MySQL server are we setting up?"), options) | ||||
else: | else: | ||||
answer = 1 | answer = 1 | ||||
if answer == "1" or answer == 1: | if answer == "1" or answer == 1: | ||||
if not conf.mysqlrootpw: | if not conf.mysqlrootpw: | ||||
print >> sys.stderr, utils.multiline_message( | print >> sys.stderr, utils.multiline_message( | ||||
_(""" | _(""" | ||||
Please supply the root password for MySQL, so we can set | Please supply the root password for MySQL, so we can set | ||||
up user accounts for other components that use MySQL. | up user accounts for other components that use MySQL. | ||||
""") | """) | ||||
) | ) | ||||
mysql_root_password = utils.ask_question( | mysql_root_password = utils.ask_question( | ||||
_("MySQL root password"), | _("MySQL root password"), | ||||
password=True | password=True | ||||
) | ) | ||||
else: | else: | ||||
mysql_root_password = conf.mysqlrootpw | mysql_root_password = conf.mysqlrootpw | ||||
elif answer == "2" or answer == 2: | |||||
mysql_root_password = 'unix_socket' | |||||
else: | else: | ||||
print >> sys.stderr, utils.multiline_message( | print >> sys.stderr, utils.multiline_message( | ||||
_(""" | _(""" | ||||
Please supply a root password for MySQL. This password | Please supply a root password for MySQL. This password | ||||
will be the administrative user for this MySQL server, | will be the administrative user for this MySQL server, | ||||
and it should be kept a secret. After this setup process | and it should be kept a secret. After this setup process | ||||
has completed, Kolab is going to discard and forget | has completed, Kolab is going to discard and forget | ||||
about this password, but you will need it for | about this password, but you will need it for | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | else: | ||||
p1.stdout.close() | p1.stdout.close() | ||||
p2.communicate() | p2.communicate() | ||||
p1 = subprocess.Popen(['echo', 'FLUSH PRIVILEGES;'], stdout=subprocess.PIPE) | p1 = subprocess.Popen(['echo', 'FLUSH PRIVILEGES;'], stdout=subprocess.PIPE) | ||||
p2 = subprocess.Popen(['mysql'], stdin=p1.stdout) | p2 = subprocess.Popen(['mysql'], stdin=p1.stdout) | ||||
p1.stdout.close() | p1.stdout.close() | ||||
p2.communicate() | p2.communicate() | ||||
socket_path = None | |||||
socket_paths = [ | |||||
"/var/lib/mysql/mysql.sock", | |||||
"/var/run/mysqld/mysqld.sock", | |||||
"/var/run/mysql/mysql.sock" | |||||
] | |||||
for sp in socket_paths: | |||||
if os.path.exists(sp): | |||||
socket_path = sp | |||||
if mysql_root_password == "unix_socket" and socket_path is not None: | |||||
data = """ | |||||
[mysql] | |||||
user=root | |||||
password= | |||||
host=localhost | |||||
socket=%s | |||||
""" % (socket_path) | |||||
else: | |||||
data = """ | data = """ | ||||
[mysql] | [mysql] | ||||
user=root | user=root | ||||
password='%s' | password='%s' | ||||
host=%s | host=%s | ||||
""" % (mysql_root_password, conf.mysqlhost) | """ % (mysql_root_password, conf.mysqlhost) | ||||
fp = open('/tmp/kolab-setup-my.cnf', 'w') | fp = open('/tmp/kolab-setup-my.cnf', 'w') | ||||
os.chmod('/tmp/kolab-setup-my.cnf', 600) | os.chmod('/tmp/kolab-setup-my.cnf', 600) | ||||
fp.write(data) | fp.write(data) | ||||
fp.close() | fp.close() | ||||
schema_file = None | schema_file = None | ||||
for root, directories, filenames in os.walk('/usr/share/doc/'): | for root, directories, filenames in os.walk('/usr/share/doc/'): | ||||
for filename in filenames: | for filename in filenames: | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |