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