]>
Commit | Line | Data |
---|---|---|
d6aaa55d MT |
1 | /* SmoothWall install program. |
2 | * | |
3 | * This program is distributed under the terms of the GNU General Public | |
4 | * Licence. See the file COPYING for details. | |
5 | * | |
6 | * (c) Lawrence Manning, 2001 | |
7 | * Contains main entry point, and misc functions. | |
8 | * | |
10bc6f06 | 9 | * $Id: main.c,v 1.63.2.57 2005/09/25 19:57:46 gespinasse Exp $ |
d6aaa55d MT |
10 | * |
11 | */ | |
10bc6f06 | 12 | |
d6aaa55d MT |
13 | #include "install.h" |
14 | ||
15 | #define CDROM_INSTALL 0 | |
16 | #define URL_INSTALL 1 | |
17 | ||
18 | int raid_disk = 0; | |
19 | FILE *flog = NULL; | |
20 | char *mylog; | |
10bc6f06 | 21 | |
d6aaa55d MT |
22 | char **ctr; |
23 | ||
24 | char *pcmcia = NULL; | |
25 | extern char url[STRING_SIZE]; | |
26 | ||
10bc6f06 MT |
27 | extern char *bz_tr[]; |
28 | extern char *cs_tr[]; | |
29 | extern char *da_tr[]; | |
30 | extern char *en_tr[]; | |
31 | extern char *es_tr[]; | |
32 | extern char *fi_tr[]; | |
33 | extern char *fr_tr[]; | |
34 | extern char *hu_tr[]; | |
35 | extern char *la_tr[]; | |
36 | extern char *nl_tr[]; | |
37 | extern char *de_tr[]; | |
38 | extern char *tr_tr[]; | |
39 | extern char *it_tr[]; | |
40 | extern char *el_tr[]; | |
41 | extern char *pl_tr[]; | |
42 | extern char *pt_tr[]; | |
43 | extern char *so_tr[]; | |
44 | extern char *sv_tr[]; | |
45 | extern char *no_tr[]; | |
46 | extern char *vi_tr[]; | |
d6aaa55d MT |
47 | |
48 | int main(int argc, char *argv[]) | |
49 | { | |
50 | #ifdef LANG_EN_ONLY | |
51 | char *langnames[] = { "English", NULL }; | |
52 | char *shortlangnames[] = { "en", NULL }; | |
53 | char **langtrs[] = { en_tr, NULL }; | |
54 | #else | |
10bc6f06 MT |
55 | char *langnames[] = { "Brasil", "Cestina", "Dansk", "Deutsch", "English", "Español", "Français", "Hellenic", "Italiano", "Spanish Latino", "Magyar", "Nederlands", "Norsk", "Polski", "Português", "Soomali", "Suomi", "Svenska", "Türkçe", "Tieng Viet", NULL }; |
56 | char *shortlangnames[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "so", "fi", "sv", "tr", "vi", NULL }; | |
57 | char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL }; | |
d6aaa55d MT |
58 | #endif |
59 | char hdletter, cdletter; | |
60 | char harddrive[5], cdromdrive[5]; /* Device holder. */ | |
61 | struct devparams hdparams, cdromparams; /* Params for CDROM and HD */ | |
62 | int cdmounted = 0; /* Loop flag for inserting a cd. */ | |
63 | int rc; | |
64 | char commandstring[STRING_SIZE]; | |
10bc6f06 | 65 | char *installtypes[] = { "CDROM", "HTTP/FTP", NULL }; |
d6aaa55d MT |
66 | int installtype = CDROM_INSTALL; |
67 | char insertmessage[STRING_SIZE]; | |
68 | char insertdevnode[STRING_SIZE]; | |
69 | int choice; | |
70 | char shortlangname[10]; | |
71 | char message[1000]; | |
72 | char title[STRING_SIZE]; | |
73 | int allok = 0; | |
10bc6f06 | 74 | int allok_fastexit=0; |
d6aaa55d MT |
75 | int unmount_before=0; |
76 | struct keyvalue *ethernetkv = initkeyvalues(); | |
77 | FILE *handle, *cmdfile; | |
78 | char line[STRING_SIZE]; | |
79 | char string[STRING_SIZE]; | |
80 | int maximum_free = 0, current_free; | |
81 | int memory = 0; | |
82 | int log_partition, boot_partition, root_partition, swap_file; | |
83 | int scsi_disk = 0; | |
84 | int pcmcia_disk = 0; | |
85 | int pcmcia_cdrom = 0; | |
86 | int scsi_cdrom = 0; | |
87 | int ide_cdrom = 0; | |
88 | int fdisk = 0; | |
10bc6f06 | 89 | |
d6aaa55d MT |
90 | |
91 | setlocale (LC_ALL, ""); | |
10bc6f06 | 92 | sethostname( SNAME , 10); |
d6aaa55d MT |
93 | |
94 | memset(&hdparams, 0, sizeof(struct devparams)); | |
95 | memset(&cdromparams, 0, sizeof(struct devparams)); | |
96 | ||
97 | /* Log file/terminal stuff. */ | |
98 | if (argc >= 2) | |
99 | { | |
100 | if (!(flog = fopen(argv[1], "w+"))) | |
101 | return 0; | |
102 | } | |
103 | else | |
104 | return 0; | |
105 | ||
106 | mylog = argv[1]; | |
107 | ||
108 | fprintf(flog, "Install program started.\n"); | |
109 | ||
110 | newtInit(); | |
111 | newtCls(); | |
112 | ||
113 | /* Do usb detection first for usb keyboard */ | |
114 | if (! (cmdfile = fopen("/proc/cmdline", "r"))) | |
115 | { | |
116 | fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); | |
117 | } else { | |
118 | fgets(line, STRING_SIZE, cmdfile); | |
119 | if (strstr (line, "fdisk") != NULL) { | |
120 | fprintf(flog, "Manual FDISK selected.\n"); | |
121 | fdisk = 1; | |
122 | } | |
123 | if (strstr (line, "nopcmcia") == NULL) { | |
124 | fprintf(flog, "Initializing PCMCIA controllers.\n"); | |
125 | pcmcia = initialize_pcmcia(); | |
126 | if (pcmcia) { | |
127 | fprintf (flog, "Detected PCMCIA Controller: %s.\n", pcmcia); | |
128 | sprintf(commandstring, "/sbin/modprobe %s", pcmcia); | |
129 | mysystem("/sbin/modprobe pcmcia_core"); | |
130 | mysystem(commandstring); | |
131 | mysystem("/sbin/modprobe ds"); | |
132 | /* pcmcia netcard drivers are not available from Boot floppy, | |
133 | * they will be loaded from Drivers floppy later */ | |
134 | } else { | |
135 | fprintf (flog, "Detected No PCMCIA Controller.\n"); | |
136 | } | |
137 | } else { | |
138 | fprintf(flog, "Skipping PCMCIA detection.\n"); | |
139 | } | |
140 | if (strstr (line, "nousb") == NULL) { | |
141 | fprintf(flog, "Initializing USB controllers.\n"); | |
142 | initialize_usb(); | |
143 | } else { | |
144 | fprintf(flog, "Skipping USB detection.\n"); | |
145 | } | |
146 | } | |
147 | ||
148 | /* English is the default */ | |
149 | for (choice = 0; langnames[choice]; choice++) | |
150 | { | |
151 | if (strcmp(langnames[choice], "English") == 0) | |
152 | break; | |
153 | } | |
154 | if (!langnames[choice]) | |
155 | goto EXIT; | |
156 | ||
157 | #ifdef LANG_EN_ONLY | |
158 | /* No need to ask. "choice" already has the index for English */ | |
159 | #else | |
160 | rc = newtWinMenu("Language selection", | |
161 | "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, | |
162 | langnames, &choice, "Ok", NULL); | |
163 | #endif | |
164 | ctr = langtrs[choice]; | |
165 | strcpy(shortlangname, shortlangnames[choice]); | |
166 | if (strcmp(shortlangname, "el") == 0) | |
167 | mysystem("/bin/setfont iso07u-16"); | |
168 | else if (strcmp(shortlangname, "pt") == 0) | |
169 | mysystem("/bin/setfont lat1-16"); | |
170 | else if (strcmp(shortlangname, "bz") == 0) | |
171 | mysystem("/bin/setfont lat1-16"); | |
172 | else if (strcmp(shortlangname, "cs") == 0) | |
173 | mysystem("/bin/setfont lat2-16"); | |
174 | else if (strcmp(shortlangname, "hu") == 0) | |
175 | mysystem("/bin/setfont lat2-16"); | |
176 | else if (strcmp(shortlangname, "pl") == 0) | |
177 | mysystem("/bin/setfont lat2-16"); | |
d6aaa55d MT |
178 | else if (strcmp(shortlangname, "tr") == 0) |
179 | mysystem("/bin/setfont lat5-16"); | |
180 | else if (strcmp(shortlangname, "vi") == 0) | |
181 | mysystem("/bin/setfont viscii10-8x16"); | |
182 | else | |
183 | mysystem("/bin/setfont lat0-16"); | |
10bc6f06 | 184 | |
d6aaa55d MT |
185 | newtDrawRootText(14, 0, NAME " v" VERSION " - " SLOGAN ); |
186 | newtPushHelpLine(ctr[TR_HELPLINE]); | |
187 | ||
10bc6f06 MT |
188 | sprintf(message, ctr[TR_WELCOME], NAME); |
189 | sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); | |
d6aaa55d MT |
190 | newtWinMessage(title, ctr[TR_OK], message); |
191 | ||
10bc6f06 | 192 | sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME); |
d6aaa55d MT |
193 | rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message, |
194 | 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK], | |
195 | ctr[TR_CANCEL], NULL); | |
10bc6f06 | 196 | |
d6aaa55d MT |
197 | if (rc == 2) |
198 | goto EXIT; | |
10bc6f06 MT |
199 | |
200 | if (installtype == CDROM_INSTALL) | |
201 | { | |
202 | /* First look for an IDE CDROM. */ | |
203 | if (!(cdletter = findidetype(IDE_CDROM))) | |
d6aaa55d | 204 | { |
10bc6f06 MT |
205 | /* If we have a USB attached CDROM then it will |
206 | * have already appeared at /dev/scd0, so we | |
207 | * try to access it first, before asking for the | |
208 | * SCSI drivers disk. | |
209 | */ | |
210 | if (!(try_scsi("scd0"))) { | |
211 | sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME" SCSI"); | |
212 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); | |
213 | if (rc != 1) | |
214 | { | |
215 | errorbox(ctr[TR_INSTALLATION_CANCELED]); | |
216 | goto EXIT; | |
217 | } | |
218 | ||
219 | if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr[TR_EXTRACTING_MODULES])) | |
220 | { | |
221 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
222 | goto EXIT; | |
223 | } | |
224 | ||
225 | if (pcmcia) | |
226 | { | |
227 | /* trying to support SCSI pcmcia :-) */ | |
228 | runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi", | |
229 | ctr[TR_LOADING_PCMCIA]); | |
230 | if (try_scsi("scd0")) | |
231 | pcmcia_cdrom = 1; | |
232 | } | |
233 | ||
234 | /* try loading all SCSI modules with default options */ | |
235 | /* Should expand this to allow options later though */ | |
236 | if (!pcmcia_cdrom) | |
237 | runcommandwithstatus("/bin/probescsi.sh", | |
238 | ctr[TR_PROBING_SCSI]); | |
239 | ||
240 | /* If it fails, give up. */ | |
241 | if (!(try_scsi("scd0"))) { | |
242 | errorbox(ctr[TR_NO_CDROM]); | |
243 | goto EXIT; | |
244 | } | |
d6aaa55d | 245 | } |
d6aaa55d | 246 | |
d6aaa55d MT |
247 | sprintf(cdromdrive, "scd0"); |
248 | scsi_cdrom = 1; | |
10bc6f06 MT |
249 | } else { |
250 | sprintf(cdromdrive, "hd%c", cdletter); | |
251 | ide_cdrom = 1; | |
d6aaa55d MT |
252 | } |
253 | ||
10bc6f06 MT |
254 | snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", cdromdrive); |
255 | cdromparams.module = 0; | |
256 | ||
257 | sprintf(insertmessage, ctr[TR_INSERT_CDROM], NAME); | |
258 | strcpy (insertdevnode, cdromparams.devnode); | |
d6aaa55d | 259 | } |
10bc6f06 | 260 | else |
d6aaa55d MT |
261 | { |
262 | /* If we've done a PXE boot, we can skip the Drivers floppy, | |
263 | * as we've already got the modules in our instroot.gz */ | |
264 | if (!(handle = fopen("/CDROMBOOT", "r"))) { | |
10bc6f06 | 265 | sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME); |
d6aaa55d MT |
266 | strcpy (insertdevnode , "/dev/floppy"); |
267 | } else { | |
268 | fclose(handle); | |
269 | cdmounted = 1; | |
270 | unmount_before = 1; | |
271 | } | |
272 | } | |
273 | ||
10bc6f06 MT |
274 | if (scsi_cdrom || ide_cdrom) { |
275 | /* Try to mount /cdrom in a loop. */ | |
d6aaa55d | 276 | snprintf(commandstring, STRING_SIZE, "/bin/mount -o ro %s /cdrom", insertdevnode); |
d6aaa55d MT |
277 | while (!cdmounted) |
278 | { | |
10bc6f06 MT |
279 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); |
280 | if (rc != 1) | |
281 | { | |
d6aaa55d MT |
282 | errorbox(ctr[TR_INSTALLATION_CANCELED]); |
283 | goto EXIT; | |
d6aaa55d | 284 | } |
10bc6f06 MT |
285 | if (!(mysystem(commandstring))) { |
286 | handle = fopen ("/cdrom/" SNAME "-" VERSION ".tgz", "r"); | |
287 | if (handle != NULL) { | |
288 | fclose (handle); | |
289 | cdmounted = 1; | |
290 | /* If we've booted from CDROM, then | |
291 | * we've already got the drivers, | |
292 | * so we can skip this unpack. */ | |
293 | if (!(handle = fopen("/CDROMBOOT", "r"))) { | |
294 | sprintf(string, "/bin/tar -C / -xvzf /cdrom/images/drivers-%s.img", VERSION); | |
295 | if (runcommandwithprogress(60, 4, title, | |
296 | string, | |
297 | 175, ctr[TR_EXTRACTING_MODULES])) | |
298 | { | |
299 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
300 | ||
301 | goto EXIT; | |
302 | } | |
303 | } else | |
304 | fclose(handle); | |
305 | } else { | |
306 | mysystem ("/bin/umount /cdrom"); | |
307 | } | |
d6aaa55d MT |
308 | } |
309 | } | |
10bc6f06 MT |
310 | } else { |
311 | snprintf(commandstring, STRING_SIZE, "/bin/tar -C / -xvzf /dev/floppy"); | |
d6aaa55d MT |
312 | while (!cdmounted) |
313 | { | |
314 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); | |
315 | if (rc != 1) | |
316 | { | |
317 | errorbox(ctr[TR_INSTALLATION_CANCELED]); | |
318 | goto EXIT; | |
319 | } | |
320 | if (runcommandwithprogress(60, 4, title, | |
321 | commandstring, | |
322 | 175, ctr[TR_EXTRACTING_MODULES])) | |
323 | { | |
324 | #if 0 /* disable this, so we allow for people putting in the wrong disk */ | |
325 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
326 | goto EXIT; | |
327 | #endif | |
328 | } | |
329 | else | |
330 | { | |
331 | handle = fopen ("/bin/mke2fs", "r"); | |
332 | if (handle != NULL) { | |
333 | fclose (handle); | |
334 | cdmounted = 1; | |
335 | } | |
336 | } | |
337 | } | |
338 | } | |
339 | ||
340 | /* PCMCIA controller is already detected | |
341 | * On Boot floppy, we didn't have the PCMCIA drivers | |
342 | * so load them now because they are installed from Drivers. */ | |
343 | if (!(handle = fopen("/CDROMBOOT", "r"))) { | |
344 | if (strstr (line, "nopcmcia") == NULL) { | |
345 | fprintf(flog,"Floppy boot detected, loading PCMCIA drivers.\n"); | |
346 | if (pcmcia) { | |
347 | fprintf (flog, "Detected PCMCIA Controller: %s.\n", pcmcia); | |
348 | sprintf(commandstring, "/sbin/modprobe %s", pcmcia); | |
349 | mysystem("/sbin/modprobe pcmcia_core"); | |
350 | mysystem(commandstring); | |
351 | mysystem("/sbin/modprobe ds"); | |
352 | } else { | |
353 | fprintf (flog, "Detected No PCMCIA Controller.\n"); | |
354 | } | |
355 | } else { | |
356 | fprintf(flog, "Skipping PCMCIA detection.\n"); | |
357 | } | |
358 | if (strstr (line, "nousb") == NULL) { | |
359 | fprintf(flog, "Initializing USB controllers.\n"); | |
360 | initialize_usb(); | |
361 | } else { | |
362 | fprintf(flog, "Skipping USB detection.\n"); | |
363 | } | |
364 | } else | |
365 | fclose(handle); | |
366 | ||
367 | /* Configure the network now! */ | |
368 | if (installtype == URL_INSTALL) | |
369 | { | |
370 | /* Network driver and params. */ | |
371 | if (!(networkmenu(ethernetkv))) | |
372 | { | |
373 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
374 | goto EXIT; | |
375 | } | |
376 | ||
377 | /* Check for ipcop-<VERSION>.tgz */ | |
378 | if (!(checktarball(SNAME "-" VERSION ".tgz"))) | |
379 | { | |
380 | errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]); | |
381 | goto EXIT; | |
382 | } | |
383 | } | |
384 | ||
385 | /* Get device for the HD. This has to succeed. */ | |
10bc6f06 | 386 | if (!(hdletter = findidetype(IDE_HD))) |
d6aaa55d | 387 | { |
10bc6f06 | 388 | if (installtype == URL_INSTALL) |
d6aaa55d | 389 | { |
10bc6f06 MT |
390 | /* If we've done a PXE boot, we can skip the SCSI |
391 | * floppy as we've already got the modules in our | |
392 | * instroot.gz */ | |
393 | if (!(handle = fopen("/CDROMBOOT", "r"))) | |
d6aaa55d | 394 | { |
10bc6f06 MT |
395 | /* search img where it is on a mounted loop iso */ |
396 | sprintf(string, "images/scsidrv-%s.img", VERSION); | |
397 | if (!(checktarball(string))) | |
d6aaa55d | 398 | { |
10bc6f06 MT |
399 | /* Couldn't find the SCSI drivers on the URL page, |
400 | * so after 3 failed attempts, ask the user for the | |
401 | * SCSI drivers floppy disk. */ | |
402 | errorbox(ctr[TR_NO_SCSI_IMAGE_FOUND]); | |
403 | sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME" SCSI"); | |
404 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); | |
405 | if (rc != 1) | |
406 | { | |
407 | errorbox(ctr[TR_INSTALLATION_CANCELED]); | |
408 | goto EXIT; | |
409 | } | |
410 | ||
411 | if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr[TR_EXTRACTING_MODULES])) | |
412 | { | |
413 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
414 | goto EXIT; | |
415 | } | |
416 | } else { | |
417 | /* unpack... */ | |
418 | snprintf(commandstring, STRING_SIZE, | |
419 | "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -", | |
420 | url, string); | |
421 | if (runcommandwithprogress(60, 4, title, commandstring, | |
422 | 4500, ctr[TR_INSTALLING_FILES])) | |
423 | { | |
424 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
425 | goto EXIT; | |
426 | } | |
d6aaa55d | 427 | } |
10bc6f06 MT |
428 | } else |
429 | fclose(handle); | |
430 | } else { | |
431 | if (ide_cdrom) { | |
432 | sprintf(string, "/bin/tar -C / -xvzf /cdrom/images/scsidrv-%s.img", VERSION); | |
433 | if (runcommandwithstatus(string, ctr[TR_EXTRACTING_MODULES])) | |
d6aaa55d MT |
434 | { |
435 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
436 | goto EXIT; | |
437 | } | |
d6aaa55d MT |
438 | } |
439 | } | |
d6aaa55d | 440 | |
10bc6f06 MT |
441 | if (!scsi_cdrom) { |
442 | ||
d6aaa55d | 443 | #if 0 /* not yet */ |
10bc6f06 MT |
444 | if (pcmcia) |
445 | { | |
446 | /* trying to support SCSI pcmcia :-) */ | |
447 | runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi", | |
448 | ctr[TR_LOADING_PCMCIA]); | |
449 | if (try_scsi("sda")) | |
450 | pcmcia_disk = 1; | |
d6aaa55d | 451 | } |
10bc6f06 MT |
452 | #endif |
453 | ||
454 | /* try loading all SCSI modules with default options */ | |
455 | /* Should expand this to allow options later though */ | |
456 | if (!pcmcia_disk) | |
457 | runcommandwithstatus("/bin/probescsi.sh", | |
458 | ctr[TR_PROBING_SCSI]); | |
459 | } | |
460 | ||
461 | /* Need to clean this up at some point */ | |
462 | if (!try_scsi("sda")) { | |
463 | if (!try_scsi("ida/c0d0")) { | |
464 | if (!try_scsi("cciss/c0d0")) { | |
465 | if (!try_scsi("rd/c0d0")) { | |
466 | if (!try_scsi("ataraid/d0")) { | |
467 | errorbox(ctr[TR_NO_HARDDISK]); | |
468 | goto EXIT; | |
469 | } else { | |
470 | raid_disk = 1; | |
471 | sprintf(harddrive, "ataraid/d0"); | |
472 | } | |
473 | } else { | |
474 | raid_disk = 1; | |
475 | sprintf(harddrive, "rd/c0d0"); | |
476 | } | |
477 | } else { | |
478 | raid_disk = 1; | |
479 | sprintf(harddrive, "cciss/c0d0"); | |
480 | } | |
481 | } else { | |
482 | raid_disk = 1; | |
483 | sprintf(harddrive, "ida/c0d0"); | |
d6aaa55d | 484 | } |
10bc6f06 MT |
485 | } else { |
486 | sprintf(harddrive, "sda"); | |
d6aaa55d | 487 | } |
d6aaa55d | 488 | scsi_disk = 1; |
10bc6f06 MT |
489 | } else |
490 | sprintf(harddrive, "hd%c", hdletter); | |
491 | ||
492 | /* Make the hdparms struct and print the contents. */ | |
493 | snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive); | |
494 | hdparams.module = 0; | |
d6aaa55d MT |
495 | |
496 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], | |
10bc6f06 | 497 | ctr[TR_PREPARE_HARDDISK], hdparams.devnode); |
d6aaa55d MT |
498 | if (rc != 1) |
499 | goto EXIT; | |
500 | ||
501 | /* Calculate amount of memory in machine */ | |
502 | if ((handle = fopen("/proc/meminfo", "r"))) | |
503 | { | |
504 | while (fgets(line, STRING_SIZE-1, handle)) { | |
505 | if (sscanf (line, "MemTotal: %s kB", string)) { | |
506 | memory = atoi(string) / 1024 ; | |
507 | } | |
508 | } | |
509 | fclose(handle); | |
510 | } | |
511 | ||
512 | /* Partition, mkswp, mkfs. | |
513 | * before partitioning, first determine the sizes of each | |
514 | * partition. In order to do that we need to know the size of | |
515 | * the disk. | |
516 | */ | |
517 | /* Don't use mysystem here so we can redirect output */ | |
518 | sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive); | |
519 | system(commandstring); | |
520 | ||
521 | /* Calculate amount of disk space */ | |
522 | if ((handle = fopen("/disksize", "r"))) | |
523 | { | |
524 | fgets(line, STRING_SIZE-1, handle); | |
525 | if (sscanf (line, "%s", string)) { | |
526 | maximum_free = atoi(string) / 1024; | |
527 | } | |
528 | fclose(handle); | |
529 | } | |
530 | ||
10bc6f06 MT |
531 | fprintf(flog, "maximum_free = %d, memory = %d", |
532 | maximum_free, memory); | |
d6aaa55d MT |
533 | |
534 | /* If you need more than this, you should really add physical memory */ | |
535 | /* Minimum: 192 = 64 real + 128 swap */ | |
536 | swap_file = memory < 64 ? 2 * memory : 192 - memory ; | |
537 | swap_file = swap_file < 32 ? 32 : swap_file ; | |
538 | ||
539 | if (maximum_free < 135 + swap_file ) | |
540 | { | |
541 | if (maximum_free < 135) { | |
542 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
543 | goto EXIT; | |
544 | } | |
545 | ||
546 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
547 | if (rc != 1) | |
548 | goto EXIT; | |
549 | swap_file = 0; | |
550 | } | |
551 | ||
552 | boot_partition = 8; /* in MB */ | |
553 | current_free = maximum_free - boot_partition - swap_file; | |
554 | ||
555 | /* Give more place for add-on, extend root to 25% of current_free, upper limit to 8 gigas */ | |
556 | root_partition = current_free / 4 ; | |
557 | root_partition = root_partition > 8192 ? 8192 : root_partition ; | |
558 | root_partition = current_free < 860 ? 235 : root_partition; | |
559 | root_partition = current_free < 380 ? 110 : root_partition; | |
560 | ||
561 | current_free = current_free - root_partition; | |
562 | root_partition = root_partition + swap_file; | |
563 | ||
564 | log_partition = current_free; | |
565 | ||
566 | fprintf(flog, "boot = %d, swap = %d, mylog = %d, root = %d\n", | |
567 | boot_partition, swap_file, log_partition, root_partition); | |
568 | ||
10bc6f06 | 569 | |
d6aaa55d MT |
570 | #ifdef __alpha__ |
571 | fdisk = 1; | |
572 | #endif | |
573 | ||
574 | if (fdisk) { | |
575 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], "NOW FDISK"); | |
576 | if (rc != 1) | |
577 | goto EXIT; | |
578 | } else { | |
579 | #ifdef __i386__ | |
580 | handle = fopen("/tmp/partitiontable", "w"); | |
581 | ||
582 | fprintf(handle, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n", | |
583 | boot_partition, log_partition); | |
584 | ||
585 | fclose(handle); | |
586 | ||
10bc6f06 | 587 | snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams.devnode); |
d6aaa55d MT |
588 | if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK])) |
589 | { | |
590 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
591 | goto EXIT; | |
592 | } | |
593 | #endif | |
594 | } | |
10bc6f06 MT |
595 | |
596 | if (raid_disk) | |
597 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 0 -j %sp1", hdparams.devnode); | |
598 | else | |
599 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 0 -j %s1", hdparams.devnode); | |
d6aaa55d MT |
600 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM])) |
601 | { | |
602 | errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]); | |
603 | goto EXIT; | |
604 | } | |
10bc6f06 MT |
605 | if (raid_disk) |
606 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -j %sp2", hdparams.devnode); | |
607 | else | |
608 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -j %s2", hdparams.devnode); | |
d6aaa55d MT |
609 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM])) |
610 | { | |
611 | errorbox(ctr[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM]); | |
612 | goto EXIT; | |
613 | } | |
10bc6f06 MT |
614 | if (raid_disk) |
615 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 1 -j %sp4", hdparams.devnode); | |
616 | else | |
617 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 1 -j %s4", hdparams.devnode); | |
d6aaa55d | 618 | |
d6aaa55d MT |
619 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM])) |
620 | { | |
621 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
622 | goto EXIT; | |
623 | } | |
10bc6f06 MT |
624 | /* Mount harddisk. */ |
625 | if (raid_disk) | |
626 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %sp4 /harddisk", hdparams.devnode); | |
627 | else | |
628 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %s4 /harddisk", hdparams.devnode); | |
d6aaa55d MT |
629 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM])) |
630 | { | |
631 | errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]); | |
632 | goto EXIT; | |
633 | } | |
10bc6f06 | 634 | /* Make swapfile */ |
d6aaa55d | 635 | if (swap_file) { |
10bc6f06 | 636 | snprintf(commandstring, STRING_SIZE, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file); |
d6aaa55d MT |
637 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) |
638 | { | |
639 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
640 | goto EXIT; | |
641 | } | |
10bc6f06 MT |
642 | snprintf(commandstring, STRING_SIZE, "/bin/mkswap /harddisk/swapfile"); |
643 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) | |
d6aaa55d MT |
644 | { |
645 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
646 | goto EXIT; | |
647 | } | |
d6aaa55d | 648 | } |
10bc6f06 MT |
649 | mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO); |
650 | mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO); | |
651 | mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO); | |
652 | ||
653 | if (raid_disk) | |
654 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %sp1 /harddisk/boot", hdparams.devnode); | |
655 | else | |
656 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams.devnode); | |
d6aaa55d | 657 | |
d6aaa55d MT |
658 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM])) |
659 | { | |
660 | errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]); | |
661 | goto EXIT; | |
662 | } | |
10bc6f06 MT |
663 | if (swap_file) { |
664 | snprintf(commandstring, STRING_SIZE, "/bin/swapon /harddisk/swapfile"); | |
665 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION])) | |
666 | { | |
667 | errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]); | |
668 | goto EXIT; | |
669 | } | |
670 | } | |
671 | if (raid_disk) | |
672 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %sp2 /harddisk/var/log", hdparams.devnode); | |
673 | else | |
674 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams.devnode); | |
d6aaa55d MT |
675 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM])) |
676 | { | |
677 | errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]); | |
678 | goto EXIT; | |
679 | } | |
680 | ||
681 | /* Either use tarball from cdrom or download. */ | |
682 | if (installtype == CDROM_INSTALL) | |
683 | snprintf(commandstring, STRING_SIZE, | |
684 | "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME "-" VERSION ".tgz"); | |
685 | else | |
686 | snprintf(commandstring, STRING_SIZE, | |
687 | "/bin/wget -O - %s/" SNAME "-" VERSION ".tgz | /bin/tar -C /harddisk -xvzf -", url); | |
688 | ||
689 | if (runcommandwithprogress(60, 4, title, commandstring, 4600, | |
690 | ctr[TR_INSTALLING_FILES])) | |
691 | { | |
692 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
693 | goto EXIT; | |
694 | } | |
695 | ||
696 | /* Save USB controller type to modules.conf */ | |
697 | write_usb_modules_conf(); | |
698 | ||
699 | /* touch the modules.dep files */ | |
10bc6f06 MT |
700 | snprintf(commandstring, STRING_SIZE, |
701 | "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep", | |
702 | KERNEL_VERSION); | |
703 | mysystem(commandstring); | |
d6aaa55d | 704 | #ifdef __i386__ |
10bc6f06 MT |
705 | snprintf(commandstring, STRING_SIZE, |
706 | "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep", | |
707 | KERNEL_VERSION); | |
708 | mysystem(commandstring); | |
d6aaa55d MT |
709 | #endif |
710 | ||
711 | /* Rename uname */ | |
712 | rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname"); | |
713 | ||
714 | /* Write PCMCIA Config */ | |
715 | if (pcmcia) { | |
716 | handle = fopen("/harddisk/etc/modules.conf", "a"); | |
717 | if (handle != NULL) { | |
718 | fprintf (handle, "# PCMCIA Settings\n"); | |
719 | fprintf (handle, "alias pcmcia-controller %s\n", pcmcia); | |
720 | fclose(handle); | |
721 | } | |
722 | } | |
723 | ||
724 | handle = fopen("/harddisk/etc/pcmcia.conf", "w"); | |
725 | if (handle != NULL) { | |
726 | if (pcmcia) { | |
727 | fprintf (handle, "PCMCIA=yes\n"); | |
728 | fprintf (handle, "PCIC=%s\n", pcmcia); | |
729 | } else { | |
730 | fprintf (handle, "PCMCIA=no\n"); | |
731 | fprintf (handle, "PCIC=\n"); | |
732 | } | |
733 | fprintf (handle, "CARDMGR_OPTS=\n"); | |
734 | fprintf (handle, "SCHEME=\n"); | |
735 | fclose(handle); | |
736 | } | |
737 | ||
738 | /* *always* write disk configuration */ | |
739 | if (!(write_disk_configs(&hdparams))){ | |
10bc6f06 MT |
740 | errorbox(ctr[TR_ERROR_WRITING_CONFIG]); |
741 | goto EXIT; | |
d6aaa55d MT |
742 | } |
743 | ||
744 | /* | |
745 | Allow the user to restore their configuration from a floppy. | |
746 | It uses tar. If the tar fails for any reason, show user an | |
747 | error and go back to the restore/skip question. This gives | |
748 | the user the chance to have another go. */ | |
10bc6f06 MT |
749 | |
750 | RESTORE: | |
751 | /* set status variables to nonsense values */ | |
752 | allok_fastexit = 0; | |
753 | /* loop until floppy succeeds or user skips out */ | |
754 | while (1) | |
755 | { | |
756 | sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME); | |
757 | if (newtWinChoice(title, ctr[TR_RESTORE], ctr[TR_SKIP], message) == 1) | |
758 | { | |
759 | /* Temporarily mount /proc under /harddisk/proc, | |
760 | * run updfstab to locate the floppy, and unmount /harddisk/proc | |
761 | * again. This should be run each time the user tries to restore | |
762 | * so it can properly detect removable devices */ | |
763 | if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) { | |
764 | errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]); | |
765 | goto EXIT; | |
766 | } | |
767 | if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) { | |
768 | errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]); | |
769 | goto EXIT; | |
770 | } | |
771 | mysystem("/bin/umount /harddisk/proc"); | |
772 | ||
773 | mkdir("/harddisk/tmp/ipcop", S_IRWXU|S_IRWXG|S_IRWXO); | |
774 | ||
775 | /* Always extract to /tmp/ipcop for temporary extraction | |
776 | * just in case floppy fails */ | |
777 | ||
778 | /* try a compressed backup first because it's quicker to fail. | |
779 | * In exclude.system, files name must be without leading / or | |
780 | * on extraction, name will never match */ | |
781 | snprintf(commandstring, STRING_SIZE, | |
782 | "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog); | |
d6aaa55d | 783 | |
10bc6f06 MT |
784 | statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]); |
785 | rc = system(commandstring); | |
786 | ||
787 | if (rc) { | |
788 | /* if it's not compressed, try uncompressed first before failing*/ | |
789 | snprintf(commandstring, STRING_SIZE, | |
790 | "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog); | |
791 | rc = system(commandstring); | |
792 | if (rc) { | |
793 | newtPopWindow(); | |
794 | /* command failed trying to read from floppy */ | |
795 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
796 | ||
797 | /* remove badly restored files */ | |
798 | mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); | |
799 | goto RESTORE; | |
800 | } else { | |
801 | /* Now copy to correct location */ | |
802 | mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /"); | |
803 | mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); | |
804 | newtPopWindow(); | |
805 | allok_fastexit=1; | |
806 | ||
807 | /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */ | |
808 | upgrade_v12_v13(); | |
809 | upgrade_v130_v140(); | |
810 | break; /* out of loop at this point because floppy has | |
811 | successfully restored */ | |
812 | } | |
813 | } | |
814 | else { /* success */ | |
815 | /* Now copy to correct location */ | |
816 | mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /"); | |
817 | mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); | |
818 | newtPopWindow(); | |
819 | allok_fastexit=1; | |
820 | ||
821 | /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */ | |
822 | upgrade_v12_v13(); | |
823 | upgrade_v130_v140(); | |
824 | break; /* out of loop at this point because floppy has | |
825 | successfully restored */ | |
826 | } | |
827 | } | |
828 | else{ /* user chose to skip install from floppy */ | |
829 | if (installtype == CDROM_INSTALL){ | |
830 | /* if we installed from CD ROM then we didn't set up the | |
831 | network interface yet. Therefore, set up Network | |
832 | driver and params just before we need them. */ | |
833 | ||
834 | if (!(networkmenu(ethernetkv))){ | |
835 | /* network setup failed, tell the world */ | |
836 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
837 | goto EXIT; | |
838 | } | |
839 | } | |
840 | break; /* out of loop because we succeeded with ethernet | |
841 | set up and user is notrestarting from floppy*/ | |
842 | } | |
843 | } | |
844 | ||
845 | /* Check the SQUID acl file exists, if not use our 1.4 copy */ | |
846 | { | |
847 | FILE *aclreadfile; | |
848 | ||
849 | if (!(aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) { | |
850 | rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4", | |
851 | "/harddisk" CONFIG_ROOT "/proxy/acl"); | |
852 | } else { | |
853 | unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4"); | |
854 | fclose(aclreadfile); | |
d6aaa55d | 855 | } |
10bc6f06 | 856 | chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99); |
d6aaa55d MT |
857 | } |
858 | ||
859 | /* Build cache lang file */ | |
860 | mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); | |
861 | ||
10bc6f06 MT |
862 | if (!allok_fastexit){ |
863 | /* write ethernet and lang configs only if they have not | |
864 | been restored from floppy already. */ | |
865 | if (!(write_ethernet_configs( ethernetkv))|| | |
866 | !(write_lang_configs(shortlangname))){ | |
867 | errorbox(ctr[TR_ERROR_WRITING_CONFIG]); | |
868 | goto EXIT; | |
869 | } | |
870 | } | |
871 | ||
872 | /* if we detected SCSI then fixup */ | |
873 | if ((handle = fopen("/scsidriver", "r"))) | |
874 | { | |
875 | char *driver; | |
876 | fgets(line, STRING_SIZE-1, handle); | |
877 | fclose(handle); | |
878 | line[strlen(line) - 1] = 0; | |
879 | driver = strtok(line, "."); | |
880 | fprintf(flog, "Detected SCSI driver %s\n",driver); | |
881 | if (strlen(driver) > 1) { | |
882 | fprintf(flog, "Fixing up ipcoprd.img\n"); | |
883 | mysystem("/bin/chroot /harddisk /sbin/modprobe loop"); | |
884 | mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); | |
885 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipcoprd.img %s", driver, KERNEL_VERSION); | |
886 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); | |
887 | #ifdef __i386__ | |
888 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipcoprd-smp.img %s-smp", driver, KERNEL_VERSION); | |
889 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); | |
890 | mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); | |
891 | #endif | |
892 | #ifdef __alpha__ | |
893 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf"); | |
894 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); | |
895 | #endif | |
d6aaa55d MT |
896 | } |
897 | } | |
898 | ||
d6aaa55d MT |
899 | #if 0 /* not yet */ |
900 | if (pcmcia_disk) | |
901 | { | |
902 | fprintf(flog, "Detected SCSI driver PCMCIA\n"); | |
903 | fprintf(flog, "Fixing up ipcoprd.img\n"); | |
904 | mysystem("/bin/chroot /harddisk /sbin/modprobe loop"); | |
905 | mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); | |
10bc6f06 MT |
906 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipcoprd.img", KERNEL_VERSION); |
907 | mysystem(commandstring); | |
d6aaa55d MT |
908 | #ifdef __i386__ |
909 | mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); | |
910 | #endif | |
911 | #ifdef __alpha__ | |
912 | mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf"); | |
913 | #endif | |
914 | } | |
915 | #endif | |
916 | ||
917 | #ifdef __i386__ | |
10bc6f06 | 918 | replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode); |
d6aaa55d MT |
919 | /* restore permissions */ |
920 | chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); | |
921 | ||
10bc6f06 MT |
922 | if (raid_disk) |
923 | sprintf(string, "root=%sp4", hdparams.devnode); | |
924 | else | |
925 | sprintf(string, "root=%s4", hdparams.devnode); | |
d6aaa55d MT |
926 | replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string); |
927 | ||
928 | mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc"); | |
929 | ||
10bc6f06 MT |
930 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /boot/grub/grubbatch"); |
931 | ||
932 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) | |
d6aaa55d MT |
933 | { |
934 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
935 | goto EXIT; | |
936 | } | |
937 | mysystem("/bin/chroot /harddisk /bin/umount -n /proc"); | |
938 | #endif | |
939 | #ifdef __alpha__ | |
10bc6f06 | 940 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams.devnode); |
d6aaa55d | 941 | mysystem(commandstring); |
10bc6f06 | 942 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams.devnode); |
d6aaa55d | 943 | mysystem(commandstring); |
10bc6f06 MT |
944 | if (raid_disk) |
945 | sprintf(string, "root=%sp4", hdparams.devnode); | |
946 | else | |
947 | sprintf(string, "root=%s4", hdparams.devnode); | |
d6aaa55d MT |
948 | replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string); |
949 | #endif | |
950 | ||
951 | /* unmounting happens everywhere because there are places | |
952 | which require device is to be unmounted under certain | |
953 | circumstances. This is the last place we can unmount | |
10bc6f06 | 954 | anything and still succeed. */ |
d6aaa55d | 955 | |
10bc6f06 MT |
956 | if (!unmount_before && installtype == CDROM_INSTALL){ |
957 | if (mysystem("/sbin/umount /cdrom")) | |
958 | { | |
959 | errorbox(ctr[TR_UNABLE_TO_UNMOUNT_CDROM]); | |
960 | goto EXIT; | |
961 | } | |
d6aaa55d MT |
962 | } |
963 | ||
10bc6f06 | 964 | if (installtype == CDROM_INSTALL) |
d6aaa55d | 965 | { |
10bc6f06 MT |
966 | |
967 | if (!(ejectcdrom(cdromparams.devnode))) | |
d6aaa55d MT |
968 | { |
969 | errorbox(ctr[TR_UNABLE_TO_EJECT_CDROM]); | |
970 | // goto EXIT; | |
971 | } | |
972 | } | |
10bc6f06 MT |
973 | |
974 | ||
975 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
d6aaa55d MT |
976 | NAME, SNAME, SNAME, NAME, NAME, NAME); |
977 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message); | |
10bc6f06 | 978 | |
d6aaa55d | 979 | allok = 1; |
10bc6f06 | 980 | |
d6aaa55d | 981 | EXIT: |
10bc6f06 | 982 | fprintf(flog, "Install program ended.\n"); |
d6aaa55d MT |
983 | fflush(flog); |
984 | fclose(flog); | |
985 | ||
10bc6f06 | 986 | if (!(allok)) |
d6aaa55d | 987 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); |
10bc6f06 | 988 | |
d6aaa55d | 989 | newtFinished(); |
10bc6f06 | 990 | |
d6aaa55d | 991 | freekeyvalues(ethernetkv); |
d6aaa55d | 992 | |
10bc6f06 | 993 | if (allok && !allok_fastexit) |
d6aaa55d MT |
994 | { |
995 | /* /proc is needed by the module checker. We have to mount it | |
996 | * so it can be seen by setup, which is run chrooted. */ | |
997 | if (system("/sbin/mount proc -t proc /harddisk/proc")) | |
998 | printf("Unable to mount proc in /harddisk."); | |
999 | else | |
1000 | { | |
1001 | if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) | |
1002 | printf("Unable to run setup.\n"); | |
1003 | if (system("/sbin/umount /harddisk/proc")) | |
1004 | printf("Unable to umount /harddisk/proc.\n"); | |
1005 | } | |
1006 | } | |
1007 | ||
1008 | fcloseall(); | |
1009 | ||
1010 | system("/bin/swapoff /harddisk/swapfile"); | |
1011 | system("/sbin/umount /harddisk/var/log"); | |
1012 | system("/sbin/umount /harddisk/boot"); | |
1013 | system("/sbin/umount /harddisk"); | |
10bc6f06 | 1014 | |
d6aaa55d MT |
1015 | system("/etc/halt"); |
1016 | ||
1017 | return 0; | |
1018 | } |