Added support to specify a root directory for xbps.
All xbps metadata files will go into <rootdir>/var/cache/xbps and package data will go into <rootdir>/<data>. --HG-- extra : convert_revision : 37007ac4f9b99b31465612a58749713b3164139b
This commit is contained in:
116
bin/xbps-bin.c
116
bin/xbps-bin.c
@@ -30,6 +30,7 @@
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <libgen.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
|
||||
@@ -41,30 +42,28 @@ typedef struct repository_info {
|
||||
} repo_info_t;
|
||||
|
||||
static bool sanitize_localpath(char *, const char *);
|
||||
static prop_dictionary_t getrepolist_dict(void);
|
||||
static prop_dictionary_t getrepolist_dict(const char *);
|
||||
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
|
||||
static void usage(void);
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
printf("Usage: xbps-bin [action] [arguments]\n\n"
|
||||
printf("Usage: xbps-bin [options] [action] [arguments]\n\n"
|
||||
" Available actions:\n"
|
||||
" install, list, repo-add, repo-list, repo-rm, search, show\n"
|
||||
" Action arguments:\n"
|
||||
" install\t[<pkgname>] [<rootdir>]\n"
|
||||
" list\n"
|
||||
" repo-add\t[<URI>]\n"
|
||||
" repo-list\t[none]\n"
|
||||
" repo-rm\t[<URI>]\n"
|
||||
" search\t[<string>]\n"
|
||||
" show\t[<pkgname>]\n"
|
||||
" Environment:\n"
|
||||
" XBPS_META_PATH\tPath to the xbps metadata directory\n"
|
||||
" Actions with arguments:\n"
|
||||
" install\t<pkgname>\n"
|
||||
" repo-add\t<URI>\n"
|
||||
" repo-rm\t<URI>\n"
|
||||
" search\t<string>\n"
|
||||
" show\t<pkgname>\n"
|
||||
" Options shared by all actions:\n"
|
||||
" -r\t\t<rootdir>\n"
|
||||
"\n"
|
||||
" Examples:\n"
|
||||
" $ xbps-bin install klibc\n"
|
||||
" $ xbps-bin install klibc /path/to/directory\n"
|
||||
" $ xbps-bin -r /path/to/root install klibc\n"
|
||||
" $ xbps-bin list\n"
|
||||
" $ xbps-bin repo-add /path/to/directory\n"
|
||||
" $ xbps-bin repo-add http://www.location.org/xbps-repo\n"
|
||||
@@ -104,12 +103,14 @@ pkgindex_getinfo(prop_dictionary_t dict, repo_info_t *ri)
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
getrepolist_dict(void)
|
||||
getrepolist_dict(const char *root)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
char plist[PATH_MAX];
|
||||
|
||||
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST))
|
||||
xbps_set_rootdir(root);
|
||||
|
||||
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
|
||||
exit(1);
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
@@ -169,22 +170,41 @@ main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
repo_info_t *rinfo = NULL;
|
||||
char dpkgidx[PATH_MAX], repolist[PATH_MAX];
|
||||
int rv = 0;
|
||||
char dpkgidx[PATH_MAX], repolist[PATH_MAX], *root = NULL;
|
||||
int c, rv = 0;
|
||||
|
||||
if (argc < 2)
|
||||
while ((c = getopt(argc, argv, "r:")) != -1) {
|
||||
switch (c) {
|
||||
case 'r':
|
||||
/* To specify the root directory */
|
||||
root = strdup(optarg);
|
||||
if (root == NULL)
|
||||
exit(ENOMEM);
|
||||
xbps_set_rootdir(root);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
if (strcasecmp(argv[1], "repo-add") == 0) {
|
||||
if (strcasecmp(argv[0], "repo-add") == 0) {
|
||||
/* Adds a new repository to the pool. */
|
||||
if (argc != 3)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (!sanitize_localpath(dpkgidx, argv[2]))
|
||||
if (!sanitize_localpath(dpkgidx, argv[1]))
|
||||
exit(EINVAL);
|
||||
|
||||
/* Temp buffer to verify pkgindex file. */
|
||||
if (!xbps_append_full_path(repolist, dpkgidx, XBPS_PKGINDEX))
|
||||
if (!xbps_append_full_path(false, repolist, dpkgidx,
|
||||
XBPS_PKGINDEX))
|
||||
exit(EINVAL);
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(repolist);
|
||||
@@ -222,22 +242,22 @@ main(int argc, char **argv)
|
||||
prop_object_release(dict);
|
||||
free(rinfo);
|
||||
|
||||
} else if (strcasecmp(argv[1], "repo-list") == 0) {
|
||||
} else if (strcasecmp(argv[0], "repo-list") == 0) {
|
||||
/* Lists all repositories registered in pool. */
|
||||
if (argc != 2)
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
dict = getrepolist_dict();
|
||||
dict = getrepolist_dict(root);
|
||||
(void)xbps_callback_array_iter_in_dict(dict,
|
||||
"repository-list", xbps_list_strings_in_array, NULL);
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[1], "repo-rm") == 0) {
|
||||
} else if (strcasecmp(argv[0], "repo-rm") == 0) {
|
||||
/* Remove a repository from the pool. */
|
||||
if (argc != 3)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (!sanitize_localpath(dpkgidx, argv[2]))
|
||||
if (!sanitize_localpath(dpkgidx, argv[1]))
|
||||
exit(EINVAL);
|
||||
|
||||
if (!xbps_unregister_repository(dpkgidx)) {
|
||||
@@ -250,37 +270,37 @@ main(int argc, char **argv)
|
||||
exit(EINVAL);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[1], "search") == 0) {
|
||||
} else if (strcasecmp(argv[0], "search") == 0) {
|
||||
/* Search for a package by looking at short_desc. */
|
||||
if (argc != 3)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
dict = getrepolist_dict();
|
||||
dict = getrepolist_dict(root);
|
||||
(void)xbps_callback_array_iter_in_dict(dict,
|
||||
"repository-list", xbps_search_string_in_pkgs, argv[2]);
|
||||
"repository-list", xbps_search_string_in_pkgs, argv[1]);
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[1], "show") == 0) {
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about a binary package. */
|
||||
if (argc != 3)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
dict = getrepolist_dict();
|
||||
dict = getrepolist_dict(root);
|
||||
if (xbps_callback_array_iter_in_dict(dict, "repository-list",
|
||||
xbps_show_pkg_info_from_repolist, argv[2]) != 0) {
|
||||
xbps_show_pkg_info_from_repolist, argv[1]) != 0) {
|
||||
prop_object_release(dict);
|
||||
printf("ERROR: unable to locate package '%s'.\n",
|
||||
argv[2]);
|
||||
argv[1]);
|
||||
exit(EINVAL);
|
||||
}
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[1], "list") == 0) {
|
||||
} else if (strcasecmp(argv[0], "list") == 0) {
|
||||
/* Lists packages currently registered in database. */
|
||||
if (argc != 2)
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
if (!xbps_append_full_path(dpkgidx, NULL, XBPS_REGPKGDB))
|
||||
if (!xbps_append_full_path(true, dpkgidx, NULL, XBPS_REGPKGDB))
|
||||
exit(EINVAL);
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(dpkgidx);
|
||||
@@ -296,21 +316,15 @@ main(int argc, char **argv)
|
||||
}
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[1], "install") == 0) {
|
||||
} else if (strcasecmp(argv[0], "install") == 0) {
|
||||
/* Installs a binary package and required deps. */
|
||||
if (argc < 3 || argc > 4)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (argc == 3) {
|
||||
/* Install into root directory by default. */
|
||||
rv = xbps_install_binary_pkg(argv[2], "/");
|
||||
} else {
|
||||
/* install into specified directory. */
|
||||
rv = xbps_install_binary_pkg(argv[2], argv[3]);
|
||||
}
|
||||
|
||||
/* Install into root directory by default. */
|
||||
rv = xbps_install_binary_pkg(argv[1], root);
|
||||
if (rv) {
|
||||
printf("ERROR: unable to install %s.\n", argv[2]);
|
||||
printf("ERROR: unable to install %s.\n", argv[1]);
|
||||
exit(rv);
|
||||
}
|
||||
} else {
|
||||
|
||||
103
bin/xbps-pkgdb.c
103
bin/xbps-pkgdb.c
@@ -48,16 +48,17 @@ write_plist_file(prop_dictionary_t dict, const char *file)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
printf("usage: xbps-pkgdb <action> [args]\n\n"
|
||||
printf("usage: xbps-pkgdb [options] [action] [args]\n\n"
|
||||
" Available actions:\n"
|
||||
" register, sanitize-plist, unregister, version\n"
|
||||
" Action arguments:\n"
|
||||
" register\t[<pkgname> <version> <shortdesc>]\n"
|
||||
" sanitize-plist\t[<plist>]\n"
|
||||
" unregister\t[<pkgname> <version>]\n"
|
||||
" version\t[<pkgname>]\n"
|
||||
" Environment:\n"
|
||||
" XBPS_META_PATH\tPath to xbps metadata root directory\n\n"
|
||||
" register\t\t<pkgname> <version> <shortdesc>\n"
|
||||
" sanitize-plist\t<plist>\n"
|
||||
" unregister\t\t<pkgname> <version>\n"
|
||||
" version\t\t<pkgname>\n"
|
||||
" Options shared by all actions:\n"
|
||||
" -r\t\t\t<rootdir>\n"
|
||||
"\n"
|
||||
" Examples:\n"
|
||||
" $ xbps-pkgdb register pkgname 2.0 \"A short description\"\n"
|
||||
" $ xbps-pkgdb sanitize-plist /blah/foo.plist\n"
|
||||
@@ -71,14 +72,32 @@ main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dbdict = NULL, pkgdict;
|
||||
const char *version;
|
||||
char dbfile[PATH_MAX], *in_chroot_env;
|
||||
char dbfile[PATH_MAX], *in_chroot_env, *root = NULL;
|
||||
bool in_chroot = false;
|
||||
int rv = 0;
|
||||
int c, rv = 0;
|
||||
|
||||
if (argc < 2)
|
||||
while ((c = getopt(argc, argv, "r:")) != -1) {
|
||||
switch (c) {
|
||||
case 'r':
|
||||
/* To specify the root directory */
|
||||
root = strdup(optarg);
|
||||
if (root == NULL)
|
||||
exit(ENOMEM);
|
||||
xbps_set_rootdir(root);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
if (!xbps_append_full_path(dbfile, NULL, XBPS_REGPKGDB)) {
|
||||
if (!xbps_append_full_path(true, dbfile, NULL, XBPS_REGPKGDB)) {
|
||||
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
|
||||
strerror(errno));
|
||||
exit(EINVAL);
|
||||
@@ -88,53 +107,53 @@ main(int argc, char **argv)
|
||||
if (in_chroot_env != NULL)
|
||||
in_chroot = true;
|
||||
|
||||
if (strcasecmp(argv[1], "register") == 0) {
|
||||
if (strcasecmp(argv[0], "register") == 0) {
|
||||
/* Registers a package into the database */
|
||||
if (argc != 5)
|
||||
usage();
|
||||
|
||||
rv = xbps_register_pkg(argv[2], argv[3], argv[4]);
|
||||
if (rv == EEXIST) {
|
||||
printf("%s=> %s-%s already registered.\n",
|
||||
in_chroot ? "[chroot] " : "", argv[2], argv[3]);
|
||||
} else if (rv != 0) {
|
||||
printf("%s=> couldn't register %s-%s (%s).\n",
|
||||
in_chroot ? "[chroot] " : "" , argv[2], argv[3],
|
||||
strerror(rv));
|
||||
} else {
|
||||
printf("%s=> %s-%s registered successfully.\n",
|
||||
in_chroot ? "[chroot] " : "", argv[2], argv[3]);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[1], "unregister") == 0) {
|
||||
/* Unregisters a package from the database */
|
||||
if (argc != 4)
|
||||
usage();
|
||||
|
||||
if (!xbps_remove_pkg_dict_from_file(argv[2], dbfile)) {
|
||||
rv = xbps_register_pkg(argv[1], argv[2], argv[3]);
|
||||
if (rv == EEXIST) {
|
||||
printf("%s=> %s-%s already registered.\n",
|
||||
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
|
||||
} else if (rv != 0) {
|
||||
printf("%s=> couldn't register %s-%s (%s).\n",
|
||||
in_chroot ? "[chroot] " : "" , argv[1], argv[2],
|
||||
strerror(rv));
|
||||
} else {
|
||||
printf("%s=> %s-%s registered successfully.\n",
|
||||
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "unregister") == 0) {
|
||||
/* Unregisters a package from the database */
|
||||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
if (!xbps_remove_pkg_dict_from_file(argv[1], dbfile)) {
|
||||
if (errno == ENODEV)
|
||||
printf("=> ERROR: %s not registered "
|
||||
"in database.\n", argv[2]);
|
||||
"in database.\n", argv[1]);
|
||||
else
|
||||
printf("=> ERROR: couldn't unregister %s "
|
||||
"from database (%s)\n", argv[2],
|
||||
"from database (%s)\n", argv[1],
|
||||
strerror(errno));
|
||||
exit(EINVAL);
|
||||
}
|
||||
|
||||
printf("%s=> %s-%s unregistered successfully.\n",
|
||||
in_chroot ? "[chroot] " : "", argv[2], argv[3]);
|
||||
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
|
||||
|
||||
} else if (strcasecmp(argv[1], "version") == 0) {
|
||||
} else if (strcasecmp(argv[0], "version") == 0) {
|
||||
/* Prints version of an installed package */
|
||||
if (argc != 3)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
dbdict = prop_dictionary_internalize_from_file(dbfile);
|
||||
if (dbdict == NULL)
|
||||
exit(1);
|
||||
|
||||
pkgdict = xbps_find_pkg_in_dict(dbdict, argv[2]);
|
||||
pkgdict = xbps_find_pkg_in_dict(dbdict, argv[1]);
|
||||
if (pkgdict == NULL)
|
||||
exit(1);
|
||||
|
||||
@@ -144,18 +163,18 @@ main(int argc, char **argv)
|
||||
|
||||
printf("%s\n", version);
|
||||
|
||||
} else if (strcasecmp(argv[1], "sanitize-plist") == 0) {
|
||||
} else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
|
||||
/* Sanitize a plist file (indent the file properly) */
|
||||
if (argc != 3)
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
dbdict = prop_dictionary_internalize_from_file(argv[2]);
|
||||
dbdict = prop_dictionary_internalize_from_file(argv[1]);
|
||||
if (dbdict == NULL) {
|
||||
printf("=> ERROR: couldn't sanitize %s plist file "
|
||||
"(%s)\n", argv[2], strerror(errno));
|
||||
"(%s)\n", argv[1], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
write_plist_file(dbdict, argv[2]);
|
||||
write_plist_file(dbdict, argv[1]);
|
||||
|
||||
} else {
|
||||
usage();
|
||||
|
||||
@@ -110,8 +110,8 @@ set_defvars()
|
||||
[ ! -d "$val" ] && msg_error "cannot find $i, aborting."
|
||||
done
|
||||
|
||||
XBPS_REGPKGDB_CMD="env XBPS_META_PATH=$XBPS_META_PATH xbps-pkgdb"
|
||||
XBPS_BIN_CMD="env XBPS_META_PATH=$XBPS_META_PATH xbps-bin"
|
||||
XBPS_REGPKGDB_CMD="xbps-pkgdb -r $XBPS_MASTERDIR"
|
||||
XBPS_BIN_CMD="xbps-bin -r $XBPS_MASTERDIR"
|
||||
}
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user