diff --git a/centos2anolis.py b/centos2anolis.py index bd9eb1ac4de1806a316dc3486be0c55517d4e2b7..564a66035fd12ad511436c3bb8218842baace3fd 100644 --- a/centos2anolis.py +++ b/centos2anolis.py @@ -307,6 +307,53 @@ def yum_remove_pkg(): subprocess.run("rpm -q libreport-plugin-mantisbt && yum -y remove libreport-plugin-mantisbt", shell=True) subprocess.run("rpm -q libreport-rhel-anaconda-bugzilla && yum -y remove libreport-rhel-anaconda-bugzilla", shell=True) +def get_version_from_rpm(string): + length = len(string) + release_pos = -1 + version = "" + for c in range(length-1, -1, -1): + if string[c] == '-': + if release_pos == -1: + release_pos = c + else: + version = string[c+1:release_pos] + if version != "": + break + + if version.find(':') != -1: + version = version.split(':')[1] + + return version + +def check_mysql(internal_ecs): + print('Checking mysql version') + mysql_install = False + try: + subprocess.check_call('rpm -q mysql-server', shell=True) + mysql_install = True + except: + pass + + if not mysql_install: + return + + install_pkg = subprocess.check_output('rpm -q mysql-server', shell=True).decode().split('\n')[0] + install_ver = get_version_from_rpm(install_pkg) + print("Get mysql version from anolis repos") + arch = platform.machine() + url = "http://mirrors.aliyun.com/anolis/8/AppStream/" + arch + "/os/" + if internal_ecs: + url = "http://mirrors.cloud.aliyuncs.com/anolis/8/AppStream/" + arch + "/os/" + cmd = 'repoquery --repofrompath=anolis-updates-test,' + url + ' --disablerepo=* --enablerepo=anolis-updates-test mysql-server --disable-modular-filtering -q' + repo_pkg = subprocess.check_output(cmd, shell=True).decode().split('\n')[0] + if len(repo_pkg) == 0: + return + repo_version = get_version_from_rpm(repo_pkg) + print("Install mysql version is " + install_ver + ", and anolis mysql version is " + repo_version) + if install_ver > repo_version: + print("Install mysql version is higher than anolis mysql version, cannnot migrate to anolis.") + sys.exit(1) + def main(reinstall_all_rpms=False, verify_all_rpms=False, accelerate=False, version=False): global reposdir @@ -476,6 +523,9 @@ def main(reinstall_all_rpms=False, verify_all_rpms=False, accelerate=False, vers print(err) pass + print("========= Start Check: mysql server =========") + check_mysql(internal_ecs) + print("========= Start converting =========") diff --git a/centos2anolis.spec b/centos2anolis.spec index 42530bb8d1418d9ccf800bc57f3fd9f665f2cc9d..2392d34a7eed03656f89d0f94f53bba0e173d524 100644 --- a/centos2anolis.spec +++ b/centos2anolis.spec @@ -1,6 +1,6 @@ Name: centos2anolis Version: 0.1 -Release: 3%{?dist} +Release: 4%{?dist} Summary: Transfer CentOS to Anolis. License: MIT @@ -37,6 +37,9 @@ install -m 755 %{SOURCE0} %{buildroot}/%{_sbindir} %changelog +* Fri Jan 28 2022 mgb0110571 - 0.1-4 +- Add mysql-server check + * Wed Jan 12 2021 mgb0110571 - 0.1-3 - handle 3rd-part repository files and try using an internal web address