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

Collapse All | Expand All

(-)usr.sbin/bsdinstall/distfetch/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=	distfetch
6
PROG=	distfetch
5
LIBADD=	fetch ncursesw dialog m
7
LIBADD=	fetch 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/distfetch/distfetch.c (-15 / +71 lines)
Lines 31-44 Link Here
31
#include <sys/param.h>
31
#include <sys/param.h>
32
#include <ctype.h>
32
#include <ctype.h>
33
#include <err.h>
33
#include <err.h>
34
#ifdef HAVE_DIALOG
34
#include <dialog.h>
35
#include <dialog.h>
36
#endif
35
#include <errno.h>
37
#include <errno.h>
38
#include <stdio.h>
36
#include <fetch.h>
39
#include <fetch.h>
37
#include <stdio.h>
38
#include <stdlib.h>
40
#include <stdlib.h>
39
#include <string.h>
41
#include <string.h>
40
#include <unistd.h>
42
#include <unistd.h>
41
43
44
#ifdef HAVE_DIALOG
45
/* Enable/disable dialog(3) */
46
static uint8_t notty = 0;
47
#define _hastty (!notty)
48
#endif
49
42
static int fetch_files(int nfiles, char **urls);
50
static int fetch_files(int nfiles, char **urls);
43
51
44
int
52
int
Lines 51-56 Link Here
51
	int nfetched;
59
	int nfetched;
52
	char error[PATH_MAX + 512];
60
	char error[PATH_MAX + 512];
53
61
62
#ifdef HAVE_DIALOG
63
	if ((getenv("noTty") != NULL) || !isatty(fileno(stdout)))
64
		notty = 1;
65
#endif
66
54
	if (getenv("DISTRIBUTIONS") == NULL)
67
	if (getenv("DISTRIBUTIONS") == NULL)
55
		errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set");
68
		errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set");
56
69
Lines 66-74 Link Here
66
		errx(EXIT_FAILURE, "Out of memory!");
79
		errx(EXIT_FAILURE, "Out of memory!");
67
	}
80
	}
68
81
69
	init_dialog(stdin, stdout);
82
#ifdef HAVE_DIALOG
70
	dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer");
83
	if (_hastty) {
71
	dlg_put_backtitle();
84
		init_dialog(stdin, stdout);
85
		dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer");
86
		dlg_put_backtitle();
87
	}
88
#endif
72
89
73
	for (i = 0; i < ndists; i++) {
90
	for (i = 0; i < ndists; i++) {
74
		urls[i] = malloc(PATH_MAX);
91
		urls[i] = malloc(PATH_MAX);
Lines 80-93 Link Here
80
		snprintf(error, sizeof(error),
97
		snprintf(error, sizeof(error),
81
		    "Could not change to directory %s: %s\n",
98
		    "Could not change to directory %s: %s\n",
82
		    getenv("BSDINSTALL_DISTDIR"), strerror(errno));
99
		    getenv("BSDINSTALL_DISTDIR"), strerror(errno));
83
		dialog_msgbox("Error", error, 0, 0, TRUE);
100
#ifdef HAVE_DIALOG
84
		end_dialog();
101
		if (_hastty) {
102
			dialog_msgbox("Error", error, 0, 0, TRUE);
103
			end_dialog();
104
		} else
105
#endif
106
			fprintf(stderr, "%s", error);
85
		return (EXIT_FAILURE);
107
		return (EXIT_FAILURE);
86
	}
108
	}
87
109
88
	nfetched = fetch_files(ndists, urls);
110
	nfetched = fetch_files(ndists, urls);
89
111
90
	end_dialog();
112
#ifdef HAVE_DIALOG
113
	if (_hastty)
114
		end_dialog();
115
#endif
91
116
92
	free(diststring);
117
	free(diststring);
93
	for (i = 0; i < ndists; i++) 
118
	for (i = 0; i < ndists; i++) 
Lines 130-136 Link Here
130
		items[i*2 + 1] = "Pending";
155
		items[i*2 + 1] = "Pending";
131
	}
156
	}
132
157
133
	dialog_msgbox("", "Connecting to server.\nPlease wait...", 0, 0, FALSE);
158
#ifdef HAVE_DIALOG
159
	if (_hastty)
160
		dialog_msgbox("",
161
		    "Connecting to server.\nPlease wait...", 0, 0, FALSE);
162
	else
163
#endif
164
		printf("Connecting to server. Please wait...\n");
134
165
135
	/* Try to stat all the files */
166
	/* Try to stat all the files */
136
	total_bytes = 0;
167
	total_bytes = 0;
Lines 145-150 Link Here
145
		if (total_bytes == 0)
176
		if (total_bytes == 0)
146
			progress = (i*100)/nfiles;
177
			progress = (i*100)/nfiles;
147
178
179
#ifdef HAVE_DIALOG
180
		if (!_hastty) {
181
#endif
182
			printf("Fetching %s\n", urls[i]);
183
			fflush(stdout);
184
#ifdef HAVE_DIALOG
185
		}
186
#endif
148
		fetchLastErrCode = 0;
187
		fetchLastErrCode = 0;
149
		fetch_out = fetchXGetURL(urls[i], &ustat, "");
188
		fetch_out = fetchXGetURL(urls[i], &ustat, "");
150
		if (fetch_out == NULL) {
189
		if (fetch_out == NULL) {
Lines 152-159 Link Here
152
			    "Error while fetching %s: %s\n", urls[i],
191
			    "Error while fetching %s: %s\n", urls[i],
153
			    fetchLastErrString);
192
			    fetchLastErrString);
154
			items[i*2 + 1] = "Failed";
193
			items[i*2 + 1] = "Failed";
155
			dialog_msgbox("Fetch Error", errormsg, 0, 0,
194
#ifdef HAVE_DIALOG
156
			    TRUE);
195
			if (_hastty)
196
				dialog_msgbox("Fetch Error", errormsg, 0, 0,
197
				    TRUE);
198
			else
199
#endif
200
				fprintf(stderr, "%s", errormsg);
157
			continue;
201
			continue;
158
		}
202
		}
159
203
Lines 165-172 Link Here
165
			    "Error while fetching %s: %s\n",
209
			    "Error while fetching %s: %s\n",
166
			    urls[i], strerror(errno));
210
			    urls[i], strerror(errno));
167
			items[i*2 + 1] = "Failed";
211
			items[i*2 + 1] = "Failed";
168
			dialog_msgbox("Fetch Error", errormsg, 0, 0,
212
#ifdef HAVE_DIALOG
169
			    TRUE);
213
			if (_hastty)
214
				dialog_msgbox("Fetch Error", errormsg, 0, 0,
215
				    TRUE);
216
			else
217
#endif
218
				fprintf(stderr, "%s", errormsg);
170
			fclose(fetch_out);
219
			fclose(fetch_out);
171
			continue;
220
			continue;
172
		}
221
		}
Lines 190-200 Link Here
190
				items[i*2 + 1] = status;
239
				items[i*2 + 1] = status;
191
			}
240
			}
192
241
193
			if (progress > last_progress)
242
#ifdef HAVE_DIALOG
243
			if (_hastty && (progress > last_progress))
194
				dialog_mixedgauge("Fetching Distribution",
244
				dialog_mixedgauge("Fetching Distribution",
195
				    "Fetching distribution files...", 0, 0,
245
				    "Fetching distribution files...", 0, 0,
196
				    progress, nfiles,
246
				    progress, nfiles,
197
				    __DECONST(char **, items));
247
				    __DECONST(char **, items));
248
#endif
198
		}
249
		}
199
250
200
		if (ustat.size > 0 && fsize < ustat.size) {
251
		if (ustat.size > 0 && fsize < ustat.size) {
Lines 207-214 Link Here
207
				    "Error while fetching %s: %s\n",
258
				    "Error while fetching %s: %s\n",
208
				    urls[i], fetchLastErrString);
259
				    urls[i], fetchLastErrString);
209
			items[i*2 + 1] = "Failed";
260
			items[i*2 + 1] = "Failed";
210
			dialog_msgbox("Fetch Error", errormsg, 0, 0,
261
#ifdef HAVE_DIALOG
211
				    TRUE);
262
			if (_hastty)
263
				dialog_msgbox("Fetch Error", errormsg, 0, 0,
264
					    TRUE);
265
			else
266
#endif
267
				fprintf(stderr, "%s", errormsg);
212
		} else {
268
		} else {
213
			items[i*2 + 1] = "Done";
269
			items[i*2 + 1] = "Done";
214
			nsuccess++;
270
			nsuccess++;

Return to bug 202058