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