Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/src/repo.c
2065 views
1
/*-
2
* Copyright (c) 2011-2024 Baptiste Daroussin <[email protected]>
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
6
* are met:
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer
9
* in this position and unchanged.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
*
14
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
*/
25
26
#ifdef HAVE_CONFIG_H
27
#include "pkg_config.h"
28
#endif
29
30
#include <bsd_compat.h>
31
#include <getopt.h>
32
#include <signal.h>
33
#include <stdio.h>
34
#include <string.h>
35
36
#ifdef HAVE_READPASSPHRASE_H
37
#include <readpassphrase.h>
38
#elif defined(HAVE_BSD_READPASSPHRASE_H)
39
#include <bsd/readpassphrase.h>
40
#else
41
#include "readpassphrase_compat.h"
42
#endif
43
44
#include <unistd.h>
45
46
#include <pkg.h>
47
#include "pkgcli.h"
48
49
void
50
usage_repo(void)
51
{
52
fprintf(stderr, "Usage: pkg repo [-hlqs] [-m metafile] [-o output-dir] <repo-path> "
53
"[rsa:<rsa-key>|signing_command: <the command>]\n\n");
54
fprintf(stderr, "For more information see 'pkg help repo'.\n");
55
}
56
57
int
58
exec_repo(int argc, char **argv)
59
{
60
int ch;
61
bool hash = false;
62
bool hash_symlink = false;
63
struct pkg_repo_create *prc = pkg_repo_create_new();
64
65
hash = (getenv("PKG_REPO_HASH") != NULL);
66
hash_symlink = (getenv("PKG_REPO_SYMLINK") != NULL);
67
68
struct option longopts[] = {
69
{ "groups", required_argument, NULL, 'g' },
70
{ "hash", no_argument, NULL, 'h' },
71
{ "list-files", no_argument, NULL, 'l' },
72
{ "meta-file", required_argument, NULL, 'm' },
73
{ "output-dir", required_argument, NULL, 'o' },
74
{ "quiet", no_argument, NULL, 'q' },
75
{ "symlink", no_argument, NULL, 's' },
76
{ NULL, 0, NULL, 0 },
77
};
78
79
while ((ch = getopt_long(argc, argv, "+hg:lo:qm:s", longopts, NULL)) != -1) {
80
switch (ch) {
81
case 'g':
82
pkg_repo_create_set_groups(prc, optarg);
83
break;
84
case 'h':
85
hash = true;
86
break;
87
case 'l':
88
pkg_repo_create_set_create_filelist(prc, true);
89
break;
90
case 'o':
91
pkg_repo_create_set_output_dir(prc, optarg);
92
break;
93
case 'q':
94
quiet = true;
95
break;
96
case 'm':
97
pkg_repo_create_set_metafile(prc, optarg);
98
break;
99
case 's':
100
hash_symlink = true;
101
break;
102
default:
103
usage_repo();
104
return (EXIT_FAILURE);
105
}
106
}
107
argc -= optind;
108
argv += optind;
109
110
pkg_repo_create_set_hash(prc, hash);
111
pkg_repo_create_set_hash_symlink(prc, hash_symlink);
112
pkg_repo_create_set_sign(prc, argv + 1, argc - 1, password_cb);
113
114
if (argc < 1) {
115
pkg_repo_create_free(prc);
116
usage_repo();
117
return (EXIT_FAILURE);
118
}
119
120
if (argc > 2 && !STREQ(argv[1], "signing_command:")) {
121
pkg_repo_create_free(prc);
122
usage_repo();
123
return (EXIT_FAILURE);
124
}
125
126
if (pkg_repo_create(prc, argv[0]) != EPKG_OK) {
127
printf("Cannot create repository catalogue\n");
128
pkg_repo_create_free(prc);
129
return (EXIT_FAILURE);
130
}
131
132
pkg_repo_create_free(prc);
133
return (EXIT_SUCCESS);
134
}
135
136