2 * Copyright (C) 2003 by Glenn McGrath <bug1@optushome.com.au>
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.
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.
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.
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(...) ?
26 #include <sys/types.h>
35 extern int install_main(int argc, char **argv)
39 int ret = EXIT_SUCCESS;
47 /* -c exists for backwards compatability, its needed */
48 while ((i = getopt(argc, argv, "cdg:m:o:ps")) != -1) {
50 case 'd': /* Create directories */
54 gid = get_ug_id(optarg, my_getgrnam);
57 bb_parse_mode(optarg, &mode);
60 uid = get_ug_id(optarg, my_getpwnam);
62 case 'p': /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
63 copy_flags |= FILEUTILS_PRESERVE_STATUS;
65 case 's': /* Strip binaries */
74 for (argv += optind; *argv; argv++) {
75 unsigned char *dir_name = *argv;
76 unsigned char *argv_ptr;
78 ret |= bb_make_directory(dir_name, mode, FILEUTILS_RECUR);
80 argv_ptr = strrchr(dir_name, '/');
82 /* Skip the "." and ".." directories */
83 if ((dir_name[0] == '.') && ((dir_name[1] == '\0') || ((dir_name[1] == '.') && (dir_name[2] == '\0')))) {
86 if (chown(dir_name, uid, gid) == -1) {
87 bb_perror_msg("cannot change ownership of %s", argv_ptr);
98 if ((stat(argv[argc - 1], &statbuf) == -1) && (errno != ENOENT)) {
99 bb_perror_msg_and_die("stat failed for %s: ", argv[argc - 1]);
102 for (i = optind; i < argc - 1; i++) {
105 if (S_ISDIR(statbuf.st_mode)) {
106 dest = concat_path_file(argv[argc - 1], argv[i]);
108 dest = argv[argc - 1];
110 ret |= copy_file(argv[i], dest, copy_flags);
112 /* Set the file mode */
113 if (chmod(dest, mode) == -1) {
114 bb_perror_msg("cannot change permissions of %s", dest);
118 /* Set the user and group id */
119 if (chown(dest, uid, gid) == -1) {
120 bb_perror_msg("cannot change ownership of %s", dest);
124 if (execlp("strip", "strip", dest, NULL) == -1) {
125 bb_error_msg("strip failed");