diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 7e33e81d..8eb2890a 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -74,7 +74,7 @@ class EEStackController(CementBaseController): "$(hostname -f)\" | debconf-set-selections") if set(EEVariables.ee_mysql).issubset(set(apt_packages)): print("Adding repository for mysql ... ") - EERepo.add(ppa=EEVariables.ee_mysql_repo) + EERepo.add(repo_url=EEVariables.ee_mysql_repo) EERepo.add_key('1C4CBDCDCD2EFD2A') chars = ''.join(random.sample(string.ascii_letters, 8)) print("Pre-seeding mysql variables ... ") @@ -86,6 +86,16 @@ class EEStackController(CementBaseController): "percona-server-server/root_password_again " "password {chars}\" | " "debconf-set-selections".format(chars=chars)) + mysql_config = """ + [mysqld] + user = root + password = {chars} + """.format(chars=chars) + config = configparser.ConfigParser() + config.read_string(mysql_config) + with open(os.path.expanduser("~")+'/.my.cnf', 'w') as configfile: + config.write(configfile) + if set(EEVariables.ee_nginx).issubset(set(apt_packages)): print("Adding repository for nginx ... ") if EEVariables.ee_platform_distro == 'Debian': @@ -182,6 +192,23 @@ class EEStackController(CementBaseController): with open('/etc/mysql/my.cnf', 'w') as configfile: config.write(configfile) + if set(EEVariables.ee_dovecot).issubset(set(apt_packages)): + EEShellExec.cmd_exec("adduser --uid 5000 --home /var/vmail" + "--disabled-password --gecos '' vmail") + EEShellExec.cmd_exec("openssl req -new -x509 -days 3650 -nodes" + " -subj /commonName={HOSTNAME}/emailAddre" + "ss={EMAIL} -out /etc/ssl/certs/dovecot." + "pem -keyout /etc/ssl/private/dovecot.pem" + .format(HOSTNAME=EEVariables.ee_fqdn, + EMAIL=EEVariables.ee_email)) + EEShellExec.cmd_exec("chmod 0600 /etc/ssl/private/dovecot.pem") + + # Custom Dovecot configuration by EasyEngine + data = dict() + ee_dovecot = open('/etc/dovecot/conf.d/99-ee.conf', 'w') + self.app.render((data), 'dovecot.mustache', out=ee_dovecot) + ee_dovecot.close() + if len(packages): if any('/usr/bin/wp' == x[1] for x in packages): EEShellExec.cmd_exec("chmod +x /usr/bin/wp") @@ -314,7 +341,6 @@ class EEStackController(CementBaseController): self.pre_pref(apt_packages) if len(apt_packages): - pkg.update() pkg.install(apt_packages) if len(packages): EEDownload.download(packages) diff --git a/ee/cli/templates/auth-sql-conf.mustache b/ee/cli/templates/auth-sql-conf.mustache new file mode 100644 index 00000000..8854747b --- /dev/null +++ b/ee/cli/templates/auth-sql-conf.mustache @@ -0,0 +1,11 @@ +passdb { + driver = sql + args = /etc/dovecot/dovecot-sql.conf.ext +} +userdb { + driver = prefetch +} +userdb { + driver = sql + args = /etc/dovecot/dovecot-sql.conf.ext +} diff --git a/ee/cli/templates/dovecot-sql-conf.mustache b/ee/cli/templates/dovecot-sql-conf.mustache new file mode 100644 index 00000000..8c76123d --- /dev/null +++ b/ee/cli/templates/dovecot-sql-conf.mustache @@ -0,0 +1,12 @@ +driver = mysql +connect = host=localhost user=vimbadmin password={{password}} dbname=vimbadmin +default_pass_scheme = MD5 +password_query = SELECT username as user, password as password, \ +homedir AS home, maildir AS mail, \ +concat('*:bytes=', quota) as quota_rule, uid, gid \ +FROM mailbox \ +WHERE username = '%Lu' AND active = '1' \ +AND ( access_restriction = 'ALL' OR LOCATE( access_restriction, '%Us' ) > 0 ) +user_query = SELECT homedir AS home, maildir AS mail, \ +concat('*:bytes=', quota) as quota_rule, uid, gid \ +FROM mailbox WHERE username = '%u' diff --git a/ee/core/aptget.py b/ee/core/aptget.py index 5c10b1e9..285c3a96 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -14,13 +14,14 @@ class EEAptGet: def update(self): """Similar to apt-get update""" self.cache.update(self.fprogress) - pass + self.cache.open() def upgrade(self, packages): """Similar to apt-get update""" my_selected_packages = [] # Cache Initialization - self.cache = apt.Cache() + if not self.cache: + self.cache = apt.Cache() # Cache Read self.cache.open() for package in packages: @@ -64,9 +65,11 @@ class EEAptGet: """Installation of packages""" my_selected_packages = [] # Cache Initialization - self.cache = apt.Cache() + if not self.cache: + self.cache = apt.Cache() # Cache Read self.cache.open() + for package in packages: pkg = self.cache[package] # Check Package Installed @@ -132,6 +135,11 @@ class EEAptGet: def remove(self, packages, auto=True, purge=False): my_selected_packages = [] + # Cache Initialization + if not self.cache: + self.cache = apt.Cache() + # Cache Read + self.cache.open() for package in packages: print("processing", package) package = self.cache[package] diff --git a/ee/core/variables.py b/ee/core/variables.py index 3618388d..d67f4028 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -1,15 +1,27 @@ """EasyEngine core variable module""" import platform +import socket +import configparser +import os class EEVariables(): """Intialization of core variables""" + config = configparser.ConfigParser() + config.read(os.path.expanduser("~")+'/.gitconfig') # EasyEngine core variables ee_platform_distro = platform.linux_distribution()[0] ee_platform_version = platform.linux_distribution()[1] ee_platform_codename = platform.linux_distribution()[2] + # Get FQDN of system + ee_fqdn = socket.getfqdn() + + # Get git user name and EMail + ee_user = config['user']['name'] + ee_email = config['user']['email'] + # EasyEngine stack installation varibales # Nginx repo and packages if ee_platform_distro == 'Ubuntu': @@ -32,7 +44,8 @@ class EEVariables(): "php5-mcrypt", "php5-xdebug"] # MySQL repo and packages - ee_mysql_repo = "" + ee_mysql_repo = ("deb http://repo.percona.com/apt {codename} main" + .format(codename=ee_platform_codename)) ee_mysql = ["percona-server-server-5.6"] # Postfix repo and packages @@ -42,7 +55,7 @@ class EEVariables(): # Dovecot repo and packages ee_dovecot_repo = ("deb http://http.debian.net/debian-backports {codename}" "-backports main".format(codename=ee_platform_codename)) - + ee_dovecot = ["dovecot-core", "dovecot-imapd", "dovecot-pop3d", "dovecot-lmtpd", "dovecot-mysql", "dovecot-sieve", "dovecot-managesieved"]