|
| 1 | +/* |
| 2 | + * Copyright (C) 2015 Colin Walters <[email protected]> |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LGPL-2.0+ |
| 5 | + * |
| 6 | + * This library is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 2 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This library is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public |
| 17 | + * License along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +#include "config.h" |
| 21 | + |
| 22 | +#include "ot-admin-builtins.h" |
| 23 | +#include "ot-admin-functions.h" |
| 24 | +#include "otutil.h" |
| 25 | + |
| 26 | +static char **opt_set; |
| 27 | +static char **opt_get; |
| 28 | + |
| 29 | +static GOptionEntry options[] |
| 30 | + = { { "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, |
| 31 | + "Set deployment metadata, like DATE=030424; this overrides any metadata with the " |
| 32 | + "same name", |
| 33 | + "KEY=VALUE" }, |
| 34 | + { "get", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_get, |
| 35 | + "Get the value of a deployment metadata.", "KEY" }, |
| 36 | + { NULL } }; |
| 37 | + |
| 38 | +gboolean |
| 39 | +ot_admin_builtin_metadata (int argc, char **argv, OstreeCommandInvocation *invocation, |
| 40 | + GCancellable *cancellable, GError **error) |
| 41 | +{ |
| 42 | + gboolean ret = FALSE; |
| 43 | + g_autoptr (GPtrArray) deployments = NULL; |
| 44 | + OstreeDeployment *first_deployment = NULL; |
| 45 | + g_autoptr (GOptionContext) context = NULL; |
| 46 | + g_autoptr (OstreeSysroot) sysroot = NULL; |
| 47 | + |
| 48 | + if (!ostree_admin_option_context_parse (context, options, &argc, &argv, |
| 49 | + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, |
| 50 | + cancellable, error)) |
| 51 | + goto out; |
| 52 | + |
| 53 | + if (deployments->len == 0) |
| 54 | + { |
| 55 | + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find a deployment in sysroot"); |
| 56 | + goto out; |
| 57 | + } |
| 58 | + |
| 59 | + first_deployment = deployments->pdata[0]; |
| 60 | + |
| 61 | + if (opt_set) |
| 62 | + { |
| 63 | + char *key = strtok(*opt_set, "="); |
| 64 | + char *value = strtok(NULL, "="); |
| 65 | + // ^^ This needs error checking and probably is wrong... but builds! |
| 66 | + ostree_deployment_set_ext_metadata(first_deployment, key, value, error); |
| 67 | + } |
| 68 | + |
| 69 | + if (opt_get) |
| 70 | + { |
| 71 | + ostree_deployment_get_ext_metadata (first_deployment, *opt_get, error); |
| 72 | + } |
| 73 | + |
| 74 | + ret = TRUE; |
| 75 | +out: |
| 76 | + return ret; |
| 77 | +} |
0 commit comments