#ifdef HAVE_CONFIG_H
#include "pkg_config.h"
#endif
#include <bsd_compat.h>
#include <getopt.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_READPASSPHRASE_H
#include <readpassphrase.h>
#elif defined(HAVE_BSD_READPASSPHRASE_H)
#include <bsd/readpassphrase.h>
#else
#include "readpassphrase_compat.h"
#endif
#include <unistd.h>
#include <pkg.h>
#include "pkgcli.h"
void
usage_repo(void)
{
fprintf(stderr, "Usage: pkg repo [-hlqs] [-m metafile] [-o output-dir] <repo-path> "
"[rsa:<rsa-key>|signing_command: <the command>]\n\n");
fprintf(stderr, "For more information see 'pkg help repo'.\n");
}
int
exec_repo(int argc, char **argv)
{
int ch;
bool hash = false;
bool hash_symlink = false;
struct pkg_repo_create *prc = pkg_repo_create_new();
hash = (getenv("PKG_REPO_HASH") != NULL);
hash_symlink = (getenv("PKG_REPO_SYMLINK") != NULL);
struct option longopts[] = {
{ "groups", required_argument, NULL, 'g' },
{ "hash", no_argument, NULL, 'h' },
{ "list-files", no_argument, NULL, 'l' },
{ "meta-file", required_argument, NULL, 'm' },
{ "output-dir", required_argument, NULL, 'o' },
{ "quiet", no_argument, NULL, 'q' },
{ "symlink", no_argument, NULL, 's' },
{ NULL, 0, NULL, 0 },
};
while ((ch = getopt_long(argc, argv, "+hg:lo:qm:s", longopts, NULL)) != -1) {
switch (ch) {
case 'g':
pkg_repo_create_set_groups(prc, optarg);
break;
case 'h':
hash = true;
break;
case 'l':
pkg_repo_create_set_create_filelist(prc, true);
break;
case 'o':
pkg_repo_create_set_output_dir(prc, optarg);
break;
case 'q':
quiet = true;
break;
case 'm':
pkg_repo_create_set_metafile(prc, optarg);
break;
case 's':
hash_symlink = true;
break;
default:
usage_repo();
return (EXIT_FAILURE);
}
}
argc -= optind;
argv += optind;
pkg_repo_create_set_hash(prc, hash);
pkg_repo_create_set_hash_symlink(prc, hash_symlink);
pkg_repo_create_set_sign(prc, argv + 1, argc - 1, password_cb);
if (argc < 1) {
pkg_repo_create_free(prc);
usage_repo();
return (EXIT_FAILURE);
}
if (argc > 2 && !STREQ(argv[1], "signing_command:")) {
pkg_repo_create_free(prc);
usage_repo();
return (EXIT_FAILURE);
}
if (pkg_repo_create(prc, argv[0]) != EPKG_OK) {
printf("Cannot create repository catalogue\n");
pkg_repo_create_free(prc);
return (EXIT_FAILURE);
}
pkg_repo_create_free(prc);
return (EXIT_SUCCESS);
}