-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This command allows to list repositories it takes 3 arguemnts: -l: only list the repository names -e: show only enabled ones (by default all repositories are shown) -d: show only disabled ones (by default all repositories are shown) if -d and -e are provided all the repositories are shown Fixes: #2134
- Loading branch information
Showing
5 changed files
with
164 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ SRCS= add.c \ | |
query.c \ | ||
register.c \ | ||
repo.c \ | ||
repositories.c \ | ||
rquery.c \ | ||
search.c \ | ||
set.c \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,12 @@ | ||
/*- | ||
* Copyright (c) 2011-2013 Baptiste Daroussin <[email protected]> | ||
* Copyright (c) 2011-2024 Baptiste Daroussin <[email protected]> | ||
* Copyright (c) 2011-2012 Julien Laffaye <[email protected]> | ||
* Copyright (c) 2011 Will Andrews <[email protected]> | ||
* Copyright (c) 2011-2012 Marin Atanasov Nikolov <[email protected]> | ||
* Copyright (c) 2014-2015 Matthew Seaman <[email protected]> | ||
* Copyright (c) 2014 Vsevolod Stakhov <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer | ||
* in this position and unchanged. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
|
@@ -100,6 +80,7 @@ static struct commands { | |
{ "register", "Registers a package into the local database", exec_register, usage_register}, | ||
{ "remove", "Deletes packages from the database and the system", exec_delete, usage_delete}, | ||
{ "repo", "Creates a package repository catalogue", exec_repo, usage_repo}, | ||
{ "repositories", "Show repositories informations", exec_repositories, usage_repositories}, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
{ "rquery", "Queries information in repository catalogues", exec_rquery, usage_rquery}, | ||
{ "search", "Performs a search of package repository catalogues", exec_search, usage_search}, | ||
{ "set", "Modifies information about packages in the local database", exec_set, usage_set}, | ||
|
@@ -302,64 +283,11 @@ show_plugin_info(void) | |
static void | ||
show_repository_info(void) | ||
{ | ||
const char *mirror, *sig; | ||
struct pkg_repo *repo = NULL; | ||
|
||
printf("\nRepositories:\n"); | ||
while (pkg_repos(&repo) == EPKG_OK) { | ||
switch (pkg_repo_mirror_type(repo)) { | ||
case SRV: | ||
mirror = "SRV"; | ||
break; | ||
case HTTP: | ||
mirror = "HTTP"; | ||
break; | ||
case NOMIRROR: | ||
mirror = "NONE"; | ||
break; | ||
default: | ||
mirror = "-unknown-"; | ||
break; | ||
} | ||
switch (pkg_repo_signature_type(repo)) { | ||
case SIG_PUBKEY: | ||
sig = "PUBKEY"; | ||
break; | ||
case SIG_FINGERPRINT: | ||
sig = "FINGERPRINTS"; | ||
break; | ||
case SIG_NONE: | ||
sig = "NONE"; | ||
break; | ||
default: | ||
sig = "-unknown-"; | ||
break; | ||
} | ||
|
||
printf(" %s: { \n %-16s: \"%s\",\n %-16s: %s,\n" | ||
" %-16s: %u", | ||
pkg_repo_name(repo), | ||
"url", pkg_repo_url(repo), | ||
"enabled", pkg_repo_enabled(repo) ? "yes" : "no", | ||
"priority", pkg_repo_priority(repo)); | ||
|
||
if (pkg_repo_mirror_type(repo) != NOMIRROR) | ||
printf(",\n %-16s: \"%s\"", | ||
"mirror_type", mirror); | ||
if (pkg_repo_signature_type(repo) != SIG_NONE) | ||
printf(",\n %-16s: \"%s\"", | ||
"signature_type", sig); | ||
if (pkg_repo_fingerprints(repo) != NULL) | ||
printf(",\n %-16s: \"%s\"", | ||
"fingerprints", pkg_repo_fingerprints(repo)); | ||
if (pkg_repo_key(repo) != NULL) | ||
printf(",\n %-16s: \"%s\"", | ||
"pubkey", pkg_repo_key(repo)); | ||
if (pkg_repo_ip_version(repo) != 0) | ||
printf(",\n %-16s: %u", | ||
"ip_version", pkg_repo_ip_version(repo)); | ||
printf("\n }\n"); | ||
} | ||
while (pkg_repos(&repo) == EPKG_OK) | ||
print_repository(repo, true); | ||
} | ||
|
||
static void | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,8 @@ | ||
/*- | ||
* Copyright (c) 2011-2012 Baptiste Daroussin <[email protected]> | ||
* Copyright (c) 2011-2024 Baptiste Daroussin <[email protected]> | ||
* Copyright (c) 2013 Matthew Seaman <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer | ||
* in this position and unchanged. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#ifndef _PKGCLI_H | ||
|
@@ -115,6 +95,10 @@ int exec_register(int argc, char **argv); | |
int exec_repo(int, char **); | ||
void usage_repo(void); | ||
|
||
/* pkg repo */ | ||
int exec_repositories(int, char **); | ||
void usage_repositories(void); | ||
|
||
/* pkg rquery */ | ||
int exec_rquery(int, char **); | ||
void usage_rquery(void); | ||
|
@@ -278,6 +262,7 @@ void job_status_end(xstring *); | |
|
||
int event_callback(void *data, struct pkg_event *ev); | ||
int print_pkg(struct pkg *p, void *ctx); | ||
void print_repository(struct pkg_repo *repo, bool pad); | ||
void progressbar_start(const char *pmsg); | ||
void progressbar_tick(int64_t current, int64_t total); | ||
void progressbar_stop(void); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*- | ||
* Copyright(c) 2024 Baptiste Daroussin <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <getopt.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <unistd.h> | ||
|
||
#include <pkg.h> | ||
|
||
#include "pkgcli.h" | ||
|
||
void | ||
usage_repositories(void) | ||
{ | ||
fprintf(stderr, "Usage: pkg repositories [-edl] [repository]\n\n"); | ||
} | ||
|
||
|
||
typedef enum { | ||
REPO_SHOW_ALL = 0, | ||
REPO_SHOW_ENABLED = 1U << 0, | ||
REPO_SHOW_DISABLED = 1U << 1, | ||
} repo_show_t; | ||
|
||
int | ||
exec_repositories(int argc, char **argv) | ||
{ | ||
const char *r = NULL; | ||
struct pkg_repo *repo = NULL; | ||
bool list_only = false; | ||
repo_show_t rs = REPO_SHOW_ALL; | ||
int ch; | ||
|
||
struct option longopts[] = { | ||
{ "list", no_argument, NULL, 'l' }, | ||
{ "enabled", no_argument, NULL, 'e' }, | ||
{ "disabled", no_argument, NULL, 'd' }, | ||
{ NULL, 0, NULL, 0 }, | ||
}; | ||
|
||
while ((ch = getopt_long(argc, argv, "+led", longopts, NULL)) != -1) { | ||
switch (ch) { | ||
case 'l': | ||
list_only = true; | ||
break; | ||
case 'e': | ||
rs |= REPO_SHOW_ENABLED; | ||
break; | ||
case 'd': | ||
rs |= REPO_SHOW_DISABLED; | ||
break; | ||
default: | ||
usage_repositories(); | ||
return (EXIT_FAILURE); | ||
} | ||
} | ||
|
||
if (rs == REPO_SHOW_ALL) | ||
rs |= REPO_SHOW_DISABLED|REPO_SHOW_ENABLED; | ||
|
||
argc -= optind; | ||
argv += optind; | ||
|
||
if (argc == 1) | ||
r = argv[0]; | ||
|
||
while (pkg_repos(&repo) == EPKG_OK) { | ||
if (r && !STREQ(r, pkg_repo_name(repo))) | ||
continue; | ||
if (pkg_repo_enabled(repo)) { | ||
if ((rs & REPO_SHOW_ENABLED) == 0) | ||
continue; | ||
} else { | ||
if ((rs & REPO_SHOW_DISABLED) == 0) | ||
continue; | ||
} | ||
if (list_only) { | ||
printf("%s\n", pkg_repo_name(repo)); | ||
continue; | ||
} | ||
print_repository(repo, false); | ||
} | ||
|
||
|
||
return (EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,26 +5,7 @@ | |
* Copyright (c) 2012-2015 Matthew Seaman <[email protected]> | ||
* Copyright (c) 2013-2016 Vsevolod Stakhov <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer | ||
* in this position and unchanged. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
|
@@ -1105,3 +1086,63 @@ print_pkg(struct pkg *p, void *ctx) | |
|
||
return 0; | ||
} | ||
|
||
void | ||
print_repository(struct pkg_repo *repo, bool pad) | ||
{ | ||
const char *mirror, *sig; | ||
|
||
switch (pkg_repo_mirror_type(repo)) { | ||
case SRV: | ||
mirror = "SRV"; | ||
break; | ||
case HTTP: | ||
mirror = "HTTP"; | ||
break; | ||
case NOMIRROR: | ||
mirror = "NONE"; | ||
break; | ||
default: | ||
mirror = "-unknown-"; | ||
break; | ||
} | ||
switch (pkg_repo_signature_type(repo)) { | ||
case SIG_PUBKEY: | ||
sig = "PUBKEY"; | ||
break; | ||
case SIG_FINGERPRINT: | ||
sig = "FINGERPRINTS"; | ||
break; | ||
case SIG_NONE: | ||
sig = "NONE"; | ||
break; | ||
default: | ||
sig = "-unknown-"; | ||
break; | ||
} | ||
|
||
printf("%s%s: { \n %-16s: \"%s\",\n %-16s: %s,\n" | ||
" %-16s: %u", | ||
pad ? " " : "", | ||
pkg_repo_name(repo), | ||
"url", pkg_repo_url(repo), | ||
"enabled", pkg_repo_enabled(repo) ? "yes" : "no", | ||
"priority", pkg_repo_priority(repo)); | ||
|
||
if (pkg_repo_mirror_type(repo) != NOMIRROR) | ||
printf(",\n %-16s: \"%s\"", | ||
"mirror_type", mirror); | ||
if (pkg_repo_signature_type(repo) != SIG_NONE) | ||
printf(",\n %-16s: \"%s\"", | ||
"signature_type", sig); | ||
if (pkg_repo_fingerprints(repo) != NULL) | ||
printf(",\n %-16s: \"%s\"", | ||
"fingerprints", pkg_repo_fingerprints(repo)); | ||
if (pkg_repo_key(repo) != NULL) | ||
printf(",\n %-16s: \"%s\"", | ||
"pubkey", pkg_repo_key(repo)); | ||
if (pkg_repo_ip_version(repo) != 0) | ||
printf(",\n %-16s: %u", | ||
"ip_version", pkg_repo_ip_version(repo)); | ||
printf("\n }\n"); | ||
} |
information, always singular in English.