[PATCH] install: support -t option

Aaro Koskinen aaro.koskinen at iki.fi
Tue Sep 23 19:12:07 UTC 2014


Some packages want to install themselves using "-t" to specify
the directory (as supported by GNU coreutils). Add support for the option
for compatibility reasons.

Tested by building & installing "perf" from Linux kernel tree
(its install uses -t), plus some other packages which don't use it
to check there's no breakage.

Signed-off-by: Aaro Koskinen <aaro.koskinen at iki.fi>
---
 coreutils/install.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/coreutils/install.c b/coreutils/install.c
index 6c88ae1..14d6a4e 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -19,6 +19,7 @@
 //usage:     "\n	-o USER	Set ownership"
 //usage:     "\n	-g GRP	Set group ownership"
 //usage:     "\n	-m MODE	Set permissions"
+//usage:     "\n	-t DEST	Set DEST directory"
 //usage:	IF_SELINUX(
 //usage:     "\n	-Z	Set security context"
 //usage:	)
@@ -37,6 +38,7 @@ static const char install_longopts[] ALIGN1 =
 	"group\0"               Required_argument "g"
 	"mode\0"                Required_argument "m"
 	"owner\0"               Required_argument "o"
+	"target-directory\0"	Required_argument "t"
 /* autofs build insists of using -b --suffix=.orig */
 /* TODO? (short option for --suffix is -S) */
 #if ENABLE_SELINUX
@@ -113,9 +115,10 @@ int install_main(int argc, char **argv)
 		OPT_GROUP         = 1 << 7,
 		OPT_MODE          = 1 << 8,
 		OPT_OWNER         = 1 << 9,
+		OPT_TARGET        = 1 << 10,
 #if ENABLE_SELINUX
-		OPT_SET_SECURITY_CONTEXT = 1 << 10,
-		OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
+		OPT_SET_SECURITY_CONTEXT = 1 << 11,
+		OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
 #endif
 	};
 
@@ -125,8 +128,9 @@ int install_main(int argc, char **argv)
 	opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
 	/* -c exists for backwards compatibility, it's needed */
 	/* -b is ignored ("make a backup of each existing destination file") */
-	opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
-			&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
+	opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
+			&gid_str, &mode_str, &uid_str, &last
+			IF_SELINUX(, &scontext));
 	argc -= optind;
 	argv += optind;
 
@@ -160,13 +164,23 @@ int install_main(int argc, char **argv)
 	uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
 	gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
 
-	last = argv[argc - 1];
-	if (!(opts & OPT_DIRECTORY)) {
-		argv[argc - 1] = NULL;
-		min_args++;
-
-		/* coreutils install resolves link in this case, don't use lstat */
-		isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
+	if (opts & OPT_TARGET) {
+		if (opts & OPT_DIRECTORY)
+			bb_error_msg_and_die("-t not allowed with -d");
+		isdir = 1;
+	} else {
+		last = argv[argc - 1];
+		if (!(opts & OPT_DIRECTORY)) {
+			argv[argc - 1] = NULL;
+			min_args++;
+
+			/*
+			 * coreutils install resolves link in this case, don't
+			 * use lstat
+			 */
+			isdir = stat(last, &statbuf) < 0 ? 0 :
+				S_ISDIR(statbuf.st_mode);
+		}
 	}
 
 	if (argc < min_args)
-- 
2.1.0



More information about the busybox mailing list