nstall(1): add support for -v

Reviewed by rillig@ and thorpej@, thanks!
This commit is contained in:
wiz 2024-05-10 09:14:52 +00:00
parent 40dd220a53
commit 30bb22f9da
2 changed files with 40 additions and 19 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: install.1,v 1.47 2012/04/08 22:00:40 wiz Exp $ .\" $NetBSD: install.1,v 1.48 2024/05/10 09:14:52 wiz Exp $
.\" .\"
.\" Copyright (c) 1987, 1990, 1993 .\" Copyright (c) 1987, 1990, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\" .\"
.\" @(#)install.1 8.1 (Berkeley) 6/6/93 .\" @(#)install.1 8.1 (Berkeley) 6/6/93
.\" .\"
.Dd May 1, 2009 .Dd May 9, 2024
.Dt INSTALL 1 .Dt INSTALL 1
.Os .Os
.Sh NAME .Sh NAME
@ -37,7 +37,7 @@
.Nd install binaries .Nd install binaries
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl bcprsU .Op Fl bcprsUv
.Op Fl a Ar command .Op Fl a Ar command
.Op Fl B Ar suffix .Op Fl B Ar suffix
.Op Fl D Ar destdir .Op Fl D Ar destdir
@ -297,6 +297,11 @@ try to change the owner, the group, or the file flags of the destination.
The information that would have been updated can be stored in a log The information that would have been updated can be stored in a log
file with file with
.Fl M Ar metalog . .Fl M Ar metalog .
.It Fl v
Cause
.Nm
to be verbose,
showing files as they are installed or backed up.
.El .El
.Pp .Pp
By default, By default,

View File

@ -1,4 +1,4 @@
/* $NetBSD: xinstall.c,v 1.127 2023/07/20 16:21:23 lukem Exp $ */ /* $NetBSD: xinstall.c,v 1.128 2024/05/10 09:14:52 wiz Exp $ */
/* /*
* Copyright (c) 1987, 1993 * Copyright (c) 1987, 1993
@ -78,7 +78,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93"; static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93";
#else #else
__RCSID("$NetBSD: xinstall.c,v 1.127 2023/07/20 16:21:23 lukem Exp $"); __RCSID("$NetBSD: xinstall.c,v 1.128 2024/05/10 09:14:52 wiz Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -120,6 +120,7 @@ __RCSID("$NetBSD: xinstall.c,v 1.127 2023/07/20 16:21:23 lukem Exp $");
static int dobackup, dodir, dostrip, dolink, dopreserve, dorename, dounpriv; static int dobackup, dodir, dostrip, dolink, dopreserve, dorename, dounpriv;
static int haveopt_f, haveopt_g, haveopt_m, haveopt_o; static int haveopt_f, haveopt_g, haveopt_m, haveopt_o;
static int numberedbackup; static int numberedbackup;
static int verbose;
static int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; static int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
static char pathbuf[MAXPATHLEN]; static char pathbuf[MAXPATHLEN];
static uid_t uid = -1; static uid_t uid = -1;
@ -186,7 +187,7 @@ main(int argc, char *argv[])
setprogname(argv[0]); setprogname(argv[0]);
iflags = 0; iflags = 0;
while ((ch = getopt(argc, argv, "a:cbB:dD:f:g:h:l:m:M:N:o:prsS:T:U")) while ((ch = getopt(argc, argv, "a:cbB:dD:f:g:h:l:m:M:N:o:prsS:T:Uv"))
!= -1) != -1)
switch((char)ch) { switch((char)ch) {
case 'a': case 'a':
@ -307,6 +308,9 @@ main(int argc, char *argv[])
case 'U': case 'U':
dounpriv = 1; dounpriv = 1;
break; break;
case 'v':
verbose = 1;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -477,9 +481,12 @@ do_link(char *from_name, char *to_name)
*/ */
(void)unlink(tmpl); (void)unlink(tmpl);
} }
return (ret); } else {
} else ret = link(from_name, to_name);
return (link(from_name, to_name)); }
if (ret == 0 && verbose)
(void)printf("install: link %s -> %s\n", from_name, to_name);
return ret;
} }
/* /*
@ -509,6 +516,8 @@ do_symlink(char *from_name, char *to_name)
if (symlink(from_name, to_name) == -1) if (symlink(from_name, to_name) == -1)
err(EXIT_FAILURE, "symlink %s -> %s", from_name, to_name); err(EXIT_FAILURE, "symlink %s -> %s", from_name, to_name);
} }
if (verbose)
(void)printf("install: symlink %s -> %s\n", from_name, to_name);
} }
/* /*
@ -641,7 +650,7 @@ makelink(char *from_name, char *to_name)
} }
/* /*
* If absolute or relative was not specified, * If absolute or relative was not specified,
* try the names the user provided * try the names the user provided
*/ */
do_symlink(from_name, to_name); do_symlink(from_name, to_name);
@ -821,6 +830,8 @@ install(char *from_name, char *to_name, u_int flags)
err(EXIT_FAILURE, "%s: rename", to_name); err(EXIT_FAILURE, "%s: rename", to_name);
to_name = oto_name; to_name = oto_name;
} }
if (verbose)
(void)printf("install: %s -> %s\n", from_name, to_name);
/* /*
* If provided a set of flags, set them, otherwise, preserve the * If provided a set of flags, set them, otherwise, preserve the
@ -1116,12 +1127,12 @@ static void
backup(const char *to_name) backup(const char *to_name)
{ {
char bname[FILENAME_MAX]; char bname[FILENAME_MAX];
if (numberedbackup) { if (numberedbackup) {
/* Do numbered backup */ /* Do numbered backup */
int cnt; int cnt;
char suffix_expanded[FILENAME_MAX]; char suffix_expanded[FILENAME_MAX];
cnt=0; cnt=0;
do { do {
(void)snprintf(suffix_expanded, FILENAME_MAX, suffix, (void)snprintf(suffix_expanded, FILENAME_MAX, suffix,
@ -1129,13 +1140,16 @@ backup(const char *to_name)
(void)snprintf(bname, FILENAME_MAX, "%s%s", to_name, (void)snprintf(bname, FILENAME_MAX, "%s%s", to_name,
suffix_expanded); suffix_expanded);
cnt++; cnt++;
} while (access(bname, F_OK) == 0); } while (access(bname, F_OK) == 0);
} else { } else {
/* Do simple backup */ /* Do simple backup */
(void)snprintf(bname, FILENAME_MAX, "%s%s", to_name, suffix); (void)snprintf(bname, FILENAME_MAX, "%s%s", to_name, suffix);
} }
(void)rename(to_name, bname); if (rename(to_name, bname) == 0) {
if (verbose)
(void)printf("install: %s -> %s\n", to_name, bname);
}
} }
/* /*
@ -1171,6 +1185,8 @@ install_dir(char *path, u_int flags)
path); path);
} }
} }
if (verbose)
(void)printf("install: mkdir %s\n", path);
if (!(*p = ch)) if (!(*p = ch))
break; break;
} }
@ -1202,7 +1218,7 @@ metadata_log(const char *path, const char *type, struct timeval *tv,
size_t destlen; size_t destlen;
struct flock metalog_lock; struct flock metalog_lock;
if (!metafp) if (!metafp)
return; return;
buf = malloc(4 * strlen(path) + 1); /* buf for strsvis(3) */ buf = malloc(4 * strlen(path) + 1); /* buf for strsvis(3) */
if (buf == NULL) { if (buf == NULL) {
@ -1305,13 +1321,13 @@ usage(void)
prog = getprogname(); prog = getprogname();
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: %s [-Ubcprs] [-M log] [-D dest] [-T tags] [-B suffix]\n" "usage: %s [-bcprsUv] [-M log] [-D dest] [-T tags] [-B suffix]\n"
" [-a aftercmd] [-f flags] [-m mode] [-N dbdir] [-o owner] [-g group] \n" " [-a aftercmd] [-f flags] [-m mode] [-N dbdir] [-o owner] [-g group] \n"
" [-l linkflags] [-h hash] [-S stripflags] file1 file2\n" " [-l linkflags] [-h hash] [-S stripflags] file1 file2\n"
" %s [-Ubcprs] [-M log] [-D dest] [-T tags] [-B suffix]\n" " %s [-bcprsUv] [-M log] [-D dest] [-T tags] [-B suffix]\n"
" [-a aftercmd] [-f flags] [-m mode] [-N dbdir] [-o owner] [-g group]\n" " [-a aftercmd] [-f flags] [-m mode] [-N dbdir] [-o owner] [-g group]\n"
" [-l linkflags] [-h hash] [-S stripflags] file1 ... fileN directory\n" " [-l linkflags] [-h hash] [-S stripflags] file1 ... fileN directory\n"
" %s -d [-Up] [-M log] [-D dest] [-T tags] [-a aftercmd] [-m mode]\n" " %s -d [-pUv] [-M log] [-D dest] [-T tags] [-a aftercmd] [-m mode]\n"
" [-N dbdir] [-o owner] [-g group] directory ...\n", " [-N dbdir] [-o owner] [-g group] directory ...\n",
prog, prog, prog); prog, prog, prog);
exit(1); exit(1);