2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2015-03-03 20:40:03 +05:30
|
|
|
* Copyright (c) 2012-2015 Juan Romero Pardines.
|
2012-11-02 19:34:25 +05:30
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
2014-11-06 15:24:52 +05:30
|
|
|
" -d --debug Debug mode shown to stderr\n"
|
2013-05-02 14:16:30 +05:30
|
|
|
" -f --force Force mode to overwrite entry in add mode\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
" -h --help Show help usage\n"
|
2013-10-10 14:13:01 +05:30
|
|
|
" -v --verbose Verbose messages\n"
|
2013-10-05 15:08:04 +05:30
|
|
|
" -V --version Show XBPS version\n"
|
2018-07-03 11:37:23 +05:30
|
|
|
" -C --hashcheck Consider file hashes for cleaning up packages\n"
|
2013-10-05 15:08:04 +05:30
|
|
|
" --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"
|
|
|
|
" -a --add <repodir/pkg> ... Add package(s) to repository index\n"
|
2013-11-02 16:04:55 +05:30
|
|
|
" -c --clean <repodir> Clean repository index\n"
|
2013-10-05 15:08:04 +05:30
|
|
|
" -r --remove-obsoletes <repodir> Removes obsolete packages from repository\n"
|
2015-06-04 19:31:43 +05:30
|
|
|
" -s --sign <repodir> Initialize repository metadata signature\n"
|
|
|
|
" -S --sign-pkg archive.xbps ... Sign binary package archive\n\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' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
struct xbps_handle xh;
|
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;
|
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);
|
|
|
|
}
|
|
|
|
}
|
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);
|
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))) {
|
2013-11-02 16:04:55 +05:30
|
|
|
fprintf(stderr, "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) {
|
|
|
|
fprintf(stderr, "failed to initialize libxbps: %s\n",
|
|
|
|
strerror(rv));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
if (add_mode)
|
2014-10-07 13:41:14 +05:30
|
|
|
rv = index_add(&xh, optind, argc, argv, force);
|
2013-11-02 16:04:55 +05:30
|
|
|
else if (clean_mode)
|
2018-07-03 11:37:23 +05:30
|
|
|
rv = index_clean(&xh, argv[optind], hashcheck);
|
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)
|
|
|
|
rv = sign_repo(&xh, argv[optind], privkey, signedby);
|
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);
|
|
|
|
}
|