Initial import of xbps with code as August '09.
--HG-- extra : convert_revision : juan%40xbps-20090817170720-amxxac4a2e8bza1j
This commit is contained in:
26
bin/Makefile
Normal file
26
bin/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
include ../vars.mk
|
||||
|
||||
SUBDIRS = xbps-bin
|
||||
SUBDIRS += xbps-cmpver
|
||||
SUBDIRS += xbps-digest
|
||||
SUBDIRS += xbps-pkgdb
|
||||
SUBDIRS += xbps-repo
|
||||
SUBDIRS += xbps-src
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
for dir in $(SUBDIRS); do \
|
||||
$(MAKE) -C $$dir; \
|
||||
done
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
for dir in $(SUBDIRS); do \
|
||||
$(MAKE) -C $$dir install; \
|
||||
done
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
for dir in $(SUBDIRS); do \
|
||||
$(MAKE) -C $$dir clean; \
|
||||
done
|
||||
5
bin/xbps-bin/Makefile
Normal file
5
bin/xbps-bin/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
BIN = xbps-bin
|
||||
OBJS = check.o install.o main.o remove.o ../xbps-repo/util.o
|
||||
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/prog.mk
|
||||
275
bin/xbps-bin/check.c
Normal file
275
bin/xbps-bin/check.c
Normal file
@@ -0,0 +1,275 @@
|
||||
/*-
|
||||
* Copyright (c) 2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
|
||||
/*
|
||||
* Checks package integrity of an installed package. This
|
||||
* consists in four tasks:
|
||||
*
|
||||
* o Check for metadata files (files.plist and props.plist),
|
||||
* we only check if the file exists and its dictionary can
|
||||
* be externalized and is not empty.
|
||||
* o Check for missing installed files.
|
||||
* o Check the hash for all installed files, except
|
||||
* configuration files (which is expected if they are modified).
|
||||
* o Check for missing run time dependencies.
|
||||
*
|
||||
* If any of these checks fail, the package will change its
|
||||
* state to 'broken'.
|
||||
*/
|
||||
|
||||
int
|
||||
xbps_check_pkg_integrity(const char *pkgname)
|
||||
{
|
||||
prop_dictionary_t pkgd, propsd, filesd;
|
||||
prop_array_t array;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *rootdir, *file, *sha256, *reqpkg;
|
||||
char *path;
|
||||
int rv = 0;
|
||||
bool files_broken = false, broken = false;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
|
||||
rootdir = xbps_get_rootdir();
|
||||
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
||||
if (pkgd == NULL) {
|
||||
printf("Package %s is not installed.\n", pkgname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for props.plist metadata file.
|
||||
*/
|
||||
path = xbps_xasprintf("%s/%s/metadata/%s/%s", rootdir,
|
||||
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
||||
if (path == NULL) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
propsd = prop_dictionary_internalize_from_file(path);
|
||||
free(path);
|
||||
if (propsd == NULL) {
|
||||
printf("%s: unexistent %s metadata file.\n", pkgname,
|
||||
XBPS_PKGPROPS);
|
||||
rv = errno;
|
||||
broken = true;
|
||||
goto out;
|
||||
} else if (prop_object_type(propsd) != PROP_TYPE_DICTIONARY) {
|
||||
printf("%s: invalid %s metadata file.\n", pkgname,
|
||||
XBPS_PKGPROPS);
|
||||
rv = EINVAL;
|
||||
broken = true;
|
||||
goto out1;
|
||||
} else if (prop_dictionary_count(propsd) == 0) {
|
||||
printf("%s: incomplete %s metadata file.\n", pkgname,
|
||||
XBPS_PKGPROPS);
|
||||
rv = EINVAL;
|
||||
broken = true;
|
||||
goto out1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for files.plist metadata file.
|
||||
*/
|
||||
path = xbps_xasprintf("%s/%s/metadata/%s/%s", rootdir,
|
||||
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
||||
if (path == NULL) {
|
||||
rv = errno;
|
||||
goto out1;
|
||||
}
|
||||
|
||||
filesd = prop_dictionary_internalize_from_file(path);
|
||||
free(path);
|
||||
if (filesd == NULL) {
|
||||
printf("%s: unexistent %s metadata file.\n", pkgname,
|
||||
XBPS_PKGPROPS);
|
||||
rv = ENOENT;
|
||||
broken = true;
|
||||
goto out1;
|
||||
} else if (prop_object_type(filesd) != PROP_TYPE_DICTIONARY) {
|
||||
printf("%s: invalid %s metadata file.\n", pkgname,
|
||||
XBPS_PKGFILES);
|
||||
rv = EINVAL;
|
||||
broken = true;
|
||||
goto out2;
|
||||
} else if (prop_dictionary_count(filesd) == 0) {
|
||||
printf("%s: incomplete %s metadata file.\n", pkgname,
|
||||
XBPS_PKGFILES);
|
||||
rv = EINVAL;
|
||||
broken = true;
|
||||
goto out2;
|
||||
} else if (((array = prop_dictionary_get(filesd, "files")) == NULL) ||
|
||||
((array = prop_dictionary_get(filesd, "links")) == NULL) ||
|
||||
((array = prop_dictionary_get(filesd, "dirs")) == NULL)) {
|
||||
printf("%s: incomplete %s metadata file.\n", pkgname,
|
||||
XBPS_PKGFILES);
|
||||
rv = EINVAL;
|
||||
broken = true;
|
||||
goto out2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for missing files and its hash.
|
||||
*/
|
||||
array = prop_dictionary_get(filesd, "files");
|
||||
if ((prop_object_type(array) == PROP_TYPE_ARRAY) &&
|
||||
prop_array_count(array) > 0) {
|
||||
iter = xbps_get_array_iter_from_dict(filesd, "files");
|
||||
if (iter == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out2;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
path = xbps_xasprintf("%s/%s", rootdir, file);
|
||||
if (path == NULL) {
|
||||
prop_object_iterator_release(iter);
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"sha256", &sha256);
|
||||
rv = xbps_check_file_hash(path, sha256);
|
||||
switch (rv) {
|
||||
case 0:
|
||||
break;
|
||||
case ENOENT:
|
||||
printf("%s: unexistent file %s.\n",
|
||||
pkgname, file);
|
||||
files_broken = true;
|
||||
broken = true;
|
||||
break;
|
||||
case ERANGE:
|
||||
printf("%s: hash mismatch for %s.\n",
|
||||
pkgname, file);
|
||||
files_broken = true;
|
||||
broken = true;
|
||||
break;
|
||||
default:
|
||||
printf("%s: unexpected error for %s (%s)\n",
|
||||
pkgname, file, strerror(rv));
|
||||
break;
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
if (files_broken)
|
||||
printf("%s: files check FAILED.\n", pkgname);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for missing configuration files.
|
||||
*/
|
||||
array = prop_dictionary_get(filesd, "conf_files");
|
||||
if (array && prop_object_type(array) == PROP_TYPE_ARRAY &&
|
||||
prop_array_count(array) > 0) {
|
||||
iter = xbps_get_array_iter_from_dict(filesd, "conf_files");
|
||||
if (iter == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out2;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
path = xbps_xasprintf("%s/%s", rootdir, file);
|
||||
if (path == NULL) {
|
||||
prop_object_iterator_release(iter);
|
||||
rv = ENOMEM;
|
||||
goto out2;
|
||||
}
|
||||
if ((rv = access(path, R_OK)) == -1) {
|
||||
if (errno == ENOENT) {
|
||||
printf("%s: unexistent file %s\n",
|
||||
pkgname, file);
|
||||
broken = true;
|
||||
} else
|
||||
printf("%s: unexpected error for "
|
||||
"%s (%s)\n", pkgname, file,
|
||||
strerror(errno));
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
if (rv != 0)
|
||||
printf("%s: configuration files check FAILED.\n",
|
||||
pkgname);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for missing run time dependencies.
|
||||
*/
|
||||
if (xbps_pkg_has_rundeps(propsd)) {
|
||||
iter = xbps_get_array_iter_from_dict(propsd, "run_depends");
|
||||
if (iter == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out2;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
reqpkg = prop_string_cstring_nocopy(obj);
|
||||
if (xbps_check_is_installed_pkg(reqpkg) < 0) {
|
||||
rv = ENOENT;
|
||||
printf("%s: dependency not satisfied: %s\n",
|
||||
pkgname, reqpkg);
|
||||
broken = true;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
if (rv == ENOENT)
|
||||
printf("%s: run-time dependency check FAILED.\n",
|
||||
pkgname);
|
||||
}
|
||||
|
||||
out2:
|
||||
prop_object_release(filesd);
|
||||
out1:
|
||||
prop_object_release(propsd);
|
||||
out:
|
||||
prop_object_release(pkgd);
|
||||
|
||||
if (broken) {
|
||||
rv = xbps_set_pkg_state_installed(pkgname,
|
||||
XBPS_PKG_STATE_BROKEN);
|
||||
if (rv == 0)
|
||||
printf("%s: changed package state to broken.\n",
|
||||
pkgname);
|
||||
else
|
||||
printf("%s: can't change package state (%s).\n",
|
||||
pkgname, strerror(rv));
|
||||
}
|
||||
|
||||
xbps_release_regpkgdb_dict();
|
||||
|
||||
return rv;
|
||||
}
|
||||
35
bin/xbps-bin/defs.h
Normal file
35
bin/xbps-bin/defs.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*-
|
||||
* Copyright (c) 2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _XBPS_BIN_DEFS_H_
|
||||
#define _XBPS_BIN_DEFS_H_
|
||||
|
||||
void xbps_install_pkg(const char *, bool, bool);
|
||||
void xbps_autoremove_pkgs(void);
|
||||
void xbps_remove_installed_pkg(const char *, bool);
|
||||
void xbps_autoupdate_pkgs(bool);
|
||||
int xbps_check_pkg_integrity(const char *);
|
||||
|
||||
#endif /* !_XBPS_BIN_DEFS_H_ */
|
||||
501
bin/xbps-bin/install.c
Normal file
501
bin/xbps-bin/install.c
Normal file
@@ -0,0 +1,501 @@
|
||||
/*-
|
||||
* Copyright (c) 2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
|
||||
struct transaction {
|
||||
prop_dictionary_t dict;
|
||||
prop_object_iterator_t iter;
|
||||
const char *originpkgname;
|
||||
bool force;
|
||||
};
|
||||
|
||||
static void cleanup(int);
|
||||
static int exec_transaction(struct transaction *);
|
||||
static void show_missing_deps(prop_dictionary_t, const char *);
|
||||
static int show_missing_dep_cb(prop_object_t, void *, bool *);
|
||||
static void show_package_list(prop_object_iterator_t, const char *);
|
||||
|
||||
static void
|
||||
show_missing_deps(prop_dictionary_t d, const char *pkgname)
|
||||
{
|
||||
printf("Unable to locate some required packages for %s:\n",
|
||||
pkgname);
|
||||
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
|
||||
show_missing_dep_cb, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
const char *pkgname, *version;
|
||||
|
||||
(void)arg;
|
||||
(void)loop_done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
if (pkgname && version) {
|
||||
printf(" * Missing binary package for: %s >= %s\n",
|
||||
pkgname, version);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
check_pkg_hashes(prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *pkgname, *repoloc, *filename;
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
printf("Checking binary package file(s) integrity...\n");
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
state = 0;
|
||||
if (xbps_get_pkg_state_dictionary(obj, &state) != 0)
|
||||
return EINVAL;
|
||||
|
||||
if (state == XBPS_PKG_STATE_UNPACKED)
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
rv = xbps_check_pkg_file_hash(obj, repoloc);
|
||||
if (rv != 0 && rv != ERANGE) {
|
||||
printf("Unexpected error while checking hash for "
|
||||
"%s (%s)\n", filename, strerror(rv));
|
||||
return -1;
|
||||
} else if (rv != 0 && rv == ERANGE) {
|
||||
printf("Hash mismatch for %s, exiting.\n",
|
||||
filename);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
show_package_list(prop_object_iterator_t iter, const char *match)
|
||||
{
|
||||
prop_object_t obj;
|
||||
size_t cols = 0;
|
||||
const char *pkgname, *version, *tract;
|
||||
bool first = false;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
||||
if (strcmp(match, tract))
|
||||
continue;
|
||||
|
||||
cols += strlen(pkgname) + strlen(version) + 4;
|
||||
if (cols <= 80) {
|
||||
if (first == false) {
|
||||
printf(" ");
|
||||
first = true;
|
||||
}
|
||||
} else {
|
||||
printf("\n ");
|
||||
cols = strlen(pkgname) + strlen(version) + 4;
|
||||
}
|
||||
printf("%s-%s ", pkgname, version);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
}
|
||||
|
||||
static int
|
||||
show_transaction_sizes(prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
uint64_t tsize = 0, dlsize = 0, instsize = 0;
|
||||
const char *tract;
|
||||
char size[64];
|
||||
bool trans_inst = false, trans_up = false;
|
||||
|
||||
/*
|
||||
* Iterate over the list of packages that are going to be
|
||||
* installed and check the file hash.
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_uint64(obj, "filename-size", &tsize);
|
||||
dlsize += tsize;
|
||||
tsize = 0;
|
||||
prop_dictionary_get_uint64(obj, "installed_size", &tsize);
|
||||
instsize += tsize;
|
||||
tsize = 0;
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
||||
if (strcmp(tract, "install") == 0)
|
||||
trans_inst = true;
|
||||
else if (strcmp(tract, "update") == 0)
|
||||
trans_up = true;
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
/*
|
||||
* Show the list of packages that will be installed.
|
||||
*/
|
||||
if (trans_inst) {
|
||||
printf("The following packages will be installed:\n\n");
|
||||
show_package_list(iter, "install");
|
||||
printf("\n\n");
|
||||
}
|
||||
if (trans_up) {
|
||||
printf("The following packages will be updated:\n\n");
|
||||
show_package_list(iter, "update");
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Show total download/installed size for all required packages.
|
||||
*/
|
||||
if (xbps_humanize_number(size, 5, (int64_t)dlsize,
|
||||
"", HN_AUTOSCALE, HN_NOSPACE) == -1) {
|
||||
printf("error: humanize_number returns %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
printf("Total download size: %s\n", size);
|
||||
if (xbps_humanize_number(size, 5, (int64_t)instsize,
|
||||
"", HN_AUTOSCALE, HN_NOSPACE) == -1) {
|
||||
printf("error: humanize_number2 returns %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
printf("Total installed size: %s\n\n", size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
xbps_install_pkg(const char *pkg, bool force, bool update)
|
||||
{
|
||||
struct transaction *trans;
|
||||
prop_dictionary_t pkgd;
|
||||
prop_array_t array;
|
||||
int rv = 0;
|
||||
|
||||
/*
|
||||
* Find all required pkgs and sort the package transaction.
|
||||
*/
|
||||
pkgd = xbps_find_pkg_installed_from_plist(pkg);
|
||||
if (update) {
|
||||
if (pkgd) {
|
||||
if ((rv = xbps_find_new_pkg(pkg, pkgd)) == 0) {
|
||||
printf("Package '%s' is up to date.\n", pkg);
|
||||
prop_object_release(pkgd);
|
||||
cleanup(rv);
|
||||
}
|
||||
prop_object_release(pkgd);
|
||||
} else {
|
||||
printf("Package '%s' not installed.\n", pkg);
|
||||
cleanup(rv);
|
||||
}
|
||||
} else {
|
||||
if (pkgd) {
|
||||
printf("Package '%s' is already installed.\n", pkg);
|
||||
prop_object_release(pkgd);
|
||||
cleanup(rv);
|
||||
}
|
||||
rv = xbps_prepare_pkg(pkg);
|
||||
if (rv != 0 && rv == EAGAIN) {
|
||||
printf("unable to locate %s in repository pool.", pkg);
|
||||
cleanup(rv);
|
||||
} else if (rv != 0 && rv != ENOENT) {
|
||||
printf("unexpected error: %s", strerror(rv));
|
||||
cleanup(rv);
|
||||
}
|
||||
}
|
||||
|
||||
trans = calloc(1, sizeof(struct transaction));
|
||||
if (trans == NULL)
|
||||
goto out;
|
||||
|
||||
trans->dict = xbps_get_pkg_props();
|
||||
if (trans->dict == NULL) {
|
||||
printf("error: unexistent props dictionary!\n");
|
||||
goto out1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bail out if there are unresolved deps.
|
||||
*/
|
||||
array = prop_dictionary_get(trans->dict, "missing_deps");
|
||||
if (prop_array_count(array) > 0) {
|
||||
show_missing_deps(trans->dict, pkg);
|
||||
goto out2;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(trans->dict,
|
||||
"origin", &trans->originpkgname);
|
||||
|
||||
/*
|
||||
* It's time to run the transaction!
|
||||
*/
|
||||
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
|
||||
if (trans->iter == NULL) {
|
||||
printf("error: allocating array mem! (%s)",
|
||||
strerror(errno));
|
||||
goto out2;
|
||||
}
|
||||
|
||||
trans->force = force;
|
||||
rv = exec_transaction(trans);
|
||||
|
||||
prop_object_iterator_release(trans->iter);
|
||||
out2:
|
||||
prop_object_release(trans->dict);
|
||||
out1:
|
||||
free(trans);
|
||||
out:
|
||||
cleanup(rv);
|
||||
}
|
||||
|
||||
static int
|
||||
exec_transaction(struct transaction *trans)
|
||||
{
|
||||
prop_dictionary_t instpkgd;
|
||||
prop_object_t obj;
|
||||
const char *pkgname, *version, *instver, *filename, *tract;
|
||||
int rv = 0;
|
||||
bool essential, isdep, autoinst;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
assert(trans != NULL);
|
||||
assert(trans->dict != NULL);
|
||||
assert(trans->iter != NULL);
|
||||
|
||||
essential = isdep = autoinst = false;
|
||||
/*
|
||||
* Show download/installed size for the transaction.
|
||||
*/
|
||||
rv = show_transaction_sizes(trans->iter);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
|
||||
/*
|
||||
* Ask interactively (if -f not set).
|
||||
*/
|
||||
if (trans->force == false) {
|
||||
if (xbps_noyes("Do you want to continue?") == false) {
|
||||
printf("Aborting!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the SHA256 hash for all required packages.
|
||||
*/
|
||||
if ((rv = check_pkg_hashes(trans->iter)) != 0)
|
||||
return rv;
|
||||
|
||||
/*
|
||||
* Iterate over the transaction dictionary.
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_bool(obj, "essential", &essential);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
||||
|
||||
if (trans->originpkgname &&
|
||||
strcmp(trans->originpkgname, pkgname))
|
||||
isdep = true;
|
||||
|
||||
/*
|
||||
* If dependency is already unpacked skip this phase.
|
||||
*/
|
||||
state = 0;
|
||||
if (xbps_get_pkg_state_dictionary(obj, &state) != 0)
|
||||
return EINVAL;
|
||||
|
||||
if (state == XBPS_PKG_STATE_UNPACKED)
|
||||
continue;
|
||||
|
||||
if (strcmp(tract, "update") == 0) {
|
||||
instpkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
||||
if (instpkgd == NULL) {
|
||||
printf("error: unable to find %s installed "
|
||||
"dict!\n", pkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(instpkgd,
|
||||
"version", &instver);
|
||||
autoinst = false;
|
||||
prop_dictionary_get_bool(instpkgd, "automatic-install",
|
||||
&autoinst);
|
||||
isdep = autoinst;
|
||||
prop_object_release(instpkgd);
|
||||
|
||||
/*
|
||||
* If this package is not 'essential', just remove
|
||||
* the old package and install the new one. Otherwise
|
||||
* we just overwrite the files.
|
||||
*/
|
||||
if (essential == false) {
|
||||
rv = xbps_remove_pkg(pkgname, version, true);
|
||||
if (rv != 0) {
|
||||
printf("error: removing %s-%s (%s)\n",
|
||||
pkgname, instver, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Unpack binary package.
|
||||
*/
|
||||
printf("Unpacking %s-%s (from .../%s) ...\n", pkgname, version,
|
||||
filename);
|
||||
if ((rv = xbps_unpack_binary_pkg(obj, essential)) != 0) {
|
||||
printf("error: unpacking %s-%s (%s)\n", pkgname,
|
||||
version, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
/*
|
||||
* Register binary package.
|
||||
*/
|
||||
if ((rv = xbps_register_pkg(obj, isdep)) != 0) {
|
||||
printf("error: registering %s-%s! (%s)\n",
|
||||
pkgname, version, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
isdep = false;
|
||||
/*
|
||||
* Set package state to unpacked in the transaction
|
||||
* dictionary.
|
||||
*/
|
||||
if ((rv = xbps_set_pkg_state_dictionary(obj,
|
||||
XBPS_PKG_STATE_UNPACKED)) != 0)
|
||||
return rv;
|
||||
}
|
||||
prop_object_iterator_reset(trans->iter);
|
||||
/*
|
||||
* Configure all unpacked packages.
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
if ((rv = xbps_configure_pkg(pkgname)) != 0) {
|
||||
printf("Error configuring package %s (%s)\n",
|
||||
pkgname, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
xbps_autoupdate_pkgs(bool force)
|
||||
{
|
||||
struct transaction *trans;
|
||||
int rv = 0;
|
||||
|
||||
/*
|
||||
* Find new package versions.
|
||||
*/
|
||||
if ((rv = xbps_find_new_packages()) != 0) {
|
||||
if (rv == ENOENT) {
|
||||
printf("No packages currently registered.\n");
|
||||
cleanup(0);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare transaction data.
|
||||
*/
|
||||
trans = calloc(1, sizeof(struct transaction));
|
||||
if (trans == NULL)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Get package transaction dictionary.
|
||||
*/
|
||||
trans->dict = xbps_get_pkg_props();
|
||||
if (trans->dict == NULL) {
|
||||
if (errno == 0) {
|
||||
printf("All packages are up-to-date.\n");
|
||||
goto out;
|
||||
}
|
||||
printf("Error while checking for new pkgs: %s\n",
|
||||
strerror(errno));
|
||||
goto out1;
|
||||
}
|
||||
/*
|
||||
* Sort the package transaction dictionary.
|
||||
*/
|
||||
if ((rv = xbps_sort_pkg_deps(trans->dict)) != 0) {
|
||||
printf("Error while sorting packages: %s\n",
|
||||
strerror(rv));
|
||||
goto out2;
|
||||
}
|
||||
|
||||
/*
|
||||
* It's time to run the transaction!
|
||||
*/
|
||||
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
|
||||
if (trans->iter == NULL) {
|
||||
printf("error: allocating array mem! (%s)\n", strerror(errno));
|
||||
goto out2;
|
||||
}
|
||||
|
||||
trans->force = force;
|
||||
rv = exec_transaction(trans);
|
||||
|
||||
prop_object_iterator_release(trans->iter);
|
||||
out2:
|
||||
prop_object_release(trans->dict);
|
||||
out1:
|
||||
free(trans);
|
||||
out:
|
||||
cleanup(rv);
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup(int rv)
|
||||
{
|
||||
xbps_release_repolist_data();
|
||||
xbps_release_regpkgdb_dict();
|
||||
exit(rv == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
276
bin/xbps-bin/main.c
Normal file
276
bin/xbps-bin/main.c
Normal file
@@ -0,0 +1,276 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
#include "../xbps-repo/util.h"
|
||||
|
||||
static void usage(void);
|
||||
static int list_pkgs_in_dict(prop_object_t, void *, bool *);
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
printf("Usage: xbps-bin [options] [target] [arguments]\n\n"
|
||||
" Available targets:\n"
|
||||
" autoremove, autoupdate, check, files, install, list\n"
|
||||
" purge, remove, show, update\n"
|
||||
" Targets with arguments:\n"
|
||||
" check\t<pkgname>\n"
|
||||
" files\t<pkgname>\n"
|
||||
" install\t<pkgname>\n"
|
||||
" purge\t[<pkgname>|<all>]\n"
|
||||
" reconfigure\t[<pkgname>|<all>]\n"
|
||||
" remove\t<pkgname>\n"
|
||||
" show\t<pkgname>\n"
|
||||
" update\t<pkgname>\n"
|
||||
" Options shared by all targets:\n"
|
||||
" -r\t\t<rootdir>\n"
|
||||
" -v\t\t<verbose>\n"
|
||||
" Options used by the (auto)remove and install target:\n"
|
||||
" -f\t\tForce installation or removal of packages.\n"
|
||||
" \t\tBeware with this option if you use autoremove!\n"
|
||||
"\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int
|
||||
list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
const char *pkgname, *version, *short_desc;
|
||||
|
||||
(void)arg;
|
||||
(void)loop_done;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc);
|
||||
if (pkgname && version && short_desc) {
|
||||
printf("%s-%s\t%s\n", pkgname, version, short_desc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *curpkgname;
|
||||
int c, flags = 0, rv = 0;
|
||||
bool force = false, verbose = false;
|
||||
|
||||
while ((c = getopt(argc, argv, "Cfr:v")) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
flags |= XBPS_FLAG_FORCE;
|
||||
force = true;
|
||||
break;
|
||||
case 'r':
|
||||
/* To specify the root directory */
|
||||
xbps_set_rootdir(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
flags |= XBPS_FLAG_VERBOSE;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
if (flags != 0)
|
||||
xbps_set_flags(flags);
|
||||
|
||||
if ((dict = xbps_prepare_regpkgdb_dict()) == NULL) {
|
||||
if (errno != ENOENT) {
|
||||
rv = errno;
|
||||
printf("Couldn't initialized regpkgdb dict: %s\n",
|
||||
strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[0], "list") == 0) {
|
||||
/* Lists packages currently registered in database. */
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
if (dict == NULL) {
|
||||
printf("No packages currently installed.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!xbps_callback_array_iter_in_dict(dict, "packages",
|
||||
list_pkgs_in_dict, NULL)) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "install") == 0) {
|
||||
/* Installs a binary package and required deps. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
xbps_install_pkg(argv[1], force, false);
|
||||
|
||||
} else if (strcasecmp(argv[0], "update") == 0) {
|
||||
/* Update an installed package. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
xbps_install_pkg(argv[1], force, true);
|
||||
|
||||
} else if (strcasecmp(argv[0], "remove") == 0) {
|
||||
/* Removes a binary package. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
xbps_remove_installed_pkg(argv[1], force);
|
||||
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about an installed binary package. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = show_pkg_info_from_metadir(argv[1]);
|
||||
if (rv != 0) {
|
||||
printf("Package %s not installed.\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "files") == 0) {
|
||||
/* Shows files installed by a binary package. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = show_pkg_files_from_metadir(argv[1]);
|
||||
if (rv != 0) {
|
||||
printf("Package %s not installed.\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "check") == 0) {
|
||||
/* Checks the integrity of an installed package. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = xbps_check_pkg_integrity(argv[1]);
|
||||
|
||||
} else if (strcasecmp(argv[0], "autoupdate") == 0) {
|
||||
/*
|
||||
* To update all packages currently installed.
|
||||
*/
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
xbps_autoupdate_pkgs(force);
|
||||
|
||||
} else if (strcasecmp(argv[0], "autoremove") == 0) {
|
||||
/*
|
||||
* Removes orphan pkgs. These packages were installed
|
||||
* as dependency and any installed package does not depend
|
||||
* on it currently.
|
||||
*/
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
xbps_autoremove_pkgs();
|
||||
|
||||
} else if (strcasecmp(argv[0], "purge") == 0) {
|
||||
/*
|
||||
* Purge a package completely.
|
||||
*/
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (strcasecmp(argv[1], "all") == 0) {
|
||||
iter = xbps_get_array_iter_from_dict(dict, "packages");
|
||||
if (iter == NULL)
|
||||
goto out;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &curpkgname);
|
||||
if ((rv = xbps_purge_pkg(curpkgname)) != 0)
|
||||
break;
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
} else {
|
||||
rv = xbps_purge_pkg(argv[1]);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "reconfigure") == 0) {
|
||||
/*
|
||||
* Reconfigure a package.
|
||||
*/
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (strcasecmp(argv[1], "all") == 0) {
|
||||
iter = xbps_get_array_iter_from_dict(dict, "packages");
|
||||
if (iter == NULL)
|
||||
goto out;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &curpkgname);
|
||||
if ((rv = xbps_configure_pkg(curpkgname)) != 0)
|
||||
break;
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
} else {
|
||||
rv = xbps_configure_pkg(argv[1]);
|
||||
}
|
||||
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
||||
out:
|
||||
xbps_release_regpkgdb_dict();
|
||||
if (rv != 0)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
162
bin/xbps-bin/remove.c
Normal file
162
bin/xbps-bin/remove.c
Normal file
@@ -0,0 +1,162 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
#include "../xbps-repo/util.h"
|
||||
|
||||
void
|
||||
xbps_autoremove_pkgs(void)
|
||||
{
|
||||
prop_array_t orphans;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname, *version;
|
||||
size_t cols = 0;
|
||||
int rv = 0;
|
||||
bool first = false;
|
||||
|
||||
/*
|
||||
* Removes orphan pkgs. These packages were installed
|
||||
* as dependency and any installed package does not depend
|
||||
* on it currently.
|
||||
*/
|
||||
|
||||
orphans = xbps_find_orphan_packages();
|
||||
if (orphans == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
if (orphans != NULL && prop_array_count(orphans) == 0) {
|
||||
printf("There are not orphaned packages currently.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
iter = prop_array_iterator(orphans);
|
||||
if (iter == NULL)
|
||||
goto out;
|
||||
|
||||
printf("The following packages were installed automatically\n"
|
||||
"(as dependencies) and aren't needed anymore:\n\n");
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
cols += strlen(pkgname) + strlen(version) + 4;
|
||||
if (cols <= 80) {
|
||||
if (first == false) {
|
||||
printf(" ");
|
||||
first = true;
|
||||
}
|
||||
} else {
|
||||
printf("\n ");
|
||||
cols = strlen(pkgname) + strlen(version) + 4;
|
||||
}
|
||||
printf("%s-%s ", pkgname, version);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
printf("\n\n");
|
||||
|
||||
if (xbps_noyes("Do you want to remove them?") == false) {
|
||||
printf("Cancelled!\n");
|
||||
goto out2;
|
||||
}
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
|
||||
printf("Removing package %s-%s ...\n", pkgname, version);
|
||||
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0)
|
||||
goto out2;
|
||||
}
|
||||
out2:
|
||||
prop_object_iterator_release(iter);
|
||||
out:
|
||||
prop_object_release(orphans);
|
||||
if (rv != 0)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
xbps_remove_installed_pkg(const char *pkgname, bool force)
|
||||
{
|
||||
prop_array_t reqby;
|
||||
prop_dictionary_t dict;
|
||||
const char *version;
|
||||
int rv = 0;
|
||||
|
||||
/*
|
||||
* First check if package is required by other packages.
|
||||
*/
|
||||
dict = xbps_find_pkg_installed_from_plist(pkgname);
|
||||
if (dict == NULL) {
|
||||
printf("Package %s is not installed.\n", pkgname);
|
||||
goto out;
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
|
||||
reqby = prop_dictionary_get(dict, "requiredby");
|
||||
if (reqby != NULL && prop_array_count(reqby) > 0) {
|
||||
printf("WARNING! %s-%s is required by the following "
|
||||
"packages:\n\n", pkgname, version);
|
||||
(void)xbps_callback_array_iter_in_dict(dict,
|
||||
"requiredby", list_strings_in_array, NULL);
|
||||
printf("\n\n");
|
||||
if (!force) {
|
||||
if (!xbps_noyes("Do you want to remove %s?", pkgname)) {
|
||||
printf("Cancelling!\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
printf("Forcing %s-%s for deletion!\n", pkgname, version);
|
||||
} else {
|
||||
if (!force) {
|
||||
if (!xbps_noyes("Do you want to remove %s?", pkgname)) {
|
||||
printf("Cancelling!\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Removing package %s-%s ...\n", pkgname, version);
|
||||
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) {
|
||||
printf("Unable to remove %s-%s (%s).\n",
|
||||
pkgname, version, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
xbps_release_regpkgdb_dict();
|
||||
if (rv != 0)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
4
bin/xbps-cmpver/Makefile
Normal file
4
bin/xbps-cmpver/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
BIN = xbps-cmpver
|
||||
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/prog.mk
|
||||
19
bin/xbps-cmpver/main.c
Normal file
19
bin/xbps-cmpver/main.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Compare package and version strings
|
||||
* @ 2008
|
||||
* Author: pancake <youterm.com>
|
||||
*/
|
||||
#include <xbps_api.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
printf("Usage: xbps-cmpver [installed] [required]\n");
|
||||
printf(" xbps-cmpver foo-1.2 foo-2.2 # $? = 1\n");
|
||||
printf(" xbps-cmpver foo-1.2 foo-1.1.0 # $? = 0\n");
|
||||
printf(" xbps-cmpver foo-1.2 foo-1.2 # $? = 0\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return xbps_cmpver(argv[1], argv[2]);
|
||||
}
|
||||
4
bin/xbps-digest/Makefile
Normal file
4
bin/xbps-digest/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
BIN = xbps-digest
|
||||
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/prog.mk
|
||||
76
bin/xbps-digest/main.c
Normal file
76
bin/xbps-digest/main.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: xbps-digest <file> <file1+N> ...\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
uint8_t buffer[BUFSIZ * 20], *digest;
|
||||
ssize_t bytes;
|
||||
int i, fd;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if ((fd = open(argv[i], O_RDONLY)) == -1) {
|
||||
printf("xbps-digest: cannot open %s (%s)\n", argv[i],
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
digest = malloc(SHA256_DIGEST_STRING_LENGTH);
|
||||
if (digest == NULL) {
|
||||
printf("xbps-digest: malloc failed (%s)\n",
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
SHA256_Init(&ctx);
|
||||
while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
|
||||
SHA256_Update(&ctx, buffer, (size_t)bytes);
|
||||
|
||||
printf("%s\n", SHA256_End(&ctx, digest));
|
||||
free(digest);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
4
bin/xbps-pkgdb/Makefile
Normal file
4
bin/xbps-pkgdb/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
BIN = xbps-pkgdb
|
||||
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/prog.mk
|
||||
246
bin/xbps-pkgdb/main.c
Normal file
246
bin/xbps-pkgdb/main.c
Normal file
@@ -0,0 +1,246 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
|
||||
static void
|
||||
write_plist_file(prop_dictionary_t dict, const char *file)
|
||||
{
|
||||
assert(dict != NULL || file != NULL);
|
||||
|
||||
if (!prop_dictionary_externalize_to_file(dict, file)) {
|
||||
prop_object_release(dict);
|
||||
printf("=> ERROR: couldn't write to %s (%s)",
|
||||
file, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
printf("usage: xbps-pkgdb [options] [action] [args]\n"
|
||||
"\n"
|
||||
" Available actions:\n"
|
||||
" getpkgname, getpkgrevision, getpkgversion, register\n"
|
||||
" sanitize-plist, unregister, version\n"
|
||||
"\n"
|
||||
" Action arguments:\n"
|
||||
" getpkgname\t\t<string>\n"
|
||||
" getpkgrevision\t<string>\n"
|
||||
" getpkgversion\t<string>\n"
|
||||
" register\t\t<pkgname> <version> <shortdesc>\n"
|
||||
" sanitize-plist\t<plist>\n"
|
||||
" unregister\t\t<pkgname> <version>\n"
|
||||
" version\t\t<pkgname>\n"
|
||||
"\n"
|
||||
" Options shared by all actions:\n"
|
||||
" -r\t\t\t<rootdir>\n"
|
||||
"\n"
|
||||
" Options used by the register action:\n"
|
||||
" -a\t\t\tSet automatic installation flag.\n"
|
||||
"\n"
|
||||
" Examples:\n"
|
||||
" $ xbps-pkgdb getpkgname foo-2.0\n"
|
||||
" $ xbps-pkgdb getpkgrevision foo-2.0_1\n"
|
||||
" $ xbps-pkgdb getpkgversion foo-2.0\n"
|
||||
" $ xbps-pkgdb register pkgname 2.0 \"A short description\"\n"
|
||||
" $ xbps-pkgdb sanitize-plist /blah/foo.plist\n"
|
||||
" $ xbps-pkgdb unregister pkgname 2.0\n"
|
||||
" $ xbps-pkgdb version pkgname\n");
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
const char *version;
|
||||
char *plist, *pkgname, *in_chroot_env, *root = NULL;
|
||||
bool automatic = false, in_chroot = false;
|
||||
int c, rv = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "ar:")) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
/* Set automatic install flag */
|
||||
automatic = true;
|
||||
break;
|
||||
case 'r':
|
||||
/* To specify the root directory */
|
||||
root = strdup(optarg);
|
||||
if (root == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
xbps_set_rootdir(root);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
plist = xbps_xasprintf("%s/%s/%s", root, XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL) {
|
||||
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
in_chroot_env = getenv("in_chroot");
|
||||
if (in_chroot_env != NULL)
|
||||
in_chroot = true;
|
||||
|
||||
if (strcasecmp(argv[0], "register") == 0) {
|
||||
/* Registers a package into the database */
|
||||
if (argc != 4)
|
||||
usage();
|
||||
|
||||
dict = prop_dictionary_create();
|
||||
if (dict == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
prop_dictionary_set_cstring_nocopy(dict, "pkgname", argv[1]);
|
||||
prop_dictionary_set_cstring_nocopy(dict, "version", argv[2]);
|
||||
prop_dictionary_set_cstring_nocopy(dict, "short_desc", argv[3]);
|
||||
|
||||
rv = xbps_set_pkg_state_installed(argv[1],
|
||||
XBPS_PKG_STATE_INSTALLED);
|
||||
if (rv != 0)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
rv = xbps_register_pkg(dict, automatic);
|
||||
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();
|
||||
|
||||
rv = xbps_remove_pkg_dict_from_file(argv[1], plist);
|
||||
if (rv == ENOENT) {
|
||||
printf("=> ERROR: %s not registered in database.\n",
|
||||
argv[1]);
|
||||
} else if (rv != 0) {
|
||||
printf("=> ERROR: couldn't unregister %s "
|
||||
"from database (%s)\n", argv[1], strerror(rv));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("%s=> %s-%s unregistered successfully.\n",
|
||||
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
|
||||
|
||||
} else if (strcasecmp(argv[0], "version") == 0) {
|
||||
/* Prints version of an installed package */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
dict = xbps_find_pkg_from_plist(plist, argv[1]);
|
||||
if (dict == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (!prop_dictionary_get_cstring_nocopy(dict, "version",
|
||||
&version))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
printf("%s\n", version);
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
|
||||
/* Sanitize a plist file (properly indent the file) */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(argv[1]);
|
||||
if (dict == NULL) {
|
||||
printf("=> ERROR: couldn't sanitize %s plist file "
|
||||
"(%s)\n", argv[1], strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
write_plist_file(dict, argv[1]);
|
||||
|
||||
} else if (strcasecmp(argv[0], "getpkgversion") == 0) {
|
||||
/* Returns the version of a pkg string */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
version = xbps_get_pkg_version(argv[1]);
|
||||
if (version == NULL) {
|
||||
printf("Invalid string, expected <string>-<version>\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("%s\n", version);
|
||||
|
||||
} else if (strcasecmp(argv[0], "getpkgname") == 0) {
|
||||
/* Returns the name of a pkg string */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
pkgname = xbps_get_pkg_name(argv[1]);
|
||||
if (pkgname == NULL) {
|
||||
printf("Invalid string, expected <string>-<version>\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("%s\n", pkgname);
|
||||
free(pkgname);
|
||||
|
||||
} else if (strcasecmp(argv[0], "getpkgrevision") == 0) {
|
||||
/* Returns the revision of a pkg string */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
version = xbps_get_pkg_revision(argv[1]);
|
||||
if (version == NULL)
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
printf("%s\n", version);
|
||||
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
5
bin/xbps-repo/Makefile
Normal file
5
bin/xbps-repo/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
BIN = xbps-repo
|
||||
OBJS = main.o util.o index.o
|
||||
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/prog.mk
|
||||
289
bin/xbps-repo/index.c
Normal file
289
bin/xbps-repo/index.c
Normal file
@@ -0,0 +1,289 @@
|
||||
/*-
|
||||
* Copyright (c) 2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "index.h"
|
||||
|
||||
/* Array of valid architectures */
|
||||
static const char *archdirs[] = { "i686", "x86_64", "noarch", NULL };
|
||||
|
||||
static prop_dictionary_t
|
||||
repoidx_getdict(const char *pkgdir)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
prop_array_t array;
|
||||
char *plist;
|
||||
|
||||
plist = xbps_get_pkg_index_plist(pkgdir);
|
||||
if (plist == NULL)
|
||||
return NULL;
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL) {
|
||||
dict = prop_dictionary_create();
|
||||
if (dict == NULL)
|
||||
goto out;
|
||||
|
||||
array = prop_array_create();
|
||||
if (array == NULL) {
|
||||
prop_object_release(dict);
|
||||
goto out;
|
||||
}
|
||||
|
||||
prop_dictionary_set(dict, "packages", array);
|
||||
prop_object_release(array);
|
||||
prop_dictionary_set_cstring_nocopy(dict,
|
||||
"location-local", pkgdir);
|
||||
prop_dictionary_set_cstring_nocopy(dict,
|
||||
"pkgindex-version", XBPS_PKGINDEX_VERSION);
|
||||
}
|
||||
out:
|
||||
free(plist);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
static int
|
||||
repoidx_addpkg(const char *file, const char *filename, const char *pkgdir)
|
||||
{
|
||||
prop_dictionary_t newpkgd, idxdict, curpkgd;
|
||||
prop_array_t pkgar;
|
||||
struct archive *ar;
|
||||
struct archive_entry *entry;
|
||||
struct stat st;
|
||||
const char *pkgname, *version, *regver;
|
||||
char *sha256, *plist;
|
||||
int rv = 0;
|
||||
|
||||
ar = archive_read_new();
|
||||
if (ar == NULL) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
/* Enable support for tar format and all compression methods */
|
||||
archive_read_support_compression_all(ar);
|
||||
archive_read_support_format_tar(ar);
|
||||
|
||||
if ((rv = archive_read_open_filename(ar, file,
|
||||
ARCHIVE_READ_BLOCKSIZE)) == -1) {
|
||||
rv = errno;
|
||||
goto out1;
|
||||
}
|
||||
|
||||
/* Get existing or create repo index dictionary */
|
||||
idxdict = repoidx_getdict(pkgdir);
|
||||
if (idxdict == NULL) {
|
||||
rv = errno;
|
||||
goto out1;
|
||||
}
|
||||
plist = xbps_get_pkg_index_plist(pkgdir);
|
||||
if (plist == NULL) {
|
||||
prop_dictionary_remove(idxdict, "packages");
|
||||
rv = ENOMEM;
|
||||
goto out2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open the binary package and read the props.plist
|
||||
* into a buffer.
|
||||
*/
|
||||
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
||||
if (strstr(archive_entry_pathname(entry), XBPS_PKGPROPS) == 0) {
|
||||
archive_read_data_skip(ar);
|
||||
continue;
|
||||
}
|
||||
newpkgd = xbps_read_dict_from_archive_entry(ar, entry);
|
||||
if (newpkgd == NULL) {
|
||||
printf("%s: can't read %s metadata file, skipping!\n",
|
||||
file, XBPS_PKGPROPS);
|
||||
break;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname",
|
||||
&pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(newpkgd, "version",
|
||||
&version);
|
||||
/*
|
||||
* Check if this package exists already in the index, but first
|
||||
* checking the version. If current package version is greater
|
||||
* than current registered package, update the index; otherwise
|
||||
* pass to the next one.
|
||||
*/
|
||||
curpkgd = xbps_find_pkg_in_dict(idxdict, "packages", pkgname);
|
||||
if (curpkgd) {
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||
"version", ®ver);
|
||||
if (xbps_cmpver(version, regver) <= 0) {
|
||||
printf("Skipping %s. Version %s already "
|
||||
"registered.\n", filename, regver);
|
||||
prop_object_release(newpkgd);
|
||||
archive_read_data_skip(ar);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Current package is newer than the one that is
|
||||
* registered actually, remove old package from
|
||||
* the index.
|
||||
*/
|
||||
rv = xbps_remove_pkg_from_dict(idxdict,
|
||||
"packages", pkgname);
|
||||
if (rv != 0) {
|
||||
prop_object_release(newpkgd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We have the dictionary now, add the required
|
||||
* objects for the index.
|
||||
*/
|
||||
prop_dictionary_set_cstring_nocopy(newpkgd, "filename",
|
||||
filename);
|
||||
sha256 = xbps_get_file_hash(file);
|
||||
if (sha256 == NULL) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
prop_dictionary_set_cstring(newpkgd, "filename-sha256",
|
||||
sha256);
|
||||
free(sha256);
|
||||
|
||||
if (stat(file, &st) == -1) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
prop_dictionary_set_uint64(newpkgd, "filename-size",
|
||||
(uint64_t)st.st_size);
|
||||
/*
|
||||
* Add dictionary into the index and update package count.
|
||||
*/
|
||||
pkgar = prop_dictionary_get(idxdict, "packages");
|
||||
if (pkgar == NULL) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
if (!xbps_add_obj_to_array(pkgar, newpkgd)) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
prop_dictionary_set_uint64(idxdict, "total-pkgs",
|
||||
prop_array_count(pkgar));
|
||||
if (!prop_dictionary_externalize_to_file(idxdict, plist)) {
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
printf("Registered %s-%s in package index.\n",
|
||||
pkgname, version);
|
||||
break;
|
||||
}
|
||||
|
||||
free(plist);
|
||||
out2:
|
||||
prop_object_release(idxdict);
|
||||
out1:
|
||||
archive_read_finish(ar);
|
||||
out:
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_repo_genindex(const char *pkgdir)
|
||||
{
|
||||
struct dirent *dp;
|
||||
DIR *dirp;
|
||||
struct utsname un;
|
||||
char *binfile, *path;
|
||||
size_t i;
|
||||
int rv = 0;
|
||||
bool foundpkg = false;
|
||||
|
||||
if (uname(&un) == -1)
|
||||
return errno;
|
||||
/*
|
||||
* Iterate over the known architecture directories to find
|
||||
* binary packages.
|
||||
*/
|
||||
for (i = 0; archdirs[i] != NULL; i++) {
|
||||
if ((strcmp(archdirs[i], un.machine)) &&
|
||||
(strcmp(archdirs[i], "noarch")))
|
||||
continue;
|
||||
|
||||
path = xbps_xasprintf("%s/%s", pkgdir, archdirs[i]);
|
||||
if (path == NULL)
|
||||
return errno;
|
||||
|
||||
dirp = opendir(path);
|
||||
if (dirp == NULL) {
|
||||
free(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((dp = readdir(dirp)) != NULL) {
|
||||
if ((strcmp(dp->d_name, ".") == 0) ||
|
||||
(strcmp(dp->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
/* Ignore unknown files */
|
||||
if (strstr(dp->d_name, ".xbps") == NULL)
|
||||
continue;
|
||||
|
||||
foundpkg = true;
|
||||
binfile = xbps_xasprintf("%s/%s", path, dp->d_name);
|
||||
if (binfile == NULL) {
|
||||
(void)closedir(dirp);
|
||||
free(path);
|
||||
return errno;
|
||||
}
|
||||
rv = repoidx_addpkg(binfile, dp->d_name, pkgdir);
|
||||
free(binfile);
|
||||
if (rv != 0) {
|
||||
(void)closedir(dirp);
|
||||
free(path);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
(void)closedir(dirp);
|
||||
free(path);
|
||||
}
|
||||
|
||||
if (foundpkg == false)
|
||||
rv = ENOENT;
|
||||
|
||||
return rv;
|
||||
}
|
||||
31
bin/xbps-repo/index.h
Normal file
31
bin/xbps-repo/index.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*-
|
||||
* Copyright (c) 2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _XBPS_REPO_INDEX_H_
|
||||
#define _XBPS_REPO_INDEX_H_
|
||||
|
||||
int xbps_repo_genindex(const char *);
|
||||
|
||||
#endif /* !_XBPS_REPO_INDEX_H_ */
|
||||
288
bin/xbps-repo/main.c
Normal file
288
bin/xbps-repo/main.c
Normal file
@@ -0,0 +1,288 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "index.h"
|
||||
#include "util.h"
|
||||
|
||||
typedef struct repository_info {
|
||||
const char *index_version;
|
||||
const char *location_local;
|
||||
const char *location_remote;
|
||||
uint64_t total_pkgs;
|
||||
} repo_info_t;
|
||||
|
||||
static bool sanitize_localpath(char *, const char *);
|
||||
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
|
||||
static void usage(void);
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
printf("Usage: xbps-repo [options] [action] [arguments]\n\n"
|
||||
" Available actions:\n"
|
||||
" add, genindex, list, remove, search, show\n"
|
||||
" Actions with arguments:\n"
|
||||
" add\t\t<URI>\n"
|
||||
" genindex\t<path>\n"
|
||||
" remove\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-repo add /path/to/directory\n"
|
||||
" $ xbps-repo add http://www.location.org/xbps-repo\n"
|
||||
" $ xbps-repo list\n"
|
||||
" $ xbps-repo remove /path/to/directory\n"
|
||||
" $ xbps-repo search klibc\n"
|
||||
" $ xbps-repo show klibc\n"
|
||||
" $ xbps-repo genindex /path/to/packages/dir\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static bool
|
||||
pkgindex_getinfo(prop_dictionary_t dict, repo_info_t *ri)
|
||||
{
|
||||
assert(dict != NULL || ri != NULL);
|
||||
|
||||
if (!prop_dictionary_get_cstring_nocopy(dict,
|
||||
"pkgindex-version", &ri->index_version))
|
||||
return false;
|
||||
|
||||
if (!prop_dictionary_get_cstring_nocopy(dict,
|
||||
"location-local", &ri->location_local))
|
||||
return false;
|
||||
|
||||
/* This one is optional, thus don't panic */
|
||||
prop_dictionary_get_cstring_nocopy(dict, "location-remote",
|
||||
&ri->location_remote);
|
||||
|
||||
if (!prop_dictionary_get_uint64(dict, "total-pkgs",
|
||||
&ri->total_pkgs))
|
||||
return false;
|
||||
|
||||
/* Reject empty repositories, how could this happen? :-) */
|
||||
if (ri->total_pkgs <= 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
sanitize_localpath(char *buf, const char *path)
|
||||
{
|
||||
char *dirnp, *basenp, *dir, *base, *tmp;
|
||||
bool rv = false;
|
||||
|
||||
dir = strdup(path);
|
||||
if (dir == NULL)
|
||||
return false;
|
||||
|
||||
base = strdup(path);
|
||||
if (base == NULL) {
|
||||
free(dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
dirnp = dirname(dir);
|
||||
if (strcmp(dirnp, ".") == 0)
|
||||
goto out;
|
||||
|
||||
basenp = basename(base);
|
||||
if (strcmp(basenp, base) == 0)
|
||||
goto out;
|
||||
|
||||
tmp = strncpy(buf, dirnp, PATH_MAX - 1);
|
||||
if (sizeof(*tmp) >= PATH_MAX)
|
||||
goto out;
|
||||
|
||||
buf[strlen(buf) + 1] = '\0';
|
||||
if (strcmp(dirnp, "/"))
|
||||
strncat(buf, "/", 1);
|
||||
strncat(buf, basenp, PATH_MAX - strlen(buf) - 1);
|
||||
rv = true;
|
||||
|
||||
out:
|
||||
free(dir);
|
||||
free(base);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
repo_info_t *rinfo = NULL;
|
||||
char dpkgidx[PATH_MAX], *plist, *root = NULL;
|
||||
int c, rv = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "r:")) != -1) {
|
||||
switch (c) {
|
||||
case 'r':
|
||||
/* To specify the root directory */
|
||||
root = optarg;
|
||||
xbps_set_rootdir(root);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
if (strcasecmp(argv[0], "add") == 0) {
|
||||
/* Adds a new repository to the pool. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (!sanitize_localpath(dpkgidx, argv[1]))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
/* Temp buffer to verify pkgindex file. */
|
||||
plist = xbps_get_pkg_index_plist(dpkgidx);
|
||||
if (plist == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL) {
|
||||
printf("Directory %s does not contain any "
|
||||
"xbps pkgindex file.\n", dpkgidx);
|
||||
free(plist);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
rinfo = malloc(sizeof(*rinfo));
|
||||
if (rinfo == NULL) {
|
||||
prop_object_release(dict);
|
||||
free(plist);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!pkgindex_getinfo(dict, rinfo)) {
|
||||
printf("'%s' is incomplete.\n", plist);
|
||||
prop_object_release(dict);
|
||||
free(rinfo);
|
||||
free(plist);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((rv = xbps_register_repository(dpkgidx)) != 0) {
|
||||
printf("ERROR: couldn't register repository (%s)\n",
|
||||
strerror(rv));
|
||||
prop_object_release(dict);
|
||||
free(rinfo);
|
||||
free(plist);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Added repository at %s (%s) with %ju packages.\n",
|
||||
rinfo->location_local, rinfo->index_version,
|
||||
rinfo->total_pkgs);
|
||||
|
||||
prop_object_release(dict);
|
||||
free(rinfo);
|
||||
free(plist);
|
||||
|
||||
} else if (strcasecmp(argv[0], "list") == 0) {
|
||||
/* Lists all repositories registered in pool. */
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
(void)xbps_callback_array_iter_in_repolist(
|
||||
list_strings_sep_in_array, NULL);
|
||||
|
||||
} else if ((strcasecmp(argv[0], "rm") == 0) ||
|
||||
(strcasecmp(argv[0], "remove") == 0)) {
|
||||
/* Remove a repository from the pool. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (!sanitize_localpath(dpkgidx, argv[1]))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if ((rv = xbps_unregister_repository(dpkgidx)) != 0) {
|
||||
if (rv == ENOENT)
|
||||
printf("Repository '%s' not actually "
|
||||
"registered.\n", dpkgidx);
|
||||
else
|
||||
printf("ERROR: couldn't unregister "
|
||||
"repository (%s)\n", strerror(rv));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "search") == 0) {
|
||||
/*
|
||||
* Search for a package by looking at pkgname/short_desc
|
||||
* by using shell style match patterns (fnmatch(3)).
|
||||
*/
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
(void)xbps_callback_array_iter_in_repolist(
|
||||
search_string_in_pkgs, argv[1]);
|
||||
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about a binary package. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = xbps_callback_array_iter_in_repolist(
|
||||
show_pkg_info_from_repolist, argv[1]);
|
||||
if (rv == 0 && errno == ENOENT) {
|
||||
printf("Unable to locate package '%s' from "
|
||||
"repository pool.\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "genindex") == 0) {
|
||||
/* Generates a package repository index plist file. */
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = xbps_repo_genindex(argv[1]);
|
||||
exit(rv);
|
||||
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
377
bin/xbps-repo/util.c
Normal file
377
bin/xbps-repo/util.c
Normal file
@@ -0,0 +1,377 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "util.h"
|
||||
|
||||
static void show_pkg_info(prop_dictionary_t);
|
||||
static int show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||
|
||||
static void
|
||||
show_pkg_info(prop_dictionary_t dict)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *sep;
|
||||
char size[64];
|
||||
int rv = 0;
|
||||
|
||||
assert(dict != NULL);
|
||||
assert(prop_dictionary_count(dict) != 0);
|
||||
|
||||
obj = prop_dictionary_get(dict, "pkgname");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING)
|
||||
printf("Package: %s\n", prop_string_cstring_nocopy(obj));
|
||||
|
||||
obj = prop_dictionary_get(dict, "installed_size");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_NUMBER) {
|
||||
printf("Installed size: ");
|
||||
rv = xbps_humanize_number(size, 5,
|
||||
(int64_t)prop_number_unsigned_integer_value(obj),
|
||||
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE);
|
||||
if (rv == -1)
|
||||
printf("%ju\n",
|
||||
prop_number_unsigned_integer_value(obj));
|
||||
else
|
||||
printf("%s\n", size);
|
||||
}
|
||||
|
||||
obj = prop_dictionary_get(dict, "maintainer");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING)
|
||||
printf("Maintainer: %s\n", prop_string_cstring_nocopy(obj));
|
||||
|
||||
obj = prop_dictionary_get(dict, "architecture");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING)
|
||||
printf("Architecture: %s\n", prop_string_cstring_nocopy(obj));
|
||||
|
||||
obj = prop_dictionary_get(dict, "version");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING)
|
||||
printf("Version: %s\n", prop_string_cstring_nocopy(obj));
|
||||
|
||||
obj = prop_dictionary_get(dict, "filename");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING) {
|
||||
printf("Filename: %s", prop_string_cstring_nocopy(obj));
|
||||
obj = prop_dictionary_get(dict, "filename-size");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_NUMBER) {
|
||||
rv = xbps_humanize_number(size, 5,
|
||||
(int64_t)prop_number_unsigned_integer_value(obj),
|
||||
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE);
|
||||
if (rv == -1)
|
||||
printf(" (size: %ju)\n",
|
||||
prop_number_unsigned_integer_value(obj));
|
||||
else
|
||||
printf(" (size: %s)\n", size);
|
||||
} else
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
obj = prop_dictionary_get(dict, "filename-sha256");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING)
|
||||
printf("SHA256: %s\n", prop_string_cstring_nocopy(obj));
|
||||
|
||||
obj = prop_dictionary_get(dict, "run_depends");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_ARRAY) {
|
||||
printf("Dependencies:\n");
|
||||
(void)xbps_callback_array_iter_in_dict(dict, "run_depends",
|
||||
list_strings_in_array, NULL);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
obj = prop_dictionary_get(dict, "conf_files");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_ARRAY) {
|
||||
printf("Configuration files:\n");
|
||||
sep = " ";
|
||||
(void)xbps_callback_array_iter_in_dict(dict, "conf_files",
|
||||
list_strings_sep_in_array, __UNCONST(sep));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
obj = prop_dictionary_get(dict, "keep_dirs");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_ARRAY) {
|
||||
printf("Permanent directories:\n");
|
||||
sep = " ";
|
||||
(void)xbps_callback_array_iter_in_dict(dict, "keep_dirs",
|
||||
list_strings_sep_in_array, __UNCONST(sep));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
obj = prop_dictionary_get(dict, "short_desc");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING)
|
||||
printf("Description: %s", prop_string_cstring_nocopy(obj));
|
||||
|
||||
obj = prop_dictionary_get(dict, "long_desc");
|
||||
if (obj && prop_object_type(obj) == PROP_TYPE_STRING)
|
||||
printf(" %s\n", prop_string_cstring_nocopy(obj));
|
||||
}
|
||||
|
||||
int
|
||||
search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
const char *repofile;
|
||||
char *plist;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
|
||||
/* Get the location of pkgindex file. */
|
||||
repofile = prop_string_cstring_nocopy(obj);
|
||||
assert(repofile != NULL);
|
||||
|
||||
plist = xbps_get_pkg_index_plist(repofile);
|
||||
if (plist == NULL) {
|
||||
errno = ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL) {
|
||||
free(plist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("From %s repository ...\n", repofile);
|
||||
xbps_callback_array_iter_in_dict(dict, "packages",
|
||||
show_pkg_namedesc, arg);
|
||||
prop_object_release(dict);
|
||||
free(plist);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
show_pkg_info_from_metadir(const char *pkgname)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
const char *rootdir;
|
||||
char *plist;
|
||||
|
||||
rootdir = xbps_get_rootdir();
|
||||
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", rootdir,
|
||||
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
||||
if (plist == NULL)
|
||||
return EINVAL;
|
||||
|
||||
pkgd = prop_dictionary_internalize_from_file(plist);
|
||||
if (pkgd == NULL) {
|
||||
free(plist);
|
||||
return errno;
|
||||
}
|
||||
|
||||
show_pkg_info(pkgd);
|
||||
prop_object_release(pkgd);
|
||||
free(plist);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
show_pkg_files_from_metadir(const char *pkgname)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_array_t array;
|
||||
prop_object_iterator_t iter = NULL;
|
||||
prop_object_t obj;
|
||||
const char *destdir, *file;
|
||||
char *plist, *array_str = "files";
|
||||
int i, rv = 0;
|
||||
|
||||
destdir = xbps_get_rootdir();
|
||||
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", destdir,
|
||||
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
||||
if (plist == NULL)
|
||||
return EINVAL;
|
||||
|
||||
pkgd = prop_dictionary_internalize_from_file(plist);
|
||||
if (pkgd == NULL) {
|
||||
free(plist);
|
||||
return errno;
|
||||
}
|
||||
free(plist);
|
||||
|
||||
/* Links. */
|
||||
array = prop_dictionary_get(pkgd, "links");
|
||||
if (array && prop_array_count(array) > 0) {
|
||||
iter = xbps_get_array_iter_from_dict(pkgd, "links");
|
||||
if (iter == NULL) {
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
printf("%s\n", file);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
}
|
||||
|
||||
/* Files and configuration files. */
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (i == 0)
|
||||
array_str = "conf_files";
|
||||
else
|
||||
array_str = "files";
|
||||
|
||||
array = prop_dictionary_get(pkgd, array_str);
|
||||
if (array == NULL || prop_array_count(array) == 0)
|
||||
continue;
|
||||
|
||||
iter = xbps_get_array_iter_from_dict(pkgd, array_str);
|
||||
if (iter == NULL) {
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
printf("%s\n", file);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
}
|
||||
out:
|
||||
prop_object_release(pkgd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
prop_dictionary_t dict, pkgdict;
|
||||
prop_string_t oloc;
|
||||
const char *repofile, *repoloc;
|
||||
char *plist;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
|
||||
/* Get the location */
|
||||
repofile = prop_string_cstring_nocopy(obj);
|
||||
|
||||
plist = xbps_get_pkg_index_plist(repofile);
|
||||
if (plist == NULL)
|
||||
return EINVAL;
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL || prop_dictionary_count(dict) == 0) {
|
||||
free(plist);
|
||||
errno = ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pkgdict = xbps_find_pkg_in_dict(dict, "packages", arg);
|
||||
if (pkgdict == NULL) {
|
||||
prop_object_release(dict);
|
||||
free(plist);
|
||||
errno = ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
oloc = prop_dictionary_get(dict, "location-remote");
|
||||
if (oloc == NULL)
|
||||
oloc = prop_dictionary_get(dict, "location-local");
|
||||
|
||||
if (oloc && prop_object_type(oloc) == PROP_TYPE_STRING)
|
||||
repoloc = prop_string_cstring_nocopy(oloc);
|
||||
else {
|
||||
prop_object_release(dict);
|
||||
free(plist);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
printf("Repository: %s\n", repoloc);
|
||||
show_pkg_info(pkgdict);
|
||||
*loop_done = true;
|
||||
prop_object_release(dict);
|
||||
free(plist);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
const char *pkgname, *desc, *ver, *pattern = arg;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
|
||||
assert(pattern != NULL);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &ver);
|
||||
assert(ver != NULL);
|
||||
|
||||
if ((fnmatch(pattern, pkgname, 0) == 0) ||
|
||||
(fnmatch(pattern, desc, 0) == 0))
|
||||
printf(" %s-%s - %s\n", pkgname, ver, desc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
list_strings_in_array(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
static size_t cols;
|
||||
static bool first;
|
||||
|
||||
(void)arg;
|
||||
(void)loop_done;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
|
||||
cols += strlen(prop_string_cstring_nocopy(obj)) + 4;
|
||||
if (cols <= 80) {
|
||||
if (first == false) {
|
||||
printf(" ");
|
||||
first = true;
|
||||
}
|
||||
} else {
|
||||
printf("\n ");
|
||||
cols = strlen(prop_string_cstring_nocopy(obj)) + 4;
|
||||
}
|
||||
printf("%s ", prop_string_cstring_nocopy(obj));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
list_strings_sep_in_array(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
const char *sep = arg;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
|
||||
printf("%s%s\n", sep ? sep : "", prop_string_cstring_nocopy(obj));
|
||||
|
||||
return 0;
|
||||
}
|
||||
36
bin/xbps-repo/util.h
Normal file
36
bin/xbps-repo/util.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _XBPS_REPO_UTIL_H_
|
||||
#define _XBPS_REPO_UTIL_H_
|
||||
|
||||
int search_string_in_pkgs(prop_object_t, void *, bool *);
|
||||
int show_pkg_info_from_metadir(const char *);
|
||||
int show_pkg_files_from_metadir(const char *);
|
||||
int show_pkg_info_from_repolist(prop_object_t, void *, bool *);
|
||||
int list_strings_in_array(prop_object_t, void *, bool *);
|
||||
int list_strings_sep_in_array(prop_object_t, void *, bool *);
|
||||
|
||||
#endif /* !_XBPS_REPO_UTIL_H_ */
|
||||
18
bin/xbps-src/Makefile
Normal file
18
bin/xbps-src/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/vars.mk
|
||||
|
||||
BIN = xbps-src
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" \
|
||||
-e "s|@@XBPS_INSTALL_ETCDIR@@|$(ETCDIR)|g" \
|
||||
main.sh > xbps-src
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-rm -f $(BIN)
|
||||
|
||||
install: all
|
||||
install -d $(SBINDIR)
|
||||
install -m 755 $(BIN) $(SBINDIR)
|
||||
291
bin/xbps-src/main.sh
Executable file
291
bin/xbps-src/main.sh
Executable file
@@ -0,0 +1,291 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# xbps - A simple, minimal, fast and uncomplete build package system.
|
||||
#-
|
||||
# Copyright (c) 2008 Juan Romero Pardines.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#-
|
||||
trap "echo && exit 1" INT QUIT
|
||||
|
||||
: ${XBPS_CONFIG_FILE:=@@XBPS_INSTALL_ETCDIR@@/xbps.conf}
|
||||
|
||||
: ${progname:=$(basename $0)}
|
||||
: ${fakeroot_cmd:=fakeroot}
|
||||
: ${fetch_cmd:=wget}
|
||||
: ${xbps_machine:=$(uname -m)}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _EOF
|
||||
$progname: [-C] [-c <config_file>] [-u] <target> <pkg>
|
||||
|
||||
Targets:
|
||||
build <pkg> Build a package (fetch + extract + configure + build).
|
||||
build-pkg [<pkg>|all] Build a binary package from <pkg>.
|
||||
Package must be installed into destdir. If the <all>
|
||||
keyword is used instead of <pkg>, all packages
|
||||
currently installed will be used.
|
||||
chroot Enter to the chroot in masterdir.
|
||||
configure <pkg> Configure a package (fetch + extract + configure).
|
||||
extract <pkg> Extract distribution file(s) into build directory.
|
||||
fetch <pkg> Download distribution file(s).
|
||||
info <pkg> Show information about <pkg>.
|
||||
install-destdir <pkg> build + install into destdir.
|
||||
install <pkg> install-destdir + stow.
|
||||
list List installed packages in masterdir.
|
||||
listfiles <pkg> List installed files from <pkg>.
|
||||
remove <pkg> Remove package completely (destdir + masterdir).
|
||||
stow <pkg> Copy <pkg> files from destdir into masterdir and
|
||||
register package in database.
|
||||
unstow <pkg> Remove <pkg> files from masterdir and unregister
|
||||
package from database.
|
||||
|
||||
Options:
|
||||
-C Do not remove build directory after successful installation.
|
||||
-c Path to global configuration file:
|
||||
if not specified @@XBPS_INSTALL_ETCDIR@@/xbps.conf is used.
|
||||
-u Update the checksum in template file if used in 'fetch' target.
|
||||
_EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_path()
|
||||
{
|
||||
eval local orig="$1"
|
||||
|
||||
case "$orig" in
|
||||
/) ;;
|
||||
/*) orig="${orig%/}" ;;
|
||||
*) orig="$(pwd)/${orig%/}" ;;
|
||||
esac
|
||||
|
||||
path_fixed="$orig"
|
||||
}
|
||||
|
||||
run_file()
|
||||
{
|
||||
local file="$1"
|
||||
|
||||
check_path "$file"
|
||||
. $path_fixed
|
||||
}
|
||||
|
||||
set_defvars()
|
||||
{
|
||||
local DDIRS i
|
||||
|
||||
: ${XBPS_TEMPLATESDIR:=$XBPS_DISTRIBUTIONDIR/templates}
|
||||
: ${XBPS_TRIGGERSDIR:=$XBPS_DISTRIBUTIONDIR/triggers}
|
||||
: ${XBPS_HELPERSDIR:=$XBPS_TEMPLATESDIR/helpers}
|
||||
: ${XBPS_DBDIR:=$XBPS_MASTERDIR/var/db/xbps}
|
||||
: ${XBPS_META_PATH:=$XBPS_DBDIR/}
|
||||
: ${XBPS_PKGMETADIR:=$XBPS_DBDIR/metadata}
|
||||
: ${XBPS_SHUTILSDIR:=$XBPS_DISTRIBUTIONDIR/shutils}
|
||||
|
||||
DDIRS="XBPS_TEMPLATESDIR XBPS_TRIGGERSDIR"
|
||||
DDIRS="$DDIRS XBPS_HELPERSDIR XBPS_SHUTILSDIR"
|
||||
for i in ${DDIRS}; do
|
||||
eval val="\$$i"
|
||||
[ ! -d "$val" ] && msg_error "cannot find $i, aborting."
|
||||
done
|
||||
|
||||
XBPS_REGPKGDB_CMD="xbps-pkgdb -r $XBPS_MASTERDIR"
|
||||
XBPS_BIN_CMD="xbps-bin -r $XBPS_MASTERDIR"
|
||||
}
|
||||
|
||||
#
|
||||
# Checks that all required variables specified in the configuration
|
||||
# file are properly working.
|
||||
#
|
||||
check_config_vars()
|
||||
{
|
||||
local cffound=
|
||||
local f=
|
||||
|
||||
if [ -z "$config_file_specified" ]; then
|
||||
config_file_paths="$XBPS_CONFIG_FILE ./etc/xbps.conf"
|
||||
for f in $config_file_paths; do
|
||||
[ -f $f ] && XBPS_CONFIG_FILE=$f && \
|
||||
cffound=yes && break
|
||||
done
|
||||
[ -z "$cffound" ] && msg_error "cannot find a config file"
|
||||
fi
|
||||
|
||||
run_file ${XBPS_CONFIG_FILE}
|
||||
XBPS_CONFIG_FILE=$path_fixed
|
||||
|
||||
if [ ! -f "$XBPS_CONFIG_FILE" ]; then
|
||||
msg_error "cannot find configuration file: $XBPS_CONFIG_FILE"
|
||||
fi
|
||||
|
||||
local XBPS_VARS="XBPS_MASTERDIR XBPS_DESTDIR XBPS_BUILDDIR \
|
||||
XBPS_SRCDISTDIR"
|
||||
|
||||
for f in ${XBPS_VARS}; do
|
||||
eval val="\$$f"
|
||||
[ -z "$val" ] && msg_error "'$f' not set in configuration file"
|
||||
|
||||
if [ ! -d "$val" ]; then
|
||||
mkdir "$val"
|
||||
[ $? -ne 0 ] && msg_error "couldn't create '$f' directory"
|
||||
fi
|
||||
done
|
||||
|
||||
export PATH="$PATH:@@XBPS_INSTALL_PREFIX@@/sbin"
|
||||
}
|
||||
|
||||
#
|
||||
# main()
|
||||
#
|
||||
while getopts "Cc:u" opt; do
|
||||
case $opt in
|
||||
C) dontrm_builddir=yes;;
|
||||
c) config_file_specified=yes; XBPS_CONFIG_FILE="$OPTARG";;
|
||||
u) update_checksum=yes;;
|
||||
--) shift; break;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
[ $# -eq 0 -o $# -gt 2 ] && usage
|
||||
|
||||
target="$1"
|
||||
if [ -z "$target" ]; then
|
||||
echo "=> ERROR: missing target."
|
||||
usage
|
||||
fi
|
||||
|
||||
#
|
||||
# Check configuration vars before anyting else, and set defaults vars.
|
||||
#
|
||||
check_config_vars
|
||||
set_defvars
|
||||
. $XBPS_SHUTILSDIR/common_funcs.sh
|
||||
|
||||
# Main switch
|
||||
case "$target" in
|
||||
build|configure)
|
||||
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
||||
setup_tmpl $2
|
||||
|
||||
if [ -z "$base_chroot" -a -z "$in_chroot" ]; then
|
||||
. $XBPS_SHUTILSDIR/chroot.sh
|
||||
if [ "$target" = "build" ]; then
|
||||
xbps_chroot_handler build $2
|
||||
else
|
||||
xbps_chroot_handler configure $2
|
||||
fi
|
||||
else
|
||||
. $XBPS_SHUTILSDIR/fetch_funcs.sh
|
||||
fetch_distfiles $2
|
||||
if [ ! -f "$XBPS_EXTRACT_DONE" ]; then
|
||||
. $XBPS_SHUTILSDIR/extract_funcs.sh
|
||||
extract_distfiles $2
|
||||
fi
|
||||
if [ "$target" = "configure" ]; then
|
||||
. $XBPS_SHUTILSDIR/configure_funcs.sh
|
||||
configure_src_phase $2
|
||||
else
|
||||
if [ ! -f "$XBPS_CONFIGURE_DONE" ]; then
|
||||
. $XBPS_SHUTILSDIR/configure_funcs.sh
|
||||
configure_src_phase $2
|
||||
fi
|
||||
. $XBPS_SHUTILSDIR/build_funcs.sh
|
||||
build_src_phase $2
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
build-pkg)
|
||||
. $XBPS_SHUTILSDIR/make-binpkg.sh
|
||||
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
||||
if [ "$2" = "all" ]; then
|
||||
for f in $($XBPS_BIN_CMD list|awk '{print $1}'); do
|
||||
pkg=$(xbps-pkgdb getpkgname $f)
|
||||
setup_tmpl ${pkg}
|
||||
xbps_make_binpkg ${pkg}
|
||||
reset_tmpl_vars
|
||||
done
|
||||
else
|
||||
setup_tmpl $2
|
||||
xbps_make_binpkg $2
|
||||
fi
|
||||
;;
|
||||
chroot)
|
||||
. $XBPS_SHUTILSDIR/chroot.sh
|
||||
xbps_chroot_handler chroot dummy
|
||||
;;
|
||||
extract|fetch|info)
|
||||
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
||||
setup_tmpl $2
|
||||
if [ "$target" = "info" ]; then
|
||||
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
||||
info_tmpl $2
|
||||
exit $?
|
||||
fi
|
||||
if [ "$target" = "fetch" ]; then
|
||||
. $XBPS_SHUTILSDIR/fetch_funcs.sh
|
||||
fetch_distfiles $2 $update_checksum
|
||||
exit $?
|
||||
fi
|
||||
. $XBPS_SHUTILSDIR/extract_funcs.sh
|
||||
extract_distfiles $2
|
||||
;;
|
||||
install|install-destdir)
|
||||
[ -z "$2" ] && msg_error "missing package name after target."
|
||||
[ "$target" = "install-destdir" ] && install_destdir_target=yes
|
||||
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
|
||||
install_pkg $2
|
||||
;;
|
||||
list|listfiles)
|
||||
if [ "$target" = "list" ]; then
|
||||
$XBPS_BIN_CMD list
|
||||
exit $?
|
||||
fi
|
||||
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
|
||||
list_pkg_files $2
|
||||
;;
|
||||
remove)
|
||||
[ -z "$2" ] && msg_error "missing package name after target."
|
||||
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
|
||||
remove_pkg $2
|
||||
;;
|
||||
stow)
|
||||
stow_flag=yes
|
||||
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
||||
setup_tmpl $2
|
||||
. $XBPS_SHUTILSDIR/stow_funcs.sh
|
||||
stow_pkg $2
|
||||
;;
|
||||
unstow)
|
||||
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
||||
setup_tmpl $2
|
||||
. $XBPS_SHUTILSDIR/stow_funcs.sh
|
||||
unstow_pkg $2
|
||||
;;
|
||||
*)
|
||||
echo "=> ERROR: invalid target: $target."
|
||||
usage
|
||||
esac
|
||||
|
||||
# Agur
|
||||
exit $?
|
||||
Reference in New Issue
Block a user