xbps-fetch(1): new utility that replaces 'xbps-uhelper fetch'.

xbps-install(1): document all libfetch env vars.

Signed-off-by: Juan RP <xtraeme@gmail.com>
This commit is contained in:
Juan RP
2019-06-12 17:57:03 +02:00
committed by Duncan Overbruck
parent 9cda7ef72a
commit 8cea3e351b
21 changed files with 314 additions and 48 deletions

7
bin/xbps-fetch/Makefile Normal file
View File

@@ -0,0 +1,7 @@
TOPDIR = ../..
-include $(TOPDIR)/config.mk
BIN = xbps-fetch
OBJS = main.o ../xbps-install/fetch_cb.o
include $(TOPDIR)/mk/prog.mk

134
bin/xbps-fetch/main.c Normal file
View File

@@ -0,0 +1,134 @@
/*-
* Copyright (c) 2019 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 <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <unistd.h>
#include <getopt.h>
#include <xbps.h>
#include "../xbps-install/defs.h"
static void __attribute__((noreturn))
usage(void)
{
fprintf(stdout,
"Usage: xbps-fetch [options] <url> <url+N>\n\n"
"OPTIONS:\n"
" -d\t\tEnable debug messages to stderr\n"
" -h\t\tShow usage()\n"
" -o <file>\tRename downloaded file to <file>\n"
" -v\t\tEnable verbose output\n"
" -V\t\tPrints the xbps release version\n");
exit(EXIT_FAILURE);
}
static char *
fname(char *url)
{
char *filename;
if ((filename = strrchr(url, '>'))) {
*filename = '\0';
} else {
filename = strrchr(url, '/');
}
if (filename == NULL)
return NULL;
return filename + 1;
}
int
main(int argc, char **argv)
{
int flags = 0, c = 0, rv = 0;
bool verbose = false;
struct xbps_handle xh = {};
struct xferstat xfer = {};
const char *filename = NULL, *progname = argv[0];
const struct option longopts[] = {
{ NULL, 0, NULL, 0 }
};
while ((c = getopt_long(argc, argv, "o:dhVv", longopts, NULL)) != -1) {
switch (c) {
case 'o':
filename = optarg;
break;
case 'd':
flags |= XBPS_FLAG_DEBUG;
break;
case 'v':
verbose = true;
break;
case 'V':
printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS);
case '?':
case 'h':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (!argc)
usage();
/*
* Initialize libxbps.
*/
xh.flags = flags;
xh.fetch_cb = fetch_file_progress_cb;
xh.fetch_cb_data = &xfer;
if ((rv = xbps_init(&xh)) != 0) {
xbps_error_printf("%s: failed to initialize libxbps: %s\n",
progname, strerror(rv));
exit(EXIT_FAILURE);
}
for (int i = 0; i < argc; i++) {
if ((argc == 1) && !filename)
filename = fname(argv[i]);
rv = xbps_fetch_file_dest(&xh, argv[i], filename, verbose ? "v" : "");
if (rv == -1) {
fprintf(stderr, "%s: %s\n", argv[i], xbps_fetch_error_string());
} else if (rv == 0) {
printf("%s: file is identical with remote.\n", argv[i]);
} else {
rv = 0;
}
}
xbps_end(&xh);
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
}

101
bin/xbps-fetch/xbps-fetch.1 Normal file
View File

@@ -0,0 +1,101 @@
.Dd June 12, 2019
.Dt XBPS-FETCH 1
.Sh NAME
.Nm xbps-fetch
.Nd XBPS utility to fetch files from URLs
.Sh SYNOPSIS
.Nm xbps-fetch
.Op OPTIONS
.Ar <URL>
.Ar <URL+N>
.Sh DESCRIPTION
The
.Nm
utility downloads files from specified URLs.
Multiple protocols are supported:
.Ar ftp ,
.Ar http ,
.Ar https ,
.Ar socks5 .
.Sh OPTIONS
.Bl -tag -width -x
.It Fl d
Enables debug messages on stderr.
.It Fl h
Show the help message.
.It Fl o Ar output
Rename file from specified URL to
.Ar output .
.It Fl v
Enables verbose messages.
.It Fl V
Show the version information.
.El
.Sh ENVIRONMENT
.Bl -tag -width -x
.It Sy FTP_PASSIVE_MODE
If set to anything else than
.Ar "no"
passive mode will be set for the ftp connection.
.It Sy FTP_LOGIN
User name to be set for ftp authentication.
.It Sy FTP_PASSWORD
Password to be set for ftp authentication.
.It Sy FTP_PROXY
Proxy URL that will be used to establish a ftp connection.
.It Sy HTTP_PROXY
Proxy URL that will be used to establish a http connection.
.It Sy HTTP_PROXY_AUTH
Sets the credentials to authenticate a user agent to a proxy server, in the form
.Ar user:pass .
.It Sy HTTP_AUTH
Sets the credentials to authenticate to a http server, in the form
.Ar user:pass .
.It Sy HTTP_REFERER
Overrides the default Referer http header.
.It Sy HTTP_USER_AGENT
Override the default User-Agent http header.
.It Sy NO_PROXY
Specifies a set of domains for which the proxy should not be consulted.
The contents is a comma-, or space-separated list of domain names.
A single asterisk will override all proxy variables and no transactions
will be proxied.
.It Sy SOCKS_PROXY
Proxy URL that will be used to establish a socks connection.
.It Sy SSL_NO_VERIFY_HOSTNAME
Disables SSL/TLS hostname verification.
.It Sy SSL_NO_VERIFY_PEER
Disables SSL/TLS peer verification.
.It Sy SSL_CA_CERT_FILE
Overrides the default CA certificates file, by default set to
.Ar /etc/ssl/certs/ca-certificates.crt .
.It Sy SSL_CA_CERT_PATH
Overrides the default CA certificates path, by default set to
.Ar /etc/ssl/certs .
.It Sy SSL_CLIENT_CERT_FILE
Sets the SSL/TLS client verification certificate file.
.It Sy SSL_CLIENT_KEY_FILE
Sets the SSL/TLS client verification key file.
.El
.Sh SEE ALSO
.Xr xbps-checkvers 1 ,
.Xr xbps-create 1 ,
.Xr xbps-dgraph 1 ,
.Xr xbps-digest 1 ,
.Xr xbps-fbulk 1 ,
.Xr xbps-install 1 ,
.Xr xbps-pkgdb 1 ,
.Xr xbps-query 1 ,
.Xr xbps-reconfigure 1 ,
.Xr xbps-remove 1 ,
.Xr xbps-rindex 1 ,
.Xr xbps-uchroot 1 ,
.Xr xbps-uunshare 1 ,
.Xr xbps.d 5
.Sh AUTHORS
.An Juan Romero Pardines <xtraeme@gmail.com>
.Sh BUGS
Probably, but I try to make this not happen.
Use it under your own responsibility and enjoy your life.
.Pp
Report bugs at https://github.com/void-linux/xbps/issues