summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg/pkg.c
diff options
context:
space:
mode:
authorkan <kan@FreeBSD.org>2012-07-15 04:15:27 +0000
committerkan <kan@FreeBSD.org>2012-07-15 04:15:27 +0000
commitee2618962b33577dd93a943b7af68f109afa23c5 (patch)
tree702899e1d092198c06d03d7db6ee4b71c6a80b29 /usr.sbin/pkg/pkg.c
parent86ea1d09c964eeae1fe6cad1aaac3b325a9d0966 (diff)
downloadFreeBSD-src-ee2618962b33577dd93a943b7af68f109afa23c5.zip
FreeBSD-src-ee2618962b33577dd93a943b7af68f109afa23c5.tar.gz
Make pkg bootstrap program ask for confirmation before proceeding.
The previous behaviour was to silently download and install the pkg package, without ever telling user about what it was doing and why. Discussed with: bapt Reviewed by: kib
Diffstat (limited to 'usr.sbin/pkg/pkg.c')
-rw-r--r--usr.sbin/pkg/pkg.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c
index b6c0207..1849eeb 100644
--- a/usr.sbin/pkg/pkg.c
+++ b/usr.sbin/pkg/pkg.c
@@ -389,6 +389,28 @@ cleanup:
return (ret);
}
+static const char confirmation_message[] =
+"The package management tool is not yet installed on your system.\n"
+"Do you want to fetch and install it now? [y/N]: ";
+
+static int
+pkg_query_yes_no(void)
+{
+ int ret, c;
+
+ c = getchar();
+
+ if (c == 'y' || c == 'Y')
+ ret = 1;
+ else
+ ret = 0;
+
+ while (c != '\n' && c != EOF)
+ c = getchar();
+
+ return (ret);
+}
+
int
main(__unused int argc, char *argv[])
{
@@ -397,9 +419,21 @@ main(__unused int argc, char *argv[])
snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg",
getenv("LOCALBASE") ? getenv("LOCALBASE") : _LOCALBASE);
- if (access(pkgpath, X_OK) == -1)
+ if (access(pkgpath, X_OK) == -1) {
+ /*
+ * Do not ask for confirmation if either of stdin or stdout is
+ * not tty. Check the environment to see if user has answer
+ * tucked in there already.
+ */
+ if (getenv("ALWAYS_ASSUME_YES") == NULL &&
+ isatty(fileno(stdin))) {
+ printf("%s", confirmation_message);
+ if (pkg_query_yes_no() == 0)
+ exit(EXIT_FAILURE);
+ }
if (bootstrap_pkg() != 0)
exit(EXIT_FAILURE);
+ }
execv(pkgpath, argv);
OpenPOWER on IntegriCloud