2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
14 #include <package/RepositoryConfig.h>
15 #include <package/RepositoryInfo.h>
18 #define DIE(error, ...) \
20 fprintf(stderr, "Error: " __VA_ARGS__); \
21 fprintf(stderr, ": %s\n", strerror(error)); \
25 #define DIE_ON_ERROR(error, ...) \
27 status_t _error = error; \
29 DIE(_error, __VA_ARGS__); \
33 static const char* sProgramName
= "create_repository_config";
37 print_usage_and_exit(bool error
)
39 fprintf(error
? stderr
: stdout
,
40 "Usage: %s [ <URL> ] <repository info> <repository config>\n"
41 "Creates a repository config file from a given repository info and\n"
42 "the base URL (the directory in which the \"repo\", \"repo.info\',\n"
43 "and \"repo.sha256 files can be found). If the URL is not specified,\n"
44 "the one from the repository info is used.",
51 main(int argc
, const char* const* argv
)
53 if (argc
< 3 || argc
> 4) {
55 && (strcmp(argv
[1], "-h") == 0 || strcmp(argv
[1], "--help") == 0)) {
56 print_usage_and_exit(false);
58 print_usage_and_exit(true);
62 const char* url
= argc
== 4 ? argv
[argi
++] : NULL
;
63 const char* infoPath
= argv
[argi
++];
64 const char* configPath
= argv
[argi
++];
67 BPackageKit::BRepositoryInfo repoInfo
;
68 DIE_ON_ERROR(repoInfo
.SetTo(infoPath
),
69 "failed to read repository info file \"%s\"", infoPath
);
72 url
= repoInfo
.OriginalBaseURL();
74 // init and write the config
75 BPackageKit::BRepositoryConfig repoConfig
;
76 repoConfig
.SetName(repoInfo
.Name());
77 repoConfig
.SetBaseURL(url
);
78 repoConfig
.SetPriority(repoInfo
.Priority());
79 DIE_ON_ERROR(repoConfig
.Store(configPath
),
80 "failed to write repository config file \"%s\"", configPath
);