Skip to content

Commit

Permalink
Fixed issue with Debian bullseye (11).
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioo committed Sep 22, 2021
1 parent 32041a4 commit 58f5a8a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 41 deletions.
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ An installer which deploy a complete mail server based on Modoboa.

This tool is still in beta stage, it has been tested on:

* Debian Jessie (8) / Stretch (9) / Buster (10)
* Debian Jessie (8) / Stretch (9) / Buster (10) / Bullseye (11)
* Ubuntu Trusty (14.04) and upper
* CentOS 7

Expand Down Expand Up @@ -69,6 +69,10 @@ a previous one using the ``--version`` option::

Version selection is available only for Modoboa >= 1.8.1.

You can also install beta releases using the ``--beta`` flag::

$ sudo ./run.py --beta <your domain>

If you want more information about the installation process, add the
``--debug`` option to your command line.

Expand Down
45 changes: 29 additions & 16 deletions modoboa_installer/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, config):

def install_package(self):
"""Install database if required."""
name, version, _id = utils.dist_info()
name, version = utils.dist_info()
if "CentOS" in name:
if version.startswith("7"):
# Install newer version of postgres in this case
Expand Down Expand Up @@ -158,31 +158,44 @@ def _escape(self, query):

def install_package(self):
"""Preseed package installation."""
name, version, _id = utils.dist_info()
name, version = utils.dist_info()
name = name.lower()
if name == "debian":
mysql_name = "mysql" if version.startswith("8") else "mariadb"
self.packages["deb"].append("lib{}client-dev".format(mysql_name))
if name.startswith("debian"):
if version.startswith("8"):
self.packages["deb"].append("libmysqlclient-dev")
elif version.startswith("11"):
self.packages["deb"].append("libmariadb-dev")
else:
self.packages["deb"].append("libmariadbclient-dev")
elif name == "ubuntu":
self.packages["deb"].append("libmysqlclient-dev")
super(MySQL, self).install_package()
if name == "debian" and version.startswith("8"):
package.backend.preconfigure(
"mariadb-server", "root_password", "password",
self.dbpassword)
package.backend.preconfigure(
"mariadb-server", "root_password_again", "password",
self.dbpassword)
else:
queries = []
if name.startswith("debian"):
if version.startswith("8"):
package.backend.preconfigure(
"mariadb-server", "root_password", "password",
self.dbpassword)
package.backend.preconfigure(
"mariadb-server", "root_password_again", "password",
self.dbpassword)
return
if version.startswith("11"):
queries = [
"SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{}')"
.format(self.dbpassword),
"flush privileges"
]
if not queries:
queries = [
"UPDATE user SET plugin='' WHERE user='root'",
"UPDATE user SET password=PASSWORD('{}') WHERE USER='root'"
.format(self.dbpassword),
"flush privileges"
]
for query in queries:
utils.exec_cmd(
"mysql -D mysql -e '{}'".format(self._escape(query)))
for query in queries:
utils.exec_cmd(
"mysql -D mysql -e '{}'".format(self._escape(query)))

def _exec_query(self, query, dbname=None, dbuser=None, dbpassword=None):
"""Exec a mysql query."""
Expand Down
2 changes: 1 addition & 1 deletion modoboa_installer/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_backend():
"""Return the appropriate package backend."""
distname = utils.dist_name()
backend = None
if distname in ["debian", "ubuntu"]:
if distname in ["debian", "debian gnu/linux", "ubuntu"]:
backend = DEBPackage
elif "centos" in distname:
backend = RPMPackage
Expand Down
11 changes: 8 additions & 3 deletions modoboa_installer/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ def get_pip_path(venv):

def install_package(name, venv=None, upgrade=False, binary=True, **kwargs):
"""Install a Python package using pip."""
cmd = "{} install{}{} {}".format(
cmd = "{} install{}{}{} {}".format(
get_pip_path(venv),
" -U" if upgrade else "",
" --no-binary :all:" if not binary else "",
" --pre" if kwargs.pop("beta", False) else "",
name
)
utils.exec_cmd(cmd, **kwargs)


def install_packages(names, venv=None, upgrade=False, **kwargs):
"""Install a Python package using pip."""
cmd = "{} install {}{}".format(
get_pip_path(venv), " -U " if upgrade else "", " ".join(names))
cmd = "{} install{}{} {}".format(
get_pip_path(venv),
" -U " if upgrade else "",
" --pre" if kwargs.pop("beta", False) else "",
" ".join(names)
)
utils.exec_cmd(cmd, **kwargs)


Expand Down
11 changes: 11 additions & 0 deletions modoboa_installer/scripts/files/nginx/modoboa.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ server {
try_files $uri $uri/ =404;
}

location ^~ /new-admin {
alias %{app_instance_path}/frontend/;
index index.html;

expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";

try_files $uri $uri/ /index.html = 404;
}

location / {
include uwsgi_params;
uwsgi_param UWSGI_SCRIPT instance.wsgi:application;
Expand Down
22 changes: 12 additions & 10 deletions modoboa_installer/scripts/modoboa.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Modoboa(base.Installer):
"deb": [
"build-essential", "python3-dev", "libxml2-dev", "libxslt-dev",
"libjpeg-dev", "librrd-dev", "rrdtool", "libffi-dev", "cron",
"libssl-dev", "redis-server", "supervisor"
"libssl-dev", "redis-server", "supervisor", "rustc"
],
"rpm": [
"gcc", "gcc-c++", "python3-devel", "libxml2-devel", "libxslt-devel",
Expand Down Expand Up @@ -75,11 +75,10 @@ def _setup_venv(self):
packages = ["rrdtool"]
version = self.config.get("modoboa", "version")
if version == "latest":
modoboa_package = "modoboa"
packages += self.extensions
packages += ["modoboa"] + self.extensions
else:
matrix = compatibility_matrix.COMPATIBILITY_MATRIX[version]
modoboa_package = "modoboa=={}".format(version)
packages.append("modoboa=={}".format(version))
for extension in list(self.extensions):
if not self.is_extension_ok_for_version(extension, version):
self.extensions.remove(extension)
Expand All @@ -91,12 +90,13 @@ def _setup_venv(self):
packages.append("{}{}".format(extension, req_version))
else:
packages.append(extension)
# Temp fix for https://github.com/modoboa/modoboa-installer/issues/197
# Temp fix for django-braces
python.install_package(
modoboa_package, self.venv_path,
upgrade=self.upgrade, binary=False, sudo_user=self.user)
"django-braces", self.venv_path, upgrade=self.upgrade,
sudo_user=self.user
)
if self.dbengine == "postgres":
packages.append("psycopg2-binary")
packages.append("psycopg2-binary\<2.9")
else:
packages.append("mysqlclient")
if sys.version_info.major == 2 and sys.version_info.micro < 9:
Expand All @@ -105,8 +105,10 @@ def _setup_venv(self):
# Temp fix for https://github.com/modoboa/modoboa/issues/2247
packages.append("django-webpack-loader==0.7.0")
python.install_packages(
packages, self.venv_path, upgrade=self.upgrade,
sudo_user=self.user
packages, self.venv_path,
upgrade=self.upgrade,
sudo_user=self.user,
beta=self.config.getboolean("modoboa", "install_beta")
)
if self.devmode:
# FIXME: use dev-requirements instead
Expand Down
24 changes: 14 additions & 10 deletions modoboa_installer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ def exec_cmd(cmd, sudo_user=None, pinput=None, login=True, **kwargs):

def dist_info():
"""Try to return information about the system we're running on."""
try:
# Python 3.8 and up way
import distro
return distro.linux_distribution()
except ImportError:
# Python 3.7 and down way
import platform
return platform.linux_distribution()
path = "/etc/os-release"
if os.path.exists(path):
info = {}
with open(path) as fp:
while True:
l = fp.readline()
if not l:
break
key, value = l.split("=")
value = value.rstrip('"\n')
value = value.strip('"')
info[key] = value
return info["NAME"], info["VERSION_ID"]
printcolor(
"Failed to retrieve information about your system, aborting.",
RED)
Expand All @@ -91,8 +96,7 @@ def dist_info():

def dist_name():
"""Try to guess the distribution name."""
name, version, _id = dist_info()
return name.lower()
return dist_info()[0].lower()


def mkdir(path, mode, uid, gid):
Expand Down
4 changes: 4 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def main(input_args):
parser.add_argument(
"--upgrade", action="store_true", default=False,
help="Run the installer in upgrade mode")
parser.add_argument(
"--beta", action="store_true", default=False,
help="Install latest beta release of Modoboa instead of the stable one")
parser.add_argument("domain", type=str,
help="The main domain of your future mail server")
args = parser.parse_args(input_args)
Expand All @@ -87,6 +90,7 @@ def main(input_args):
config.set("general", "domain", args.domain)
config.set("dovecot", "domain", args.domain)
config.set("modoboa", "version", args.version)
config.set("modoboa", "install_beta", str(args.beta))
# Display disclaimerpython 3 linux distribution
if not args.upgrade:
installation_disclaimer(args, config)
Expand Down

0 comments on commit 58f5a8a

Please sign in to comment.