initial commit
This commit is contained in:
@@ -6,12 +6,16 @@ import sys
|
|||||||
from .. import utils
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
def install(appname, config, upgrade):
|
def install(appname, config, upgrade, restore):
|
||||||
"""Install an application."""
|
"""Install an application."""
|
||||||
if (config.has_option(appname, "enabled") and
|
if (config.has_option(appname, "enabled") and
|
||||||
not config.getboolean(appname, "enabled")):
|
not config.getboolean(appname, "enabled")):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not restore:
|
||||||
utils.printcolor("Installing {}".format(appname), utils.MAGENTA)
|
utils.printcolor("Installing {}".format(appname), utils.MAGENTA)
|
||||||
|
else:
|
||||||
|
utils.printcolor("Restoring {}".format(appname), utils.MAGENTA)
|
||||||
try:
|
try:
|
||||||
script = importlib.import_module(
|
script = importlib.import_module(
|
||||||
"modoboa_installer.scripts.{}".format(appname))
|
"modoboa_installer.scripts.{}".format(appname))
|
||||||
@@ -19,7 +23,7 @@ def install(appname, config, upgrade):
|
|||||||
print("Unknown application {}".format(appname))
|
print("Unknown application {}".format(appname))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
getattr(script, appname.capitalize())(config, upgrade).run()
|
getattr(script, appname.capitalize())(config, upgrade, restore).run()
|
||||||
except utils.FatalError as inst:
|
except utils.FatalError as inst:
|
||||||
utils.printcolor(u"{}".format(inst), utils.RED)
|
utils.printcolor(u"{}".format(inst), utils.RED)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ class Installer(object):
|
|||||||
with_db = False
|
with_db = False
|
||||||
config_files = []
|
config_files = []
|
||||||
|
|
||||||
def __init__(self, config, upgrade):
|
def __init__(self, config, upgrade, restore):
|
||||||
"""Get configuration."""
|
"""Get configuration."""
|
||||||
self.config = config
|
self.config = config
|
||||||
self.upgrade = upgrade
|
self.upgrade = upgrade
|
||||||
|
self.restore = restore
|
||||||
if self.config.has_section(self.appname):
|
if self.config.has_section(self.appname):
|
||||||
self.app_config = dict(self.config.items(self.appname))
|
self.app_config = dict(self.config.items(self.appname))
|
||||||
self.dbengine = self.config.get("database", "engine")
|
self.dbengine = self.config.get("database", "engine")
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ def copy_from_template(template, dest, context):
|
|||||||
fp.write(ConfigFileTemplate(buf).substitute(context))
|
fp.write(ConfigFileTemplate(buf).substitute(context))
|
||||||
|
|
||||||
|
|
||||||
def check_config_file(dest, interactive=False, upgrade=False, backup=False):
|
def check_config_file(dest, interactive=False, upgrade=False, backup=False, restore=False):
|
||||||
"""Create a new installer config file if needed."""
|
"""Create a new installer config file if needed."""
|
||||||
isPresent = True
|
isPresent = True
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
@@ -183,6 +183,12 @@ def check_config_file(dest, interactive=False, upgrade=False, backup=False):
|
|||||||
printcolor(
|
printcolor(
|
||||||
"Your configuration file hasn't been found. A new one will be generated. "
|
"Your configuration file hasn't been found. A new one will be generated. "
|
||||||
"Please edit it with correct password for the databases !", RED)
|
"Please edit it with correct password for the databases !", RED)
|
||||||
|
elif restore:
|
||||||
|
printcolor(
|
||||||
|
"You cannot restore an existing installation without a "
|
||||||
|
f"configuration file. (file : {dest} has not been found...", RED)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
printcolor(
|
printcolor(
|
||||||
"Configuration file {} not found, creating new one."
|
"Configuration file {} not found, creating new one."
|
||||||
.format(dest), YELLOW)
|
.format(dest), YELLOW)
|
||||||
|
|||||||
49
run.py
49
run.py
@@ -3,6 +3,8 @@
|
|||||||
"""An installer for Modoboa."""
|
"""An installer for Modoboa."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from ast import parse
|
||||||
|
from ctypes import util
|
||||||
try:
|
try:
|
||||||
import configparser
|
import configparser
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -50,6 +52,12 @@ def backup_disclamer():
|
|||||||
" !! You should really transfer the backup somewhere else..."
|
" !! You should really transfer the backup somewhere else..."
|
||||||
" Custom configuration (like to postfix) won't be saved.", utils.BLUE)
|
" Custom configuration (like to postfix) won't be saved.", utils.BLUE)
|
||||||
|
|
||||||
|
def restore_disclamer(path):
|
||||||
|
"""Display restore disclamer. """
|
||||||
|
utils.printcolor(
|
||||||
|
"You are about to restore a previous installation of Modoboa."
|
||||||
|
"Is a new version has been released in between, please update your database !",
|
||||||
|
utils.BLUE)
|
||||||
|
|
||||||
def main(input_args):
|
def main(input_args):
|
||||||
"""Install process."""
|
"""Install process."""
|
||||||
@@ -89,6 +97,10 @@ def main(input_args):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-mail", action="store_true", default=False,
|
"--no-mail", action="store_true", default=False,
|
||||||
help="Disable mail backup (save space)")
|
help="Disable mail backup (save space)")
|
||||||
|
parser.add_argument(
|
||||||
|
"--restore", type=str, metavar="path",
|
||||||
|
help="Restore a previously backup up modoboa instance on a NEW machine. You Must provide backup directory"
|
||||||
|
)
|
||||||
parser.add_argument("domain", type=str,
|
parser.add_argument("domain", type=str,
|
||||||
help="The main domain of your future mail server")
|
help="The main domain of your future mail server")
|
||||||
args = parser.parse_args(input_args)
|
args = parser.parse_args(input_args)
|
||||||
@@ -107,8 +119,16 @@ def main(input_args):
|
|||||||
elif args.bash == "TRUE":
|
elif args.bash == "TRUE":
|
||||||
utils.printcolor("You can't pick *TRUE* as backup directory !", utils.RED)
|
utils.printcolor("You can't pick *TRUE* as backup directory !", utils.RED)
|
||||||
|
|
||||||
|
#Restore prep
|
||||||
|
isRestoring = False
|
||||||
|
if args.restore != None:
|
||||||
|
isRestoring = True
|
||||||
|
if args.restore[-1] != "/":
|
||||||
|
args.restore += "/"
|
||||||
|
args.configfile = args.restore + "installer.cfg"
|
||||||
|
|
||||||
utils.printcolor("Welcome to Modoboa installer!\n", utils.GREEN)
|
utils.printcolor("Welcome to Modoboa installer!\n", utils.GREEN)
|
||||||
wasConfigFileAlreadyThere = utils.check_config_file(args.configfile, args.interactive, args.upgrade, args.backup)
|
wasConfigFileAlreadyThere = utils.check_config_file(args.configfile, args.interactive, args.upgrade, args.backup, isRestoring)
|
||||||
|
|
||||||
if args.stop_after_configfile_check or (not wasConfigFileAlreadyThere and args.backup):
|
if args.stop_after_configfile_check or (not wasConfigFileAlreadyThere and args.backup):
|
||||||
return
|
return
|
||||||
@@ -134,6 +154,8 @@ def main(input_args):
|
|||||||
bashArg = "TRUE"
|
bashArg = "TRUE"
|
||||||
scripts.backup(config, bashArg, args.no_mail)
|
scripts.backup(config, bashArg, args.no_mail)
|
||||||
return
|
return
|
||||||
|
elif args.restore:
|
||||||
|
restore_disclamer()
|
||||||
else:
|
else:
|
||||||
installation_disclaimer(args, config)
|
installation_disclaimer(args, config)
|
||||||
|
|
||||||
@@ -162,22 +184,27 @@ def main(input_args):
|
|||||||
ssl_backend = ssl.get_backend(config)
|
ssl_backend = ssl.get_backend(config)
|
||||||
if ssl_backend and not args.upgrade:
|
if ssl_backend and not args.upgrade:
|
||||||
ssl_backend.generate_cert()
|
ssl_backend.generate_cert()
|
||||||
scripts.install("amavis", config, args.upgrade)
|
scripts.install("amavis", config, args.upgrade, args.restore)
|
||||||
scripts.install("modoboa", config, args.upgrade)
|
scripts.install("modoboa", config, args.upgrade, args.restore)
|
||||||
scripts.install("automx", config, args.upgrade)
|
scripts.install("automx", config, args.upgrade, args.restore)
|
||||||
scripts.install("radicale", config, args.upgrade)
|
scripts.install("radicale", config, args.upgrade, args.restore)
|
||||||
scripts.install("uwsgi", config, args.upgrade)
|
scripts.install("uwsgi", config, args.upgrade, args.restore)
|
||||||
scripts.install("nginx", config, args.upgrade)
|
scripts.install("nginx", config, args.upgrade, args.restore)
|
||||||
scripts.install("opendkim", config, args.upgrade)
|
scripts.install("opendkim", config, args.upgrade, args.restore)
|
||||||
scripts.install("postfix", config, args.upgrade)
|
scripts.install("postfix", config, args.upgrade, args.restore)
|
||||||
scripts.install("dovecot", config, args.upgrade)
|
scripts.install("dovecot", config, args.upgrade, args.restore)
|
||||||
system.restart_service("cron")
|
system.restart_service("cron")
|
||||||
package.backend.restore_system()
|
package.backend.restore_system()
|
||||||
|
if not args.restore:
|
||||||
utils.printcolor(
|
utils.printcolor(
|
||||||
"Congratulations! You can enjoy Modoboa at https://{} (admin:password)"
|
"Congratulations! You can enjoy Modoboa at https://{} (admin:password)"
|
||||||
.format(config.get("general", "hostname")),
|
.format(config.get("general", "hostname")),
|
||||||
utils.GREEN)
|
utils.GREEN)
|
||||||
|
else:
|
||||||
|
utils.printcolor(
|
||||||
|
"Resotre complete! You can enjoy Modoboa at https://{} (same credentials as before)"
|
||||||
|
.format(config.get("general", "hostname")),
|
||||||
|
utils.GREEN)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv[1:])
|
main(sys.argv[1:])
|
||||||
|
|||||||
Reference in New Issue
Block a user