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