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