Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/setup.py
blob: ea346426c1cf0a452015854a12f12d5359c0dd6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/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 <http://www.gnu.org/licenses/>

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 = '''
    <VirtualHost *:80>
        DocumentRoot /var/www/dx-activity-server
        ServerName %s
    </VirtualHost>
    ''' % 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()