diff --git a/centos2anolis.py b/centos2anolis.py index 94c2f9898765f6f6dba3ce6626a7c6a0502a1b7c..0e9cd698c63b1798fe35f0f76d22907f7cbe9970 100644 --- a/centos2anolis.py +++ b/centos2anolis.py @@ -13,9 +13,10 @@ import sys import shutil import argparse import platform +import urllib.request yum_url="https://mirrors.openanolis.org/anolis/" -github_url="http://codeup.openanolis.cn/codeup/migration/centos2anolis" +github_url="https://gitee.com/anolis/centos2anolis" repostr_an7 = '''[an7_os] name=AnolisOS-7 - OS baseurl=http://mirrors.openanolis.org/anolis/7/os/$basearch/os @@ -441,6 +442,14 @@ def main(reinstall_all_rpms=False, verify_all_rpms=False, accelerate=False, vers print("Could not locate your repository directory.") sys.exit(1) + print("Backing up and removing old repository files...") + old_version = backup_repofiles(old_version) + + + print("Backing up and removing 3rd-part repository files...") + subprocess.run("mkdir /etc/yum.repos.d/migration-bak", shell=True) + subprocess.run("mv $(find /etc/yum.repos.d/*.repo) /etc/yum.repos.d/migration-bak", shell=True) + repofile = os.path.join(reposdir, 'switch-to-anolis.repo') with open(repofile, 'w') as f: if centosversion == 7: @@ -451,10 +460,22 @@ def main(reinstall_all_rpms=False, verify_all_rpms=False, accelerate=False, vers if accelerate: change_repo_mirror(reposdir, 'switch-to-anolis.repo') + print("check network environment") + dst_url = "http://mirrors.cloud.aliyuncs.com" + internal_ecs = False + try: + dst_status = urllib.request.urlopen(dst_url, timeout=5).code + internal_ecs = True + subprocess.run('sed -i \'s/mirrors.openanolis.org/mirrors.cloud.aliyuncs.com/g\' /etc/yum.repos.d/switch-to-anolis.repo', shell=True) + subprocess.run('sed -i \'s/mirrors.openanolis.cn/mirrors.cloud.aliyuncs.com/g\' /etc/yum.repos.d/switch-to-anolis.repo', shell=True) + subprocess.run('sed -i \'s/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g\' /etc/yum.repos.d/switch-to-anolis.repo', shell=True) + print("check internal network environment is True") + except Exception as err: + print(err) + pass + print("========= Start converting =========") - print("Backing up and removing old repository files...") - old_version = backup_repofiles(old_version) print("Removing CentOS-specific yum configuration from /etc/yum.conf ...") with open('/etc/yum.conf', 'r') as f: @@ -494,6 +515,11 @@ def main(reinstall_all_rpms=False, verify_all_rpms=False, accelerate=False, vers if accelerate: change_repo_mirror(reposdir, 'AnolisOS-') + if internal_ecs: + subprocess.run('sed -i \'s/mirrors.openanolis.cn/mirrors.cloud.aliyuncs.com/g\' /etc/yum.repos.d/*.repo', shell=True) + subprocess.run('sed -i \'s/mirrors.openanolis.org/mirrors.cloud.aliyuncs.com/g\' /etc/yum.repos.d/*.repo', shell=True) + subprocess.run('sed -i \'s/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g\' /etc/yum.repos.d/*.repo', shell=True) + print("Installing base packages for Anolis OS...") subprocess.run('yum clean all', shell=True) cmd = 'yum shell -y < - 0.1-3 +- handle 3rd-part repository files and try using an internal web address + * Wed Jan 05 2022 Chunmei Xu - 0.1-2 - add check for i686 packages