Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge pull request #421 from smortex/no-script
Matthew Seaman committed 13 years ago
commit c5cbc4de0a8aa19a3928e26cf94e9b0ecfa178c7
parent dd9bfd6
13 files changed +98 -37
modified libpkg/pkg.h.in
@@ -295,6 +295,7 @@ typedef enum _pkg_flags {
	PKG_FLAG_RECURSIVE = (1U << 2),
	PKG_FLAG_AUTOMATIC = (1U << 3),
	PKG_FLAG_WITH_DEPS = (1U << 4),
+
	PKG_FLAG_NOSCRIPT = (1U << 5),
} pkg_flags;

typedef enum _pkg_config_key {
@@ -945,6 +946,7 @@ int pkg_add(struct pkgdb *db, const char *path, unsigned flags);
#define PKG_ADD_USE_UPGRADE_SCRIPTS	(1U << 1)
#define PKG_ADD_AUTOMATIC		(1U << 2)
#define PKG_ADD_FORCE			(1U << 3)
+
#define PKG_ADD_NOSCRIPT		(1U << 4)

/**
 * Allocate a new pkg_jobs.
modified libpkg/pkg_add.c
@@ -281,7 +281,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	/*
	 * Execute pre-install scripts
	 */
-
	if ((flags & PKG_ADD_USE_UPGRADE_SCRIPTS) == 0)
+
	if ((flags & (PKG_ADD_NOSCRIPT | PKG_ADD_USE_UPGRADE_SCRIPTS)) == 0)
		pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL);

	/* add the user and group if necessary */
@@ -300,10 +300,12 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	/*
	 * Execute post install scripts
	 */
-
	if (flags & PKG_ADD_USE_UPGRADE_SCRIPTS)
-
		pkg_script_run(pkg, PKG_SCRIPT_POST_UPGRADE);
-
	else
-
		pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL);
+
	if ((flags & PKG_ADD_NOSCRIPT) == 0) {
+
		if (flags & PKG_ADD_USE_UPGRADE_SCRIPTS)
+
			pkg_script_run(pkg, PKG_SCRIPT_POST_UPGRADE);
+
		else
+
			pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL);
+
	}

	/*
	 * start the different related services if the users do want that
modified libpkg/pkg_delete.c
@@ -97,20 +97,22 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)
	if (handle_rc)
		pkg_start_stop_rc_scripts(pkg, PKG_RC_STOP);

-
	if (flags & PKG_DELETE_UPGRADE) {
-
		ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_UPGRADE);
-
		if (ret != EPKG_OK)
-
			return (ret);
-
	} else {
-
		ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_DEINSTALL);
-
		if (ret != EPKG_OK)
-
			return (ret);
+
	if ((flags & PKG_DELETE_NOSCRIPT) == 0) {
+
		if (flags & PKG_DELETE_UPGRADE) {
+
			ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_UPGRADE);
+
			if (ret != EPKG_OK)
+
				return (ret);
+
		} else {
+
			ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_DEINSTALL);
+
			if (ret != EPKG_OK)
+
				return (ret);
+
		}
	}

	if ((ret = pkg_delete_files(pkg, flags & PKG_DELETE_FORCE)) != EPKG_OK)
		return (ret);

-
	if ((flags & PKG_DELETE_UPGRADE) == 0) {
+
	if ((flags & (PKG_DELETE_NOSCRIPT | PKG_DELETE_UPGRADE)) == 0) {
		ret = pkg_script_run(pkg, PKG_SCRIPT_POST_DEINSTALL);
		if (ret != EPKG_OK)
			return (ret);
modified libpkg/pkg_jobs.c
@@ -393,8 +393,9 @@ pkg_jobs_install(struct pkg_jobs *j)
					}

					LL_APPEND(pkg_queue, pkg);
-
					pkg_script_run(pkg,
-
					    PKG_SCRIPT_PRE_DEINSTALL);
+
					if ((j->flags & PKG_FLAG_NOSCRIPT) == 0)
+
						pkg_script_run(pkg,
+
						    PKG_SCRIPT_PRE_DEINSTALL);
					pkg_get(pkg, PKG_ORIGIN, &origin);
					/*
					 * stop the different related services
@@ -427,7 +428,9 @@ pkg_jobs_install(struct pkg_jobs *j)
				}

				LL_APPEND(pkg_queue, pkg);
-
				pkg_script_run(pkg, PKG_SCRIPT_PRE_DEINSTALL);
+
				if ((j->flags & PKG_FLAG_NOSCRIPT) == 0)
+
					pkg_script_run(pkg,
+
					    PKG_SCRIPT_PRE_DEINSTALL);
				pkg_get(pkg, PKG_ORIGIN, &origin);
				/*
				 * stop the different related services if the
@@ -457,7 +460,9 @@ pkg_jobs_install(struct pkg_jobs *j)
			if (strcmp(pkgorigin, origin) == 0) {
				LL_DELETE(pkg_queue, pkg);
				pkg_delete_files(pkg, 1);
-
				pkg_script_run(pkg, PKG_SCRIPT_POST_DEINSTALL);
+
				if ((j->flags & PKG_FLAG_NOSCRIPT) == 0)
+
					pkg_script_run(pkg,
+
					    PKG_SCRIPT_POST_DEINSTALL);
				pkg_delete_dirs(j->db, pkg, 0);
				pkg_free(pkg);
				break;
@@ -466,6 +471,8 @@ pkg_jobs_install(struct pkg_jobs *j)

		if ((j->flags & PKG_FLAG_FORCE) != 0)
			flags |= PKG_ADD_FORCE;
+
		if ((j->flags & PKG_FLAG_NOSCRIPT) != 0)
+
			flags |= PKG_ADD_NOSCRIPT;
		flags |= PKG_ADD_UPGRADE;
		if (automatic)
			flags |= PKG_ADD_AUTOMATIC;
@@ -508,6 +515,9 @@ pkg_jobs_deinstall(struct pkg_jobs *j)
	if ((j->flags & PKG_FLAG_FORCE) != 0)
		flags = PKG_DELETE_FORCE;

+
	if ((j->flags & PKG_FLAG_NOSCRIPT) != 0)
+
		flags |= PKG_DELETE_NOSCRIPT;
+

	while (pkg_jobs(j, &p) == EPKG_OK) {
		retcode = pkg_delete(p, j->db, flags);

modified libpkg/private/pkg.h
@@ -257,6 +257,7 @@ typedef enum {
int pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags);
#define PKG_DELETE_FORCE (1<<0)
#define PKG_DELETE_UPGRADE (1<<1)
+
#define PKG_DELETE_NOSCRIPT (1<<2)

int pkg_fetch_file_to_fd(const char *url, int dest, time_t t);
int pkg_repo_fetch(struct pkg *pkg);
modified pkg/add.c
@@ -54,8 +54,8 @@ is_url(const char * const pattern)
void
usage_add(void)
{
-
	fprintf(stderr, "usage: pkg add <pkg-name>\n");
-
	fprintf(stderr, "       pkg add <protocol>://<path>/<pkg-name>\n\n");
+
	fprintf(stderr, "usage: pkg add [-I] <pkg-name>\n");
+
	fprintf(stderr, "       pkg add [-I] <protocol>://<path>/<pkg-name>\n\n");
	fprintf(stderr, "For more information see 'pkg help add'.\n");
}

@@ -67,11 +67,26 @@ exec_add(int argc, char **argv)
	char path[MAXPATHLEN + 1];
	char *file;
	int retcode;
+
	int ch;
	int i;
	int failedpkgcount = 0;
	struct pkg *p = NULL;
+
	pkg_flags f = PKG_FLAG_NONE;
+

+
	while ((ch = getopt(argc, argv, "I")) != -1) {
+
		switch (ch) {
+
		case 'I':
+
			f |= PKG_ADD_NOSCRIPT;
+
			break;
+
		default:
+
			usage_add();
+
			return (EX_USAGE);
+
		}
+
	}
+
	argc -= optind;
+
	argv += optind;

-
	if (argc < 2) {
+
	if (argc < 1) {
		usage_add();
		return (EX_USAGE);
	}
@@ -90,7 +105,7 @@ exec_add(int argc, char **argv)
		return (EX_IOERR);

	failedpkgs = sbuf_new_auto();
-
	for (i = 1; i < argc; i++) {
+
	for (i = 0; i < argc; i++) {
		if (is_url(argv[i]) == EPKG_OK) {
			snprintf(path, sizeof(path), "./%s", basename(argv[i]));
			if ((retcode = pkg_fetch_file(argv[i], path, 0)) != EPKG_OK)
@@ -114,7 +129,7 @@ exec_add(int argc, char **argv)
			
		pkg_open(&p, file);

-
		if ((retcode = pkg_add(db, file, 0)) != EPKG_OK) {
+
		if ((retcode = pkg_add(db, file, f)) != EPKG_OK) {
			sbuf_cat(failedpkgs, argv[i]);
			if (i != argc - 1)
				sbuf_printf(failedpkgs, ", ");
modified pkg/delete.c
@@ -40,8 +40,8 @@
void
usage_delete(void)
{
-
	fprintf(stderr, "usage: pkg delete [-fginqRxy] <pkg-name> ...\n");
-
	fprintf(stderr, "       pkg delete [-nqy] -a\n\n");
+
	fprintf(stderr, "usage: pkg delete [-DfginqRxy] <pkg-name> ...\n");
+
	fprintf(stderr, "       pkg delete [-Dnqy] -a\n\n");
	fprintf(stderr, "For more information see 'pkg help delete'.\n");
}

@@ -62,11 +62,14 @@ exec_delete(int argc, char **argv)

	pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);

-
	while ((ch = getopt(argc, argv, "afginqRxy")) != -1) {
+
	while ((ch = getopt(argc, argv, "aDfginqRxy")) != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
			break;
+
		case 'D':
+
			f |= PKG_FLAG_NOSCRIPT;
+
			break;
		case 'f':
			f |= PKG_FLAG_FORCE;
			force = true;
modified pkg/install.c
@@ -45,7 +45,7 @@ void
usage_install(void)
{
	fprintf(stderr,
-
	    "usage: pkg install [-AfgiLnqRxy] [-r reponame] <pkg-name> ...\n\n");
+
	    "usage: pkg install [-AfgIiLnqRxy] [-r reponame] <pkg-name> ...\n\n");
	fprintf(stderr, "For more information see 'pkg help install'.\n");
}

@@ -68,7 +68,7 @@ exec_install(int argc, char **argv)
	pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
	pkg_config_bool(PKG_CONFIG_REPO_AUTOUPDATE, &auto_update);

-
	while ((ch = getopt(argc, argv, "AfgiLnqRr:xy")) != -1) {
+
	while ((ch = getopt(argc, argv, "AfgIiLnqRr:xy")) != -1) {
		switch (ch) {
		case 'A':
			f |= PKG_FLAG_AUTOMATIC;
@@ -79,6 +79,9 @@ exec_install(int argc, char **argv)
		case 'g':
			match = MATCH_GLOB;
			break;
+
		case 'I':
+
			f |= PKG_FLAG_NOSCRIPT;
+
			break;
		case 'i':
			pkgdb_set_case_sensitivity(false);
			break;
modified pkg/pkg-add.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd June 12, 2012
+
.Dd January 25, 2013
.Dt PKG-ADD 8
.Os
.Sh NAME
@@ -23,8 +23,10 @@
.Nd Registers a package and installs it on the system
.Sh SYNOPSIS
.Nm
+
.Op Fl I
.Ar <pkg-name>
.Nm
+
.Op Fl I
.Ar <protocol>://<path>/<pkg-name>
.Sh DESCRIPTION
.Nm
@@ -34,6 +36,14 @@ When installing from a remote source you need to specify
the protocol to use when fetching the package.
.Pp
Currently supported protocols are FTP, HTTP and HTTPS.
+
.Sh OPTIONS
+
The following options are supported by
+
.Nm :
+
.Bl -tag -width I1
+
.It Fl I
+
If any installation scripts (pre-install or post-install) exist for a given
+
package, do not execute them.
+
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
.Nm .
modified pkg/pkg-delete.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd January 20, 2013
+
.Dd January 25, 2013
.Dt PKG-DELETE 8
.Os
.Sh NAME
@@ -23,10 +23,10 @@
.Nd deletes packages from the database and the system
.Sh SYNOPSIS
.Nm
-
.Op Fl fginqRxy
+
.Op Fl DfginqRxy
.Ar <pkg-name> ...
.Nm
-
.Op Fl nqy
+
.Op Fl Dnqy
.Fl a
.Sh DESCRIPTION
.Nm
@@ -55,6 +55,8 @@ The following options are supported by
.Bl -tag -width F1
.It Fl a
Deletes all installed packages from the system and empties the database.
+
.It Fl D
+
If a deinstallation script exists for a given package, do not execute it.
.It Fl f
Forces packages to be removed despite leaving unresolved dependencies.
.It Fl g
modified pkg/pkg-install.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd January 20, 2013
+
.Dd January 25, 2013
.Dt PKG-INSTALL 8
.Os
.Sh NAME
@@ -23,7 +23,7 @@
.Nd installs packages from remote package repositories
.Sh SYNOPSIS
.Nm
-
.Op Fl AfgiLnqRxy
+
.Op Fl AfgIiLnqRxy
.Op Fl r Ar reponame
.Ar <pkg-origin> ...
.Sh DESCRIPTION
@@ -115,6 +115,10 @@ For more information please refer to
Force the reinstallation of the package if already installed.
.It Fl g
Treat the package names as shell glob patterns.
+
.It Fl I
+
If any installation scripts (pre-install or post-install) exist for a given
+
package, do not execute them.  When a package is updated, deinstallation
+
scripts (pre-deinstall or post-deinstall) are not run either.
.It Fl i
Make the standard or the regular expression
.Fl ( x )
modified pkg/pkg-upgrade.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd May 16, 2012
+
.Dd January 25, 2013
.Dt PKG-UPGRADE 8
.Os
.Sh NAME
@@ -23,7 +23,7 @@
.Nd performs upgrades of package software distributions
.Sh SYNOPSIS
.Nm
-
.Op Fl fLnqy
+
.Op Fl fILnqy
.Op Fl r Ar reponame
.Sh DESCRIPTION
.Nm
@@ -53,6 +53,10 @@ The following options are supported by
.Bl -tag -width F1
.It Fl f
Force reinstalling/upgrading the whole set of packages
+
.It Fl I
+
If any installation scripts (pre-install or post-install) or deinstallation
+
scripts (pre-deinstall or post-deinstall) exist for a given package, do not
+
execute them.
.It Fl L
Skip updating the repository catalogues with
.Xr pkg-update 8 .
modified pkg/upgrade.c
@@ -37,7 +37,7 @@
void
usage_upgrade(void)
{
-
	fprintf(stderr, "usage: pkg upgrade [-fLnqy] [-r reponame]\n\n");
+
	fprintf(stderr, "usage: pkg upgrade [-fILnqy] [-r reponame]\n\n");
	fprintf(stderr, "For more information see 'pkg help upgrade'.\n");
}

@@ -65,6 +65,9 @@ exec_upgrade(int argc, char **argv)
		case 'f':
			f |= PKG_FLAG_FORCE;
			break;
+
		case 'I':
+
			f |= PKG_FLAG_NOSCRIPT;
+
			break;
		case 'L':
			auto_update = false;
			break;