From bcce348e1bbc9957ad34cde6ca3a5bb894a3e4c4 Mon Sep 17 00:00:00 2001 From: Mario Alfredo Carrillo Arevalo Date: Fri, 13 Jan 2017 12:04:42 -0600 Subject: [PATCH] Add new bundle-list sub-command This is a new sub-command for swupd called "bundle-list", this command will show which bundles are installed in the local system. This information is obtained reading /usr/share/clear/bundles path in local filesystem. Signed-off-by: Mario Alfredo Carrillo Arevalo --- Makefile.am | 2 ++ include/swupd-internal.h | 1 + src/clr_bundle_ls.c | 64 ++++++++++++++++++++++++++++++++++++++++ src/swupd.c | 1 + 4 files changed, 68 insertions(+) create mode 100644 src/clr_bundle_ls.c diff --git a/Makefile.am b/Makefile.am index faeffdcb..3378d107 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,7 @@ swupd_SOURCES = \ $(swupd_verify_SOURCES) \ $(clr_bundle_add_SOURCES) \ $(clr_bundle_rm_SOURCES) \ + $(clr_bundle_ls_SOURCES) \ $(swupd_search_SOURCES) check_PROGRAMS = \ @@ -65,6 +66,7 @@ swupd_search_SOURCES = src/search.c clr_bundle_add_SOURCES = src/clr_bundle_add.c clr_bundle_rm_SOURCES = src/clr_bundle_rm.c +clr_bundle_ls_SOURCES = src/clr_bundle_ls.c swupd_hashdump_SOURCES = src/hashdump.c diff --git a/include/swupd-internal.h b/include/swupd-internal.h index c67e3934..a88f9503 100644 --- a/include/swupd-internal.h +++ b/include/swupd-internal.h @@ -3,6 +3,7 @@ extern int bundle_add_main(int argc, char **argv); extern int bundle_remove_main(int argc, char **argv); +extern int bundle_list_main(int argc, char **argv); extern int hashdump_main(int argc, char **argv); extern int update_main(int argc, char **argv); extern int verify_main(int argc, char **argv); diff --git a/src/clr_bundle_ls.c b/src/clr_bundle_ls.c new file mode 100644 index 00000000..f44f7e47 --- /dev/null +++ b/src/clr_bundle_ls.c @@ -0,0 +1,64 @@ +/* + * Software Updater - client side + * + * Copyright © 2012-2016 Intel Corporation. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 or later of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: + * Mario Alfredo Carrillo Arevalo + * Jaime A. Garcia + */ + +#define _GNU_SOURCE +#include "swupd.h" +#include "config.h" + +int bundle_list_main(int argc, char **argv) +{ + int current_version; + int lock_fd; + int ret; + struct list *list_bundles = NULL; + struct list *item = NULL; + + copyright_header("bundle list"); + + ret = swupd_init(&lock_fd); + if (ret != 0) { + printf("Error: Failed updater initialization. Exiting now\n"); + return ret; + } + + current_version = get_current_version(path_prefix); + if (current_version < 0) { + printf("Error: Unable to determine current OS version\n"); + v_lockfile(lock_fd); + return ECURRENT_VERSION; + } + + read_local_bundles(&list_bundles); + + item = list_head(list_bundles); + + while (item) { + printf("%s\n", (char *)item->data); + item = item->next; + } + + printf("Current OS version: %d\n", current_version); + + list_free_list(list_bundles); + + return ret; +} diff --git a/src/swupd.c b/src/swupd.c index 85d61778..c3eea076 100644 --- a/src/swupd.c +++ b/src/swupd.c @@ -36,6 +36,7 @@ struct subcmd { static struct subcmd commands[] = { { "bundle-add", "Install a new bundle", bundle_add_main }, { "bundle-remove", "Uninstall a bundle", bundle_remove_main }, + { "bundle-list", "List installed bundles", bundle_list_main }, { "hashdump", "Dumps the HMAC hash of a file", hashdump_main }, { "update", "Update to latest OS version", update_main }, { "verify", "Verify content for OS version", verify_main },