2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2012-2019 Juan Romero Pardines.
|
|
|
|
* 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.
|
|
|
|
* 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 ``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 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.
|
2012-11-02 19:34:25 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
|
|
|
usage(bool fail)
|
|
|
|
{
|
|
|
|
fprintf(stdout,
|
|
|
|
"Usage: xbps-rindex [OPTIONS] MODE ARGUMENTS\n\n"
|
|
|
|
"OPTIONS\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -d, --debug Debug mode shown to stderr\n"
|
|
|
|
" -f, --force Force mode to overwrite entry in add mode\n"
|
|
|
|
" -h, --help Show usage\n"
|
|
|
|
" -v, --verbose Verbose messages\n"
|
|
|
|
" -V, --version Show XBPS version\n"
|
|
|
|
" -C, --hashcheck Consider file hashes for cleaning up packages\n"
|
|
|
|
" --compression <fmt> Compression format: none, gzip, bzip2, lz4, xz, zstd (default)\n"
|
|
|
|
" --privkey <key> Path to the private key for signing\n"
|
|
|
|
" --signedby <string> Signature details, i.e \"name <email>\"\n\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
"MODE\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -a, --add <repodir/file.xbps> ... Add package(s) to repository index\n"
|
|
|
|
" -c, --clean <repodir> Clean repository index\n"
|
|
|
|
" -r, --remove-obsoletes <repodir> Removes obsolete packages from repository\n"
|
|
|
|
" -s, --sign <repodir> Initialize repository metadata signature\n"
|
|
|
|
" -S, --sign-pkg <file.xbps> ... Sign binary package archive\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2018-07-03 11:37:23 +05:30
|
|
|
const char *shortopts = "acdfhrsCSVv";
|
2012-11-02 19:34:25 +05:30
|
|
|
struct option longopts[] = {
|
|
|
|
{ "add", no_argument, NULL, 'a' },
|
2013-11-02 16:04:55 +05:30
|
|
|
{ "clean", no_argument, NULL, 'c' },
|
2014-11-06 15:24:52 +05:30
|
|
|
{ "debug", no_argument, NULL, 'd' },
|
2013-05-02 14:16:30 +05:30
|
|
|
{ "force", no_argument, NULL, 'f' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "remove-obsoletes", no_argument, NULL, 'r' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2013-10-10 14:13:01 +05:30
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
2013-10-05 15:08:04 +05:30
|
|
|
{ "privkey", required_argument, NULL, 0},
|
|
|
|
{ "signedby", required_argument, NULL, 1},
|
|
|
|
{ "sign", no_argument, NULL, 's'},
|
2015-06-04 19:31:43 +05:30
|
|
|
{ "sign-pkg", no_argument, NULL, 'S'},
|
2018-07-03 11:37:23 +05:30
|
|
|
{ "hashcheck", no_argument, NULL, 'C' },
|
2019-06-17 10:54:05 +05:30
|
|
|
{ "compression", required_argument, NULL, 2},
|
2012-11-02 19:34:25 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
struct xbps_handle xh;
|
2019-06-17 10:54:05 +05:30
|
|
|
const char *compression = NULL;
|
2013-10-05 15:08:04 +05:30
|
|
|
const char *privkey = NULL, *signedby = NULL;
|
2013-10-10 14:13:01 +05:30
|
|
|
int rv, c, flags = 0;
|
2018-07-03 11:37:23 +05:30
|
|
|
bool add_mode, clean_mode, rm_mode, sign_mode, sign_pkg_mode, force,
|
|
|
|
hashcheck;
|
2013-10-05 15:08:04 +05:30
|
|
|
|
2018-07-03 11:37:23 +05:30
|
|
|
add_mode = clean_mode = rm_mode = sign_mode = sign_pkg_mode = force =
|
|
|
|
hashcheck = false;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
|
|
|
switch (c) {
|
2013-10-05 15:08:04 +05:30
|
|
|
case 0:
|
|
|
|
privkey = optarg;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
signedby = optarg;
|
|
|
|
break;
|
2019-06-17 10:54:05 +05:30
|
|
|
case 2:
|
|
|
|
compression = optarg;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'a':
|
|
|
|
add_mode = true;
|
|
|
|
break;
|
2013-11-02 16:04:55 +05:30
|
|
|
case 'c':
|
|
|
|
clean_mode = true;
|
|
|
|
break;
|
2014-11-06 15:24:52 +05:30
|
|
|
case 'd':
|
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
2013-05-02 14:16:30 +05:30
|
|
|
case 'f':
|
|
|
|
force = true;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'h':
|
|
|
|
usage(false);
|
|
|
|
/* NOTREACHED */
|
2012-11-21 10:33:41 +05:30
|
|
|
case 'r':
|
2012-11-02 19:34:25 +05:30
|
|
|
rm_mode = true;
|
|
|
|
break;
|
2013-10-05 15:08:04 +05:30
|
|
|
case 's':
|
|
|
|
sign_mode = true;
|
|
|
|
break;
|
2018-07-03 11:37:23 +05:30
|
|
|
case 'C':
|
|
|
|
hashcheck = true;
|
|
|
|
break;
|
2015-06-04 19:31:43 +05:30
|
|
|
case 'S':
|
|
|
|
sign_pkg_mode = true;
|
|
|
|
break;
|
2013-10-10 14:13:01 +05:30
|
|
|
case 'v':
|
|
|
|
flags |= XBPS_FLAG_VERBOSE;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
2020-04-21 00:55:14 +05:30
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
}
|
2015-06-04 19:31:43 +05:30
|
|
|
if ((argc == optind) ||
|
|
|
|
(!add_mode && !clean_mode && !rm_mode && !sign_mode && !sign_pkg_mode)) {
|
2012-11-02 19:34:25 +05:30
|
|
|
usage(true);
|
2020-04-21 00:55:14 +05:30
|
|
|
/* NOTREACHED */
|
2015-06-04 19:31:43 +05:30
|
|
|
} else if ((add_mode && (clean_mode || rm_mode || sign_mode || sign_pkg_mode)) ||
|
|
|
|
(clean_mode && (add_mode || rm_mode || sign_mode || sign_pkg_mode)) ||
|
|
|
|
(rm_mode && (add_mode || clean_mode || sign_mode || sign_pkg_mode)) ||
|
|
|
|
(sign_mode && (add_mode || clean_mode || rm_mode || sign_pkg_mode)) ||
|
|
|
|
(sign_pkg_mode && (add_mode || clean_mode || rm_mode || sign_mode))) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Only one mode can be specified: add, clean, "
|
2015-06-04 19:31:43 +05:30
|
|
|
"remove-obsoletes, sign or sign-pkg.\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize libxbps */
|
|
|
|
memset(&xh, 0, sizeof(xh));
|
2013-10-10 14:13:01 +05:30
|
|
|
xh.flags = flags;
|
2012-11-02 19:34:25 +05:30
|
|
|
if ((rv = xbps_init(&xh)) != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("failed to initialize libxbps: %s\n",
|
2012-11-02 19:34:25 +05:30
|
|
|
strerror(rv));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
if (add_mode)
|
2020-01-06 19:01:40 +05:30
|
|
|
rv = index_add(&xh, optind, argc, argv, force, compression);
|
2013-11-02 16:04:55 +05:30
|
|
|
else if (clean_mode)
|
2020-01-06 19:01:40 +05:30
|
|
|
rv = index_clean(&xh, argv[optind], hashcheck, compression);
|
2012-11-30 11:41:51 +05:30
|
|
|
else if (rm_mode)
|
2012-11-02 19:34:25 +05:30
|
|
|
rv = remove_obsoletes(&xh, argv[optind]);
|
2013-10-05 15:08:04 +05:30
|
|
|
else if (sign_mode)
|
2019-06-17 10:54:05 +05:30
|
|
|
rv = sign_repo(&xh, argv[optind], privkey, signedby, compression);
|
2015-06-04 19:31:43 +05:30
|
|
|
else if (sign_pkg_mode)
|
|
|
|
rv = sign_pkgs(&xh, optind, argc, argv, privkey, force);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|