diff --git a/bin/Makefile b/bin/Makefile index d0ca2feb..50a65e15 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,9 +1,6 @@ include ../vars.mk -SUBDIRS = xbps-cmpver -SUBDIRS += xbps-digest -SUBDIRS += xbps-fetch -SUBDIRS += xbps-pkgdb +SUBDIRS = xbps-uhelper SUBDIRS += xbps-repo SUBDIRS += xbps-bin diff --git a/bin/xbps-cmpver/main.c b/bin/xbps-cmpver/main.c deleted file mode 100644 index abf99c36..00000000 --- a/bin/xbps-cmpver/main.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Compare package and version strings - * @ 2008 - * Author: pancake - */ -#include - -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]); -} diff --git a/bin/xbps-digest/Makefile b/bin/xbps-digest/Makefile deleted file mode 100644 index 0529461c..00000000 --- a/bin/xbps-digest/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -TOPDIR = ../.. -include $(TOPDIR)/vars.mk - -BIN = xbps-digest - -include $(TOPDIR)/prog.mk diff --git a/bin/xbps-digest/main.c b/bin/xbps-digest/main.c deleted file mode 100644 index 0e9553e8..00000000 --- a/bin/xbps-digest/main.c +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * 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 -#include -#include -#include -#include - -#include - -static void -usage(void) -{ - fprintf(stderr, "usage: xbps-digest ...\n"); - exit(EXIT_FAILURE); -} - -int -main(int argc, char **argv) -{ - char *hash; - int i; - - if (argc < 2) - usage(); - - for (i = 1; i < argc; i++) { - hash = xbps_get_file_hash(argv[i]); - if (hash == NULL) { - printf("Couldn't get hash for %s (%s)\n", - argv[i], strerror(errno)); - exit(EXIT_FAILURE); - } - printf("%s\n", hash); - free(hash); - } - - exit(EXIT_SUCCESS); -} diff --git a/bin/xbps-fetch/Makefile b/bin/xbps-fetch/Makefile deleted file mode 100644 index 890d2c86..00000000 --- a/bin/xbps-fetch/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -TOPDIR = ../.. -include $(TOPDIR)/vars.mk - -BIN = xbps-fetch - -include $(TOPDIR)/prog.mk diff --git a/bin/xbps-fetch/main.c b/bin/xbps-fetch/main.c deleted file mode 100644 index bed61c54..00000000 --- a/bin/xbps-fetch/main.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include -#include "fetch.h" - -static void -usage(void) -{ - printf("usage: xbps-fetch [-v] URL\n"); - exit(EXIT_FAILURE); -} - -int -main(int argc, char **argv) -{ - char flags[8]; - int c, rv = 0; - - while ((c = getopt(argc, argv, "v")) != -1) { - switch (c) { - case 'v': - strcat(flags, "v"); - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - rv = xbps_fetch_file(argv[0], ".", false, flags); - if (rv == -1) { - printf("%s: %s\n", argv[0], xbps_fetch_error_string()); - exit(EXIT_FAILURE); - } else if (rv == 0) { - printf("%s: file is identical than remote.\n", argv[0]); - } - exit(EXIT_SUCCESS); -} diff --git a/bin/xbps-pkgdb/Makefile b/bin/xbps-pkgdb/Makefile deleted file mode 100644 index 3c3b00b0..00000000 --- a/bin/xbps-pkgdb/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -TOPDIR = ../.. -include $(TOPDIR)/vars.mk - -BIN = xbps-pkgdb - -include $(TOPDIR)/prog.mk diff --git a/bin/xbps-cmpver/Makefile b/bin/xbps-uhelper/Makefile similarity index 78% rename from bin/xbps-cmpver/Makefile rename to bin/xbps-uhelper/Makefile index 93817347..b385d43b 100644 --- a/bin/xbps-cmpver/Makefile +++ b/bin/xbps-uhelper/Makefile @@ -1,6 +1,6 @@ TOPDIR = ../.. include $(TOPDIR)/vars.mk -BIN = xbps-cmpver +BIN = xbps-uhelper include $(TOPDIR)/prog.mk diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-uhelper/main.c similarity index 80% rename from bin/xbps-pkgdb/main.c rename to bin/xbps-uhelper/main.c index 7be7902b..021762d2 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-uhelper/main.c @@ -56,13 +56,17 @@ write_plist_file(prop_dictionary_t dict, const char *file) static void usage(void) { - printf("usage: xbps-pkgdb [options] [action] [args]\n" + printf("usage: xbps-uhelper [options] [action] [args]\n" "\n" " Available actions:\n" - " getpkgdepname, getpkgname, getpkgrevision, getpkgversion,\n" - " pkgmatch, register, sanitize-plist, unregister, version\n" + " cmpver, digest, fetch, getpkgdepname, getpkgname, getpkgrevision,\n" + " getpkgversion, pkgmatch, register, sanitize-plist, unregister,\n" + " version\n" "\n" " Action arguments:\n" + " cmpver\t\t \n" + " digest\t\t \n" + " fetch\t\t\n" " getpkgdepname\t\n" " getpkgname\t\t\n" " getpkgrevision\t\n" @@ -78,13 +82,16 @@ usage(void) " -V\t\tPrints the xbps release version\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"); + " $ xbps-uhelper cmpver 'foo-1.0' 'foo-2.1'\n" + " $ xbps-uhelper digest /foo/blah.txt\n" + " $ xbps-uhelper fetch http://www.foo.org/file.blob\n" + " $ xbps-uhelper getpkgname foo-2.0\n" + " $ xbps-uhelper getpkgrevision foo-2.0_1\n" + " $ xbps-uhelper getpkgversion foo-2.0\n" + " $ xbps-uhelper register pkgname 2.0 \"A short description\"\n" + " $ xbps-uhelper sanitize-plist /blah/foo.plist\n" + " $ xbps-uhelper unregister pkgname 2.0\n" + " $ xbps-uhelper version pkgname\n"); exit(EXIT_FAILURE); } @@ -273,8 +280,46 @@ main(int argc, char **argv) if (argc != 3) usage(); - rv = xbps_pkgdep_match(argv[1], argv[2]); - exit(rv); + exit(xbps_pkgdep_match(argv[1], argv[2])); + + } else if (strcasecmp(argv[0], "cmpver") == 0) { + /* Compare two version strings, installed vs required */ + if (argc != 3) + usage(); + + exit(xbps_cmpver(argv[1], argv[2])); + + } else if (strcasecmp(argv[0], "digest") == 0) { + /* Prints SHA256 hashes for specified files */ + if (argc < 2) + usage(); + + char *hash; + int i; + + for (i = 1; i < argc; i++) { + hash = xbps_get_file_hash(argv[i]); + if (hash == NULL) { + printf("Couldn't get hash for %s (%s)\n", + argv[i], strerror(errno)); + exit(EXIT_FAILURE); + } + printf("%s\n", hash); + free(hash); + } + + } else if (strcasecmp(argv[0], "fetch") == 0) { + /* Fetch a file from specified URL */ + if (argc != 2) + usage(); + + rv = xbps_fetch_file(argv[1], ".", false, "v"); + if (rv == -1) { + printf("%s: %s\n", argv[1], xbps_fetch_error_string()); + exit(EXIT_FAILURE); + } else if (rv == 0) { + printf("%s: file is identical than remote.\n", argv[1]); + } } else { usage(); diff --git a/include/xbps_api.h b/include/xbps_api.h index 624f86d4..45c4231a 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -38,7 +38,7 @@ #include /* Current release version */ -#define XBPS_RELVER "20091124" +#define XBPS_RELVER "20091124-1" /* Default root PATH for xbps to store metadata info. */ #define XBPS_META_PATH "/var/db/xbps"