From 9a62f2bc5e113bff13cce60e576f5e9bc5c4f0b1 Mon Sep 17 00:00:00 2001 From: shim_ <> Date: Thu, 4 Oct 2018 16:30:46 +0200 Subject: [PATCH] handle existing install --- scripts/upgrade.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade.py b/scripts/upgrade.py index 82cc1cc..5d649a0 100755 --- a/scripts/upgrade.py +++ b/scripts/upgrade.py @@ -37,6 +37,14 @@ def list_command(page="https://www.seafile.com/en/download/"): def current_version_command(): print(current_version()) +def installed_versions(): + installed = [] + for f in os.listdir(seaf_home): + m = re.findall(version_re,f) + if len(m) > 0: + installed.append(m[0]) + return installed + def current_version(): current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest")) res = re.findall(version_re,current) @@ -80,6 +88,7 @@ def install_command(url): if not os.path.exists(dest): shutil.move(os.path.join(tmp,f), dest) else: + shutil.rmtree(tmp) print("Found previous installation, resuming setup") current = current_version() target_version = ''.join(re.findall(version_re,dest)) @@ -87,7 +96,7 @@ def install_command(url): else: current = "0.0.0" print("Upgrading from: %s -> %s" % (current, target_version)) perform_upgrade_command(target_version,mysql=("SEAF_MYSQL" in os.environ and os.environ["SEAF_MYSQL"])) - if len(os.listdir(tmp)) != 0: + if os.exists(tmp) and len(os.listdir(tmp)) != 0: print("Failed to unpack update") os.rmdir(tmp) return 1 @@ -106,6 +115,8 @@ def main_command(version="latest",page="https://www.seafile.com/en/download/"): if version_int(current_version()) == version_int(version): print("%s(%s) is already installed" % (version,version_int(version))) return 1 + if version in installed_versions(): + return perform_upgrade_command(version) if install: print("Installing: %s" % version) return install_command(install)