aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Config.in6
-rw-r--r--coreutils/Makefile.in1
-rw-r--r--coreutils/chgrp.c5
-rw-r--r--coreutils/chown.c13
-rw-r--r--coreutils/install.c102
5 files changed, 110 insertions, 17 deletions
diff --git a/coreutils/Config.in b/coreutils/Config.in
index 074312b6e..c2ae399ef 100644
--- a/coreutils/Config.in
+++ b/coreutils/Config.in
@@ -218,6 +218,12 @@ config CONFIG_ID
218 help 218 help
219 id displays the current user and group ID names. 219 id displays the current user and group ID names.
220 220
221config CONFIG_INSTALL
222 bool "install"
223 default n
224 help
225 Copy files and set attributes.
226
221config CONFIG_LENGTH 227config CONFIG_LENGTH
222 bool "length" 228 bool "length"
223 default n 229 default n
diff --git a/coreutils/Makefile.in b/coreutils/Makefile.in
index 95eda1ac7..b672f08f7 100644
--- a/coreutils/Makefile.in
+++ b/coreutils/Makefile.in
@@ -47,6 +47,7 @@ COREUTILS-$(CONFIG_FOLD) += fold.o
47COREUTILS-$(CONFIG_HEAD) += head.o 47COREUTILS-$(CONFIG_HEAD) += head.o
48COREUTILS-$(CONFIG_HOSTID) += hostid.o 48COREUTILS-$(CONFIG_HOSTID) += hostid.o
49COREUTILS-$(CONFIG_ID) += id.o 49COREUTILS-$(CONFIG_ID) += id.o
50COREUTILS-$(CONFIG_INSTALL) += install.o
50COREUTILS-$(CONFIG_LENGTH) += length.o 51COREUTILS-$(CONFIG_LENGTH) += length.o
51COREUTILS-$(CONFIG_LN) += ln.o 52COREUTILS-$(CONFIG_LN) += ln.o
52COREUTILS-$(CONFIG_LOGNAME) += logname.o 53COREUTILS-$(CONFIG_LOGNAME) += logname.o
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c
index 2f3fa4197..8c969d7b6 100644
--- a/coreutils/chgrp.c
+++ b/coreutils/chgrp.c
@@ -59,10 +59,7 @@ int chgrp_main(int argc, char **argv)
59 argv += optind; 59 argv += optind;
60 60
61 /* Find the selected group */ 61 /* Find the selected group */
62 gid = strtoul(*argv, &p, 10); /* maybe it's already numeric */ 62 gid = get_ug_id(*argv, my_getgrnam);
63 if (*p || (p == *argv)) { /* trailing chars or nonnumeric */
64 gid = my_getgrnam(*argv);
65 }
66 ++argv; 63 ++argv;
67 64
68 /* Ok, ready to do the deed now */ 65 /* Ok, ready to do the deed now */
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 02b752474..07d673f28 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -53,19 +53,6 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
53#define FLAG_R 1 53#define FLAG_R 1
54#define FLAG_h 2 54#define FLAG_h 2
55 55
56static unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *))
57{
58 unsigned long r;
59 char *p;
60
61 r = strtoul(s, &p, 10);
62 if (*p || (s == p)) {
63 r = my_getxxnam(s);
64 }
65
66 return r;
67}
68
69int chown_main(int argc, char **argv) 56int chown_main(int argc, char **argv)
70{ 57{
71 int flags; 58 int flags;
diff --git a/coreutils/install.c b/coreutils/install.c
new file mode 100644
index 000000000..b235817cc
--- /dev/null
+++ b/coreutils/install.c
@@ -0,0 +1,102 @@
1/*
2 * Copyright (C) 2003 by Glenn McGrath <bug1@optushome.com.au>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 *
19 * TODO: -d option, need a way of recursively making directories and changing
20 * owner/group, will probably modify bb_make_directory(...)
21 * Use bb_getopt_ulflags(...) ?
22 *
23 */
24
25#include <sys/stat.h>
26#include <sys/types.h>
27#include <errno.h>
28#include <getopt.h>
29#include <stdlib.h>
30#include <unistd.h>
31
32#include "libbb.h"
33
34extern int install_main(int argc, char **argv)
35{
36 struct stat statbuf;
37 int i;
38 int ret = EXIT_SUCCESS;
39 uid_t uid = -1;
40 gid_t gid = -1;
41 int copy_flags = 0;
42 int strip_flag = 0;
43 mode_t mode = 0755;
44
45 /* -c exists for backwards compatability, its needed */
46 while ((i = getopt(argc, argv, "cg:m:o:ps")) != -1) {
47 switch (i) {
48 case 'g': /* group */
49 gid = get_ug_id(optarg, my_getgrnam);
50 break;
51 case 'm': /* mode */
52 bb_parse_mode(optarg, &mode);
53 break;
54 case 'o': /* owner */
55 uid = get_ug_id(optarg, my_getpwnam);
56 break;
57 case 'p': /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
58 copy_flags |= FILEUTILS_PRESERVE_STATUS;
59 break;
60 case 's': /* Strip binaries */
61 strip_flag = 1;
62 break;
63 default:
64 bb_show_usage();
65 }
66 }
67
68 if ((stat(argv[argc - 1], &statbuf) == -1) && (errno != ENOENT)) {
69 bb_perror_msg_and_die("stat failed for %s: ", argv[argc - 1]);
70 }
71
72 for (i = optind; i < argc - 1; i++) {
73 unsigned char *dest;
74
75 if (S_ISDIR(statbuf.st_mode)) {
76 dest = concat_path_file(argv[argc - 1], argv[i]);
77 } else {
78 dest = argv[argc - 1];
79 }
80 ret |= copy_file(argv[i], dest, copy_flags);
81
82 /* Set the file mode */
83 if (chmod(dest, mode) == -1) {
84 bb_perror_msg("cannot change permissions of %s", dest);
85 ret |= EXIT_FAILURE;
86 }
87
88 /* Set the user and group id */
89 if (chown(dest, uid, gid) == -1) {
90 bb_perror_msg("cannot change ownership of %s", dest);
91 ret |= EXIT_FAILURE;
92 }
93 if (strip_flag) {
94 if (execlp("strip", "strip", dest, NULL) == -1) {
95 bb_error_msg("strip failed");
96 ret |= EXIT_FAILURE;
97 }
98 }
99 }
100
101 return(ret);
102}