ntpd: default to FEATURE_NTP_AUTH=y
[oweals/busybox.git] / coreutils / install.c
index 73f9c70d573e30dec4690245e28d406a12b42e19..8270490bd47c00cc563408bcf9036d2066f63147 100644 (file)
@@ -5,6 +5,20 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
+//config:config INSTALL
+//config:      bool "install (12 kb)"
+//config:      default y
+//config:      help
+//config:      Copy files and set attributes.
+//config:
+//config:config FEATURE_INSTALL_LONG_OPTIONS
+//config:      bool "Enable long options"
+//config:      default y
+//config:      depends on INSTALL && LONG_OPTS
+
+//applet:IF_INSTALL(APPLET(install, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_INSTALL) += install.o
 
 /* -v, -b, -c are ignored */
 //usage:#define install_trivial_usage
@@ -41,12 +55,17 @@ static const char install_longopts[] ALIGN1 =
        "target-directory\0"    Required_argument "t"
 /* autofs build insists of using -b --suffix=.orig */
 /* TODO? (short option for --suffix is -S) */
-#if ENABLE_SELINUX
+# if ENABLE_SELINUX
        "context\0"             Required_argument "Z"
        "preserve_context\0"    No_argument       "\xff"
        "preserve-context\0"    No_argument       "\xff"
-#endif
+# endif
        ;
+# define GETOPT32 getopt32long
+# define LONGOPTS install_longopts,
+#else
+# define GETOPT32 getopt32
+# define LONGOPTS
 #endif
 
 
@@ -121,15 +140,17 @@ int install_main(int argc, char **argv)
 #endif
        };
 
-#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
-       applet_long_options = install_longopts;
-#endif
-       opt_complementary = "t--d:d--t: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:t:" IF_SELINUX("Z:"),
-                       &gid_str, &mode_str, &uid_str, &last
-                       IF_SELINUX(, &scontext));
+       opts = GETOPT32(argv, "^"
+               "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:")
+               "\0"
+               "t--d:d--t:s--d:d--s"
+               IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")),
+               LONGOPTS
+               &gid_str, &mode_str, &uid_str, &last
+               IF_SELINUX(, &scontext)
+       );
        argc -= optind;
        argv += optind;
 
@@ -159,7 +180,7 @@ int install_main(int argc, char **argv)
        }
        mode = 0755; /* GNU coreutils 6.10 compat */
        if (opts & OPT_MODE)
-               bb_parse_mode(mode_str, &mode);
+               mode = bb_parse_mode(mode_str, mode);
        uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
        gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
 
@@ -193,9 +214,14 @@ int install_main(int argc, char **argv)
                        dest = last;
                        if (opts & OPT_MKDIR_LEADING) {
                                char *ddir = xstrdup(dest);
-                               bb_make_directory(dirname(ddir), 0755, mkdir_flags);
+                               /*
+                                * -D -t DIR1/DIR2/F3 FILE: create DIR1/DIR2/F3, copy FILE there
+                                * -D FILE DIR1/DIR2/F3: create DIR1/DIR2, copy FILE there as F3
+                                */
+                               bb_make_directory((opts & OPT_TARGET) ? ddir : dirname(ddir), 0755, mkdir_flags);
                                /* errors are not checked. copy_file
-                                * will fail if dir is not created. */
+                                * will fail if dir is not created.
+                                */
                                free(ddir);
                        }
                        if (isdir)