diff --git a/README.md b/README.md index 9f3e2f02248046abe4bac0479acf4ef917bf4649..548f29849599776d4aa761b2084fd13391168a10 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,13 @@ 该选项会在用户自定义json文件路径下创建文件,不使用该选项则创建默认文件`/var/log/centostoanolis.json`。 +* `-l` 离线迁移 + + 在无法接入到mirrors.openanolis.org 或 mirrors.aliyun.com时,使用本地源迁移系统。 + + 在运行工具之前,编辑Anolis仓库的repo文件:/etc/yum.repos.d/switch-to-anolis.repo + + ## 问题反馈 任何问题,需求或者疑问,都可以在[bugzilla.openanolis.cn][1]上提交。 diff --git a/centos2anolis.py b/centos2anolis.py index 8718d96f071f46aa591035da2f2a94c44c85df7e..53302763b5732cb6fef6a1daed58d12caaa937ce 100644 --- a/centos2anolis.py +++ b/centos2anolis.py @@ -666,7 +666,7 @@ def download_anolis_release(): update_json_info() clean_and_exit() -def switch_release_pkgs(): +def switch_release_pkgs(local_flag): log_it(logging.INFO, "Switching old release package with Anolis OS...", True) dst_rpms = [s + '*.rpm' for s in dst_release] subprocess.run('rpm -i --force ' + ' '.join(dst_rpms) + ' --nodeps', shell=True) @@ -674,7 +674,10 @@ def switch_release_pkgs(): subprocess.run('rpm -e --nodeps ' + old_release_pkg, shell=True) else: subprocess.run('rpm -e --nodeps ' + old_release_pkg + ' centos-gpg-keys', shell=True) - os.remove(os.path.join(reposdir, 'switch-to-anolis.repo')) + if not local_flag: + os.remove(os.path.join(reposdir, 'switch-to-anolis.repo')) + else: + local_disabled_release_repo() def optimise_repofile(accelerate): log_it(logging.INFO, "optimise repofile", True) @@ -838,7 +841,42 @@ def update_json_info(info=False): with open("/var/log/centostoanolis.json", "w") as f: json.dump(jd,f) -def main(verify_all_rpms=False, accelerate=False, version=False, continue_after_sync=False, custom_log_dir = False, custom_json_file=False): + +def local_disabled_release_repo(): + path = '/etc/yum.repos.d' + if os.path.exists(path): + file_list = os.listdir(path) + for file in file_list: + fpath = os.path.join(path, file) + if os.path.isdir(fpath): + continue + else: + if re.fullmatch('switch-to-anolis.repo', file, re.IGNORECASE): + continue + elif not re.search('repo$', file, re.IGNORECASE): + continue + with open(fpath, 'r') as fdst: + allrepo = fdst.read() + fdst.close() + with open(fpath + '.disabled', 'w+') as fdsta: + fdsta.write( + '#This is a yum repository file that was disabled . \n' + allrepo) + fdsta.close() + os.remove(fpath) + + +def check_local_repo(localrepo): + if not localrepo: + return + repopath = '/etc/yum.repos.d/switch-to-anolis.repo' + if os.path.exists(repopath): + local_disabled_release_repo() + return + else: + log_it(logging.ERROR, "Please write the file of the anolis repository: /etc/yum.repos.d/switch-to-anolis.repo") + sys.exit(1) + +def main(verify_all_rpms=False, accelerate=False, version=False, continue_after_sync=False, custom_log_dir = False, custom_json_file=False, local_repo=False): global jd global jsoncount global custom_json_file1 @@ -847,6 +885,7 @@ def main(verify_all_rpms=False, accelerate=False, version=False, continue_after_ custom_json_file1=custom_json_file log_it(logging.INFO, "====== Start ======") check_user() + check_local_repo(local_repo) get_current_version(continue_after_sync) if not continue_after_sync: try: @@ -861,12 +900,13 @@ def main(verify_all_rpms=False, accelerate=False, version=False, continue_after_ check_yumdownloader() check_mysql(version) check_repodir() - backup_repofiles() - process_third_repos() - write_switch_repo(accelerate) + if not local_repo: + backup_repofiles() + process_third_repos() + write_switch_repo(accelerate) modify_yum_conf() download_anolis_release() - switch_release_pkgs() + switch_release_pkgs(local_repo) optimise_repofile(accelerate) install_base_pkgs() process_pkgs_for_c7() @@ -900,7 +940,8 @@ if __name__ == "__main__": parser.add_argument('-c', action='store_true', help='Continue to migration after distro-sync') parser.add_argument('--log_dir', help='Set Custom log directory') parser.add_argument('--progress_file', help='Set Custom json file') + parser.add_argument('-l', action='store_true', help='Select the local repo file') args = parser.parse_args() - sys.exit(main(args.V, args.s, args.v, args.c, args.log_dir, args.progress_file)) + sys.exit(main(args.V, args.s, args.v, args.c, args.log_dir, args.progress_file, args.l)) diff --git a/centos2anolis.spec b/centos2anolis.spec index 55a35ca0cf6d35fe3d3c3fa19fcb6911f3b28792..02a37faafb8bf57a27808d051ae5a6c1756a8f07 100644 --- a/centos2anolis.spec +++ b/centos2anolis.spec @@ -1,4 +1,4 @@ -%define anolis_release 5 +%define anolis_release 6 Name: centos2anolis Version: 0.1 @@ -39,6 +39,9 @@ install -m 755 %{SOURCE0} %{buildroot}/%{_sbindir} %changelog +* Thu May 26 2022 XueZhixin - 0.1-6 +- Add offline migration + * Thu May 26 2022 mgb0110571 - 0.1-5 - add custom log path - add custom json file