From 0ba3bfe4fd0c11f403c08cfabd710bfa5ca2c38a Mon Sep 17 00:00:00 2001 From: Huijing Hei Date: Wed, 18 May 2022 10:45:46 +0800 Subject: [PATCH] Teach --karg-delete option to ostree admin deploy See https://github.com/ostreedev/ostree/issues/2586 --- src/ostree/ot-admin-builtin-deploy.c | 22 +++++++++++++++++++++- tests/test-admin-deploy-karg.sh | 12 +++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index d4743890..6691053b 100644 --- a/src/ostree/ot-admin-builtin-deploy.c +++ b/src/ostree/ot-admin-builtin-deploy.c @@ -41,6 +41,7 @@ static gboolean opt_no_prune; static gboolean opt_no_merge; static char **opt_kernel_argv; static char **opt_kernel_argv_append; +static char *opt_kernel_argv_delete; static gboolean opt_kernel_proc_cmdline; static char *opt_osname; static char *opt_origin_path; @@ -62,6 +63,7 @@ static GOptionEntry options[] = { { "karg", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv, "Set kernel argument, like root=/dev/sda1; this overrides any earlier argument with the same name", "NAME=VALUE" }, { "karg-append", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv_append, "Append kernel argument; useful with e.g. console= that can be used multiple times", "NAME=VALUE" }, { "karg-none", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_arg_none, "Do not import kernel arguments", NULL }, + { "karg-delete", 0, 0, G_OPTION_ARG_STRING, &opt_kernel_argv_delete, "Delete kernel argument if exists", "NAME=VALUE" }, { "overlay-initrd", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_overlay_initrds, "Overlay iniramfs file", "FILE" }, { NULL } }; @@ -90,6 +92,18 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat return FALSE; } + if (opt_kernel_arg_none && opt_kernel_argv_delete) + { + ot_util_usage_error (context, "Can't specify both --karg-none and --karg-delete", error); + return FALSE; + } + + if (opt_no_merge && opt_kernel_argv_delete) + { + ot_util_usage_error (context, "Can't specify both --no-merge and --karg-delete", error); + return FALSE; + } + const char *refspec = argv[1]; OstreeRepo *repo = ostree_sysroot_repo (sysroot); @@ -145,7 +159,7 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat if (!ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error)) return FALSE; } - else if (merge_deployment && (opt_kernel_argv || opt_kernel_argv_append)) + else if (merge_deployment && (opt_kernel_argv || opt_kernel_argv_append || opt_kernel_argv_delete)) { OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (merge_deployment); g_auto(GStrv) previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); @@ -171,6 +185,12 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat ostree_kernel_args_append_argv (kargs, opt_kernel_argv_append); } + if (opt_kernel_argv_delete) + { + if (!ostree_kernel_args_delete (kargs, opt_kernel_argv_delete, error)) + return FALSE; + } + g_autoptr(GPtrArray) overlay_initrd_chksums = NULL; for (char **it = opt_overlay_initrds; it && *it; it++) { diff --git a/tests/test-admin-deploy-karg.sh b/tests/test-admin-deploy-karg.sh index 8667231b..047ca63b 100755 --- a/tests/test-admin-deploy-karg.sh +++ b/tests/test-admin-deploy-karg.sh @@ -24,7 +24,7 @@ set -euo pipefail # Exports OSTREE_SYSROOT so --sysroot not needed. setup_os_repository "archive" "syslinux" -echo "1..3" +echo "1..4" ${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmain/x86_64-runtime rev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmain/x86_64-runtime) @@ -69,3 +69,13 @@ ${CMD_PREFIX} ostree admin deploy --os=testos --karg-append=FOO=TESTORDERED --k assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*APPENDARG=VALAPPEND .*APPENDARG=2NDAPPEND .*FOO=TESTORDERED .*APPENDARG=3RDAPPEND' echo "ok deploy --karg-append" + +assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*quiet .*TESTARG=TESTVALUE .*APPENDARG=VALAPPEND .*APPENDARG=2NDAPPEND' +${CMD_PREFIX} ostree admin deploy --os=testos --karg-delete=TESTARG=TESTVALUE testos:testos/buildmain/x86_64-runtime +assert_not_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*TESTARG=TESTVALUE' +${CMD_PREFIX} ostree admin deploy --os=testos --karg-delete=quiet testos:testos/buildmain/x86_64-runtime +assert_not_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*quiet' +${CMD_PREFIX} ostree admin deploy --os=testos --karg-delete=APPENDARG=VALAPPEND testos:testos/buildmain/x86_64-runtime +assert_not_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*APPENDARG=VALAPPEND' + +echo "ok deploy --karg-delete"