Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: python-qpid-0.…
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 143 lines (115 sloc) 4.11 kb
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2010 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.

import optparse
import os
import shutil
import sys

DIRS = (
    '/etc',
    '/etc/httpd',
    '/etc/httpd/conf.d',
    '/etc/pulp',
    '/etc/pki/juicer',
    '/srv',
    '/srv/juicer',
    '/var/lib/pulp',
    '/var/log/pulp',
    '/var/www/.python-eggs', # needed for older versions of mod_wsgi
)

LINKS = (
    'etc/pulp/juicer.conf',
    'etc/pulp/pulp.conf',
    'etc/pulp/client.conf',
    'etc/httpd/conf.d/juicer.conf',
    'etc/pki/juicer/ca.crt',
    'etc/pki/juicer/server.crt',
    'etc/pki/juicer/server.key',
    'srv/juicer/juicer.wsgi',
)

def parse_cmdline():
    """
Parse and validate the command line options.
"""
    parser = optparse.OptionParser()
    
    parser.add_option('-I', '--install',
                      action='store_true',
                      help='install pulp development files')
    parser.add_option('-U', '--uninstall',
                      action='store_true',
                      help='uninstall pulp development files')
    parser.add_option('-D', '--debug',
                      action='store_true',
                      help=optparse.SUPPRESS_HELP)
    
    parser.set_defaults(install=False,
                        uninstall=False,
                        debug=False)
    
    opts, args = parser.parse_args()
    
    if opts.install and opts.uninstall:
        parser.error('both install and uninstall specified')
    
    if not (opts.install or opts.uninstall):
        parser.error('neither install or uninstall specified')
        
    return (opts, args)


def debug(opts, msg):
    if not opts.debug:
        return
    sys.stderr.write('%s\n' % msg)
    

def create_dirs(opts):
    for d in DIRS:
        debug(opts, 'creating directory: %s' % d)
        if os.path.exists(d) and os.path.isdir(d):
            debug(opts, '%s exists, skipping' % d)
            continue
        os.mkdir(d, 0777)


def install(opts):
    create_dirs(opts)
    currdir = os.path.abspath(os.path.dirname(__file__))
    for l in LINKS:
        debug(opts, 'creating link: /%s' % l)
        if os.path.exists('/'+l):
            debug(opts, '/%s exists, skipping' % l)
            continue
        os.symlink(os.path.join(currdir, l), '/'+l)

    # Link between pulp and apache
    if not os.path.exists('/var/www/pub'):
        os.symlink('/var/lib/pulp', '/var/www/pub')

    # Grant apache write access to the pulp tools log file
    os.system('setfacl -m user:apache:rwx /var/log/pulp')

    # Disable existing SSL configuration
    if os.path.exists('/etc/httpd/conf.d/ssl.conf'):
        shutil.move('/etc/httpd/conf.d/ssl.conf', '/etc/httpd/conf.d/ssl.off')

    return os.EX_OK


def uninstall(opts):
    for l in LINKS:
        debug(opts, 'removing link: /%s' % l)
        if not os.path.exists('/'+l):
            debug(opts, '/%s does not exist, skipping' % l)
            continue
        os.unlink('/'+l)

    # Link between pulp and apache
    if os.path.exists('/var/www/pub'):
        os.unlink('/var/www/pub')

    # Old link between pulp and apache, make sure it's cleaned up
    if os.path.exists('/var/www/html/pub'):
        os.unlink('/var/www/html/pub')

    return os.EX_OK

# -----------------------------------------------------------------------------

if __name__ == '__main__':
    # TODO add something to check for permissions
    opts, args = parse_cmdline()
    if opts.install:
        sys.exit(install(opts))
    if opts.uninstall:
        sys.exit(uninstall(opts))
Something went wrong with that request. Please try again.