From f4e265d53ceb0ec56bdcf7f68595903330a79b5e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 6 Jul 2013 02:21:47 +0200 Subject: [PATCH] Add build tool create_repository_config Given a repository base URL and a repository info, it creates a repository config file. --- src/tools/Jamfile | 1 + src/tools/create_repository_config/Jamfile | 11 +++ .../create_repository_config.cpp | 78 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/tools/create_repository_config/Jamfile create mode 100644 src/tools/create_repository_config/create_repository_config.cpp diff --git a/src/tools/Jamfile b/src/tools/Jamfile index 046744def3..cf7ecbfff0 100644 --- a/src/tools/Jamfile +++ b/src/tools/Jamfile @@ -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 ; diff --git a/src/tools/create_repository_config/Jamfile b/src/tools/create_repository_config/Jamfile new file mode 100644 index 0000000000..cfc462c9bc --- /dev/null +++ b/src/tools/create_repository_config/Jamfile @@ -0,0 +1,11 @@ +SubDir HAIKU_TOP src tools create_repository_config ; + +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src bin pkgman ] ; + +USES_BE_API on create_repository_config = true ; + +BuildPlatformMain create_repository_config : + create_repository_config.cpp + : + libpackage_build.so $(HOST_LIBBE) $(HOST_LIBSTDC++) + ; diff --git a/src/tools/create_repository_config/create_repository_config.cpp b/src/tools/create_repository_config/create_repository_config.cpp new file mode 100644 index 0000000000..86e78dcd7a --- /dev/null +++ b/src/tools/create_repository_config/create_repository_config.cpp @@ -0,0 +1,78 @@ +/* + * Copyright 2013, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold + */ + + +#include +#include +#include + +#include +#include + + +#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 \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; +}