]> git.ipfire.org Git - ipfire-2.x.git/blame - src/install+setup/install/main.c
Bugfixes:
[ipfire-2.x.git] / src / install+setup / install / main.c
CommitLineData
d6aaa55d
MT
1/* SmoothWall install program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * Contains main entry point, and misc functions.
8 *
10bc6f06 9 * $Id: main.c,v 1.63.2.57 2005/09/25 19:57:46 gespinasse Exp $
d6aaa55d
MT
10 *
11 */
10bc6f06 12
d6aaa55d
MT
13#include "install.h"
14
15#define CDROM_INSTALL 0
16#define URL_INSTALL 1
17
18int raid_disk = 0;
19FILE *flog = NULL;
20char *mylog;
10bc6f06 21
d6aaa55d
MT
22char **ctr;
23
24char *pcmcia = NULL;
25extern char url[STRING_SIZE];
26
10bc6f06
MT
27extern char *bz_tr[];
28extern char *cs_tr[];
29extern char *da_tr[];
30extern char *en_tr[];
31extern char *es_tr[];
32extern char *fi_tr[];
33extern char *fr_tr[];
34extern char *hu_tr[];
35extern char *la_tr[];
36extern char *nl_tr[];
37extern char *de_tr[];
38extern char *tr_tr[];
39extern char *it_tr[];
40extern char *el_tr[];
41extern char *pl_tr[];
42extern char *pt_tr[];
43extern char *so_tr[];
44extern char *sv_tr[];
45extern char *no_tr[];
46extern char *vi_tr[];
d6aaa55d
MT
47
48int 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 };
1217aa01
HS
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
b4e3cd7f
HS
59 char *langnames[] = { "Deutsch", "English", NULL };
60 char *shortlangnames[] = { "de", "en", NULL };
61 char **langtrs[] = { de_tr, en_tr, NULL };
d6aaa55d
MT
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];
10bc6f06 69 char *installtypes[] = { "CDROM", "HTTP/FTP", NULL };
d6aaa55d
MT
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;
10bc6f06 78 int allok_fastexit=0;
d6aaa55d
MT
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;
10bc6f06 93
d6aaa55d
MT
94
95 setlocale (LC_ALL, "");
10bc6f06 96 sethostname( SNAME , 10);
d6aaa55d
MT
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
b4e3cd7f 152 /* Deutsch is the default */
d6aaa55d
MT
153 for (choice = 0; langnames[choice]; choice++)
154 {
b4e3cd7f 155 if (strcmp(langnames[choice], "Deutsch") == 0)
d6aaa55d
MT
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");
d6aaa55d
MT
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");
10bc6f06 188
d6aaa55d
MT
189 newtDrawRootText(14, 0, NAME " v" VERSION " - " SLOGAN );
190 newtPushHelpLine(ctr[TR_HELPLINE]);
191
10bc6f06
MT
192 sprintf(message, ctr[TR_WELCOME], NAME);
193 sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
d6aaa55d
MT
194 newtWinMessage(title, ctr[TR_OK], message);
195
10bc6f06 196 sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME);
d6aaa55d
MT
197 rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message,
198 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK],
199 ctr[TR_CANCEL], NULL);
10bc6f06 200
d6aaa55d
MT
201 if (rc == 2)
202 goto EXIT;
10bc6f06
MT
203
204 if (installtype == CDROM_INSTALL)
205 {
206 /* First look for an IDE CDROM. */
207 if (!(cdletter = findidetype(IDE_CDROM)))
d6aaa55d 208 {
10bc6f06
MT
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 }
d6aaa55d 249 }
d6aaa55d 250
d6aaa55d
MT
251 sprintf(cdromdrive, "scd0");
252 scsi_cdrom = 1;
10bc6f06
MT
253 } else {
254 sprintf(cdromdrive, "hd%c", cdletter);
255 ide_cdrom = 1;
d6aaa55d
MT
256 }
257
10bc6f06
MT
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);
d6aaa55d 263 }
10bc6f06 264 else
d6aaa55d
MT
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"))) {
10bc6f06 269 sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME);
d6aaa55d
MT
270 strcpy (insertdevnode , "/dev/floppy");
271 } else {
272 fclose(handle);
273 cdmounted = 1;
274 unmount_before = 1;
275 }
276 }
277
10bc6f06
MT
278 if (scsi_cdrom || ide_cdrom) {
279 /* Try to mount /cdrom in a loop. */
d6aaa55d 280 snprintf(commandstring, STRING_SIZE, "/bin/mount -o ro %s /cdrom", insertdevnode);
d6aaa55d
MT
281 while (!cdmounted)
282 {
10bc6f06
MT
283 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage);
284 if (rc != 1)
285 {
d6aaa55d
MT
286 errorbox(ctr[TR_INSTALLATION_CANCELED]);
287 goto EXIT;
d6aaa55d 288 }
10bc6f06
MT
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 }
d6aaa55d
MT
312 }
313 }
10bc6f06
MT
314 } else {
315 snprintf(commandstring, STRING_SIZE, "/bin/tar -C / -xvzf /dev/floppy");
d6aaa55d
MT
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 ipcop-<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. */
10bc6f06 390 if (!(hdletter = findidetype(IDE_HD)))
d6aaa55d 391 {
10bc6f06 392 if (installtype == URL_INSTALL)
d6aaa55d 393 {
10bc6f06
MT
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")))
d6aaa55d 398 {
10bc6f06
MT
399 /* search img where it is on a mounted loop iso */
400 sprintf(string, "images/scsidrv-%s.img", VERSION);
401 if (!(checktarball(string)))
d6aaa55d 402 {
10bc6f06
MT
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 }
d6aaa55d 431 }
10bc6f06
MT
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]))
d6aaa55d
MT
438 {
439 errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]);
440 goto EXIT;
441 }
d6aaa55d
MT
442 }
443 }
d6aaa55d 444
10bc6f06
MT
445 if (!scsi_cdrom) {
446
d6aaa55d 447#if 0 /* not yet */
10bc6f06
MT
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;
d6aaa55d 455 }
10bc6f06
MT
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");
d6aaa55d 488 }
10bc6f06
MT
489 } else {
490 sprintf(harddrive, "sda");
d6aaa55d 491 }
d6aaa55d 492 scsi_disk = 1;
10bc6f06
MT
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;
d6aaa55d
MT
499
500 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL],
10bc6f06 501 ctr[TR_PREPARE_HARDDISK], hdparams.devnode);
d6aaa55d
MT
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
10bc6f06
MT
535 fprintf(flog, "maximum_free = %d, memory = %d",
536 maximum_free, memory);
d6aaa55d
MT
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
10bc6f06 573
d6aaa55d
MT
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
10bc6f06 591 snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams.devnode);
d6aaa55d
MT
592 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
593 {
594 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
595 goto EXIT;
596 }
597#endif
598 }
10bc6f06
MT
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);
d6aaa55d
MT
604 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
605 {
606 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
607 goto EXIT;
608 }
10bc6f06
MT
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);
d6aaa55d
MT
613 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
614 {
615 errorbox(ctr[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM]);
616 goto EXIT;
617 }
10bc6f06
MT
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);
d6aaa55d 622
d6aaa55d
MT
623 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
624 {
625 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
626 goto EXIT;
627 }
10bc6f06
MT
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);
d6aaa55d
MT
633 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
634 {
635 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
636 goto EXIT;
637 }
10bc6f06 638 /* Make swapfile */
d6aaa55d 639 if (swap_file) {
10bc6f06 640 snprintf(commandstring, STRING_SIZE, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file);
d6aaa55d
MT
641 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
642 {
643 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
644 goto EXIT;
645 }
10bc6f06
MT
646 snprintf(commandstring, STRING_SIZE, "/bin/mkswap /harddisk/swapfile");
647 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
d6aaa55d
MT
648 {
649 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
650 goto EXIT;
651 }
d6aaa55d 652 }
10bc6f06
MT
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);
d6aaa55d 661
d6aaa55d
MT
662 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
663 {
664 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
665 goto EXIT;
666 }
10bc6f06
MT
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);
d6aaa55d
MT
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 /* Save USB controller type to modules.conf */
701 write_usb_modules_conf();
702
703 /* touch the modules.dep files */
10bc6f06
MT
704 snprintf(commandstring, STRING_SIZE,
705 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
706 KERNEL_VERSION);
707 mysystem(commandstring);
d6aaa55d 708#ifdef __i386__
10bc6f06
MT
709 snprintf(commandstring, STRING_SIZE,
710 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
711 KERNEL_VERSION);
712 mysystem(commandstring);
d6aaa55d
MT
713#endif
714
715 /* Rename uname */
716 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
717
718 /* Write PCMCIA Config */
719 if (pcmcia) {
720 handle = fopen("/harddisk/etc/modules.conf", "a");
721 if (handle != NULL) {
722 fprintf (handle, "# PCMCIA Settings\n");
723 fprintf (handle, "alias pcmcia-controller %s\n", pcmcia);
724 fclose(handle);
725 }
726 }
727
728 handle = fopen("/harddisk/etc/pcmcia.conf", "w");
729 if (handle != NULL) {
730 if (pcmcia) {
731 fprintf (handle, "PCMCIA=yes\n");
732 fprintf (handle, "PCIC=%s\n", pcmcia);
733 } else {
734 fprintf (handle, "PCMCIA=no\n");
735 fprintf (handle, "PCIC=\n");
736 }
737 fprintf (handle, "CARDMGR_OPTS=\n");
738 fprintf (handle, "SCHEME=\n");
739 fclose(handle);
740 }
741
742 /* *always* write disk configuration */
743 if (!(write_disk_configs(&hdparams))){
10bc6f06
MT
744 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
745 goto EXIT;
d6aaa55d
MT
746 }
747
748 /*
749 Allow the user to restore their configuration from a floppy.
750 It uses tar. If the tar fails for any reason, show user an
751 error and go back to the restore/skip question. This gives
752 the user the chance to have another go. */
10bc6f06 753
a6753b55 754#ifdef OLD_RESTORECFG
10bc6f06
MT
755RESTORE:
756 /* set status variables to nonsense values */
757 allok_fastexit = 0;
758 /* loop until floppy succeeds or user skips out */
759 while (1)
760 {
761 sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME);
762 if (newtWinChoice(title, ctr[TR_RESTORE], ctr[TR_SKIP], message) == 1)
763 {
764 /* Temporarily mount /proc under /harddisk/proc,
765 * run updfstab to locate the floppy, and unmount /harddisk/proc
766 * again. This should be run each time the user tries to restore
767 * so it can properly detect removable devices */
768 if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
769 errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]);
770 goto EXIT;
771 }
772 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
773 errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]);
774 goto EXIT;
775 }
776 mysystem("/bin/umount /harddisk/proc");
777
778 mkdir("/harddisk/tmp/ipcop", S_IRWXU|S_IRWXG|S_IRWXO);
779
780 /* Always extract to /tmp/ipcop for temporary extraction
781 * just in case floppy fails */
782
783 /* try a compressed backup first because it's quicker to fail.
784 * In exclude.system, files name must be without leading / or
785 * on extraction, name will never match */
786 snprintf(commandstring, STRING_SIZE,
787 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog);
d6aaa55d 788
10bc6f06
MT
789 statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]);
790 rc = system(commandstring);
791
792 if (rc) {
793 /* if it's not compressed, try uncompressed first before failing*/
794 snprintf(commandstring, STRING_SIZE,
795 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog);
796 rc = system(commandstring);
797 if (rc) {
798 newtPopWindow();
799 /* command failed trying to read from floppy */
800 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
801
802 /* remove badly restored files */
803 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
804 goto RESTORE;
805 } else {
806 /* Now copy to correct location */
807 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
808 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
809 newtPopWindow();
810 allok_fastexit=1;
811
812 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
813 upgrade_v12_v13();
814 upgrade_v130_v140();
815 break; /* out of loop at this point because floppy has
816 successfully restored */
817 }
818 }
819 else { /* success */
820 /* Now copy to correct location */
821 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
822 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
823 newtPopWindow();
824 allok_fastexit=1;
825
826 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
827 upgrade_v12_v13();
828 upgrade_v130_v140();
829 break; /* out of loop at this point because floppy has
830 successfully restored */
831 }
832 }
833 else{ /* user chose to skip install from floppy */
834 if (installtype == CDROM_INSTALL){
835 /* if we installed from CD ROM then we didn't set up the
836 network interface yet. Therefore, set up Network
837 driver and params just before we need them. */
838
839 if (!(networkmenu(ethernetkv))){
840 /* network setup failed, tell the world */
841 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
842 goto EXIT;
843 }
844 }
845 break; /* out of loop because we succeeded with ethernet
846 set up and user is notrestarting from floppy*/
847 }
848 }
a6753b55
HS
849#else
850 if (installtype == CDROM_INSTALL){
851 /* if we installed from CD ROM then we didn't set up the
852 network interface yet. Therefore, set up Network
853 driver and params just before we need them. */
854
855 if (!(networkmenu(ethernetkv))){
856 /* network setup failed, tell the world */
857 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
858 goto EXIT;
859 }
860 }
861#endif
10bc6f06
MT
862
863 /* Check the SQUID acl file exists, if not use our 1.4 copy */
864 {
865 FILE *aclreadfile;
866
867 if (!(aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) {
868 rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4",
869 "/harddisk" CONFIG_ROOT "/proxy/acl");
870 } else {
871 unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4");
872 fclose(aclreadfile);
d6aaa55d 873 }
10bc6f06 874 chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99);
d6aaa55d
MT
875 }
876
877 /* Build cache lang file */
878 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
879
10bc6f06
MT
880 if (!allok_fastexit){
881 /* write ethernet and lang configs only if they have not
882 been restored from floppy already. */
883 if (!(write_ethernet_configs( ethernetkv))||
884 !(write_lang_configs(shortlangname))){
885 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
886 goto EXIT;
887 }
888 }
889
890 /* if we detected SCSI then fixup */
891 if ((handle = fopen("/scsidriver", "r")))
892 {
893 char *driver;
894 fgets(line, STRING_SIZE-1, handle);
895 fclose(handle);
896 line[strlen(line) - 1] = 0;
897 driver = strtok(line, ".");
898 fprintf(flog, "Detected SCSI driver %s\n",driver);
899 if (strlen(driver) > 1) {
f8ae001e 900 fprintf(flog, "Fixing up ipfirerd.img\n");
10bc6f06
MT
901 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
902 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
f8ae001e 903 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);
10bc6f06
MT
904 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
905#ifdef __i386__
f8ae001e 906 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);
10bc6f06
MT
907 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
908 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
909#endif
910#ifdef __alpha__
911 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
912 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
913#endif
d6aaa55d
MT
914 }
915 }
916
d6aaa55d
MT
917#if 0 /* not yet */
918 if (pcmcia_disk)
919 {
920 fprintf(flog, "Detected SCSI driver PCMCIA\n");
f8ae001e 921 fprintf(flog, "Fixing up ipfirerd.img\n");
d6aaa55d
MT
922 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
923 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
f8ae001e 924 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipfirerd.img", KERNEL_VERSION);
10bc6f06 925 mysystem(commandstring);
d6aaa55d
MT
926#ifdef __i386__
927 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
928#endif
929#ifdef __alpha__
930 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
931#endif
932 }
933#endif
934
935#ifdef __i386__
10bc6f06 936 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
d6aaa55d
MT
937 /* restore permissions */
938 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
939
10bc6f06
MT
940 if (raid_disk)
941 sprintf(string, "root=%sp4", hdparams.devnode);
942 else
943 sprintf(string, "root=%s4", hdparams.devnode);
d6aaa55d
MT
944 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
945
946 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
947
10bc6f06
MT
948 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /boot/grub/grubbatch");
949
950 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB]))
d6aaa55d
MT
951 {
952 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
953 goto EXIT;
954 }
f8ae001e
MT
955 /* Set Bootsplash */
956 if ((handle = fopen("/scsidriver", "r")))
7628469a 957 {
6693216e 958 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf >> /harddisk/boot/ipfirerd.img");
7628469a
MT
959 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf >> /harddisk/boot/ipfirerd-smp.img");
960 }
f8ae001e 961 else
7628469a 962 {
6693216e 963 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf > /harddisk/boot/initrd.splash");
7628469a 964 }
d6aaa55d
MT
965 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
966#endif
967#ifdef __alpha__
10bc6f06 968 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams.devnode);
d6aaa55d 969 mysystem(commandstring);
10bc6f06 970 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams.devnode);
d6aaa55d 971 mysystem(commandstring);
10bc6f06
MT
972 if (raid_disk)
973 sprintf(string, "root=%sp4", hdparams.devnode);
974 else
975 sprintf(string, "root=%s4", hdparams.devnode);
d6aaa55d
MT
976 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string);
977#endif
978
979 /* unmounting happens everywhere because there are places
980 which require device is to be unmounted under certain
981 circumstances. This is the last place we can unmount
10bc6f06 982 anything and still succeed. */
d6aaa55d 983
10bc6f06
MT
984 if (!unmount_before && installtype == CDROM_INSTALL){
985 if (mysystem("/sbin/umount /cdrom"))
986 {
987 errorbox(ctr[TR_UNABLE_TO_UNMOUNT_CDROM]);
988 goto EXIT;
989 }
d6aaa55d
MT
990 }
991
10bc6f06 992 if (installtype == CDROM_INSTALL)
d6aaa55d 993 {
10bc6f06
MT
994
995 if (!(ejectcdrom(cdromparams.devnode)))
d6aaa55d
MT
996 {
997 errorbox(ctr[TR_UNABLE_TO_EJECT_CDROM]);
998 // goto EXIT;
999 }
1000 }
10bc6f06
MT
1001
1002
1003 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
d6aaa55d
MT
1004 NAME, SNAME, SNAME, NAME, NAME, NAME);
1005 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
10bc6f06 1006
d6aaa55d 1007 allok = 1;
10bc6f06 1008
d6aaa55d 1009EXIT:
10bc6f06 1010 fprintf(flog, "Install program ended.\n");
d6aaa55d
MT
1011 fflush(flog);
1012 fclose(flog);
1013
10bc6f06 1014 if (!(allok))
d6aaa55d 1015 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
10bc6f06 1016
d6aaa55d 1017 newtFinished();
10bc6f06 1018
d6aaa55d 1019 freekeyvalues(ethernetkv);
d6aaa55d 1020
10bc6f06 1021 if (allok && !allok_fastexit)
d6aaa55d
MT
1022 {
1023 /* /proc is needed by the module checker. We have to mount it
1024 * so it can be seen by setup, which is run chrooted. */
1025 if (system("/sbin/mount proc -t proc /harddisk/proc"))
1026 printf("Unable to mount proc in /harddisk.");
1027 else
1028 {
1029 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
1030 printf("Unable to run setup.\n");
1031 if (system("/sbin/umount /harddisk/proc"))
1032 printf("Unable to umount /harddisk/proc.\n");
1033 }
1034 }
1035
1036 fcloseall();
1037
1038 system("/bin/swapoff /harddisk/swapfile");
1039 system("/sbin/umount /harddisk/var/log");
1040 system("/sbin/umount /harddisk/boot");
1041 system("/sbin/umount /harddisk");
10bc6f06 1042
d6aaa55d
MT
1043 system("/etc/halt");
1044
1045 return 0;
1046}