diff --git a/Makefile b/Makefile index 13861a4..f815410 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,14 @@ SUBDIR= lib add create delete info updating version -.include +MAN= pkg.conf.5 + +.if ${MK_EXAMPLES} != "no" +FILESDIR= /etc/defaults +FILES= pkg.conf +.endif + +.include CP= /bin/cp RM= /bin/rm @@ -19,5 +26,3 @@ distfile: clean --exclude .#* --exclude *~ --exclude CVS \ --exclude pkg_install-*.tar.gz pkg_install-${DATE}; \ ${RM} -rf pkg_install-${DATE}) - - diff --git a/add/main.c b/add/main.c index fb917c4..9887f6e 100644 --- a/add/main.c +++ b/add/main.c @@ -90,7 +90,7 @@ struct { { 0, 0, NULL } }; -static char *getpackagesite(void); +static void config_init_packagesite(void); int getosreldate(void); static void usage(void); @@ -119,7 +119,7 @@ main(int argc, char **argv) { int ch, error; char **start; - char *cp, *packagesite = NULL, *remotepkg = NULL, *ptr; + char *cp, **packagesite = NULL, *remotepkg = NULL, *ptr; static char temppackageroot[MAXPATHLEN]; static char pkgaddpath[MAXPATHLEN]; @@ -203,6 +203,9 @@ main(int argc, char **argv) argc -= optind; argv += optind; + config_init(); + config_init_packagesite(); + if (AddMode != SLAVE) { pkgs = (char **)malloc((argc+1) * sizeof(char *)); for (ch = 0; ch <= argc; pkgs[ch++] = NULL) ; @@ -211,9 +214,7 @@ main(int argc, char **argv) for (ch = 0; *argv; ch++, argv++) { char temp[MAXPATHLEN]; if (Remote) { - if ((packagesite = getpackagesite()) == NULL) - errx(1, "package name too long"); - if (strlcpy(temppackageroot, packagesite, + if (strlcpy(temppackageroot, "remote://", sizeof(temppackageroot)) >= sizeof(temppackageroot)) errx(1, "package name too long"); if (strlcat(temppackageroot, *argv, sizeof(temppackageroot)) @@ -294,53 +295,41 @@ main(int argc, char **argv) return 0; } -static char * -getpackagesite(void) +void +config_init_packagesite(void) { int reldate, i; - static char sitepath[MAXPATHLEN]; struct utsname u; + char **ps, **pr; + const char *dir; - if (getenv("PACKAGESITE")) { - if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; - return sitepath; - } - - if (getenv("PACKAGEROOT")) { - if (strlcpy(sitepath, getenv("PACKAGEROOT"), sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; - } else { - if (strlcat(sitepath, "ftp://ftp.freebsd.org", sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; - } - - if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; + if ((ps = config_get_list("packagesite")) != NULL) + return ; uname(&u); - if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath)) - return NULL; - reldate = getosreldate(); - for(i = 0; releases[i].directory != NULL; i++) { + + for (i = 0; releases[i].directory != NULL; i++) { if (reldate >= releases[i].lowver && reldate <= releases[i].hiver) { - if (strlcat(sitepath, releases[i].directory, sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; break; } } - - if (strlcat(sitepath, "/Latest/", sizeof(sitepath)) >= sizeof(sitepath)) - return NULL; - - return sitepath; - + dir = releases[i].directory; + + if ((pr = config_get_list("packageroot")) != NULL) { + for (i = 0; pr[i]; ++i) + ; + ps = calloc(i+1, sizeof(char *)); + for (i = 0; pr[i]; ++i) + asprintf(&ps[i], "%s/pub/FreeBSD/ports/%s%s/Latest/", + pr[i], u.machine, dir); + config_set_list("packagesite", ps); + } else { + ps = calloc(2, sizeof(char *)); + asprintf(&ps[0], "%s/pub/FreeBSD/ports/%s%s/Latest/", + "ftp://ftp.freebsd.org", u.machine, dir); + config_set_list("packagesite", ps); + } } static void diff --git a/add/perform.c b/add/perform.c index b99ce2c..124da46 100644 --- a/add/perform.c +++ b/add/perform.c @@ -68,7 +68,7 @@ pkg_do(char *pkg) char extract_contents[FILENAME_MAX]; char *where_to, *extract; FILE *cfile; - int code; + int i, code; PackingList p; struct stat sb; int inPlace, conflictsfound, errcode; @@ -77,6 +77,8 @@ pkg_do(char *pkg) char pre_script[FILENAME_MAX] = INSTALL_FNAME; char post_script[FILENAME_MAX]; char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX]; + char remotepkg[FILENAME_MAX]; + char **ps; char *conflict[2]; char **matched; @@ -102,7 +104,18 @@ pkg_do(char *pkg) else { /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */ if (isURL(pkg)) { - if (!(Home = fileGetURL(NULL, pkg, KeepPackage))) { + if (!strncmp(pkg, "remote://", 9)) { + if ((ps = config_get_list("packagesite")) == NULL) + errx(1, "No package site to fetch packages from. Exiting."); + for (i = 0; ps[i]; ++i) { + snprintf(remotepkg, FILENAME_MAX, "%s%s", ps[i], pkg+9); + if (Home = fileGetURL(NULL, remotepkg, KeepPackage)) + break; + } + if (ps[i] == NULL) + errx(1, "Could not fetch package from any package site. Exiting."); + } + else if (!(Home = fileGetURL(NULL, pkg, KeepPackage))) { warnx("unable to fetch '%s' by URL", pkg); return 1; } diff --git a/create/main.c b/create/main.c index ac93c2a..d32ada2 100644 --- a/create/main.c +++ b/create/main.c @@ -225,6 +225,8 @@ main(int argc, char **argv) argc -= optind; argv += optind; + config_init(); + /* Get all the remaining package names, if any */ while (*argv) *pkgs++ = *argv++; diff --git a/delete/main.c b/delete/main.c index db58d2f..fbd27d5 100644 --- a/delete/main.c +++ b/delete/main.c @@ -128,6 +128,8 @@ main(int argc, char **argv) argc -= optind; argv += optind; + config_init(); + /* Get all the remaining package names, if any */ while (*argv) { /* Don't try to apply heuristics if arguments are regexs */ diff --git a/info/main.c b/info/main.c index 3a55be3..82a3ff8 100644 --- a/info/main.c +++ b/info/main.c @@ -237,6 +237,8 @@ main(int argc, char **argv) argc -= optind; argv += optind; + config_init(); + if (Flags & SHOW_PTREV) { if (!Quiet) printf("Package tools revision: "); diff --git a/lib/Makefile b/lib/Makefile index 2c578ff..50e5ff4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,8 +2,8 @@ LIB= install INTERNALLIB= -SRCS= file.c msg.c plist.c str.c exec.c global.c pen.c match.c \ - deps.c version.c pkgwrap.c url.c +SRCS= config.y deps.c exec.c file.c global.c lang.l match.c msg.c \ + pen.c pkgwrap.c plist.c str.c url.c version.c WARNS?= 3 WFORMAT?= 1 diff --git a/lib/config.y b/lib/config.y new file mode 100644 index 0000000..40017b8 --- /dev/null +++ b/lib/config.y @@ -0,0 +1,289 @@ +%{ +/*- + * Copyright (c) 2008, Florent Thoumie + * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include + +#include "lib.h" + +enum { VAR_STRING, VAR_LIST }; + +struct _str_list_t { + char **strs; + int len; +}; + +int yylex(void); +int yyparse(void); +int yyerror(const char *); + +%} + +%union { + struct _str_list_t *list; + char *str; + int i; +} + +%token NAME +%token STRING +%type list +%token EQ QMARK COMMA OBRACE CBRACE +%token PACKAGESITE PACKAGEROOT + +%% + +config + : + | options + ; + +options + : + | options option + ; + +option + : STRING EQ STRING { + config_set_str($1, $3); + free($1); + } + | STRING EQ OBRACE list CBRACE { + struct _str_list_t *list = $4; + config_set_list($1, list->strs); + free($1); + } + ; + +list + : STRING { + struct _str_list_t *list = calloc(1, sizeof(struct _str_list_t)); + list->len = 2; + list->strs = calloc(list->len, sizeof(char *)); + list->strs[0] = $1; + $$ = list; + } + | list COMMA STRING { + struct _str_list_t *list = $1; + list->len++; + list->strs = realloc(list->strs, list->len * sizeof(char *)); + list->strs[list->len-2] = $3; + $$ = list; + } + ; + +%% + +char ** +config_get_list(const char *name) +{ + struct config_var *cv; + + SLIST_FOREACH(cv, &config, next) + if (strncmp(cv->name, name, strlen(name)) == 0) { + if (cv->type != VAR_LIST) { + printf("config: %s should be of type 'list'. \ + Exiting.", name); + exit(1); + } else { + return cv->list; + } + } + + return NULL; +} + +char * +config_get_str(const char *name) +{ + struct config_var *cv; + + SLIST_FOREACH(cv, &config, next) + if (strncmp(cv->name, name, strlen(name)) == 0) { + if (cv->type != VAR_STRING) { + printf("config: %s should be of type 'string'. \ + Exiting", name); + exit(1); + } else { + return cv->str; + } + } + + return NULL; +} + +void +config_set_list(char *name, char **list) +{ + struct config_var *cv; + char *tmp; + int i; + + if (list == NULL) + return; + + tmp = strdup(name); + str_lowercase(tmp); + + /* Find and replace ... */ + SLIST_FOREACH(cv, &config, next) + if (strncmp(cv->name, tmp, strlen(tmp)) == 0) { + if (cv->type == VAR_STRING) { + free(cv->str); + } else { + for (i = 0; cv->list[i]; ++i) + free(cv->list[i]); + free(cv->list); + } + cv->type = VAR_LIST; + cv->list = list; + free(tmp); + return ; + } + + /* ... or add. */ + cv = calloc(1, sizeof(struct config_var)); + cv->name = tmp; + cv->type = VAR_LIST; + cv->list = list; + SLIST_INSERT_HEAD(&config, cv, next); +} + +void +config_set_str(char *name, char *str) +{ + struct config_var *cv; + char *tmp; + int i; + + if (str == NULL) + return; + + tmp = strdup(name); + str_lowercase(tmp); + + /* Find and replace ... */ + SLIST_FOREACH(cv, &config, next) + if (strncmp(cv->name, tmp, strlen(tmp)) == 0) { + if (cv->type == VAR_STRING) { + free(cv->str); + } else { + for (i = 0; cv->list[i]; ++i) + free(cv->list[i]); + free(cv->list); + } + cv->type = VAR_STRING; + cv->str = str; + free(tmp); + return ; + } + + /* ... or add. */ + cv = calloc(1, sizeof(struct config_var)); + cv->name = tmp; + cv->type = VAR_STRING; + cv->str = str; + SLIST_INSERT_HEAD(&config, cv, next); +} + +static char ** +str2list(char *str) +{ + char **list; + + if (str == NULL) + return NULL; + + list = calloc(2, sizeof(char *)); + list[0] = str; + return list; +} + +extern FILE* yyin; +extern char configfile[FILENAME_MAX]; + +void +config_init(void) +{ + struct config_var *cv; + char userconf[FILENAME_MAX]; + int i, error; + + SLIST_INIT(&config); + + config_set_str("dbdir", strdup("/var/db/pkg")); + config_set_str("portsdir", strdup("/usr/ports")); + config_set_str("packagesdir", strdup("/var/packages:/usr/ports/packages")); + + config_set_list("packagesite", str2list(getenv("PACKAGESITE"))); + config_set_list("packageroot", str2list(getenv("PACKAGEROOT"))); + config_set_str("tmpdir", getenv("TMPDIR")); + config_set_str("tmpdir", getenv("PKG_TMPDIR")); + config_set_str("dbdir", getenv("PKG_DBDIR")); + config_set_str("portsdir", getenv("PORTSDIR")); + config_set_str("packagesdir", getenv("PKGDIR")); + + yyin = fopen("/etc/pkg.conf", "r"); + if (yyin != NULL) { + strncpy(configfile, "/etc/pkg.conf", FILENAME_MAX); + error = yyparse(); + fclose(yyin); + } + + yyin = fopen("/etc/pkg.conf.local", "r"); + if (yyin != NULL) { + strncpy(configfile, "/etc/pkg.conf.local", FILENAME_MAX); + error = yyparse(); + fclose(yyin); + } + + snprintf(userconf, FILENAME_MAX, "%s/.pkgrc", getenv("HOME")); + + yyin = fopen(userconf, "r"); + if (yyin != NULL) { + strncpy(configfile, userconf, FILENAME_MAX); + error = yyparse(); + fclose(yyin); + } + + if (Verbose) { + SLIST_FOREACH(cv, &config, next) { + if (cv->type == VAR_STRING) + printf("config: %s = %s\n", cv->name, cv->str); + else { + printf("config: %s = { ", cv->name); + for (i = 0; cv->list[i]; ++i) + printf("%s, ", cv->list[i]); + printf(" }\n"); + } + } + } +} diff --git a/lib/file.c b/lib/file.c index 4c5a2d1..e433c89 100644 --- a/lib/file.c +++ b/lib/file.c @@ -127,7 +127,8 @@ isURL(const char *fname) while (isspace(*fname)) ++fname; if (!strncmp(fname, "ftp://", 6) || !strncmp(fname, "http://", 7) || - !strncmp(fname, "https://", 8) || !strncmp(fname, "file://", 7)) + !strncmp(fname, "https://", 8) || !strncmp(fname, "file://", 7) || + !strncmp(fname, "remote://", 9)) return TRUE; return FALSE; } @@ -163,7 +164,7 @@ fileFindByPath(const char *base, const char *fname) } } - cp = getenv("PKG_PATH"); + cp = config_get_str("packagesdir"); while (cp) { char *cp2 = strsep(&cp, ":"); diff --git a/lib/lang.l b/lib/lang.l new file mode 100644 index 0000000..b882548 --- /dev/null +++ b/lib/lang.l @@ -0,0 +1,73 @@ +%{ +/*- + * Copyright (c) 2008, Florent Thoumie + * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + * + * $FreeBSD$ + */ + +#include +#include +#include + +#include "lib.h" +#include "config.h" + +#define YY_NO_UNPUT + +int yylex(void); +void yyerror(const char *); + +int lineno = 1; +char configfile[FILENAME_MAX]; + +%} + +%option noyywrap + +%% + +#.* ; +[ \t]+ ; +\n { lineno++; } +\{ { return OBRACE; } +\} { return CBRACE; } +, { return COMMA; } += { return EQ; } +[a-zA-Z0-9.:/_-]+ { + yylval.str = strdup(yytext); + if (yylval.str == NULL) + err(1, "strdup"); + return STRING; + } + +%% + +void +yyerror(const char *s) +{ + + printf("%s: line %d: %s: %s\n", configfile, lineno, s, yytext); + exit(1); +} diff --git a/lib/lib.h b/lib/lib.h index ebd032c..9adac95 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -57,19 +57,11 @@ /* Usually "rm", but often "echo" during debugging! */ #define RMDIR_CMD "/bin/rmdir" -/* Where the ports lives by default */ -#define DEF_PORTS_DIR "/usr/ports" -/* just in case we change the environment variable name */ -#define PORTSDIR "PORTSDIR" /* macro to get name of directory where the ports lives */ -#define PORTS_DIR (getenv(PORTSDIR) ? getenv(PORTSDIR) : DEF_PORTS_DIR) +#define PORTSDIR config_get_str("portsdir") -/* Where we put logging information by default, else ${PKG_DBDIR} if set */ -#define DEF_LOG_DIR "/var/db/pkg" -/* just in case we change the environment variable name */ -#define PKG_DBDIR "PKG_DBDIR" /* macro to get name of directory where we put logging information */ -#define LOG_DIR (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR) +#define LOG_DIR config_get_str("dbdir") /* The names of our "special" files */ #define CONTENTS_FNAME "+CONTENTS" @@ -124,6 +116,15 @@ enum _plist_t { }; typedef enum _plist_t plist_t; +struct config_var { + char *name; + char *str; + char **list; + int type; + SLIST_ENTRY(config_var) next; +}; +SLIST_HEAD(, config_var) config; + enum _match_t { MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX }; @@ -155,6 +156,14 @@ struct reqr_by_entry { STAILQ_HEAD(reqr_by_head, reqr_by_entry); /* Prototypes */ + +/* Config */ +char **config_get_list(const char *); +char *config_get_str(const char *); +void config_set_list(char *, char **); +void config_set_str(char *, char *); +void config_init(void); + /* Misc */ int vsystem(const char *, ...); char *vpipe(const char *, ...); diff --git a/lib/pen.c b/lib/pen.c index b2a66e4..4915a6b 100644 --- a/lib/pen.c +++ b/lib/pen.c @@ -47,9 +47,7 @@ find_play_pen(char *pen, off_t sz) if (pen[0] && isdir(dirname(pen)) == TRUE && (min_free(dirname(pen)) >= sz)) return pen; - else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) - sprintf(pen, "%s/instmp.XXXXXX", cp); - else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) + else if ((cp = config_get_str("tmpdir")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) sprintf(pen, "%s/instmp.XXXXXX", cp); else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz) strcpy(pen, "/var/tmp/instmp.XXXXXX"); diff --git a/pkg.conf b/pkg.conf new file mode 100644 index 0000000..b6df07e --- /dev/null +++ b/pkg.conf @@ -0,0 +1,34 @@ +# +# $FreeBSD$ +# +# Package tools configuration file. +# +# Default values are commented. +# + +# Define portsdir if your ports tree doesn't live in /usr/ports +# type: string +# portsdir = /usr/ports + +# Define packagesite if you want to use alternative packages locations. +# Note: packagesite variable has a higher priority than packageroot. +# type: list +# packagesite = { ftp://ftp.freebsd.org/pub/FreeBSD/ports///Latest/ } + +# Define packageroot if you want to use alternatve ftp mirrors. +# type: list +# packageroot = { ftp://ftp.freebsd.org } + +# Define to the temporary directory you want to use as a staging area. +# type: string +# tmpdir = /var/tmp + +# Define dbdir if your package database doesn't live in /var/db/pkg. +# type: string +# dbdir = /var/db/pkg + +# Define packagesdir to a colon-separated list if you want to add directories +# to look at when adding packages. +# Note: current directory doesn't need to be added to the list. +# type: string +# packagesdir = diff --git a/pkg.conf.5 b/pkg.conf.5 new file mode 100644 index 0000000..b34c524 --- /dev/null +++ b/pkg.conf.5 @@ -0,0 +1,73 @@ +.\" Copyright (c) 2008, Florent Thoumie +.\" 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. +.\" +.\" $FreeBSD$ +.\" +.Dd April 17, 2008 +.Dt PKG.CONF 5 +.Os +.Sh NAME +.Nm pkg.conf +.Nd package tools configuration information +.Sh DESCRIPTION +The file +.Nm +contains configuration data for the package tools . +All variables are documented in +.Pa /etc/defaults/pkg.conf . +.Sh EXAMPLES +Variables can be of type string or list . +.Bd -literal -offset indent +# This is a list: +list = { foo } + +# This is a list too: +list2 = { + foo, + bar +} + +# This is a string: +string = baz +.Ed +.Sh FILES +.Bl -tag -width /etc/pkg.conf.local -compact +.It Pa /etc/pkg.conf +.It Pa /etc/pkg.conf.local +.It Pa ~/.pkgrc +.El +.Sh SEE ALSO +.Xr pkg_add 1 , +.Xr pkg_create 1 , +.Xr pkg_delete 1 , +.Xr pkg_info 1 , +.Xr pkg_updating 1 , +.Xr pkg_version 1 +.Sh HISTORY +The +.Nm +file appeared in +.Fx 8.0 . +.Sh AUTHORS +.An Florent Thoumie . diff --git a/updating/main.c b/updating/main.c index e5e649b..921570c 100644 --- a/updating/main.c +++ b/updating/main.c @@ -16,7 +16,6 @@ __FBSDID("$FreeBSD: src/usr.sbin/pkg_install/updating/main.c,v 1.3 2008/05/30 14 #include #include "lib.h" -#include "pathnames.h" typedef struct installedport { struct installedport *next; /* List of installed ports. */ @@ -34,7 +33,7 @@ static struct option longopts[] = { }; /* - * Parse /usr/port/UPDATING for corresponding entries. If no argument is + * Parse UPDATING file for corresponding entries. If no argument is * passed to pkg_updating all entries for all installed ports are displayed. * If a list of portnames is passed to pkg_updating only entries for the * given portnames are displayed. Use the -d option to define that only newer @@ -50,7 +49,7 @@ main(int argc, char *argv[]) /* Keyword for searching origin portname of installed port. */ const char *origin = "@comment ORIGIN:"; const char *pkgdbpath = LOG_DIR; /* Location of pkgdb */ - const char *updatingfile = UPDATING; /* Location of UPDATING */ + char updatingfile[FILENAME_MAX]; /* Location of UPDATING */ char *date = NULL; /* Passed -d argument */ char *dateline = NULL; /* Saved date of an entry */ @@ -90,7 +89,7 @@ main(int argc, char *argv[]) date = optarg; break; case 'f': - updatingfile = optarg; + strncpy(updatingfile, optarg, FILENAME_MAX); break; case 'h': default: @@ -100,6 +99,11 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + config_init(); + + if (updatingfile[0] == '\0') + snprintf(updatingfile, FILENAME_MAX, "%s/%s", config_get_str("portsdir"), "UPDATING"); + /* Check if passed date has a correct format. */ if (dflag == 1) { linelength = strlen(date); diff --git a/version/main.c b/version/main.c index ce19ff6..f6e64b2 100644 --- a/version/main.c +++ b/version/main.c @@ -123,6 +123,8 @@ main(int argc, char **argv) argc -= optind; argv += optind; + config_init(); + return pkg_perform(argv); } diff --git a/version/perform.c b/version/perform.c index 034e237..cfe9fb7 100644 --- a/version/perform.c +++ b/version/perform.c @@ -55,7 +55,7 @@ pkg_perform(char **indexarg) * later, if we actually need the INDEX. */ if (*indexarg == NULL) - snprintf(IndexPath, sizeof(IndexPath), "%s/%s", PORTS_DIR, INDEX_FNAME); + snprintf(IndexPath, sizeof(IndexPath), "%s/%s", PORTSDIR, INDEX_FNAME); else strlcpy(IndexPath, *indexarg, sizeof(IndexPath)); if (isURL(IndexPath)) @@ -157,7 +157,7 @@ pkg_do(char *pkg) * INDEX, first matching the origin and then the package name. */ if (plist.origin != NULL && !UseINDEXOnly) { - snprintf(tmp, PATH_MAX, "%s/%s", PORTS_DIR, plist.origin); + snprintf(tmp, PATH_MAX, "%s/%s", PORTSDIR, plist.origin); if (isdir(tmp) && chdir(tmp) != FAIL && isfile("Makefile")) { if ((latest = vpipe("/usr/bin/make -V PKGNAME", tmp)) == NULL) warnx("Failed to get PKGNAME from %s/Makefile!", tmp);