Пример #1
0
    def update(self):
        """
        Similar to `apt-get update`
        """
        try:
            with open('/var/log/sss/sss.log', 'a') as f:
                proc = subprocess.Popen('apt-get update',
                                        shell=True,
                                        stdin=None,
                                        stdout=f,
                                        stderr=subprocess.PIPE,
                                        executable="/bin/bash")
                proc.wait()
                output, error_output = proc.communicate()

                # Check what is error in error_output
                if "NO_PUBKEY" in str(error_output):
                    # Split the output
                    Log.info(self, "Fixing missing GPG keys, please wait...")
                    error_list = str(error_output).split("\\n")

                    # Use a loop to add misising keys
                    for single_error in error_list:
                        if "NO_PUBKEY" in single_error:
                            key = single_error.rsplit(None, 1)[-1]
                            SSSRepo.add_key(self,
                                            key,
                                            keyserver="hkp://pgp.mit.edu")

                    proc = subprocess.Popen('apt-get update',
                                            shell=True,
                                            stdin=None,
                                            stdout=f,
                                            stderr=f,
                                            executable="/bin/bash")
                    proc.wait()

                if proc.returncode == 0:
                    return True
                else:
                    Log.info(self, Log.FAIL + "Oops Something went wrong!!")
                    Log.error(
                        self, "Check logs for reason "
                        "`tail /var/log/sss/sss.log` & Try Again!!!")

        except Exception as e:
            Log.error(self, "apt-get update exited with error")
Пример #2
0
    def update(self):
        """
        Similar to `apt-get update`
        """
        try:
            with open("/var/log/sss/sss.log", "a") as f:
                proc = subprocess.Popen(
                    "apt-get update", shell=True, stdin=None, stdout=f, stderr=subprocess.PIPE, executable="/bin/bash"
                )
                proc.wait()
                output, error_output = proc.communicate()

                # Check what is error in error_output
                if "NO_PUBKEY" in str(error_output):
                    # Split the output
                    Log.info(self, "Fixing missing GPG keys, please wait...")
                    error_list = str(error_output).split("\\n")

                    # Use a loop to add misising keys
                    for single_error in error_list:
                        if "NO_PUBKEY" in single_error:
                            key = single_error.rsplit(None, 1)[-1]
                            SSSRepo.add_key(self, key, keyserver="hkp://pgp.mit.edu")

                    proc = subprocess.Popen(
                        "apt-get update", shell=True, stdin=None, stdout=f, stderr=f, executable="/bin/bash"
                    )
                    proc.wait()

                if proc.returncode == 0:
                    return True
                else:
                    Log.info(self, Log.FAIL + "Oops Something went wrong!!")
                    Log.error(self, "Check logs for reason " "`tail /var/log/sss/sss.log` & Try Again!!!")

        except Exception as e:
            Log.error(self, "apt-get update exited with error")
Пример #3
0
    def migrate_mariadb(self):
        # Backup all database
        SSSMysql.backupAll(self)

        # Add MariaDB repo
        Log.info(self, "Adding repository for MariaDB, please wait...")

        mysql_pref = "Package: *\nPin: origin sfo1.mirrors.digitalocean.com" "\nPin-Priority: 1000\n"
        with open("/etc/apt/preferences.d/" "MariaDB.pref", "w") as mysql_pref_file:
            mysql_pref_file.write(mysql_pref)

        SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo)
        Log.debug(self, "Adding key for {0}".format(SSSVariables.sss_mysql_repo))
        SSSRepo.add_key(self, "0xcbcb082a1bb943db", keyserver="keyserver.ubuntu.com")

        config = configparser.ConfigParser()
        if os.path.exists("/etc/mysql/conf.d/my.cnf"):
            config.read("/etc/mysql/conf.d/my.cnf")
        else:
            config.read(os.path.expanduser("~") + "/.my.cnf")

        try:
            chars = config["client"]["password"]
        except Exception as e:
            Log.error(self, "Error: process exited with error %s" % e)

        Log.debug(self, "Pre-seeding MariaDB")
        Log.debug(
            self, 'echo "mariadb-server-10.0 ' "mysql-server/root_password " 'password " | ' "debconf-set-selections"
        )
        SSSShellExec.cmd_exec(
            self,
            'echo "mariadb-server-10.0 '
            "mysql-server/root_password "
            'password {chars}" | '
            "debconf-set-selections".format(chars=chars),
            log=False,
        )
        Log.debug(
            self,
            'echo "mariadb-server-10.0 ' "mysql-server/root_password_again " 'password " | ' "debconf-set-selections",
        )
        SSSShellExec.cmd_exec(
            self,
            'echo "mariadb-server-10.0 '
            "mysql-server/root_password_again "
            'password {chars}" | '
            "debconf-set-selections".format(chars=chars),
            log=False,
        )

        # Install MariaDB
        apt_packages = SSSVariables.sss_mysql

        # If PHP is installed then install php5-mysql
        if SSSAptGet.is_installed(self, "php5-fpm"):
            apt_packages = apt_packages + ["php5-mysql"]

        # If mail server is installed then install dovecot-sql and postfix-sql
        if SSSAptGet.is_installed(self, "dovecot-core"):
            apt_packages = apt_packages + ["dovecot-mysql", "postfix-mysql", "libclass-dbi-mysql-perl"]

        Log.info(self, "Updating apt-cache, please wait...")
        SSSAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        SSSAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        SSSAptGet.auto_remove(self)
        SSSAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if SSSAptGet.is_installed(self, "dovecot-core"):
            SSSService.restart_service(self, "dovecot")
            SSSService.restart_service(self, "postfix")
Пример #4
0
    def pre_pref(self,apt_packages):
        """Pre settings to do before installation packages"""

        if set(SSSVariables.sss_mysql).issubset(set(apt_packages)):
            Log.info(self,"Adding repository for MySQL, please wait... ")
            mysql_pref = ("Package: *\nPin: origin sfo1.mirrors.digitalocean.com"
                          "\nPin-Priority: 1000\n")
            with open('/etc/apt/preferences.d/'
                      'MariaDB.pref', 'w') as mysql_pref_file:
                mysql_pref_file.write(mysql_pref)

            SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo)
            Log.debug(self, 'Adding key for {0}'
                        .format(SSSVariables.sss_mysql_repo))
            SSSRepo.add_key(self, '0xcbcb082a1bb943db',
                               keyserver="keyserver.ubuntu.com")
            chars = ''.join(random.sample(string.ascii_letters, 8))
            Log.debug(self, "Pre-seeding MySQL")
            Log.debug(self, "echo \"mariadb-server-10.1 "
                      "mysql-server/root_password "
                      "password \" | "
                      "debconf-set-selections")

            try:
                SSSShellExec.cmd_exec(self, "echo \"mariadb-server-10.1 "
                                     "mysql-server/root_password "
                                     "password {chars}\" | "
                                     "debconf-set-selections"
                                     .format(chars=chars),
                                     log=False)
            except CommandExecutionError as e:
                Log.error("Failed to initialize MySQL package")

            Log.debug(self, "echo \"mariadb-server-10.1 "
                      "mysql-server/root_password_again "
                      "password \" | "
                      "debconf-set-selections")

            try:
                SSSShellExec.cmd_exec(self, "echo \"mariadb-server-10.1 "
                                     "mysql-server/root_password_again "
                                     "password {chars}\" | "
                                     "debconf-set-selections"
                                     .format(chars=chars),
                                     log=False)
            except CommandExecutionError as e:
                Log.error("Failed to initialize MySQL package")

            mysql_config = """
            [client]
            user = root
            password = {chars}
            """.format(chars=chars)
            config = configparser.ConfigParser()
            config.read_string(mysql_config)
            Log.debug(self, 'Writting configuration into MySQL file')
            conf_path = "/etc/mysql/conf.d/my.cnf"
            os.makedirs(os.path.dirname(conf_path), exist_ok=True)
            with open(conf_path, encoding='utf-8',
                      mode='w') as configfile:
                config.write(configfile)
            Log.debug(self, 'Setting my.cnf permission')
            SSSFileUtils.chmod(self, "/etc/mysql/conf.d/my.cnf", 0o600)

        if set(SSSVariables.sss_apache).issubset(set(apt_packages)):
            Log.info(self, "Adding repository for Apache, please wait...")
            SSSRepo.add(self, ppa=SSSVariables.sss_apache_repo)

        if set(SSSVariables.sss_php).issubset(set(apt_packages)):
            Log.info(self, "Adding repository for PHP, please wait...")
            Log.debug(self, 'Adding ppa for PHP')
            SSSRepo.add(self, ppa=SSSVariables.sss_php_repo)
Пример #5
0
    def pre_pref(self, apt_packages):
        """Pre settings to do before installation packages"""

        if set(SSSVariables.sss_pma).issubset(set(apt_packages)):
            Log.info(self, "Adding repository for phpMyAdmin ,please wait...")
            """pma_pref = ("def origin http://ppa.launchpad.net/nijel/phpmyadmin/ubuntu trusty main")

            with open('/etc/apt/sources.list.d/', 'w') as pma_pref_file:
                pma_pref_file.write(pma_pref)"""
            SSSRepo.add(self, repo_url=SSSVariables.sss_pma_repo_url)

            Log.debug(self,
                      'Adding key for {0}'.format(SSSVariables.sss_pma_repo))
            SSSRepo.add_key(self, '06ED541C', keyserver="keyserver.ubuntu.com")
            chars = ''.join(random.sample(string.ascii_letters, 8))

            Log.debug(self, "Adding ppa for phpMyAdmin")
            SSSRepo.add(self, ppa=SSSVariables.sss_pma_repo)

        if set(SSSVariables.sss_mysql).issubset(set(apt_packages)):
            Log.info(self, "Adding repository for MySQL, please wait... ")
            mysql_pref = (
                "Package: *\nPin: origin sfo1.mirrors.digitalocean.com"
                "\nPin-Priority: 1000\n")
            with open('/etc/apt/preferences.d/'
                      'MariaDB.pref', 'w') as mysql_pref_file:
                mysql_pref_file.write(mysql_pref)

            SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo)
            Log.debug(self,
                      'Adding key for {0}'.format(SSSVariables.sss_mysql_repo))
            SSSRepo.add_key(self,
                            '0xcbcb082a1bb943db',
                            keyserver="keyserver.ubuntu.com")
            chars = ''.join(random.sample(string.ascii_letters, 8))
            Log.debug(self, "Pre-seeding MySQL")
            Log.debug(
                self, "echo \"mariadb-server-10.1 "
                "mysql-server/root_password "
                "password \" | "
                "debconf-set-selections")

            try:
                SSSShellExec.cmd_exec(
                    self,
                    "echo \"mariadb-server-10.1 "
                    "mysql-server/root_password "
                    "password {chars}\" | "
                    "debconf-set-selections".format(chars=chars),
                    log=False)
            except CommandExecutionError as e:
                Log.error("Failed to initialize MySQL package")

            Log.debug(
                self, "echo \"mariadb-server-10.1 "
                "mysql-server/root_password_again "
                "password \" | "
                "debconf-set-selections")

            try:
                SSSShellExec.cmd_exec(
                    self,
                    "echo \"mariadb-server-10.1 "
                    "mysql-server/root_password_again "
                    "password {chars}\" | "
                    "debconf-set-selections".format(chars=chars),
                    log=False)
            except CommandExecutionError as e:
                Log.error("Failed to initialize MySQL package")

            mysql_config = """
            [client]
            user = root
            password = {chars}
            """.format(chars=chars)
            config = configparser.ConfigParser()
            config.read_string(mysql_config)
            Log.debug(self, 'Writting configuration into MySQL file')
            conf_path = "/etc/mysql/conf.d/my.cnf"
            os.makedirs(os.path.dirname(conf_path), exist_ok=True)
            with open(conf_path, encoding='utf-8', mode='w') as configfile:
                config.write(configfile)
            Log.debug(self, 'Setting my.cnf permission')
            SSSFileUtils.chmod(self, "/etc/mysql/conf.d/my.cnf", 0o600)

        if set(SSSVariables.sss_apache).issubset(set(apt_packages)):
            Log.info(self, "Adding repository for Apache, please wait...")
            SSSRepo.add(self, ppa=SSSVariables.sss_apache_repo)

        if set(SSSVariables.sss_php).issubset(set(apt_packages)):
            Log.info(self, "Adding repository for PHP, please wait...")
            Log.debug(self, 'Adding ppa for PHP')
            SSSRepo.add(self, ppa=SSSVariables.sss_php_repo)
    def migrate_mariadb(self):
        # Backup all database
        SSSMysql.backupAll(self)

        # Add MariaDB repo
        Log.info(self, "Adding repository for MariaDB, please wait...")

        mysql_pref = ("Package: *\nPin: origin sfo1.mirrors.digitalocean.com"
                      "\nPin-Priority: 1000\n")
        with open('/etc/apt/preferences.d/'
                  'MariaDB.pref', 'w') as mysql_pref_file:
            mysql_pref_file.write(mysql_pref)

        SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo)
        Log.debug(self,
                  'Adding key for {0}'.format(SSSVariables.sss_mysql_repo))
        SSSRepo.add_key(self,
                        '0xcbcb082a1bb943db',
                        keyserver="keyserver.ubuntu.com")

        config = configparser.ConfigParser()
        if os.path.exists('/etc/mysql/conf.d/my.cnf'):
            config.read('/etc/mysql/conf.d/my.cnf')
        else:
            config.read(os.path.expanduser("~") + '/.my.cnf')

        try:
            chars = config['client']['password']
        except Exception as e:
            Log.error(self, "Error: process exited with error %s" % e)

        Log.debug(self, "Pre-seeding MariaDB")
        Log.debug(
            self, "echo \"mariadb-server-10.0 "
            "mysql-server/root_password "
            "password \" | "
            "debconf-set-selections")
        SSSShellExec.cmd_exec(self,
                              "echo \"mariadb-server-10.0 "
                              "mysql-server/root_password "
                              "password {chars}\" | "
                              "debconf-set-selections".format(chars=chars),
                              log=False)
        Log.debug(
            self, "echo \"mariadb-server-10.0 "
            "mysql-server/root_password_again "
            "password \" | "
            "debconf-set-selections")
        SSSShellExec.cmd_exec(self,
                              "echo \"mariadb-server-10.0 "
                              "mysql-server/root_password_again "
                              "password {chars}\" | "
                              "debconf-set-selections".format(chars=chars),
                              log=False)

        # Install MariaDB
        apt_packages = SSSVariables.sss_mysql

        # If PHP is installed then install php5-mysql
        if SSSAptGet.is_installed(self, "php5-fpm"):
            apt_packages = apt_packages + ["php5-mysql"]

        # If mail server is installed then install dovecot-sql and postfix-sql
        if SSSAptGet.is_installed(self, "dovecot-core"):
            apt_packages = apt_packages + [
                "dovecot-mysql", "postfix-mysql", "libclass-dbi-mysql-perl"
            ]

        Log.info(self, "Updating apt-cache, please wait...")
        SSSAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        SSSAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        SSSAptGet.auto_remove(self)
        SSSAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if SSSAptGet.is_installed(self, "dovecot-core"):
            SSSService.restart_service(self, 'dovecot')
            SSSService.restart_service(self, 'postfix')