Example #1
0
def execute():
    global servicemanager_started, rclinks_added

    source_path = os.path.join("installation", "templates", "initd")
    target_path = os.path.join("/etc", "init.d", "critic-main")

    with open(".install.data") as install_data:
        data = json.load(install_data)

    with open(target_path, "w") as target:
        created_file.append(target_path)

        os.chmod(target_path, 0755)
        os.chown(target_path, installation.system.uid, installation.system.gid)

        with open(source_path, "r") as source:
            target.write((source.read().decode("utf-8") % data).encode("utf-8"))

    process.check_call(["update-rc.d", "critic-main", "defaults"])
    rclinks_added = True

    process.check_call([target_path, "start"])
    servicemanager_started = True

    return True
Example #2
0
def execute():
    source_path = os.path.join("installation", "templates", "site")
    target_path = os.path.join("/etc", "apache2", "sites-available", "critic-main")

    with open(".install.data") as install_data:
        data = json.load(install_data)

    with open(target_path, "w") as target:
        created_file.append(target_path)

        os.chmod(target_path, 0640)

        with open(source_path, "r") as source:
            target.write((source.read().decode("utf-8") % data).encode("utf-8"))

    if installation.prereqs.a2enmod:
        process.check_call([installation.prereqs.a2enmod, "expires"])
        process.check_call([installation.prereqs.a2enmod, "rewrite"])
        process.check_call([installation.prereqs.a2enmod, "wsgi"])

    if installation.prereqs.a2ensite:
        process.check_call([installation.prereqs.a2ensite, "critic-main"])
        site_enabled = True

    if installation.prereqs.apache2ctl:
        process.check_call([installation.prereqs.apache2ctl, "restart"])

    return True
Example #3
0
def install(data):
    global site_enabled, default_site_disabled

    source_path = os.path.join(installation.root_dir, "installation", "templates", "site")
    target_path = os.path.join("/etc", "apache2", "sites-available", "critic-main")

    with open(target_path, "w") as target:
        created_file.append(target_path)

        os.chmod(target_path, 0640)

        with open(source_path, "r") as source:
            target.write((source.read().decode("utf-8") % data).encode("utf-8"))

    if installation.prereqs.a2enmod:
        process.check_call([installation.prereqs.a2enmod, "expires"])
        process.check_call([installation.prereqs.a2enmod, "rewrite"])
        process.check_call([installation.prereqs.a2enmod, "wsgi"])

    if installation.prereqs.a2ensite:
        process.check_call([installation.prereqs.a2ensite, "critic-main"])
        site_enabled = True
    if installation.prereqs.a2dissite:
        output = process.check_output([installation.prereqs.a2dissite, "default"], env={ "LANG": "C" })
        if "Site default disabled." in output:
            default_site_disabled = True

    process.check_call(["service", "apache2", "restart"])

    return True
Example #4
0
def install(data):
    global uid, gid

    if create_system_group:
        print "Creating group '%s' ..." % groupname

        process.check_call(["addgroup", "--quiet", "--system", groupname])

    if create_system_user:
        print "Creating user '%s' ..." % username

        process.check_call(
            [
                "adduser",
                "--quiet",
                "--system",
                "--ingroup=%s" % groupname,
                "--home=%s" % installation.paths.data_dir,
                "--disabled-login",
                username,
            ]
        )

    uid = pwd.getpwnam(username).pw_uid
    gid = grp.getgrnam(groupname).gr_gid

    return True
Example #5
0
def install(data):
    source_path = os.path.join(installation.root_dir, "installation",
                               "templates", "site")
    target_path = os.path.join("/etc", "apache2", "sites-available",
                               "critic-main")

    with open(target_path, "w") as target:
        created_file.append(target_path)

        os.chmod(target_path, 0640)

        with open(source_path, "r") as source:
            target.write(
                (source.read().decode("utf-8") % data).encode("utf-8"))

    if installation.prereqs.a2enmod:
        process.check_call([installation.prereqs.a2enmod, "expires"])
        process.check_call([installation.prereqs.a2enmod, "rewrite"])
        process.check_call([installation.prereqs.a2enmod, "wsgi"])

    if installation.prereqs.a2ensite:
        process.check_call([installation.prereqs.a2ensite, "critic-main"])
        site_enabled = True

    process.check_call(["service", "apache2", "restart"])

    return True
Example #6
0
def prepare(mode, arguments, data):
    if mode == "upgrade":
        if installation.migrate.will_modify_dbschema(data):
            print """
The database schema will be modified by the upgrade.  Creating a
backup of the database first is strongly recommended.
"""
            default_backup = True
        else:
            default_backup = False

        if installation.input.yes_or_no("Do you want to create a backup of the database?",
                                        default=default_backup):
            default_path = os.path.join(data["installation.paths.data_dir"],
                                        "backups",
                                        time.strftime("%Y%m%d_%H%M.dump", time.localtime()))

            backup_path = installation.input.string("Where should the backup be stored?",
                                                    default=default_path)

            try: os.makedirs(os.path.dirname(backup_path), 0750)
            except OSError, error:
                if error.errno == errno.EEXIST: pass
                else: raise

            print
            print "Dumping database ..."

            with open(backup_path, "w") as output_file:
                process.check_call(["su", "-s", "/bin/sh", "-c", "pg_dump -Fc critic", data["installation.system.username"]], stdout=output_file)

            print "Compressing database dump ..."
            print

            process.check_call(["bzip2", backup_path])
Example #7
0
def install(data):
    socket_path = os.path.join(installation.paths.run_dir, "main", "sockets",
                               "githook.unix")
    process.check_call([
        installation.prereqs.git, "config", "--system", "critic.socket",
        socket_path
    ])
    return True
Example #8
0
def undo():
    if servicemanager_started:
        process.check_call([os.path.join("/etc", "init.d", "critic-main"), "stop"])

    map(os.unlink, created_file)

    if rclinks_added:
        process.check_call(["update-rc.d", "critic-main", "remove"])
Example #9
0
def undo():
    if site_enabled:
        process.check_call([installation.prereqs.a2dissite, "critic-main"])

        if installation.prereqs.apache2ctl:
            process.check_call([installation.prereqs.apache2ctl, "restart"])

    map(os.unlink, created_file)
Example #10
0
def upgrade(arguments, data):
    source_path = os.path.join(installation.root_dir, "installation", "templates", "site")
    target_path = os.path.join("/etc", "apache2", "sites-available", "critic-main")
    backup_path = os.path.join(os.path.dirname(target_path), "_" + os.path.basename(target_path))

    source = open(source_path, "r").read().decode("utf-8") % data
    target = open(target_path, "r").read().decode("utf-8")

    if source != target:
        def generateVersion(label, path):
            if label == "updated":
                with open(path, "w") as target:
                    target.write(source.encode("utf-8"))

        update_query = installation.utils.UpdateModifiedFile(
            arguments,
            message="""\
The Apache site definition is about to be updated.  Please check that no local
modifications are being overwritten.

  Current version: %(current)s
  Updated version: %(updated)s

Please note that if the modifications are not installed, the system is
likely to break.
""",
            versions={ "current": target_path,
                       "updated": target_path + ".new" },
            options=[ ("i", "install the updated version"),
                      ("k", "keep the current version"),
                      ("d", ("current", "updated")) ],
            generateVersion=generateVersion)

        write_target = update_query.prompt() == "i"
    else:
        write_target = False

    if write_target:
        print "Updated file: %s" % target_path

        if not arguments.dry_run:
            os.rename(target_path, backup_path)
            renamed.append((target_path, backup_path))

            with open(target_path, "w") as target:
                created_file.append(target_path)
                os.chmod(target_path, 0640)
                target.write(source.encode("utf-8"))

    if write_target or installation.files.sources_modified or installation.config.modified_files:
        print
        print "Restarting Apache ..."

        if not arguments.dry_run:
            process.check_call(["service", "apache2", "restart"])

    return True
Example #11
0
def install(data):
    process.check_call([
        "sudo", "-u", installation.system.username,
        "PYTHONPATH=%s" % os.path.join(installation.paths.etc_dir, "main"),
        installation.prereqs.python,
        os.path.join(installation.paths.install_dir,
                     "maintenance/installpreferences.py")
    ])
    return True
Example #12
0
def undo():
    if created_system_user:
        print "Deleting user '%s' ..." % username

        process.check_call(["deluser", "--system", username])

    if created_system_group:
        print "Deleting group '%s' ..." % groupname

        process.check_call(["delgroup", "--system", groupname])
Example #13
0
def undo():
    if created_system_user:
        print "Deleting user '%s' ..." % username

        process.check_call(["deluser", "--system", username])

    if created_system_group:
        print "Deleting group '%s' ..." % groupname

        process.check_call(["delgroup", "--system", groupname])
Example #14
0
def undo():
    if site_enabled:
        process.check_call([installation.prereqs.a2dissite, "critic-main"])

        if installation.prereqs.apache2ctl:
            process.check_call([installation.prereqs.apache2ctl, "restart"])

    map(os.unlink, created_file)

    for target, backup in renamed:
        os.rename(backup, target)
Example #15
0
def install(data):
    process.check_call(
        [
            "sudo",
            "-u",
            installation.system.username,
            "PYTHONPATH=%s" % os.path.join(installation.paths.etc_dir, "main"),
            installation.prereqs.python,
            os.path.join(installation.paths.install_dir, "maintenance/installpreferences.py"),
        ]
    )
    return True
Example #16
0
def install(data):
    global uid, gid

    if create_system_group:
        print "Creating group '%s' ..." % groupname

        process.check_call(["addgroup", "--quiet", "--system", groupname])

    if create_system_user:
        print "Creating user '%s' ..." % username

        process.check_call([
            "adduser", "--quiet", "--system",
            "--ingroup=%s" % groupname,
            "--home=%s" % installation.paths.data_dir, "--disabled-login",
            username
        ])

    uid = pwd.getpwnam(username).pw_uid
    gid = grp.getgrnam(groupname).gr_gid

    return True
Example #17
0
def undo():
    if site_enabled:
        process.check_call([installation.prereqs.a2dissite, "critic-main"])

        if default_site_disabled:
            process.check_call([installation.prereqs.a2ensite, "default"])

        if installation.prereqs.apache2ctl:
            process.check_call([installation.prereqs.apache2ctl, "restart"])

    map(os.unlink, created_file)

    for target, backup in renamed: os.rename(backup, target)
Example #18
0
File: git.py Project: KurSh/critic
def execute():
    socket_path = os.path.join(installation.paths.run_dir, "main", "sockets", "githook.unix")
    process.check_call([installation.prereqs.git, "config", "--system", "critic.socket", socket_path])
    return True
Example #19
0
def upgrade(arguments, data):
    source_path = os.path.join(installation.root_dir, "installation",
                               "templates", "site")
    target_path = os.path.join("/etc", "apache2", "sites-available",
                               "critic-main")
    backup_path = os.path.join(os.path.dirname(target_path),
                               "_" + os.path.basename(target_path))

    source = open(source_path, "r").read().decode("utf-8") % data
    target = open(target_path, "r").read().decode("utf-8")

    if source != target:

        def generateVersion(label, path):
            if label == "updated":
                with open(path, "w") as target:
                    target.write(source.encode("utf-8"))

        update_query = installation.utils.UpdateModifiedFile(
            message="""\
The Apache site definition is about to be updated.  Please check that no local
modifications are being overwritten.

  Current version: %(current)s
  Updated version: %(updated)s

Please note that if the modifications are not installed, the system is
likely to break.
""",
            versions={
                "current": target_path,
                "updated": target_path + ".new"
            },
            options=[("i", "install the updated version"),
                     ("k", "keep the current version"),
                     ("d", ("current", "updated"))],
            generateVersion=generateVersion)

        write_target = update_query.prompt() == "i"
    else:
        write_target = False

    if write_target:
        print "Updated file: %s" % target_path

        if not arguments.dry_run:
            os.rename(target_path, backup_path)
            renamed.append((target_path, backup_path))

            with open(target_path, "w") as target:
                created_file.append(target_path)
                os.chmod(target_path, 0640)
                target.write(source.encode("utf-8"))

    if write_target or installation.files.sources_modified or installation.config.modified_files:
        print
        print "Restarting Apache ..."

        if not arguments.dry_run:
            process.check_call(["service", "apache2", "restart"])

    return True