From a64c9b83e4d559ce5d612bdfc60636d843f015ad Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Mon, 28 Nov 2016 17:06:28 +0800 Subject: [PATCH] Add a version stamp file seafile-data/current_version. --- scripts/bootstrap.py | 7 ++++++- scripts/utils/__init__.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index 971a511..a2ea919 100755 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -18,7 +18,7 @@ import time from utils import ( call, get_conf, get_install_dir, show_progress, get_script, render_template, get_seafile_version, eprint, - cert_has_valid_days + cert_has_valid_days, get_version_stamp_file, update_version_stamp ) seafile_version = get_seafile_version() @@ -117,7 +117,10 @@ def do_parse_ports(): sys.stdout.flush() def init_seafile_server(): + version_stamp_file = get_version_stamp_file() if exists(join(shared_seafiledir, 'seafile-data')): + if not exists(version_stamp_file): + update_version_stamp(version_stamp_file, os.environ['SEAFILE_VERSION']) show_progress('Skip running setup-seafile-mysql.py because there is existing seafile-data folder.') return @@ -153,6 +156,8 @@ def init_seafile_server(): if not exists(dst) and exists(src): shutil.move(src, shared_seafiledir) + update_version_stamp(version_stamp_file, os.environ['SEAFILE_VERSION']) + def main(): args = parse_args() if args.parse_ports: diff --git a/scripts/utils/__init__.py b/scripts/utils/__init__.py index 6866318..fc4eab8 100644 --- a/scripts/utils/__init__.py +++ b/scripts/utils/__init__.py @@ -247,3 +247,15 @@ def cert_has_valid_days(cert, days): secs = 86400 * int(days) retcode = call('openssl x509 -checkend {} -noout -in {}'.format(secs, cert), check_call=False) return retcode == 0 + +def get_version_stamp_file(): + return '/shared/seafile/seafile-data/current_version' + +def read_version_stamp(fn): + assert exists(fn), 'version stamp file {} does not exist!'.format(fn) + with open(fn, 'r') as fp: + return fp.read().strip() + +def update_version_stamp(fn, version): + with open(fn, 'w') as fp: + fp.write(version + '\n')