Add build tool create_repository_config
Given a repository base URL and a repository info, it creates a repository config file.
This commit is contained in:
parent
531a3d42bc
commit
f4e265d53c
@ -88,6 +88,7 @@ SubInclude HAIKU_TOP src tools addattr ;
|
||||
SubInclude HAIKU_TOP src tools anyboot ;
|
||||
SubInclude HAIKU_TOP src tools bfs_shell ;
|
||||
SubInclude HAIKU_TOP src tools cppunit ;
|
||||
SubInclude HAIKU_TOP src tools create_repository_config ;
|
||||
SubInclude HAIKU_TOP src tools docbook ;
|
||||
SubInclude HAIKU_TOP src tools elfsymbolpatcher ;
|
||||
SubInclude HAIKU_TOP src tools fixup_amiga_boot_checksum ;
|
||||
|
11
src/tools/create_repository_config/Jamfile
Normal file
11
src/tools/create_repository_config/Jamfile
Normal file
@ -0,0 +1,11 @@
|
||||
SubDir HAIKU_TOP src tools create_repository_config ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src bin pkgman ] ;
|
||||
|
||||
USES_BE_API on <build>create_repository_config = true ;
|
||||
|
||||
BuildPlatformMain <build>create_repository_config :
|
||||
create_repository_config.cpp
|
||||
:
|
||||
libpackage_build.so $(HOST_LIBBE) $(HOST_LIBSTDC++)
|
||||
;
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <package/RepositoryConfig.h>
|
||||
#include <package/RepositoryInfo.h>
|
||||
|
||||
|
||||
#define DIE(error, ...) \
|
||||
do { \
|
||||
fprintf(stderr, "Error: " __VA_ARGS__); \
|
||||
fprintf(stderr, ": %s\n", strerror(error)); \
|
||||
exit(1); \
|
||||
} while (false)
|
||||
|
||||
#define DIE_ON_ERROR(error, ...) \
|
||||
do { \
|
||||
status_t _error = error; \
|
||||
if (error != B_OK) \
|
||||
DIE(_error, __VA_ARGS__); \
|
||||
} while (false)
|
||||
|
||||
|
||||
static const char* sProgramName = "create_repository_config";
|
||||
|
||||
|
||||
void
|
||||
print_usage_and_exit(bool error)
|
||||
{
|
||||
fprintf(error ? stderr : stdout,
|
||||
"Usage: %s <URL> <repository info> <repository config>\n"
|
||||
"Creates a repository config file from a given base URL (the\n"
|
||||
"directory in which the \"repo\", \"repo.info\', and \"repo.sha256\n"
|
||||
"files can be found.\n",
|
||||
sProgramName);
|
||||
exit(error ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char* const* argv)
|
||||
{
|
||||
if (argc != 4) {
|
||||
if (argc == 2
|
||||
&& (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
|
||||
print_usage_and_exit(false);
|
||||
}
|
||||
print_usage_and_exit(true);
|
||||
}
|
||||
|
||||
const char* url = argv[1];
|
||||
const char* infoPath = argv[2];
|
||||
const char* configPath = argv[3];
|
||||
|
||||
// read the info
|
||||
BPackageKit::BRepositoryInfo repoInfo;
|
||||
DIE_ON_ERROR(repoInfo.SetTo(infoPath),
|
||||
"failed to read repository info file \"%s\"", infoPath);
|
||||
|
||||
// init and write the config
|
||||
BPackageKit::BRepositoryConfig repoConfig;
|
||||
repoConfig.SetName(repoInfo.Name());
|
||||
repoConfig.SetBaseURL(url);
|
||||
repoConfig.SetPriority(repoInfo.Priority());
|
||||
DIE_ON_ERROR(repoConfig.Store(configPath),
|
||||
"failed to write repository config file \"%s\"", configPath);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user