From 64ba5eb5436bb63e2e55e259a8baf9381cce1e4b Mon Sep 17 00:00:00 2001 From: Spitfireap Date: Fri, 12 Apr 2024 16:12:36 +0200 Subject: [PATCH] Added checks on install --- .github/workflows/versioning.yml | 4 +++- checks.py | 33 ++++++++++++++++++++++++++++++++ run.py | 12 +++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 checks.py diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml index 837ef9e..9879f00 100644 --- a/.github/workflows/versioning.yml +++ b/.github/workflows/versioning.yml @@ -1,6 +1,8 @@ name: Update version file -on: push +on: + push: + branches: [ master ] jobs: update-version: diff --git a/checks.py b/checks.py new file mode 100644 index 0000000..8a52cc3 --- /dev/null +++ b/checks.py @@ -0,0 +1,33 @@ +"""Checks to be performed before any install or upgrade""" + +import sys +from urllib.request import urlopen + +from modoboa_installer import utils + + +def check_version(): + local_version = "" + with open("version.txt", "r") as version: + local_version = version.readline() + remote_version = "" + with urlopen("https://raw.githubusercontent.com/modoboa/modoboa-installer/master/version.txt") as r_version: + remote_version = r_version.read().decode() + if local_version == "" or remote_version == "": + utils.printcolor("Could not check that your installer is up to date: " + f"local version: {local_version}, " + f"remote version: {remote_version}", + utils.YELLOW) + if remote_version != local_version: + utils.error("Your installer seems outdated.\n" + "Check the README for instruction on how to update.\n" + "No support will be provided without an up to date installer!") + answer = utils.user_input("Continue anyway? (Y/n) ") + if not answer.lower().startswith("y"): + sys.exit(0) + else: + utils.success("Installer seems up to date!") + + +def handle(): + check_version() diff --git a/run.py b/run.py index 6ceeacf..36cde1f 100755 --- a/run.py +++ b/run.py @@ -11,6 +11,7 @@ except ImportError: import ConfigParser as configparser import sys +import checks from modoboa_installer import compatibility_matrix from modoboa_installer import constants from modoboa_installer import package @@ -168,7 +169,10 @@ def main(input_args): "--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( + "--skip-checks"; action="store_true", default=False, + help="Skip the checks the installer performs initially") parser.add_argument("domain", type=str, help="The main domain of your future mail server") args = parser.parse_args(input_args) @@ -189,6 +193,12 @@ def main(input_args): 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") + is_config_file_available, outdate_config = utils.check_config_file( args.configfile, args.interactive, args.upgrade, args.backup, is_restoring)