]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/install+setup/install/main.c
uClibc haengt...
[people/teissler/ipfire-2.x.git] / src / install+setup / install / main.c
CommitLineData
d6aaa55d
MT
1/* SmoothWall install program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * Contains main entry point, and misc functions.
8 *
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
5433e2c9
MT
196 sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME);
197 rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message,
198 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK],
199 ctr[TR_CANCEL], NULL);
200
201 if (rc == 2)
202 goto EXIT;
e57bc1fd 203
10bc6f06
MT
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
e57bc1fd 381 /* Check for ipfire-<VERSION>.tgz */
d6aaa55d
MT
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
e57bc1fd
MT
693 /* if (runcommandwithprogress(60, 4, title, commandstring, 4600,
694 * ctr[TR_INSTALLING_FILES]))
695 * {
696 * errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
697 * goto EXIT;
698 * }
699 */
700
701 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_FILES]))
d6aaa55d
MT
702 {
703 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
704 goto EXIT;
705 }
e57bc1fd 706
d6aaa55d
MT
707 /* Save USB controller type to modules.conf */
708 write_usb_modules_conf();
709
710 /* touch the modules.dep files */
10bc6f06
MT
711 snprintf(commandstring, STRING_SIZE,
712 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
713 KERNEL_VERSION);
714 mysystem(commandstring);
d6aaa55d 715#ifdef __i386__
10bc6f06
MT
716 snprintf(commandstring, STRING_SIZE,
717 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
718 KERNEL_VERSION);
719 mysystem(commandstring);
d6aaa55d
MT
720#endif
721
722 /* Rename uname */
723 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
724
725 /* Write PCMCIA Config */
726 if (pcmcia) {
727 handle = fopen("/harddisk/etc/modules.conf", "a");
728 if (handle != NULL) {
729 fprintf (handle, "# PCMCIA Settings\n");
730 fprintf (handle, "alias pcmcia-controller %s\n", pcmcia);
731 fclose(handle);
732 }
733 }
734
735 handle = fopen("/harddisk/etc/pcmcia.conf", "w");
736 if (handle != NULL) {
737 if (pcmcia) {
738 fprintf (handle, "PCMCIA=yes\n");
739 fprintf (handle, "PCIC=%s\n", pcmcia);
740 } else {
741 fprintf (handle, "PCMCIA=no\n");
742 fprintf (handle, "PCIC=\n");
743 }
744 fprintf (handle, "CARDMGR_OPTS=\n");
745 fprintf (handle, "SCHEME=\n");
746 fclose(handle);
747 }
748
749 /* *always* write disk configuration */
750 if (!(write_disk_configs(&hdparams))){
10bc6f06
MT
751 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
752 goto EXIT;
d6aaa55d
MT
753 }
754
755 /*
756 Allow the user to restore their configuration from a floppy.
757 It uses tar. If the tar fails for any reason, show user an
758 error and go back to the restore/skip question. This gives
759 the user the chance to have another go. */
10bc6f06 760
a6753b55 761#ifdef OLD_RESTORECFG
10bc6f06
MT
762RESTORE:
763 /* set status variables to nonsense values */
764 allok_fastexit = 0;
765 /* loop until floppy succeeds or user skips out */
766 while (1)
767 {
768 sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME);
769 if (newtWinChoice(title, ctr[TR_RESTORE], ctr[TR_SKIP], message) == 1)
770 {
771 /* Temporarily mount /proc under /harddisk/proc,
772 * run updfstab to locate the floppy, and unmount /harddisk/proc
773 * again. This should be run each time the user tries to restore
774 * so it can properly detect removable devices */
775 if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
776 errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]);
777 goto EXIT;
778 }
779 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
780 errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]);
781 goto EXIT;
782 }
783 mysystem("/bin/umount /harddisk/proc");
784
785 mkdir("/harddisk/tmp/ipcop", S_IRWXU|S_IRWXG|S_IRWXO);
786
787 /* Always extract to /tmp/ipcop for temporary extraction
788 * just in case floppy fails */
789
790 /* try a compressed backup first because it's quicker to fail.
791 * In exclude.system, files name must be without leading / or
792 * on extraction, name will never match */
793 snprintf(commandstring, STRING_SIZE,
794 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog);
d6aaa55d 795
10bc6f06
MT
796 statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]);
797 rc = system(commandstring);
798
799 if (rc) {
800 /* if it's not compressed, try uncompressed first before failing*/
801 snprintf(commandstring, STRING_SIZE,
802 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog);
803 rc = system(commandstring);
804 if (rc) {
805 newtPopWindow();
806 /* command failed trying to read from floppy */
807 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
808
809 /* remove badly restored files */
810 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
811 goto RESTORE;
812 } else {
813 /* Now copy to correct location */
814 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
815 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
816 newtPopWindow();
817 allok_fastexit=1;
818
819 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
820 upgrade_v12_v13();
821 upgrade_v130_v140();
822 break; /* out of loop at this point because floppy has
823 successfully restored */
824 }
825 }
826 else { /* success */
827 /* Now copy to correct location */
828 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
829 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
830 newtPopWindow();
831 allok_fastexit=1;
832
833 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
834 upgrade_v12_v13();
835 upgrade_v130_v140();
836 break; /* out of loop at this point because floppy has
837 successfully restored */
838 }
839 }
840 else{ /* user chose to skip install from floppy */
841 if (installtype == CDROM_INSTALL){
842 /* if we installed from CD ROM then we didn't set up the
843 network interface yet. Therefore, set up Network
844 driver and params just before we need them. */
845
846 if (!(networkmenu(ethernetkv))){
847 /* network setup failed, tell the world */
848 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
849 goto EXIT;
850 }
851 }
852 break; /* out of loop because we succeeded with ethernet
853 set up and user is notrestarting from floppy*/
854 }
855 }
a6753b55
HS
856#else
857 if (installtype == CDROM_INSTALL){
858 /* if we installed from CD ROM then we didn't set up the
859 network interface yet. Therefore, set up Network
860 driver and params just before we need them. */
861
862 if (!(networkmenu(ethernetkv))){
863 /* network setup failed, tell the world */
864 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
865 goto EXIT;
866 }
867 }
868#endif
10bc6f06
MT
869
870 /* Check the SQUID acl file exists, if not use our 1.4 copy */
871 {
872 FILE *aclreadfile;
873
874 if (!(aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) {
875 rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4",
876 "/harddisk" CONFIG_ROOT "/proxy/acl");
877 } else {
878 unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4");
879 fclose(aclreadfile);
d6aaa55d 880 }
10bc6f06 881 chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99);
d6aaa55d
MT
882 }
883
884 /* Build cache lang file */
885 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
886
10bc6f06
MT
887 if (!allok_fastexit){
888 /* write ethernet and lang configs only if they have not
889 been restored from floppy already. */
890 if (!(write_ethernet_configs( ethernetkv))||
891 !(write_lang_configs(shortlangname))){
892 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
893 goto EXIT;
894 }
895 }
896
897 /* if we detected SCSI then fixup */
898 if ((handle = fopen("/scsidriver", "r")))
899 {
900 char *driver;
901 fgets(line, STRING_SIZE-1, handle);
902 fclose(handle);
903 line[strlen(line) - 1] = 0;
904 driver = strtok(line, ".");
905 fprintf(flog, "Detected SCSI driver %s\n",driver);
906 if (strlen(driver) > 1) {
f8ae001e 907 fprintf(flog, "Fixing up ipfirerd.img\n");
10bc6f06
MT
908 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
909 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
f8ae001e 910 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipfirerd.img %s", driver, KERNEL_VERSION);
10bc6f06
MT
911 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
912#ifdef __i386__
f8ae001e 913 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipfirerd-smp.img %s-smp", driver, KERNEL_VERSION);
10bc6f06
MT
914 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
915 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
916#endif
917#ifdef __alpha__
918 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
919 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
920#endif
d6aaa55d
MT
921 }
922 }
923
d6aaa55d
MT
924#if 0 /* not yet */
925 if (pcmcia_disk)
926 {
927 fprintf(flog, "Detected SCSI driver PCMCIA\n");
f8ae001e 928 fprintf(flog, "Fixing up ipfirerd.img\n");
d6aaa55d
MT
929 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
930 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
f8ae001e 931 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipfirerd.img", KERNEL_VERSION);
10bc6f06 932 mysystem(commandstring);
d6aaa55d
MT
933#ifdef __i386__
934 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
935#endif
936#ifdef __alpha__
937 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
938#endif
939 }
940#endif
941
942#ifdef __i386__
10bc6f06 943 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
d6aaa55d
MT
944 /* restore permissions */
945 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
946
10bc6f06
MT
947 if (raid_disk)
948 sprintf(string, "root=%sp4", hdparams.devnode);
949 else
950 sprintf(string, "root=%s4", hdparams.devnode);
d6aaa55d
MT
951 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
952
953 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
954
10bc6f06
MT
955 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /boot/grub/grubbatch");
956
957 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB]))
d6aaa55d
MT
958 {
959 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
960 goto EXIT;
961 }
f8ae001e 962 /* Set Bootsplash */
5433e2c9 963 mysystem("/bin/installbootsplash.sh");
d6aaa55d
MT
964 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
965#endif
966#ifdef __alpha__
10bc6f06 967 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams.devnode);
d6aaa55d 968 mysystem(commandstring);
10bc6f06 969 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams.devnode);
d6aaa55d 970 mysystem(commandstring);
10bc6f06
MT
971 if (raid_disk)
972 sprintf(string, "root=%sp4", hdparams.devnode);
973 else
974 sprintf(string, "root=%s4", hdparams.devnode);
d6aaa55d
MT
975 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string);
976#endif
977
978 /* unmounting happens everywhere because there are places
979 which require device is to be unmounted under certain
980 circumstances. This is the last place we can unmount
10bc6f06 981 anything and still succeed. */
d6aaa55d 982
10bc6f06
MT
983 if (!unmount_before && installtype == CDROM_INSTALL){
984 if (mysystem("/sbin/umount /cdrom"))
985 {
986 errorbox(ctr[TR_UNABLE_TO_UNMOUNT_CDROM]);
987 goto EXIT;
988 }
d6aaa55d
MT
989 }
990
10bc6f06 991 if (installtype == CDROM_INSTALL)
d6aaa55d 992 {
10bc6f06
MT
993
994 if (!(ejectcdrom(cdromparams.devnode)))
d6aaa55d
MT
995 {
996 errorbox(ctr[TR_UNABLE_TO_EJECT_CDROM]);
997 // goto EXIT;
998 }
999 }
10bc6f06
MT
1000
1001
1002 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
d6aaa55d
MT
1003 NAME, SNAME, SNAME, NAME, NAME, NAME);
1004 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
10bc6f06 1005
d6aaa55d 1006 allok = 1;
10bc6f06 1007
d6aaa55d 1008EXIT:
10bc6f06 1009 fprintf(flog, "Install program ended.\n");
d6aaa55d
MT
1010 fflush(flog);
1011 fclose(flog);
1012
10bc6f06 1013 if (!(allok))
d6aaa55d 1014 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
10bc6f06 1015
d6aaa55d 1016 newtFinished();
10bc6f06 1017
d6aaa55d 1018 freekeyvalues(ethernetkv);
d6aaa55d 1019
10bc6f06 1020 if (allok && !allok_fastexit)
d6aaa55d
MT
1021 {
1022 /* /proc is needed by the module checker. We have to mount it
1023 * so it can be seen by setup, which is run chrooted. */
1024 if (system("/sbin/mount proc -t proc /harddisk/proc"))
1025 printf("Unable to mount proc in /harddisk.");
1026 else
1027 {
1028 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
1029 printf("Unable to run setup.\n");
1030 if (system("/sbin/umount /harddisk/proc"))
1031 printf("Unable to umount /harddisk/proc.\n");
1032 }
1033 }
1034
1035 fcloseall();
1036
1037 system("/bin/swapoff /harddisk/swapfile");
1038 system("/sbin/umount /harddisk/var/log");
1039 system("/sbin/umount /harddisk/boot");
1040 system("/sbin/umount /harddisk");
10bc6f06 1041
d6aaa55d
MT
1042 system("/etc/halt");
1043
1044 return 0;
1045}