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