1 /* SmoothWall install program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Contains main entry point, and misc functions.
9 * $Id: main.c,v 1.63.2.64 2006/01/11 01:01:38 franck78 Exp $
14 #define CDROM_INSTALL 0
23 extern char url
[STRING_SIZE
];
26 To include a translated string in the final installer, you must reference
27 it here with a simplr comment. This save a lot a space in the installer
33 /* TR_SELECT_INSTALLATION_MEDIA_LONG */
34 /* TR_SELECT_INSTALLATION_MEDIA */
36 /* TR_INSERT_FLOPPY */
37 /* TR_INSTALLATION_CANCELED */
38 /* TR_EXTRACTING_MODULES */
39 /* TR_UNABLE_TO_EXTRACT_MODULES */
40 /* TR_LOADING_PCMCIA */
44 /* TR_USB_KEY_VFAT_ERR */
45 /* TR_NETWORK_SETUP_FAILED */
46 /* TR_NO_IPCOP_TARBALL_FOUND */
47 /* TR_NO_SCSI_IMAGE_FOUND */
48 /* TR_INSTALLING_FILES */
49 /* TR_UNABLE_TO_INSTALL_FILES */
51 /* TR_PREPARE_HARDDISK */
52 /* TR_DISK_TOO_SMALL */
53 /* TR_CONTINUE_NO_SWAP */
54 /* TR_PARTITIONING_DISK */
55 /* TR_UNABLE_TO_PARTITION */
56 /* TR_MAKING_BOOT_FILESYSTEM */
57 /* TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM */
58 /* TR_MAKING_LOG_FILESYSTEM */
59 /* TR_UNABLE_TO_MAKE_LOG_FILESYSTEM */
60 /* TR_MAKING_ROOT_FILESYSTEM */
61 /* TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM */
62 /* TR_MOUNTING_ROOT_FILESYSTEM */
63 /* TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM */
64 /* TR_MAKING_SWAPSPACE */
65 /* TR_UNABLE_TO_MAKE_SWAPSPACE */
66 /* TR_MOUNTING_SWAP_PARTITION */
67 /* TR_UNABLE_TO_MOUNT_SWAP_PARTITION */
68 /* TR_MOUNTING_BOOT_FILESYSTEM */
69 /* TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM */
70 /* TR_MOUNTING_LOG_FILESYSTEM */
71 /* TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM */
72 /* TR_ERROR_WRITING_CONFIG */
73 /* TR_INSTALLING_GRUB */
74 /* TR_UNABLE_TO_INSTALL_GRUB */
75 /* TR_UNABLE_TO_UNMOUNT_CDROM */
76 /* TR_UNABLE_TO_EJECT_CDROM */
77 /* TR_CONGRATULATIONS_LONG */
78 /* TR_CONGRATULATIONS */
79 /* TR_PRESS_OK_TO_REBOOT */
82 /* TR_CONFIGURE_NETWORKING */
85 /* TR_CONFIGURE_NETWORKING_LONG */
88 /* TR_INTERFACE_FAILED_TO_COME_UP */
92 /* TR_FAILED_TO_FIND */
96 /* TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK1 */
97 /* TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK2 */
98 /* TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK3 */
99 /* TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK4 */
100 /* TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK */
101 /* TR_UNABLE_TO_MAKE_SYMLINK_DEV_ROOT */
102 /* TR_PASSWORD_PROMPT */
103 /* TR_AGAIN_PROMPT */
104 /* TR_PASSWORD_CANNOT_BE_BLANK */
105 /* TR_PASSWORDS_DO_NOT_MATCH */
109 /* TR_ENTER_THE_IP_ADDRESS_INFORMATION */
111 /* TR_DHCP_HOSTNAME */
112 /* TR_IP_ADDRESS_PROMPT */
113 /* TR_NETMASK_PROMPT */
114 /* TR_INVALID_FIELDS */
115 /* TR_IP_ADDRESS_CR */
116 /* TR_NETWORK_MASK_CR */
117 /* TR_DHCP_HOSTNAME_CR */
118 /* TR_LOOKING_FOR_NIC */
120 /* TR_SELECT_NETWORK_DRIVER */
121 /* TR_SELECT_NETWORK_DRIVER_LONG */
122 /* TR_UNABLE_TO_LOAD_DRIVER_MODULE */
123 /* TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED */
124 /* TR_MODULE_PARAMETERS */
125 /* TR_LOADING_MODULE */
126 /* TR_MODULE_NAME_CANNOT_BE_BLANK */
129 int main(int argc
, char *argv
[])
132 char *langnames
[] = { "English", NULL
};
133 char *shortlangnames
[] = { "en", NULL
};
134 char **langtrs
[] = { en_tr
, NULL
};
136 char *langnames
[] = { "Brasil", "Cestina", "Dansk", "Deutsch", "English", "Español", "Français", "Hellenic", "Italiano", "Spanish Latino", "Magyar", "Nederlands", "Norsk", "Polski", "Português", "Slovak", "Soomali", "Suomi", "Svenska", "Türkçe", "Tieng Viet", NULL
};
137 char *shortlangnames
[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "sk", "so", "fi", "sv", "tr", "vi", NULL
};
138 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
, sk_tr
, so_tr
, fi_tr
, sv_tr
, tr_tr
, vi_tr
, NULL
};
140 char hdletter
, cdletter
;
141 char harddrive
[5], cdromdrive
[5]; /* Device holder. */
142 struct devparams hdparams
, cdromparams
; /* Params for CDROM and HD */
143 int cdmounted
= 0; /* Loop flag for inserting a cd. */
145 char commandstring
[STRING_SIZE
];
146 char *installtypes
[] = { "CDROM/USB-KEY", "HTTP/FTP", NULL
};
147 int installtype
= CDROM_INSTALL
;
148 char insertmessage
[STRING_SIZE
];
149 char insertdevnode
[STRING_SIZE
];
151 char shortlangname
[10];
153 char title
[STRING_SIZE
];
156 int unmount_before
=0;
157 struct keyvalue
*ethernetkv
= initkeyvalues();
158 FILE *handle
, *cmdfile
;
159 char line
[STRING_SIZE
];
160 char string
[STRING_SIZE
];
161 int maximum_free
= 0, current_free
;
163 int log_partition
, boot_partition
, root_partition
, swap_file
;
166 int pcmcia_cdrom
= 0;
172 setlocale (LC_ALL
, "");
173 sethostname(SNAME
, 10);
175 memset(&hdparams
, 0, sizeof(struct devparams
));
176 memset(&cdromparams
, 0, sizeof(struct devparams
));
178 /* Log file/terminal stuff. */
181 if (!(flog
= fopen(argv
[1], "w+")))
189 fprintf(flog
, "Install program started.\n");
194 /* Do usb detection first for usb keyboard */
195 if (! (cmdfile
= fopen("/proc/cmdline", "r")))
197 fprintf(flog
, "Couldn't open commandline: /proc/cmdline\n");
199 fgets(line
, STRING_SIZE
, cmdfile
);
200 if (strstr (line
, "fdisk") != NULL
) {
201 fprintf(flog
, "Manual FDISK selected.\n");
204 if (strstr (line
, "nopcmcia") == NULL
) {
205 fprintf(flog
, "Initializing PCMCIA controllers.\n");
206 pcmcia
= initialize_pcmcia();
208 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
209 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
210 mysystem("/sbin/modprobe pcmcia_core");
211 mysystem(commandstring
);
212 mysystem("/sbin/modprobe ds");
213 /* pcmcia netcard drivers are not available from Boot floppy,
214 * they will be loaded from Drivers floppy later */
216 fprintf (flog
, "Detected No PCMCIA Controller.\n");
219 fprintf(flog
, "Skipping PCMCIA detection.\n");
221 if (strstr (line
, "nousb") == NULL
) {
222 fprintf(flog
, "Initializing USB controllers.\n");
225 fprintf(flog
, "Skipping USB detection.\n");
229 /* English is the default */
230 for (choice
= 0; langnames
[choice
]; choice
++)
232 if (strcmp(langnames
[choice
], "English") == 0)
235 if (!langnames
[choice
])
239 /* No need to ask. "choice" already has the index for English */
241 rc
= newtWinMenu("Language selection",
242 "Select the language you wish to use for the " NAME
".", 50, 5, 5, 8,
243 langnames
, &choice
, "Ok", NULL
);
245 ctr
= langtrs
[choice
];
246 strcpy(shortlangname
, shortlangnames
[choice
]);
247 if (strcmp(shortlangname
, "el") == 0)
248 mysystem("/bin/setfont iso07u-16");
249 else if (strcmp(shortlangname
, "pt") == 0)
250 mysystem("/bin/setfont lat1-16");
251 else if (strcmp(shortlangname
, "bz") == 0)
252 mysystem("/bin/setfont lat1-16");
253 else if (strcmp(shortlangname
, "cs") == 0)
254 mysystem("/bin/setfont lat2-16");
255 else if (strcmp(shortlangname
, "hu") == 0)
256 mysystem("/bin/setfont lat2-16");
257 else if (strcmp(shortlangname
, "pl") == 0)
258 mysystem("/bin/setfont lat2-16");
259 else if (strcmp(shortlangname
, "sk") == 0)
260 mysystem("/bin/setfont lat2-16");
261 else if (strcmp(shortlangname
, "tr") == 0)
262 mysystem("/bin/setfont lat5-16");
263 else if (strcmp(shortlangname
, "vi") == 0)
264 mysystem("/bin/setfont viscii10-8x16");
266 mysystem("/bin/setfont lat0-16");
268 /* need this for reading from formatted device */
271 newtDrawRootText(14, 0, NAME
" v" VERSION
" - " SLOGAN
);
272 newtPushHelpLine(ctr
[TR_HELPLINE
]);
274 snprintf(message
, STRING_SIZE
, ctr
[TR_WELCOME
], NAME
);
275 snprintf (title
, STRING_SIZE
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
276 newtWinMessage(title
, ctr
[TR_OK
], message
);
278 snprintf(message
,STRING_SIZE
, ctr
[TR_SELECT_INSTALLATION_MEDIA_LONG
], NAME
);
279 rc
= newtWinMenu(ctr
[TR_SELECT_INSTALLATION_MEDIA
], message
,
280 50, 5, 5, 6, installtypes
, &installtype
, ctr
[TR_OK
],
281 ctr
[TR_CANCEL
], NULL
);
286 if (installtype
== CDROM_INSTALL
) // CD or USB-key
289 /* try usb key in superfloppy format only */
290 if (checkusb("sda")) {
291 sprintf(cdromdrive
, "sda");
295 if (checkusb("sdb")) {
296 sprintf(cdromdrive
, "sdb");
301 /* look for an IDE CDROM. */
302 if ((cdletter
= findidetype(IDE_CDROM
)))
304 sprintf(cdromdrive
, "hd%c", cdletter
);
309 /* If we have a USB attached CDROM then it will
310 * have already appeared at /dev/scd0, so we
311 * try to access it first, before asking for the
314 if (try_scsi("scd0")) {
315 sprintf(cdromdrive
, "scd0");
320 /* ask for supplemental SCSI driver */
321 snprintf(insertmessage
, STRING_SIZE
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
322 if (newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
) != 1)
324 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
328 /* extract new modules */
329 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
331 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
334 /* and load PCMCIA */
337 /* trying to support SCSI pcmcia :-) */
338 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
339 ctr
[TR_LOADING_PCMCIA
]);
340 if (try_scsi("scd0")) {
341 sprintf(cdromdrive
, "scd0");
347 /* try loading all SCSI modules with default options */
348 /* Should expand this to allow options later though */
349 runcommandwithstatus("/bin/probescsi.sh", ctr
[TR_PROBING_SCSI
]);
351 /* If it fails, give up. */
352 if (try_scsi("scd0")) {
353 sprintf(cdromdrive
, "scd0");
358 /* Unable to find a valid source, give up */
359 errorbox(ctr
[TR_NO_CDROM
]);
363 sprintf(cdromparams
.devnode_disk
, "/dev/%s", cdromdrive
);
364 // cdromparams.module = 0;
366 snprintf(insertmessage
,STRING_SIZE
,ctr
[TR_INSERT_CDROM
], NAME
);
367 strcpy (insertdevnode
, cdromparams
.devnode_disk
);
369 else /* don't understand why this follows... */
371 /* If we've done a PXE boot, we can skip the Drivers floppy,
372 * as we've already got the modules in our instroot.gz */
373 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
374 snprintf(insertmessage
, STRING_SIZE
-12, ctr
[TR_INSERT_FLOPPY
], NAME
);
375 strcpy (insertdevnode
, "/dev/floppy");
383 /* Try to mount /cdrom with the device discovered */
384 if (scsi_cdrom
|| ide_cdrom
|| usb_cdrom
) {
385 snprintf(commandstring
, STRING_SIZE
, "/bin/mount -o ro %s /cdrom", insertdevnode
);
390 /* for usb-key, we have to try sda then sda1. The key cannot be unpluged */
391 if (sd_test
== 1) { //change to sda1
392 sprintf(commandstring
, "/bin/mount -o ro %s1 /cdrom", insertdevnode
);
394 if (sd_test
== 2) { //the key do not contains a vfat file system
395 errorbox(ctr
[TR_USB_KEY_VFAT_ERR
]);
398 if (usb_cdrom
) sd_test
++; // next USB test
400 if (!skip_dialog
&& !usb_cdrom
) {
401 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
404 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
409 if (mysystem(commandstring
))
410 continue; //mount failed, try again
412 /*verify it's what we want */
413 handle
= fopen ("/cdrom/" SNAME
"-" VERSION
".tgz", "r");
414 if (handle
== NULL
) {
415 mysystem ("/bin/umount /cdrom");
416 continue; /* bad disk ! */
421 /* If we've booted from CDROM, then
422 * we've already got the drivers,
423 * so we can skip this unpack. */
424 if ((handle
= fopen("/CDROMBOOT", "r"))) {
426 break; /* ok we go everything */
429 if (runcommandwithprogress(60, 4, title
,
430 "/bin/tar -C / -xvzf /cdrom/images/drivers-"VERSION
".img",
431 175, ctr
[TR_EXTRACTING_MODULES
]))
433 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
437 } else { /* no cd device were discovered, ask second diskette */
438 sprintf(commandstring
, "/bin/tar -C / -xvzf /dev/floppy");
441 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
444 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
447 if (runcommandwithprogress(60, 4, title
,
449 175, ctr
[TR_EXTRACTING_MODULES
]))
451 #if 0 /* disable this, so we allow for people putting in the wrong disk */
452 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
458 handle
= fopen ("/bin/mke2fs", "r");
459 if (handle
!= NULL
) {
467 /* PCMCIA controller is already detected
468 * On Boot floppy, we didn't have the PCMCIA drivers
469 * so load them now because they are installed from Drivers. */
470 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
471 if (strstr (line
, "nopcmcia") == NULL
) {
472 fprintf(flog
,"Floppy boot detected, loading PCMCIA drivers.\n");
474 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
475 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
476 mysystem("/sbin/modprobe pcmcia_core");
477 mysystem(commandstring
);
478 mysystem("/sbin/modprobe ds");
480 fprintf (flog
, "Detected No PCMCIA Controller.\n");
483 fprintf(flog
, "Skipping PCMCIA detection.\n");
485 if (strstr (line
, "nousb") == NULL
) {
486 fprintf(flog
, "Initializing USB controllers.\n");
489 fprintf(flog
, "Skipping USB detection.\n");
494 /* Configure the network now! */
495 if (installtype
== URL_INSTALL
)
497 /* Network driver and params. */
498 if (!(networkmenu(ethernetkv
)))
500 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
504 /* Check for ipcop-<VERSION>.tgz */
505 if (!(checktarball(SNAME
"-" VERSION
".tgz")))
507 errorbox(ctr
[TR_NO_IPCOP_TARBALL_FOUND
]);
512 /* Get device for the HD. This has to succeed. */
513 /* first try an IDE disk */
514 if ((hdletter
= findidetype(IDE_HD
)))
516 sprintf(harddrive
, "hd%c", hdletter
);
517 goto FOUND_DESTINATION
;
519 /* unpack SCSI driver if not done during CD detection */
520 if (installtype
== URL_INSTALL
)
522 /* If we've done a PXE boot, we can skip the SCSI
523 * floppy as we've already got the modules in our
525 if (!(handle
= fopen("/CDROMBOOT", "r")))
527 /* search img where it is on a mounted loop iso */
528 if (!(checktarball("images/scsidrv-"VERSION
".img")))
530 /* Couldn't find the SCSI drivers on the URL page,
531 * so after 3 failed attempts, ask the user for the
532 * SCSI drivers floppy disk. */
533 errorbox(ctr
[TR_NO_SCSI_IMAGE_FOUND
]);
534 snprintf(insertmessage
, STRING_SIZE
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
535 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
538 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
542 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
544 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
548 /* unpack... THIS DO NOT WORK BECAUSE var "string" is empty*/
549 snprintf(commandstring
, STRING_SIZE
,
550 "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -",
552 if (runcommandwithprogress(60, 4, title
, commandstring
,
553 4500, ctr
[TR_INSTALLING_FILES
]))
555 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
561 } else { /* cdrom/usb install, install SCSI id not done */
563 if (runcommandwithstatus("/bin/tar -C / -xvzf /cdrom/images/scsidrv-"VERSION
".img", ctr
[TR_EXTRACTING_MODULES
]))
565 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
571 /* load SCSI/pcmcia drivers if not done during CD detection */
576 /* trying to support SCSI pcmcia :-) */
577 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
578 ctr
[TR_LOADING_PCMCIA
]);
579 if (try_scsi(usb_cdrom
? "sdb":"sda")) {
583 if (checkusb("sdb") && try_scsi("sdc")) {
589 /* try loading all SCSI modules with default options */
590 /* Should expand this to allow options later though */
592 runcommandwithstatus("/bin/probescsi.sh",
593 ctr
[TR_PROBING_SCSI
]);
595 /* Now try to find destination device...
596 Need to clean this up at some point
597 scsi disk is sdb/sdc when sda/sdb is used for usb-key
598 if scsi-disk is is sdd or more, it is not discovered
600 if (try_scsi(usb_cdrom
? "sdb":"sda")) {
602 sprintf(harddrive
, usb_cdrom
? "sdb":"sda");
603 goto FOUND_DESTINATION
;
605 if (checkusb("sdb") && try_scsi("sdc")) {
607 sprintf(harddrive
, "sdc");
608 goto FOUND_DESTINATION
;
610 if (try_scsi("ida/c0d0")) {
612 sprintf(harddrive
, "ida/c0d0");
613 goto FOUND_DESTINATION
;
615 if (try_scsi("cciss/c0d0")) {
617 sprintf(harddrive
, "cciss/c0d0");
618 goto FOUND_DESTINATION
;
620 if (try_scsi("rd/c0d0")) {
622 sprintf(harddrive
, "rd/c0d0");
623 goto FOUND_DESTINATION
;
625 if (try_scsi("ataraid/d0")) {
627 sprintf(harddrive
, "ataraid/d0");
628 goto FOUND_DESTINATION
;
630 /* nothing worked, give up */
631 errorbox(ctr
[TR_NO_HARDDISK
]);
635 /* Make the hdparms struct and print the contents.
636 With USB-KEY install and SCSI disk, while installing, the disk
637 is named 'sdb,sdc,...' (following keys)
638 On reboot, it will become 'sda'
639 To avoid many test, all names are built in the struct.
641 sprintf(hdparams
.devnode_disk
, "/dev/%s", harddrive
);
642 /* Address the partition or raid partition (eg dev/sda or /dev/sdap1 */
643 sprintf(hdparams
.devnode_part
, "/dev/%s%s", harddrive
,raid_disk
? "p" : "");
644 /* now the names after the machine is booted. Today only scsi is affected
645 and we only install on the first scsi disk.
648 strcpy(tmp
, scsi_disk
? "sda" : harddrive
);
649 sprintf(hdparams
.devnode_disk_run
, "/dev/%s", tmp
);
650 sprintf(hdparams
.devnode_part_run
, "/dev/%s%s", tmp
, raid_disk
? "p" : "");
653 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
],
654 ctr
[TR_PREPARE_HARDDISK
], hdparams
.devnode_disk_run
);
658 /* Calculate amount of memory in machine */
659 if ((handle
= fopen("/proc/meminfo", "r")))
661 while (fgets(line
, STRING_SIZE
-1, handle
)) {
662 if (sscanf (line
, "MemTotal: %s kB", string
)) {
663 memory
= atoi(string
) / 1024 ;
669 /* Partition, mkswp, mkfs.
670 * before partitioning, first determine the sizes of each
671 * partition. In order to do that we need to know the size of
674 /* Don't use mysystem here so we can redirect output */
675 sprintf(commandstring
, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive
);
676 system(commandstring
);
678 /* Calculate amount of disk space */
679 if ((handle
= fopen("/disksize", "r")))
681 fgets(line
, STRING_SIZE
-1, handle
);
682 if (sscanf (line
, "%s", string
)) {
683 maximum_free
= atoi(string
) / 1024;
688 fprintf(flog
, "maximum_free = %d, memory = %d", maximum_free
, memory
);
690 /* If you need more than this, you should really add physical memory */
691 /* Minimum: 192 = 64 real + 128 swap */
692 swap_file
= memory
< 64 ? 2 * memory
: 192 - memory
;
693 swap_file
= swap_file
< 32 ? 32 : swap_file
;
695 if (maximum_free
< 135 + swap_file
)
697 if (maximum_free
< 135) {
698 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
702 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], ctr
[TR_CONTINUE_NO_SWAP
]);
708 boot_partition
= 8; /* in MB */
709 current_free
= maximum_free
- boot_partition
- swap_file
;
711 /* Give more place for add-on, extend root to 25% of current_free, upper limit to 8 gigas */
712 root_partition
= current_free
/ 4 ;
713 root_partition
= root_partition
> 8192 ? 8192 : root_partition
;
714 root_partition
= current_free
< 860 ? 235 : root_partition
;
715 root_partition
= current_free
< 380 ? 110 : root_partition
;
717 current_free
= current_free
- root_partition
;
718 root_partition
= root_partition
+ swap_file
;
720 log_partition
= current_free
;
722 fprintf(flog
, "boot = %d, swap = %d, mylog = %d, root = %d\n",
723 boot_partition
, swap_file
, log_partition
, root_partition
);
730 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], "NOW FDISK");
735 handle
= fopen("/tmp/partitiontable", "w");
737 fprintf(handle
, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n",
738 boot_partition
, log_partition
);
742 sprintf(commandstring
, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams
.devnode_disk
);
743 if (runcommandwithstatus(commandstring
, ctr
[TR_PARTITIONING_DISK
]))
745 errorbox(ctr
[TR_UNABLE_TO_PARTITION
]);
750 /* create filesystem boot partition 1 */
751 sprintf(commandstring
, "/bin/mke2fs -m 0 -j %s1", hdparams
.devnode_part
);
752 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_BOOT_FILESYSTEM
]))
754 errorbox(ctr
[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM
]);
758 /* create filesystem log partition 2 */
759 sprintf(commandstring
, "/bin/mke2fs -j %s2", hdparams
.devnode_part
);
760 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_LOG_FILESYSTEM
]))
762 errorbox(ctr
[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM
]);
766 /* create filesystem root partition 4 */
767 sprintf(commandstring
, "/bin/mke2fs -m 1 -j %s4", hdparams
.devnode_part
);
768 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_ROOT_FILESYSTEM
]))
770 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
774 /* Mount root on partition 4 */
775 sprintf(commandstring
, "/sbin/mount -t ext2 %s4 /harddisk", hdparams
.devnode_part
);
776 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_ROOT_FILESYSTEM
]))
778 errorbox(ctr
[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM
]);
781 mkdir("/harddisk/boot", S_IRWXU
|S_IRWXG
|S_IRWXO
);
782 mkdir("/harddisk/var", S_IRWXU
|S_IRWXG
|S_IRWXO
);
783 mkdir("/harddisk/var/log", S_IRWXU
|S_IRWXG
|S_IRWXO
);
785 /* Make,mount swapfile */
787 sprintf(commandstring
, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file
);
788 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
790 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
793 if (runcommandwithstatus("/bin/mkswap /harddisk/swapfile", ctr
[TR_MAKING_SWAPSPACE
]))
795 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
798 if (runcommandwithstatus("/bin/swapon /harddisk/swapfile", ctr
[TR_MOUNTING_SWAP_PARTITION
]))
800 errorbox(ctr
[TR_UNABLE_TO_MOUNT_SWAP_PARTITION
]);
805 /* Mount boot on partition 1 */
806 sprintf(commandstring
, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams
.devnode_part
);
807 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_BOOT_FILESYSTEM
]))
809 errorbox(ctr
[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM
]);
813 /* Mount log on partition 2 */
814 sprintf(commandstring
, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams
.devnode_part
);
815 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_LOG_FILESYSTEM
]))
817 errorbox(ctr
[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM
]);
821 /* Either use tarball from cdrom or download. */
822 if (installtype
== CDROM_INSTALL
)
823 snprintf(commandstring
, STRING_SIZE
,
824 "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME
"-" VERSION
".tgz");
826 snprintf(commandstring
, STRING_SIZE
,
827 "/bin/wget -O - %s/" SNAME
"-" VERSION
".tgz | /bin/tar -C /harddisk -xvzf -", url
);
829 if (runcommandwithprogress(60, 4, title
, commandstring
, 4600,
830 ctr
[TR_INSTALLING_FILES
]))
832 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
836 /* Save USB controller type to modules.conf */
837 write_usb_modules_conf();
839 /* touch the modules.dep files */
840 mysystem("/bin/chroot /harddisk /bin/touch /lib/modules/"KERNEL_VERSION
"/modules.dep");
842 mysystem("/bin/chroot /harddisk /bin/touch /lib/modules/"KERNEL_VERSION
"-smp/modules.dep");
846 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
848 /* Write PCMCIA Config */
850 handle
= fopen("/harddisk/etc/modules.conf", "a");
851 if (handle
!= NULL
) {
852 fprintf (handle
, "# PCMCIA Settings\n");
853 fprintf (handle
, "alias pcmcia-controller %s\n", pcmcia
);
858 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
859 if (handle
!= NULL
) {
861 fprintf (handle
, "PCMCIA=yes\n");
862 fprintf (handle
, "PCIC=%s\n", pcmcia
);
864 fprintf (handle
, "PCMCIA=no\n");
865 fprintf (handle
, "PCIC=\n");
867 fprintf (handle
, "CARDMGR_OPTS=\n");
868 fprintf (handle
, "SCHEME=\n");
872 /* *always* write disk configuration */
873 if (!(write_disk_configs(&hdparams
))){
874 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
879 Allow the user to restore their configuration from a floppy.
880 It uses tar. If the tar fails for any reason, show user an
881 error and go back to the restore/skip question. This gives
882 the user the chance to have another go. */
884 /* Program is outside install to save space on floppy
886 fprintf(flog
, "Passing control to install2.\n");
889 /* pass needed parameter for install 2 by position
890 choice: index of langage selected
891 devnode_disk: to prevent unmounting of it
892 url: if network, allow restaure from it
894 sprintf(commandstring
, "/harddisk/usr/local/bin/install2 %d %s %s",
896 strlen(cdromparams
.devnode_disk
) ? cdromparams
.devnode_disk
: "none",
897 strlen(url
) ? url
: "none"
899 no_restore
= system(commandstring
);
902 /* if we installed from CD ROM then we didn't set up the
903 network interface yet. Therefore, set up Network
904 driver and params just before we need them.
906 if (no_restore
&& (installtype
== CDROM_INSTALL
)) {
907 if (!(networkmenu(ethernetkv
))){
908 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
913 /* Build cache lang file */
914 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
916 /* write ethernet and lang configs only if they have not
917 been restored from floppy already. */
919 if (!write_ethernet_configs(ethernetkv
)||
920 !write_lang_configs(shortlangname
)) {
921 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
930 fprintf(flog
, "Detected SCSI driver PCMCIA\n");
931 fprintf(flog
, "Fixing up ipcoprd.img\n");
932 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
933 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
934 mysystem("/bin/chroot /harddisk /sbin/pcinitrd -r "KERNEL_VERSION
" /boot/ipcoprd.img");
936 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
939 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
945 // to verify: with USB-key grubbatch install on sdb and boot sda....
946 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode_disk
);
947 /* restore permissions */
948 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
950 sprintf(string
, "root=%s4", hdparams
.devnode_part_run
);
951 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
953 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
955 if (runcommandwithstatus("/bin/chroot /harddisk /boot/grub/grubbatch", ctr
[TR_INSTALLING_GRUB
]))
957 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
960 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
963 sprintf(commandstring
, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams
.devnode_disk
);
964 mysystem(commandstring
);
965 sprintf(commandstring
, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams
.devnode_disk_run
);
966 mysystem(commandstring
);
967 sprintf(string
, "root=%s4", hdparams
.devnode_part_run
);
968 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string
);
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
974 anything and still succeed.
977 if (!unmount_before
&& !usb_cdrom
&& installtype
== CDROM_INSTALL
){
978 if (mysystem("/sbin/umount /cdrom"))
980 errorbox(ctr
[TR_UNABLE_TO_UNMOUNT_CDROM
]);
985 if ((installtype
== CDROM_INSTALL
) && !usb_cdrom
)
987 if (!(ejectcdrom(cdromparams
.devnode_disk
)))
989 errorbox(ctr
[TR_UNABLE_TO_EJECT_CDROM
]);
994 snprintf(message
, STRING_SIZE
, ctr
[TR_CONGRATULATIONS_LONG
],
995 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
996 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
1001 fprintf(flog
, "Install program ended.\n");
1006 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
1010 freekeyvalues(ethernetkv
);
1012 mysystem("/bin/chroot /harddisk /bin/rm /usr/local/bin/install2");
1014 /* run setup only if config not restored from floppy already. */
1015 if (allok
&& no_restore
)
1017 /* /proc is needed by the module checker. We have to mount it
1018 * so it can be seen by setup, which is run chrooted. */
1019 if (system("/sbin/mount proc -t proc /harddisk/proc"))
1020 printf("Unable to mount proc in /harddisk.");
1023 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
1024 printf("Unable to run setup.\n");
1025 if (system("/sbin/umount /harddisk/proc"))
1026 printf("Unable to umount /harddisk/proc.\n");
1032 system("/bin/swapoff /harddisk/swapfile");
1033 system("/sbin/umount /harddisk/var/log");
1034 system("/sbin/umount /harddisk/boot");
1035 system("/sbin/umount /harddisk");
1036 system("/etc/halt");
1041 int modprobe (char *mod
) {
1042 char commandstring
[STRING_SIZE
];
1043 sprintf (commandstring
,"/sbin/modprobe %s", mod
);
1044 return mysystem (commandstring
);
1047 int rmmod (char *mod
) {
1048 char commandstring
[STRING_SIZE
];
1049 sprintf (commandstring
,"/sbin/rmmod %s", mod
);
1050 return mysystem (commandstring
);