From 3802ef87f47972f4217255e326a34bf477154766 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Tue, 23 Dec 2014 14:08:30 +0530 Subject: [PATCH 1/4] More tweaks to ee stack install --- ee/cli/plugins/stack.py | 11 +++++++++++ ee/cli/templates/auth-sql-conf.mustache | 11 +++++++++++ ee/cli/templates/dovecot-sql-conf.mustache | 12 ++++++++++++ ee/core/variables.py | 14 +++++++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 ee/cli/templates/auth-sql-conf.mustache create mode 100644 ee/cli/templates/dovecot-sql-conf.mustache diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index c2f86606..90769bb4 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -182,6 +182,17 @@ 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}/emailAddres" + "s={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") + if len(packages): if any('/usr/bin/wp' == x[1] for x in packages): EEShellExec.cmd_exec("chmod +x /usr/bin/wp") 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/variables.py b/ee/core/variables.py index 3618388d..71bb0072 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -1,15 +1,27 @@ """EasyEngine core variable module""" import platform +import socket +import confiparser +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': @@ -42,7 +54,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"] From 7b344662269d0a3d0c97bdefa89027cc4189c624 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Tue, 23 Dec 2014 15:01:45 +0530 Subject: [PATCH 2/4] Some more tweaks to installation --- ee/cli/plugins/stack.py | 12 +++++++++++- ee/core/variables.py | 5 +++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 014a2d60..82f27dee 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': diff --git a/ee/core/variables.py b/ee/core/variables.py index 71bb0072..d67f4028 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -1,7 +1,7 @@ """EasyEngine core variable module""" import platform import socket -import confiparser +import configparser import os @@ -44,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 From 44aeb1c9f5c93ac38df52a72e2b33fa35a33ad33 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Tue, 23 Dec 2014 15:22:48 +0530 Subject: [PATCH 3/4] Dovecot Done --- ee/cli/plugins/stack.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 82f27dee..ad8f12b1 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -196,13 +196,19 @@ class EEStackController(CementBaseController): 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}/emailAddres" - "s={EMAIL} -out /etc/ssl/certs/dovecot." + " -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") From a5abc3dbaab2690c756ac8140cff78ac52d52358 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Tue, 23 Dec 2014 15:28:45 +0530 Subject: [PATCH 4/4] minor changes --- ee/cli/plugins/stack.py | 1 - ee/core/aptget.py | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 7e33e81d..1e35b2ed 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -314,7 +314,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/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]