View | Details | Raw Unified | Return to bug 202058 | Differences between
and this patch

Collapse All | Expand All

(-)usr.sbin/bsdinstall/distextract/Makefile (-1 / +8 lines)
Lines 1-9 Link Here
1
# $FreeBSD$
1
# $FreeBSD$
2
2
3
.include <src.opts.mk>
4
3
BINDIR= ${LIBEXECDIR}/bsdinstall
5
BINDIR= ${LIBEXECDIR}/bsdinstall
4
PROG=	distextract
6
PROG=	distextract
5
LIBADD=	archive dpv figpar ncursesw dialog m
7
LIBADD=	archive dpv figpar m
6
8
9
.if ${MK_DIALOG} != no
10
CFLAGS+=	-DHAVE_DIALOG
11
LIBADD+=	ncursesw dialog
12
.endif
13
7
WARNS?=	6
14
WARNS?=	6
8
MAN=
15
MAN=
9
16
(-)usr.sbin/bsdinstall/distextract/distextract.c (-15 / +79 lines)
Lines 31-46 Link Here
31
#include <sys/param.h>
31
#include <sys/param.h>
32
#include <archive.h>
32
#include <archive.h>
33
#include <ctype.h>
33
#include <ctype.h>
34
#ifdef HAVE_DIALOG
34
#include <dialog.h>
35
#include <dialog.h>
36
#endif
35
#include <dpv.h>
37
#include <dpv.h>
36
#include <err.h>
38
#include <err.h>
37
#include <errno.h>
39
#include <errno.h>
38
#include <limits.h>
40
#include <limits.h>
41
#include <signal.h>
39
#include <stdio.h>
42
#include <stdio.h>
40
#include <stdlib.h>
43
#include <stdlib.h>
41
#include <string.h>
44
#include <string.h>
42
#include <unistd.h>
45
#include <unistd.h>
43
46
47
#ifdef HAVE_DIALOG
48
/* Enable/disable dialog(3) */
49
static uint8_t notty = 0;
50
#endif
51
44
/* Data to process */
52
/* Data to process */
45
static char *distdir = NULL;
53
static char *distdir = NULL;
46
static struct archive *archive = NULL;
54
static struct archive *archive = NULL;
Lines 56-62 Link Here
56
	archive_read_support_compression_all(x)
64
	archive_read_support_compression_all(x)
57
#endif
65
#endif
58
66
59
#define _errx(...) (end_dialog(), errx(__VA_ARGS__))
67
#ifdef HAVE_DIALOG
68
#define _hastty (!notty)
69
#define _errx(...) { if (_hastty) end_dialog(); errx(__VA_ARGS__); }
70
#else
71
#define _errx(...) { errx(__VA_ARGS__); }
72
#endif
60
73
61
int
74
int
62
main(void)
75
main(void)
Lines 76-93 Link Here
76
	struct sigaction act;
89
	struct sigaction act;
77
	char error[PATH_MAX + 512];
90
	char error[PATH_MAX + 512];
78
91
92
#ifdef HAVE_DIALOG
93
	if ((getenv("noTty") != NULL) || !isatty(fileno(stdout)))
94
		notty = 1;
95
#endif
96
79
	if ((distributions = getenv("DISTRIBUTIONS")) == NULL)
97
	if ((distributions = getenv("DISTRIBUTIONS")) == NULL)
80
		errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set");
98
		errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set");
81
	if ((distdir = getenv("BSDINSTALL_DISTDIR")) == NULL)
99
	if ((distdir = getenv("BSDINSTALL_DISTDIR")) == NULL)
82
		distdir = __DECONST(char *, "");
100
		distdir = __DECONST(char *, "");
83
101
102
#ifdef HAVE_DIALOG
84
	/* Initialize dialog(3) */
103
	/* Initialize dialog(3) */
85
	init_dialog(stdin, stdout);
104
	if (_hastty) {
86
	dialog_vars.backtitle = backtitle;
105
		init_dialog(stdin, stdout);
87
	dlg_put_backtitle();
106
		dialog_vars.backtitle = backtitle;
107
		dlg_put_backtitle();
88
108
89
	dialog_msgbox("",
109
		dialog_msgbox("",
90
	    "Checking distribution archives.\nPlease wait...", 4, 35, FALSE);
110
		    "Checking distribution archives.\nPlease wait...", 4, 35,
111
		    FALSE);
112
	} else
113
#endif
114
		printf("Checking distribution archives. Please wait...\n");
91
115
92
	/*
116
	/*
93
	 * Parse $DISTRIBUTIONS into dpv(3) linked-list
117
	 * Parse $DISTRIBUTIONS into dpv(3) linked-list
Lines 125-131 Link Here
125
		/* Set initial length in files (-1 == error) */
149
		/* Set initial length in files (-1 == error) */
126
		dist->length = count_files(dist->path);
150
		dist->length = count_files(dist->path);
127
		if (dist->length < 0) {
151
		if (dist->length < 0) {
128
			end_dialog();
152
#ifdef HAVE_DIALOG
153
			if (_hastty)
154
				end_dialog();
155
#endif
129
			return (EXIT_FAILURE);
156
			return (EXIT_FAILURE);
130
		}
157
		}
131
158
Lines 138-145 Link Here
138
		snprintf(error, sizeof(error),
165
		snprintf(error, sizeof(error),
139
		    "Could not change to directory %s: %s\n",
166
		    "Could not change to directory %s: %s\n",
140
		    chrootdir, strerror(errno));
167
		    chrootdir, strerror(errno));
141
		dialog_msgbox("Error", error, 0, 0, TRUE);
168
#ifdef HAVE_DIALOG
142
		end_dialog();
169
		if (_hastty) {
170
			dialog_msgbox("Error", error, 0, 0, TRUE);
171
			end_dialog();
172
		} else
173
#endif
174
			fprintf(stderr, "%s", error);
143
		return (EXIT_FAILURE);
175
		return (EXIT_FAILURE);
144
	}
176
	}
145
177
Lines 163-169 Link Here
163
	    "%10lli files read @ %'9.1f files/sec.";
195
	    "%10lli files read @ %'9.1f files/sec.";
164
	config->status_many	= 
196
	config->status_many	= 
165
	    "%10lli files read @ %'9.1f files/sec. [%i/%i busy/wait]";
197
	    "%10lli files read @ %'9.1f files/sec. [%i/%i busy/wait]";
166
	end_dialog();
198
#ifdef HAVE_DIALOG
199
	if (_hastty)
200
		end_dialog();
201
	else
202
#endif
203
		config->display_type = DPV_DISPLAY_STDOUT;
167
	retval = dpv(config, dists);
204
	retval = dpv(config, dists);
168
205
169
	dpv_free();
206
	dpv_free();
Lines 235-241 Link Here
235
	if ((archive = archive_read_new()) == NULL) {
272
	if ((archive = archive_read_new()) == NULL) {
236
		snprintf(errormsg, sizeof(errormsg),
273
		snprintf(errormsg, sizeof(errormsg),
237
		    "Error: %s\n", archive_error_string(NULL));
274
		    "Error: %s\n", archive_error_string(NULL));
238
		dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
275
#ifdef HAVE_DIALOG
276
		if (_hastty)
277
			dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
278
		else
279
#endif
280
			fprintf(stderr, "%s", errormsg);
239
		return (-1);
281
		return (-1);
240
	}
282
	}
241
	archive_read_support_format_all(archive);
283
	archive_read_support_format_all(archive);
Lines 246-252 Link Here
246
		snprintf(errormsg, sizeof(errormsg),
288
		snprintf(errormsg, sizeof(errormsg),
247
		    "Error while extracting %s: %s\n", file,
289
		    "Error while extracting %s: %s\n", file,
248
		    archive_error_string(archive));
290
		    archive_error_string(archive));
249
		dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
291
#ifdef HAVE_DIALOG
292
		if (_hastty)
293
			dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
294
		else
295
#endif
296
			fprintf(stderr, "%s", errormsg);
250
		archive = NULL;
297
		archive = NULL;
251
		return (-1);
298
		return (-1);
252
	}
299
	}
Lines 273-279 Link Here
273
		if ((archive = archive_read_new()) == NULL) {
320
		if ((archive = archive_read_new()) == NULL) {
274
			snprintf(errormsg, sizeof(errormsg),
321
			snprintf(errormsg, sizeof(errormsg),
275
			    "Error: %s\n", archive_error_string(NULL));
322
			    "Error: %s\n", archive_error_string(NULL));
276
			dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
323
#ifdef HAVE_DIALOG
324
			if (_hastty)
325
				dialog_msgbox("Extract Error", errormsg, 0, 0,
326
				    TRUE);
327
			else
328
#endif
329
				fprintf(stderr, "%s", errormsg);
277
			dpv_abort = 1;
330
			dpv_abort = 1;
278
			return (-1);
331
			return (-1);
279
		}
332
		}
Lines 285-291 Link Here
285
			snprintf(errormsg, sizeof(errormsg),
338
			snprintf(errormsg, sizeof(errormsg),
286
			    "Error opening %s: %s\n", file->name,
339
			    "Error opening %s: %s\n", file->name,
287
			    archive_error_string(archive));
340
			    archive_error_string(archive));
288
			dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
341
#ifdef HAVE_DIALOG
342
			if (_hastty)
343
				dialog_msgbox("Extract Error", errormsg, 0, 0,
344
				    TRUE);
345
			else
346
#endif
347
				fprintf(stderr, "%s", errormsg);
289
			file->status = DPV_STATUS_FAILED;
348
			file->status = DPV_STATUS_FAILED;
290
			dpv_abort = 1;
349
			dpv_abort = 1;
291
			return (-1);
350
			return (-1);
Lines 312-318 Link Here
312
		snprintf(errormsg, sizeof(errormsg),
371
		snprintf(errormsg, sizeof(errormsg),
313
		    "Error while extracting %s: %s\n", file->name,
372
		    "Error while extracting %s: %s\n", file->name,
314
		    archive_error_string(archive));
373
		    archive_error_string(archive));
315
		dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
374
#ifdef HAVE_DIALOG
375
		if (_hastty)
376
			dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE);
377
		else
378
#endif
379
			fprintf(stderr, "%s", errormsg);
316
		file->status = DPV_STATUS_FAILED;
380
		file->status = DPV_STATUS_FAILED;
317
		dpv_abort = 1;
381
		dpv_abort = 1;
318
		return (-1);
382
		return (-1);

Return to bug 202058