Fixed capped default choice, removed old py2 code
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"""Utility functions."""
|
"""Utility functions."""
|
||||||
|
|
||||||
|
import configparser
|
||||||
import contextlib
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
import getpass
|
import getpass
|
||||||
@@ -13,10 +14,6 @@ import string
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
try:
|
|
||||||
import configparser
|
|
||||||
except ImportError:
|
|
||||||
import ConfigParser as configparser
|
|
||||||
|
|
||||||
from . import config_dict_template
|
from . import config_dict_template
|
||||||
from .compatibility_matrix import APP_INCOMPATIBILITY
|
from .compatibility_matrix import APP_INCOMPATIBILITY
|
||||||
@@ -35,11 +32,6 @@ class FatalError(Exception):
|
|||||||
|
|
||||||
def user_input(message):
|
def user_input(message):
|
||||||
"""Ask something to the user."""
|
"""Ask something to the user."""
|
||||||
try:
|
|
||||||
from builtins import input
|
|
||||||
except ImportError:
|
|
||||||
answer = raw_input(message)
|
|
||||||
else:
|
|
||||||
answer = input(message)
|
answer = input(message)
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
@@ -323,8 +315,8 @@ def validate(value, config_entry):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_entry_value(entry, interactive, config):
|
def get_entry_value(entry: dict, interactive: bool, config: configparser.ConfigParser) -> string:
|
||||||
default_entry = entry("default")
|
default_entry = entry["default"]
|
||||||
if type(default_entry) is type(list()):
|
if type(default_entry) is type(list()):
|
||||||
default_value = check_if_condition(config, default_entry)
|
default_value = check_if_condition(config, default_entry)
|
||||||
if callable(default_entry):
|
if callable(default_entry):
|
||||||
@@ -481,7 +473,7 @@ def validate_backup_path(path: str, silent_mode: bool):
|
|||||||
if not path_exists:
|
if not path_exists:
|
||||||
if not silent_mode:
|
if not silent_mode:
|
||||||
create_dir = input(
|
create_dir = input(
|
||||||
f"\"{path}\" doesn't exist, would you like to create it? [Y/n]\n"
|
f"\"{path}\" doesn't exist, would you like to create it? [y/N]\n"
|
||||||
).lower()
|
).lower()
|
||||||
|
|
||||||
if silent_mode or (not silent_mode and create_dir.startswith("y")):
|
if silent_mode or (not silent_mode and create_dir.startswith("y")):
|
||||||
@@ -496,7 +488,7 @@ def validate_backup_path(path: str, silent_mode: bool):
|
|||||||
if len(os.listdir(path)) != 0:
|
if len(os.listdir(path)) != 0:
|
||||||
if not silent_mode:
|
if not silent_mode:
|
||||||
delete_dir = input(
|
delete_dir = input(
|
||||||
"Warning: backup directory is not empty, it will be purged if you continue... [Y/n]\n").lower()
|
"Warning: backup directory is not empty, it will be purged if you continue... [y/N]\n").lower()
|
||||||
|
|
||||||
if silent_mode or (not silent_mode and delete_dir.startswith("y")):
|
if silent_mode or (not silent_mode and delete_dir.startswith("y")):
|
||||||
try:
|
try:
|
||||||
|
|||||||
47
run.py
47
run.py
@@ -11,7 +11,6 @@ except ImportError:
|
|||||||
import ConfigParser as configparser
|
import ConfigParser as configparser
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import checks
|
|
||||||
from modoboa_installer import compatibility_matrix
|
from modoboa_installer import compatibility_matrix
|
||||||
from modoboa_installer import constants
|
from modoboa_installer import constants
|
||||||
from modoboa_installer import package
|
from modoboa_installer import package
|
||||||
@@ -37,12 +36,6 @@ PRIMARY_APPS = [
|
|||||||
def installation_disclaimer(args, config):
|
def installation_disclaimer(args, config):
|
||||||
"""Display installation disclaimer."""
|
"""Display installation disclaimer."""
|
||||||
hostname = config.get("general", "hostname")
|
hostname = config.get("general", "hostname")
|
||||||
utils.printcolor(
|
|
||||||
"Notice:\n"
|
|
||||||
"It is recommanded to run this installer on a FRESHLY installed server.\n"
|
|
||||||
"(ie. with nothing special already installed on it)\n",
|
|
||||||
utils.CYAN
|
|
||||||
)
|
|
||||||
utils.printcolor(
|
utils.printcolor(
|
||||||
"Warning:\n"
|
"Warning:\n"
|
||||||
"Before you start the installation, please make sure the following "
|
"Before you start the installation, please make sure the following "
|
||||||
@@ -53,7 +46,7 @@ def installation_disclaimer(args, config):
|
|||||||
hostname.replace(".{}".format(args.domain), ""),
|
hostname.replace(".{}".format(args.domain), ""),
|
||||||
hostname
|
hostname
|
||||||
),
|
),
|
||||||
utils.YELLOW
|
utils.CYAN
|
||||||
)
|
)
|
||||||
utils.printcolor(
|
utils.printcolor(
|
||||||
"Your mail server will be installed with the following components:",
|
"Your mail server will be installed with the following components:",
|
||||||
@@ -119,9 +112,6 @@ def backup_system(config, args):
|
|||||||
utils.copy_file(args.configfile, backup_path)
|
utils.copy_file(args.configfile, backup_path)
|
||||||
# Backup applications
|
# Backup applications
|
||||||
for app in PRIMARY_APPS:
|
for app in PRIMARY_APPS:
|
||||||
if app == "dovecot" and args.no_mail:
|
|
||||||
utils.printcolor("Skipping mail backup", utils.BLUE)
|
|
||||||
continue
|
|
||||||
scripts.backup(app, config, backup_path)
|
scripts.backup(app, config, backup_path)
|
||||||
|
|
||||||
|
|
||||||
@@ -173,17 +163,11 @@ def main(input_args):
|
|||||||
help="For script usage, do not require user interaction "
|
help="For script usage, do not require user interaction "
|
||||||
"backup will be saved at ./modoboa_backup/Backup_M_Y_d_H_M "
|
"backup will be saved at ./modoboa_backup/Backup_M_Y_d_H_M "
|
||||||
"if --backup-path is not provided")
|
"if --backup-path is not provided")
|
||||||
parser.add_argument(
|
|
||||||
"--no-mail", action="store_true", default=False,
|
|
||||||
help="Disable mail backup (save space)")
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--restore", type=str, metavar="path",
|
"--restore", type=str, metavar="path",
|
||||||
help="Restore a previously backup up modoboa instance on a NEW machine. "
|
help="Restore a previously backup up modoboa instance on a NEW machine. "
|
||||||
"You MUST provide backup directory"
|
"You MUST provide backup directory"
|
||||||
),
|
)
|
||||||
parser.add_argument(
|
|
||||||
"--skip-checks", action="store_true", default=False,
|
|
||||||
help="Skip the checks the installer performs initially")
|
|
||||||
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)
|
||||||
@@ -204,12 +188,6 @@ def main(input_args):
|
|||||||
|
|
||||||
utils.success("Welcome to Modoboa installer!\n")
|
utils.success("Welcome to Modoboa installer!\n")
|
||||||
|
|
||||||
# Checks
|
|
||||||
if not args.skip_checks:
|
|
||||||
utils.printcolor("Checking the installer...", utils.BLUE)
|
|
||||||
checks.handle()
|
|
||||||
utils.success("Checks complete\n")
|
|
||||||
|
|
||||||
is_config_file_available, outdate_config = utils.check_config_file(
|
is_config_file_available, outdate_config = utils.check_config_file(
|
||||||
args.configfile, args.interactive, args.upgrade, args.backup, is_restoring)
|
args.configfile, args.interactive, args.upgrade, args.backup, is_restoring)
|
||||||
|
|
||||||
@@ -221,12 +199,12 @@ def main(input_args):
|
|||||||
# Check if config is outdated and ask user if it needs to be updated
|
# Check if config is outdated and ask user if it needs to be updated
|
||||||
if is_config_file_available and outdate_config:
|
if is_config_file_available and outdate_config:
|
||||||
answer = utils.user_input("It seems that your config file is outdated. "
|
answer = utils.user_input("It seems that your config file is outdated. "
|
||||||
"Would you like to update it? (Y/n) ")
|
"Would you like to update it? (y/N) ")
|
||||||
if not answer or answer.lower().startswith("y"):
|
if answer.lower().startswith("y"):
|
||||||
config_file_update_complete(utils.update_config(args.configfile))
|
config_file_update_complete(utils.update_config(args.configfile))
|
||||||
if not args.stop_after_configfile_check:
|
if not args.stop_after_configfile_check:
|
||||||
answer = utils.user_input("Would you like to stop to review the updated config? (Y/n)")
|
answer = utils.user_input("Would you like to stop to review the updated config? (y/N)")
|
||||||
if not answer or answer.lower().startswith("y"):
|
if answer.lower().startswith("y"):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
utils.error("You might encounter unexpected errors ! "
|
utils.error("You might encounter unexpected errors ! "
|
||||||
@@ -300,19 +278,6 @@ def main(input_args):
|
|||||||
"Restore complete! You can enjoy Modoboa at https://{} (same credentials as before)"
|
"Restore complete! You can enjoy Modoboa at https://{} (same credentials as before)"
|
||||||
.format(config.get("general", "hostname"))
|
.format(config.get("general", "hostname"))
|
||||||
)
|
)
|
||||||
utils.success(
|
|
||||||
"\n"
|
|
||||||
"Modoboa is a free software maintained by volunteers.\n"
|
|
||||||
"You like the project and want it to be sustainable?\n"
|
|
||||||
"Then don't wait anymore and go sponsor it here:\n"
|
|
||||||
)
|
|
||||||
utils.printcolor(
|
|
||||||
"https://github.com/sponsors/modoboa\n",
|
|
||||||
utils.YELLOW
|
|
||||||
)
|
|
||||||
utils.success(
|
|
||||||
"Thank you for your help :-)\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user