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