From d48146cc47f847ce3117ff3b953dca1c8d35f407 Mon Sep 17 00:00:00 2001 From: Yuanhe Shu Date: Tue, 6 Dec 2022 12:00:17 +0800 Subject: [PATCH] leapp: add customrepo command Signed-off-by: Yuanhe Shu --- leapp-0006-add-customrepo-command.patch | 62 +++++++++++++++++++++++++ leapp.spec | 7 ++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 leapp-0006-add-customrepo-command.patch diff --git a/leapp-0006-add-customrepo-command.patch b/leapp-0006-add-customrepo-command.patch new file mode 100644 index 0000000..0699735 --- /dev/null +++ b/leapp-0006-add-customrepo-command.patch @@ -0,0 +1,62 @@ +diff -uNrp leapp-0.12.0.orig/leapp/cli/__init__.py leapp-0.12.0/leapp/cli/__init__.py +--- leapp-0.12.0.orig/leapp/cli/__init__.py 2022-12-06 11:51:30.985828197 +0800 ++++ leapp-0.12.0/leapp/cli/__init__.py 2022-12-06 11:53:49.434825034 +0800 +@@ -13,6 +13,6 @@ def cli(args): # noqa; pylint: disable=u + + def main(): + os.environ['LEAPP_HOSTNAME'] = socket.getfqdn() +- for cmd in [upgrade.list_runs, upgrade.preupgrade, upgrade.upgrade, upgrade.answer]: ++ for cmd in [upgrade.list_runs, upgrade.preupgrade, upgrade.upgrade, upgrade.answer, upgrade.customrepo]: + cli.command.add_sub(cmd.command) + cli.command.execute('leapp version {}'.format(VERSION)) +diff -uNrp leapp-0.12.0.orig/leapp/cli/upgrade/__init__.py leapp-0.12.0/leapp/cli/upgrade/__init__.py +--- leapp-0.12.0.orig/leapp/cli/upgrade/__init__.py 2022-12-06 11:51:30.985828197 +0800 ++++ leapp-0.12.0/leapp/cli/upgrade/__init__.py 2022-12-06 14:35:25.028388200 +0800 +@@ -18,7 +18,9 @@ from leapp.utils.clicmd import command, + from leapp.utils.output import (report_errors, report_info, beautify_actor_exception, report_unsupported, + report_inhibitors) + from leapp.utils.report import fetch_upgrade_report_messages, generate_report_file ++from leapp.libraries.stdlib import run + ++CUSTOM_REPO_PATH="/etc/leapp/files/leapp_upgrade_repositories.repo" + + def archive_logfiles(): + """ Archive log files from a previous run of Leapp """ +@@ -183,6 +185,21 @@ def process_whitelist_experimental(repos + raise CommandError(msg) + + ++def reset_repo_url(): ++ for repo_name in ['BaseOS', 'AppStream', 'PowerTools', 'HighAvailability', 'Plus', 'Extras']: ++ replace_url = 's#baseurl=.*/' + repo_name + '/#baseurl=https://mirrors.openanolis.cn/anolis/8/' + repo_name + '/#' ++ cmd = ['sed', '-i', replace_url, CUSTOM_REPO_PATH] ++ run(cmd) ++ ++ ++def set_custom_url(args): ++ url_str = ";".join(args.seturl) ++ for repo_name in ['BaseOS', 'AppStream', 'PowerTools', 'HighAvailability', 'Plus', 'Extras']: ++ replace_url = 's#baseurl=.*/' + repo_name + '/#baseurl=' + url_str + '/' + repo_name + '/#' ++ cmd = ['sed', '-i', replace_url, CUSTOM_REPO_PATH] ++ run(cmd) ++ ++ + @command('upgrade', help='Upgrade the current system to the next available major version.') + @command_opt('resume', is_flag=True, help='Continue the last execution after it was stopped (e.g. after reboot)') + @command_opt('reboot', is_flag=True, help='Automatically performs reboot when requested.') +@@ -341,3 +358,15 @@ def list_runs(args): # noqa; pylint: di + file=sys.stdout) + else: + raise CommandError('No previous run found!') ++ ++ ++@command('customrepo', help='Manage costom repo url to upgrade') ++@command_opt('seturl', action='append', metavar='repourl', ++ help='Set custom repo url, please make sure the url stars with http(s) and ends with explicit version number, example: https://mirrors.openanolis.cn/anolis/8/') ++@command_opt('reset', is_flag=True, ++ help='reset repo url to Anolis') ++def customrepo(args): ++ if args.reset: ++ reset_repo_url() ++ if args.seturl: ++ set_custom_url(args) diff --git a/leapp.spec b/leapp.spec index 5a2c2aa..2b96b05 100644 --- a/leapp.spec +++ b/leapp.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.4 +%define anolis_release .0.5 # IMPORTANT: this is for the leapp-framework capability (it's not the real # version of the leapp). The capability reflects changes in api and whatever # functionality important from the point of repository. In case of @@ -41,6 +41,7 @@ Patch0002: leapp-0002-add-command-no-rhsm_skip.patch Patch0003: leapp-0003-add-disablerepo-option-to-upgrade-kernel-to-RHCK.patch Patch0004: leapp-0004-report-a-default-external-link.patch Patch0005: 0005-SMC-progress-indicator.patch +Patch0006: leapp-0006-add-customrepo-command.patch %if !0%{?fedora} %if %{with python3} @@ -163,6 +164,7 @@ Python 3 leapp framework libraries. %patch0002 -p1 %patch0003 -p1 %patch0005 -p1 +%patch0006 -p1 ################################################## # Build @@ -283,6 +285,9 @@ rm -f %{buildroot}/%{_bindir}/leapp # no files here %changelog +* Tue Dec 6 2022 Yuanhe Shu 0.12.0-1.0.5 +- patch: add customrepo command + * Mon Nov 28 2022 Weisson - 0.12.0-1.0.4 - SMC progress indicator -- Gitee