#!/usr/bin/env python
# Copyright (C) 2011, Martin Abente
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
import os
import sys
from urlparse import urlparse
from ConfigParser import ConfigParser
config = ConfigParser()
script_path = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(script_path, 'config.ini')
if len(config.read(config_path)) == 0:
print 'Can\'t load configuration file.'
sys.exit(-1)
base_url = config.get('server', 'base_url')
url_componets = urlparse(base_url)
ACTIVITIES_DOMAIN = url_componets.netloc
HOST_FILE = '/etc/hosts'
HTTPD_CONFIG = '/etc/httpd/conf.d'
def setup_host():
host_file = open(HOST_FILE, 'a')
content = host_file.read()
if content.find(ACTIVITIES_DOMAIN) == -1:
host_file.write('127.0.0.1 %s\n' % ACTIVITIES_DOMAIN)
host_file.close()
def setup_httpd_config():
config_path = os.path.join(HTTPD_CONFIG, 'dx-activity-server.conf')
config_file = open(config_path, 'w')
content = '''
DocumentRoot /var/www/dx-activity-server
ServerName %s
''' % ACTIVITIES_DOMAIN
config_file.write(content)
config_file.close()
def main():
setup_host()
setup_httpd_config()
print 'setup finished successfully.'
sys.exit(0)
if __name__ == "__main__":
main()