summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Boddie <paul@boddie.org.uk>2014-08-07 12:27:17 (GMT)
committerPaul Boddie <paul@boddie.org.uk>2014-08-07 12:27:17 (GMT)
commitcfed166d06e0976a6aa4655be702868061a6d033 (patch)
treee0b0e9ac4d685c74cd1fafb5e557b72bf47a9d59
parent53d4ddb5685673261b54ecadedabcbc08816fc76 (diff)
downloadpykolab-cfed166d06e0976a6aa4655be702868061a6d033.tar.gz
Tidied syncroton support.
-rw-r--r--pykolab/setup/setup_syncroton.py128
1 files changed, 68 insertions, 60 deletions
diff --git a/pykolab/setup/setup_syncroton.py b/pykolab/setup/setup_syncroton.py
index 2f401bd..444b00c 100644
--- a/pykolab/setup/setup_syncroton.py
+++ b/pykolab/setup/setup_syncroton.py
@@ -17,10 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from glob import glob
+from os.path import join
+from subprocess import Popen, PIPE
import os
-import subprocess
-import sys
import time
+import sys
import components
@@ -28,6 +30,7 @@ import pykolab
from pykolab import utils
from pykolab.constants import *
+from pykolab.setup.services import *
from pykolab.translate import _
log = pykolab.getLogger('pykolab.setup')
@@ -40,65 +43,70 @@ def description():
return _("Setup Syncroton.")
def execute(*args, **kw):
- schema_files = []
- for root, directories, filenames in os.walk('/usr/share/doc/'):
- for directory in directories:
- if directory.startswith("kolab-syncroton"):
- for root, directories, filenames in os.walk(os.path.join('/usr/share/doc/', directory)):
- for filename in filenames:
- if filename.startswith('mysql.initial') and filename.endswith('.sql'):
- schema_filepath = os.path.join(root,filename)
- if not schema_filepath in schema_files:
- schema_files.append(schema_filepath)
-
- break
+ schema_files = set()
+
+ for syncroton_dir in glob('/usr/share/doc/kolab-syncroton*'):
+ for root, directories, filenames in os.walk(syncroton_dir):
+ for filename in filenames:
+ if filename.startswith('mysql.initial') and filename.endswith('.sql'):
+ schema_files.add(join(root,filename))
break
- if not os.path.isfile('/tmp/kolab-setup-my.cnf'):
- utils.multiline_message(
- """Please supply the MySQL root password"""
- )
-
- mysql_root_password = utils.ask_question(
- _("MySQL root password"),
- password=True
- )
-
- data = """
-[mysql]
-user=root
-password='%s'
-""" % (mysql_root_password)
-
- fp = open('/tmp/kolab-setup-my.cnf', 'w')
- os.chmod('/tmp/kolab-setup-my.cnf', 0600)
- fp.write(data)
- fp.close()
-
- for schema_file in schema_files:
- p1 = subprocess.Popen(['cat', schema_file], stdout=subprocess.PIPE)
- p2 = subprocess.Popen(['mysql', '--defaults-file=/tmp/kolab-setup-my.cnf', 'roundcube'], stdin=p1.stdout)
- p1.stdout.close()
- p2.communicate()
-
- time.sleep(2)
-
- if os.path.isfile('/bin/systemctl'):
- subprocess.call(['/bin/systemctl', 'restart', 'httpd.service'])
- elif os.path.isfile('/sbin/service'):
- subprocess.call(['/sbin/service', 'httpd', 'restart'])
- elif os.path.isfile('/usr/sbin/service'):
- subprocess.call(['/usr/sbin/service','apache2','restart'])
- else:
- log.error(_("Could not start the webserver server service."))
-
- if os.path.isfile('/bin/systemctl'):
- subprocess.call(['/bin/systemctl', 'enable', 'httpd.service'])
- elif os.path.isfile('/sbin/chkconfig'):
- subprocess.call(['/sbin/chkconfig', 'httpd', 'on'])
- elif os.path.isfile('/usr/sbin/update-rc.d'):
- subprocess.call(['/usr/sbin/update-rc.d', 'apache2', 'defaults'])
+ # Stop if MySQL is not actually installed.
+
+ if not have_mysql():
+ if conf.check_only:
+ utils.setup_status("syncroton", _("needs setup"))
+ else:
+ log.error(_("MySQL not installed: cannot initialise Syncroton."))
+ return
+
+ defaults_file = get_mysql_defaults()
+
+ if not isfile(defaults_file):
+ if conf.check_only:
+ utils.setup_status("syncroton", _("needs setup"))
+ return
+ make_mysql_defaults_file(defaults_file)
+
+ # Test for the Roundcube database.
+
+ if not have_mysql_database(defaults_file, 'roundcube'):
+ if conf.check_only:
+ utils.setup_status("syncroton", _("needs setup"))
+ else:
+ log.error(_("Roundcube database not created: cannot initialise Syncroton."))
+ return
+
+ # Test for the presence of the plugin in Roundcube.
+
+ if have_mysql_data(defaults_file, "roundcube",
+ "select * from system where name = 'syncroton-version'",
+ "syncroton-version"):
+
+ if conf.check_only:
+ utils.setup_status("syncroton", _("setup done"))
+ return
+ else:
+ print >> sys.stderr, _("Kolab database account already exists and will not be configured.")
+ log.info(_("A user called %s already exists. Not creating another one.") % 'kolab')
+
else:
- log.error(_("Could not configure to start on boot, the " + \
- "webserver server service."))
+ if conf.check_only:
+ utils.setup_status("syncroton", _("needs setup"))
+ return
+
+ for schema_file in schema_files:
+ p1 = Popen(['cat', schema_file], stdout=PIPE)
+ p2 = Popen(['mysql', '--defaults-file=%s' % defaults_file, 'roundcube'], stdin=p1.stdout)
+ p2.communicate()
+
+ time.sleep(2)
+
+ apache = is_debian() and 'apache2' or 'httpd'
+ if not control_service(apache, 'restart'):
+ log.error(_("Could not start the webserver server service."))
+ if not configure_service(apache, True):
+ log.error(_("Could not configure to start on boot, the " + \
+ "webserver server service."))