Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
New pkg -C to specify a configuration other then ${LOCALBASE}/pkg.conf
Baptiste Daroussin committed 13 years ago
commit c7f2312edd3bd84fe8f2f6f8a9557951c2d31218
parent 4a444e6
4 files changed +47 -13
modified pkg/main.c
@@ -52,7 +52,7 @@
#define GITHASH ""
#endif

-
static void usage(void);
+
static void usage(const char *);
static void usage_help(void);
static int exec_help(int, char **);
bool quiet = false;
@@ -120,15 +120,15 @@ show_command_names(void)
}

static void
-
usage(void)
+
usage(const char *conffile)
{
	struct plugcmd *c;
	bool plugins_enabled = false;

#ifndef NO_LIBJAIL
-
 	fprintf(stderr, "usage: pkg [-v] [-d] [-N] [-j <jail name or id>|-c <chroot path>] <command> [<args>]\n\n");
+
 	fprintf(stderr, "usage: pkg [-v] [-d] [-N] [-j <jail name or id>|-c <chroot path>] [-C <configuration file>] <command> [<args>]\n\n");
#else
-
	fprintf(stderr, "usage: pkg [-v] [-d] [-N] [-c <chroot path>] <command> [<args>]\n\n");
+
	fprintf(stderr, "usage: pkg [-v] [-d] [-N] [-c <chroot path>] [-C <configuration file>] <command> [<args>]\n\n");
#endif
	fprintf(stderr, "Global options supported:\n");
	fprintf(stderr, "\t%-15s%s\n", "-d", "Increment debug level");
@@ -136,6 +136,7 @@ usage(void)
	fprintf(stderr, "\t%-15s%s\n", "-j", "Execute pkg(1) inside a jail(8)");
#endif
	fprintf(stderr, "\t%-15s%s\n", "-c", "Execute pkg(1) inside a chroot(8)");
+
	fprintf(stderr, "\t%-15s%s\n", "-C", "Use the specified configuration file");
	fprintf(stderr, "\t%-15s%s\n\n", "-v", "Display pkg(1) version");
	fprintf(stderr, "\t%-15s%s\n\n", "-N", "Test if pkg(1) is activated and avoid auto-activation");
	fprintf(stderr, "Commands supported:\n");
@@ -143,7 +144,7 @@ usage(void)
	for (unsigned int i = 0; i < cmd_len; i++)
		fprintf(stderr, "\t%-15s%s\n", cmd[i].name, cmd[i].desc);

-
	if (!pkg_initialized() && pkg_init(NULL) != EPKG_OK)
+
	if (!pkg_initialized() && pkg_init(conffile) != EPKG_OK)
		errx(EX_SOFTWARE, "Cannot parse configuration file!");
	
	pkg_config_bool(PKG_CONFIG_ENABLE_PLUGINS, &plugins_enabled);
@@ -169,7 +170,7 @@ usage(void)
static void
usage_help(void)
{
-
	usage();
+
	usage(NULL);
}

static int
@@ -236,18 +237,19 @@ main(int argc, char **argv)
	struct pkg_plugin *p = NULL;
	struct pkg_config *conf = NULL;
	const char *configname = NULL;
+
	const char *conffile = NULL;
	int64_t integer = 0;

	/* Set stdout unbuffered */
        setvbuf(stdout, NULL, _IONBF, 0);

	if (argc < 2)
-
		usage();
+
		usage(NULL);

#ifndef NO_LIBJAIL
-
	while ((ch = getopt(argc, argv, "dj:c:lNvq")) != -1) {
+
	while ((ch = getopt(argc, argv, "dj:c:C:lNvq")) != -1) {
#else
-
	while ((ch = getopt(argc, argv, "d:c:lNvq")) != -1) {
+
	while ((ch = getopt(argc, argv, "d:c:C:lNvq")) != -1) {
#endif
		switch (ch) {
		case 'd':
@@ -256,6 +258,9 @@ main(int argc, char **argv)
		case 'c':
			chroot_path = optarg;
			break;
+
		case 'C':
+
			conffile = optarg;
+
			break;
#ifndef NO_LIBJAIL
		case 'j':
			jail_str = optarg;
@@ -286,7 +291,7 @@ main(int argc, char **argv)
		exit(EX_OK);
	}
	if (argc == 0 && version == 0 && !activation_test)
-
		usage();
+
		usage(conffile);

	umask(022);
	pkg_event_register(&event_callback, &debug);
@@ -297,7 +302,7 @@ main(int argc, char **argv)

	if (jail_str != NULL && chroot_path != NULL) {
		fprintf(stderr, "-j and -c cannot be used at the same time!\n");
-
		usage();
+
		usage(conffile);
	}

	if (chroot_path != NULL)
@@ -319,7 +324,7 @@ main(int argc, char **argv)
			errx(EX_SOFTWARE, "chdir() failed");
#endif

-
	if (pkg_init(NULL) != EPKG_OK)
+
	if (pkg_init(conffile) != EPKG_OK)
		errx(EX_SOFTWARE, "Cannot parse configuration file!");

	pkg_config_bool(PKG_CONFIG_ENABLE_PLUGINS, &plugins_enabled);
@@ -487,7 +492,7 @@ main(int argc, char **argv)
		}
		
		if (ret != EPKG_OK)
-
			usage();
+
			usage(conffile);
		
		pkg_plugins_shutdown();
		pkg_shutdown();
modified pkg/pkg.8
@@ -31,6 +31,7 @@
.Op Fl l
.Op Fl N
.Op Fl j Ao jail name or id Ac | Fl c Ao chroot path Ac
+
.Op Fl C Ao configuration file Ac
.Ao command Ac Ao Ar flags Ac
.\" ---------------------------------------------------------------------------
.Sh DESCRIPTION
@@ -111,6 +112,9 @@ and
will chroot in the
.Ao chroot path Ac
Environment
+
.It Fl C Ao configuration file Ac
+
.Nm
+
will use the specified file as a configuration file
.El
.\" ---------------------------------------------------------------------------
.Sh COMMANDS
added tests/frontend/pkg-vv.out
@@ -0,0 +1,24 @@
+
PACKAGESITE: 
+
PKG_DBDIR: /var/db/pkg
+
PKG_CACHEDIR: /var/cache/pkg
+
PORTSDIR: /usr/ports
+
PUBKEY: 
+
PKG_MULTIREPOS: no
+
HANDLE_RC_SCRIPTS: no
+
ASSUME_ALWAYS_YES: no
+
REPOS:
+
PLIST_KEYWORDS_DIR: 
+
SYSLOG: yes
+
SHLIBS: no
+
AUTODEPS: no
+
ABI: freebsd
+
DEVELOPER_MODE: no
+
PORTAUDIT_SITE: http://portaudit.FreeBSD.org/auditfile.tbz
+
SRV_MIRRORS: yes
+
FETCH_RETRY: 3
+
PKG_PLUGINS_DIR: /usr/local/lib/pkg/
+
PKG_ENABLE_PLUGINS: yes
+
PLUGINS:
+
DEBUG_SCRIPTS: no
+
PLUGINS_CONF_DIR: /usr/local/etc/pkg/
+
PERMISSIVE: no
modified tests/frontend/pkg.sh
@@ -7,6 +7,7 @@ pkg_body() {
	atf_check -o empty -e inline:"pkg: package database non-existent\n" -s exit:69 -x PKG_DBDIR=/dev/null pkg -n
	eval `../../newvers.sh`
	atf_check -o match:"^${PKGVERSION} .*$" -e empty -s exit:0 pkg -v
+
	atf_check -o file:pkg-vv.out -e empty -s exit:0 -x 'ABI=freebsd pkg -C "" -vvv | grep -v "^version.*"'
}

atf_init_test_cases() {