Add Krb configuration code
[cascardo/ipsilon.git] / ipsilon / install / server.py
index 1acb8d7..4c0aef7 100755 (executable)
 from ipsilon.login.common import LoginMgrsInstall
 from ipsilon.providers.common import ProvidersInstall
 import argparse
+import cherrypy
 import logging
 import os
+import pwd
 import shutil
+import socket
 import sys
 import time
 
 
+TEMPLATES = '/usr/share/ipsilon/templates/install'
+CONFDIR = '/etc/ipsilon'
+HTTPDCONFD = '/etc/httpd/conf.d'
+
+
 class ConfigurationError(Exception):
 
     def __init__(self, message):
@@ -37,6 +45,10 @@ class ConfigurationError(Exception):
         return repr(self.message)
 
 
+#Silence cherrypy logging to screen
+cherrypy.log.screen = False
+
+# Regular logging
 LOGFILE = '/var/log/ipsilon-install.log'
 logger = logging.getLogger()
 
@@ -62,6 +74,29 @@ def openlogs():
 
 def install(plugins, args):
     logger.info('Installation initiated')
+    now = time.strftime("%Y%m%d%H%M%S", time.gmtime())
+
+    logger.info('Installing default config files')
+    ipsilon_conf = os.path.join(CONFDIR, 'ipsilon.conf')
+    idp_conf = os.path.join(CONFDIR, 'idp.conf')
+    args['httpd_conf'] = os.path.join(HTTPDCONFD, 'idp.conf')
+    if os.path.exists(ipsilon_conf):
+        shutil.move(ipsilon_conf, '%s.bakcup.%s' % (ipsilon_conf, now))
+    if os.path.exists(idp_conf):
+        shutil.move(idp_conf, '%s.backup.%s' % (idp_conf, now))
+    shutil.copy(os.path.join(TEMPLATES, 'ipsilon.conf'), CONFDIR)
+    shutil.copy(os.path.join(TEMPLATES, 'idp.conf'), CONFDIR)
+    if not os.path.exists(args['httpd_conf']):
+        os.symlink(idp_conf, args['httpd_conf'])
+    # Load the cherrypy config from the newly installed file so
+    # that db paths and all is properly set before configuring
+    # components
+    cherrypy.config.update(ipsilon_conf)
+
+    # Move pre-existing admin db away
+    admin_db = cherrypy.config['admin.config.db']
+    if os.path.exists(admin_db):
+        shutil.move(admin_db, '%s.backup.%s' % (admin_db, now))
 
     logger.info('Configuring login managers')
     for plugin_name in args['lm_order']:
@@ -93,6 +128,10 @@ def parse_args(plugins):
                         action='version', version='%(prog)s 0.1')
     parser.add_argument('-o', '--login-managers-order', dest='lm_order',
                         help='Comma separated list of login managers')
+    parser.add_argument('--hostname',
+                        help="Machine's fully qualified host name")
+    parser.add_argument('--system-user', default='ipsilon',
+                        help="User account used to run the server")
     parser.add_argument('--ipa', choices=['yes', 'no'], default='yes',
                         help='Detect and use an IPA server for authentication')
     parser.add_argument('--uninstall', action='store_true',
@@ -110,6 +149,17 @@ def parse_args(plugins):
 
     args = vars(parser.parse_args())
 
+    if not args['hostname']:
+        args['hostname'] = socket.getfqdn()
+
+    if len(args['hostname'].split('.')) < 2:
+        raise ConfigurationError('Hostname: %s is not a FQDN')
+
+    try:
+        pwd.getpwnam(args['system_user'])
+    except KeyError:
+        raise ConfigurationError('User: %s not found on the system')
+
     if args['lm_order'] is None:
         args['lm_order'] = []
         for name in lms: