Index: usr.sbin/bsdinstall/distextract/Makefile =================================================================== --- usr.sbin/bsdinstall/distextract/Makefile (revision 309246) +++ usr.sbin/bsdinstall/distextract/Makefile (working copy) @@ -1,9 +1,16 @@ # $FreeBSD$ +.include + BINDIR= ${LIBEXECDIR}/bsdinstall PROG= distextract -LIBADD= archive dpv figpar ncursesw dialog m +LIBADD= archive dpv figpar m +.if ${MK_DIALOG} != no +CFLAGS+= -DHAVE_DIALOG +LIBADD+= ncursesw dialog +.endif + WARNS?= 6 MAN= Index: usr.sbin/bsdinstall/distextract/distextract.c =================================================================== --- usr.sbin/bsdinstall/distextract/distextract.c (revision 309246) +++ usr.sbin/bsdinstall/distextract/distextract.c (working copy) @@ -31,16 +31,24 @@ #include #include #include +#ifdef HAVE_DIALOG #include +#endif #include #include #include #include +#include #include #include #include #include +#ifdef HAVE_DIALOG +/* Enable/disable dialog(3) */ +static uint8_t notty = 0; +#endif + /* Data to process */ static char *distdir = NULL; static struct archive *archive = NULL; @@ -56,7 +64,12 @@ archive_read_support_compression_all(x) #endif -#define _errx(...) (end_dialog(), errx(__VA_ARGS__)) +#ifdef HAVE_DIALOG +#define _hastty (!notty) +#define _errx(...) { if (_hastty) end_dialog(); errx(__VA_ARGS__); } +#else +#define _errx(...) { errx(__VA_ARGS__); } +#endif int main(void) @@ -76,18 +89,29 @@ struct sigaction act; char error[PATH_MAX + 512]; +#ifdef HAVE_DIALOG + if ((getenv("noTty") != NULL) || !isatty(fileno(stdout))) + notty = 1; +#endif + if ((distributions = getenv("DISTRIBUTIONS")) == NULL) errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set"); if ((distdir = getenv("BSDINSTALL_DISTDIR")) == NULL) distdir = __DECONST(char *, ""); +#ifdef HAVE_DIALOG /* Initialize dialog(3) */ - init_dialog(stdin, stdout); - dialog_vars.backtitle = backtitle; - dlg_put_backtitle(); + if (_hastty) { + init_dialog(stdin, stdout); + dialog_vars.backtitle = backtitle; + dlg_put_backtitle(); - dialog_msgbox("", - "Checking distribution archives.\nPlease wait...", 4, 35, FALSE); + dialog_msgbox("", + "Checking distribution archives.\nPlease wait...", 4, 35, + FALSE); + } else +#endif + printf("Checking distribution archives. Please wait...\n"); /* * Parse $DISTRIBUTIONS into dpv(3) linked-list @@ -125,7 +149,10 @@ /* Set initial length in files (-1 == error) */ dist->length = count_files(dist->path); if (dist->length < 0) { - end_dialog(); +#ifdef HAVE_DIALOG + if (_hastty) + end_dialog(); +#endif return (EXIT_FAILURE); } @@ -138,8 +165,13 @@ snprintf(error, sizeof(error), "Could not change to directory %s: %s\n", chrootdir, strerror(errno)); - dialog_msgbox("Error", error, 0, 0, TRUE); - end_dialog(); +#ifdef HAVE_DIALOG + if (_hastty) { + dialog_msgbox("Error", error, 0, 0, TRUE); + end_dialog(); + } else +#endif + fprintf(stderr, "%s", error); return (EXIT_FAILURE); } @@ -163,7 +195,12 @@ "%10lli files read @ %'9.1f files/sec."; config->status_many = "%10lli files read @ %'9.1f files/sec. [%i/%i busy/wait]"; - end_dialog(); +#ifdef HAVE_DIALOG + if (_hastty) + end_dialog(); + else +#endif + config->display_type = DPV_DISPLAY_STDOUT; retval = dpv(config, dists); dpv_free(); @@ -235,7 +272,12 @@ if ((archive = archive_read_new()) == NULL) { snprintf(errormsg, sizeof(errormsg), "Error: %s\n", archive_error_string(NULL)); - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); +#ifdef HAVE_DIALOG + if (_hastty) + dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); + else +#endif + fprintf(stderr, "%s", errormsg); return (-1); } archive_read_support_format_all(archive); @@ -246,7 +288,12 @@ snprintf(errormsg, sizeof(errormsg), "Error while extracting %s: %s\n", file, archive_error_string(archive)); - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); +#ifdef HAVE_DIALOG + if (_hastty) + dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); + else +#endif + fprintf(stderr, "%s", errormsg); archive = NULL; return (-1); } @@ -273,7 +320,13 @@ if ((archive = archive_read_new()) == NULL) { snprintf(errormsg, sizeof(errormsg), "Error: %s\n", archive_error_string(NULL)); - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); +#ifdef HAVE_DIALOG + if (_hastty) + dialog_msgbox("Extract Error", errormsg, 0, 0, + TRUE); + else +#endif + fprintf(stderr, "%s", errormsg); dpv_abort = 1; return (-1); } @@ -285,7 +338,13 @@ snprintf(errormsg, sizeof(errormsg), "Error opening %s: %s\n", file->name, archive_error_string(archive)); - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); +#ifdef HAVE_DIALOG + if (_hastty) + dialog_msgbox("Extract Error", errormsg, 0, 0, + TRUE); + else +#endif + fprintf(stderr, "%s", errormsg); file->status = DPV_STATUS_FAILED; dpv_abort = 1; return (-1); @@ -312,7 +371,12 @@ snprintf(errormsg, sizeof(errormsg), "Error while extracting %s: %s\n", file->name, archive_error_string(archive)); - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); +#ifdef HAVE_DIALOG + if (_hastty) + dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); + else +#endif + fprintf(stderr, "%s", errormsg); file->status = DPV_STATUS_FAILED; dpv_abort = 1; return (-1);