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.57 2005/09/25 19:57:46 gespinasse Exp $
15 #define CDROM_INSTALL 0
25 extern char url
[STRING_SIZE
];
48 int main(int argc
, char *argv
[])
51 char *langnames
[] = { "English", NULL
};
52 char *shortlangnames
[] = { "en", NULL
};
53 char **langtrs
[] = { en_tr
, NULL
};
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
};
59 char *langnames
[] = { "Deutsch", "English", NULL
};
60 char *shortlangnames
[] = { "de", "en", NULL
};
61 char **langtrs
[] = { de_tr
, en_tr
, NULL
};
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. */
68 char commandstring
[STRING_SIZE
];
69 char *installtypes
[] = { "CDROM", "HTTP/FTP", NULL
};
70 int installtype
= CDROM_INSTALL
;
71 char insertmessage
[STRING_SIZE
];
72 char insertdevnode
[STRING_SIZE
];
74 char shortlangname
[10];
76 char title
[STRING_SIZE
];
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
;
86 int log_partition
, boot_partition
, root_partition
, swap_file
;
95 setlocale (LC_ALL
, "");
96 sethostname( SNAME
, 10);
98 memset(&hdparams
, 0, sizeof(struct devparams
));
99 memset(&cdromparams
, 0, sizeof(struct devparams
));
101 /* Log file/terminal stuff. */
104 if (!(flog
= fopen(argv
[1], "w+")))
112 fprintf(flog
, "Install program started.\n");
117 /* Do usb detection first for usb keyboard */
118 if (! (cmdfile
= fopen("/proc/cmdline", "r")))
120 fprintf(flog
, "Couldn't open commandline: /proc/cmdline\n");
122 fgets(line
, STRING_SIZE
, cmdfile
);
123 if (strstr (line
, "fdisk") != NULL
) {
124 fprintf(flog
, "Manual FDISK selected.\n");
127 if (strstr (line
, "nopcmcia") == NULL
) {
128 fprintf(flog
, "Initializing PCMCIA controllers.\n");
129 pcmcia
= initialize_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 */
139 fprintf (flog
, "Detected No PCMCIA Controller.\n");
142 fprintf(flog
, "Skipping PCMCIA detection.\n");
144 if (strstr (line
, "nousb") == NULL
) {
145 fprintf(flog
, "Initializing USB controllers.\n");
148 fprintf(flog
, "Skipping USB detection.\n");
152 /* Deutsch is the default */
153 for (choice
= 0; langnames
[choice
]; choice
++)
155 if (strcmp(langnames
[choice
], "Deutsch") == 0)
158 if (!langnames
[choice
])
162 /* No need to ask. "choice" already has the index for English */
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
);
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");
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");
187 mysystem("/bin/setfont lat0-16");
189 newtDrawRootText(14, 0, NAME
" v" VERSION
" - " SLOGAN
);
190 newtPushHelpLine(ctr
[TR_HELPLINE
]);
192 sprintf(message
, ctr
[TR_WELCOME
], NAME
);
193 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
194 newtWinMessage(title
, ctr
[TR_OK
], message
);
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);
203 * This is for avoiding the question for a network installation. Set to cdrom.
205 sprintf(installtype
, CDROM_INSTALL
, NAME
);
207 if (installtype
== CDROM_INSTALL
)
209 /* First look for an IDE CDROM. */
210 if (!(cdletter
= findidetype(IDE_CDROM
)))
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
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
);
222 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
226 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
228 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
234 /* trying to support SCSI pcmcia :-) */
235 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
236 ctr
[TR_LOADING_PCMCIA
]);
237 if (try_scsi("scd0"))
241 /* try loading all SCSI modules with default options */
242 /* Should expand this to allow options later though */
244 runcommandwithstatus("/bin/probescsi.sh",
245 ctr
[TR_PROBING_SCSI
]);
247 /* If it fails, give up. */
248 if (!(try_scsi("scd0"))) {
249 errorbox(ctr
[TR_NO_CDROM
]);
254 sprintf(cdromdrive
, "scd0");
257 sprintf(cdromdrive
, "hd%c", cdletter
);
261 snprintf(cdromparams
.devnode
, STRING_SIZE
, "/dev/%s", cdromdrive
);
262 cdromparams
.module
= 0;
264 sprintf(insertmessage
, ctr
[TR_INSERT_CDROM
], NAME
);
265 strcpy (insertdevnode
, cdromparams
.devnode
);
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"))) {
272 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
);
273 strcpy (insertdevnode
, "/dev/floppy");
281 if (scsi_cdrom
|| ide_cdrom
) {
282 /* Try to mount /cdrom in a loop. */
283 snprintf(commandstring
, STRING_SIZE
, "/bin/mount -o ro %s /cdrom", insertdevnode
);
286 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
289 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
292 if (!(mysystem(commandstring
))) {
293 handle
= fopen ("/cdrom/" SNAME
"-" VERSION
".tgz", "r");
294 if (handle
!= NULL
) {
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
,
304 175, ctr
[TR_EXTRACTING_MODULES
]))
306 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
313 mysystem ("/bin/umount /cdrom");
318 snprintf(commandstring
, STRING_SIZE
, "/bin/tar -C / -xvzf /dev/floppy");
321 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
324 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
327 if (runcommandwithprogress(60, 4, title
,
329 175, ctr
[TR_EXTRACTING_MODULES
]))
331 #if 0 /* disable this, so we allow for people putting in the wrong disk */
332 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
338 handle
= fopen ("/bin/mke2fs", "r");
339 if (handle
!= NULL
) {
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");
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");
360 fprintf (flog
, "Detected No PCMCIA Controller.\n");
363 fprintf(flog
, "Skipping PCMCIA detection.\n");
365 if (strstr (line
, "nousb") == NULL
) {
366 fprintf(flog
, "Initializing USB controllers.\n");
369 fprintf(flog
, "Skipping USB detection.\n");
374 /* Configure the network now! */
375 if (installtype
== URL_INSTALL
)
377 /* Network driver and params. */
378 if (!(networkmenu(ethernetkv
)))
380 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
384 /* Check for ipfire-<VERSION>.tgz */
385 if (!(checktarball(SNAME
"-" VERSION
".tgz")))
387 errorbox(ctr
[TR_NO_IPCOP_TARBALL_FOUND
]);
392 /* Get device for the HD. This has to succeed. */
393 if (!(hdletter
= findidetype(IDE_HD
)))
395 if (installtype
== URL_INSTALL
)
397 /* If we've done a PXE boot, we can skip the SCSI
398 * floppy as we've already got the modules in our
400 if (!(handle
= fopen("/CDROMBOOT", "r")))
402 /* search img where it is on a mounted loop iso */
403 sprintf(string
, "images/scsidrv-%s.img", VERSION
);
404 if (!(checktarball(string
)))
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
);
414 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
418 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
420 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
425 snprintf(commandstring
, STRING_SIZE
,
426 "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -",
428 if (runcommandwithprogress(60, 4, title
, commandstring
,
429 4500, ctr
[TR_INSTALLING_FILES
]))
431 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
439 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/scsidrv-%s.img", VERSION
);
440 if (runcommandwithstatus(string
, ctr
[TR_EXTRACTING_MODULES
]))
442 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
453 /* trying to support SCSI pcmcia :-) */
454 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
455 ctr
[TR_LOADING_PCMCIA
]);
461 /* try loading all SCSI modules with default options */
462 /* Should expand this to allow options later though */
464 runcommandwithstatus("/bin/probescsi.sh",
465 ctr
[TR_PROBING_SCSI
]);
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
]);
478 sprintf(harddrive
, "ataraid/d0");
482 sprintf(harddrive
, "rd/c0d0");
486 sprintf(harddrive
, "cciss/c0d0");
490 sprintf(harddrive
, "ida/c0d0");
493 sprintf(harddrive
, "sda");
497 sprintf(harddrive
, "hd%c", hdletter
);
499 /* Make the hdparms struct and print the contents. */
500 snprintf(hdparams
.devnode
, STRING_SIZE
, "/dev/%s", harddrive
);
503 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
],
504 ctr
[TR_PREPARE_HARDDISK
], hdparams
.devnode
);
508 /* Calculate amount of memory in machine */
509 if ((handle
= fopen("/proc/meminfo", "r")))
511 while (fgets(line
, STRING_SIZE
-1, handle
)) {
512 if (sscanf (line
, "MemTotal: %s kB", string
)) {
513 memory
= atoi(string
) / 1024 ;
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
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
);
528 /* Calculate amount of disk space */
529 if ((handle
= fopen("/disksize", "r")))
531 fgets(line
, STRING_SIZE
-1, handle
);
532 if (sscanf (line
, "%s", string
)) {
533 maximum_free
= atoi(string
) / 1024;
538 fprintf(flog
, "maximum_free = %d, memory = %d",
539 maximum_free
, memory
);
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
;
546 if (maximum_free
< 135 + swap_file
)
548 if (maximum_free
< 135) {
549 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
553 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], ctr
[TR_CONTINUE_NO_SWAP
]);
559 boot_partition
= 8; /* in MB */
560 current_free
= maximum_free
- boot_partition
- swap_file
;
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
;
568 current_free
= current_free
- root_partition
;
569 root_partition
= root_partition
+ swap_file
;
571 log_partition
= current_free
;
573 fprintf(flog
, "boot = %d, swap = %d, mylog = %d, root = %d\n",
574 boot_partition
, swap_file
, log_partition
, root_partition
);
582 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], "NOW FDISK");
587 handle
= fopen("/tmp/partitiontable", "w");
589 fprintf(handle
, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n",
590 boot_partition
, log_partition
);
594 snprintf(commandstring
, STRING_SIZE
, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams
.devnode
);
595 if (runcommandwithstatus(commandstring
, ctr
[TR_PARTITIONING_DISK
]))
597 errorbox(ctr
[TR_UNABLE_TO_PARTITION
]);
604 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %sp1", hdparams
.devnode
);
606 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %s1", hdparams
.devnode
);
607 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_BOOT_FILESYSTEM
]))
609 errorbox(ctr
[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM
]);
613 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %sp2", hdparams
.devnode
);
615 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %s2", hdparams
.devnode
);
616 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_LOG_FILESYSTEM
]))
618 errorbox(ctr
[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM
]);
622 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %sp4", hdparams
.devnode
);
624 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %s4", hdparams
.devnode
);
626 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_ROOT_FILESYSTEM
]))
628 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
631 /* Mount harddisk. */
633 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp4 /harddisk", hdparams
.devnode
);
635 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s4 /harddisk", hdparams
.devnode
);
636 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_ROOT_FILESYSTEM
]))
638 errorbox(ctr
[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM
]);
643 snprintf(commandstring
, STRING_SIZE
, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file
);
644 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
646 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
649 snprintf(commandstring
, STRING_SIZE
, "/bin/mkswap /harddisk/swapfile");
650 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
652 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
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
);
661 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp1 /harddisk/boot", hdparams
.devnode
);
663 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams
.devnode
);
665 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_BOOT_FILESYSTEM
]))
667 errorbox(ctr
[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM
]);
671 snprintf(commandstring
, STRING_SIZE
, "/bin/swapon /harddisk/swapfile");
672 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_SWAP_PARTITION
]))
674 errorbox(ctr
[TR_UNABLE_TO_MOUNT_SWAP_PARTITION
]);
679 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp2 /harddisk/var/log", hdparams
.devnode
);
681 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams
.devnode
);
682 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_LOG_FILESYSTEM
]))
684 errorbox(ctr
[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM
]);
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");
693 snprintf(commandstring
, STRING_SIZE
,
694 "/bin/wget -O - %s/" SNAME
"-" VERSION
".tgz | /bin/tar -C /harddisk -xvzf -", url
);
696 /* if (runcommandwithprogress(60, 4, title, commandstring, 4600,
697 * ctr[TR_INSTALLING_FILES]))
699 * errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
704 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_FILES
]))
706 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
710 /* Save USB controller type to modules.conf */
711 write_usb_modules_conf();
713 /* touch the modules.dep files */
714 snprintf(commandstring
, STRING_SIZE
,
715 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
717 mysystem(commandstring
);
719 snprintf(commandstring
, STRING_SIZE
,
720 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
722 mysystem(commandstring
);
726 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
728 /* Write PCMCIA Config */
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
);
738 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
739 if (handle
!= NULL
) {
741 fprintf (handle
, "PCMCIA=yes\n");
742 fprintf (handle
, "PCIC=%s\n", pcmcia
);
744 fprintf (handle
, "PCMCIA=no\n");
745 fprintf (handle
, "PCIC=\n");
747 fprintf (handle
, "CARDMGR_OPTS=\n");
748 fprintf (handle
, "SCHEME=\n");
752 /* *always* write disk configuration */
753 if (!(write_disk_configs(&hdparams
))){
754 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
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. */
764 #ifdef OLD_RESTORECFG
766 /* set status variables to nonsense values */
768 /* loop until floppy succeeds or user skips out */
771 sprintf(message
, ctr
[TR_RESTORE_CONFIGURATION
], NAME
);
772 if (newtWinChoice(title
, ctr
[TR_RESTORE
], ctr
[TR_SKIP
], message
) == 1)
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
]);
782 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
783 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_FSTAB
]);
786 mysystem("/bin/umount /harddisk/proc");
788 mkdir("/harddisk/tmp/ipcop", S_IRWXU
|S_IRWXG
|S_IRWXO
);
790 /* Always extract to /tmp/ipcop for temporary extraction
791 * just in case floppy fails */
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
);
799 statuswindow(45, 4, title
, ctr
[TR_INSTALLING_FILES
]);
800 rc
= system(commandstring
);
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
);
809 /* command failed trying to read from floppy */
810 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
812 /* remove badly restored files */
813 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
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");
822 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
825 break; /* out of loop at this point because floppy has
826 successfully restored */
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");
836 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
839 break; /* out of loop at this point because floppy has
840 successfully restored */
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. */
849 if (!(networkmenu(ethernetkv
))){
850 /* network setup failed, tell the world */
851 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
855 break; /* out of loop because we succeeded with ethernet
856 set up and user is notrestarting from floppy*/
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. */
865 if (!(networkmenu(ethernetkv
))){
866 /* network setup failed, tell the world */
867 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
873 /* Check the SQUID acl file exists, if not use our 1.4 copy */
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");
881 unlink ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4");
884 chown ("/harddisk" CONFIG_ROOT
"/proxy/acl", 99, 99);
887 /* Build cache lang file */
888 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
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
]);
900 /* if we detected SCSI then fixup */
901 if ((handle
= fopen("/scsidriver", "r")))
904 fgets(line
, STRING_SIZE
-1, 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) {
910 fprintf(flog
, "Fixing up ipfirerd.img\n");
911 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
912 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
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
);
914 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
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
);
917 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
918 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
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
]);
930 fprintf(flog
, "Detected SCSI driver PCMCIA\n");
931 fprintf(flog
, "Fixing up ipfirerd.img\n");
932 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
933 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
934 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipfirerd.img", KERNEL_VERSION
);
935 mysystem(commandstring
);
937 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
940 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
946 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode
);
947 /* restore permissions */
948 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
951 sprintf(string
, "root=%sp4", hdparams
.devnode
);
953 sprintf(string
, "root=%s4", hdparams
.devnode
);
954 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
956 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
958 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /boot/grub/grubbatch");
960 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_GRUB
]))
962 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
966 if ((handle
= fopen("/scsidriver", "r")))
967 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf >> /harddisk/boot/ipfirerd.img");
969 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf > /harddisk/boot/initrd.splash");
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");
972 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
975 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams
.devnode
);
976 mysystem(commandstring
);
977 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams
.devnode
);
978 mysystem(commandstring
);
980 sprintf(string
, "root=%sp4", hdparams
.devnode
);
982 sprintf(string
, "root=%s4", hdparams
.devnode
);
983 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string
);
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
989 anything and still succeed. */
991 if (!unmount_before
&& installtype
== CDROM_INSTALL
){
992 if (mysystem("/sbin/umount /cdrom"))
994 errorbox(ctr
[TR_UNABLE_TO_UNMOUNT_CDROM
]);
999 if (installtype
== CDROM_INSTALL
)
1002 if (!(ejectcdrom(cdromparams
.devnode
)))
1004 errorbox(ctr
[TR_UNABLE_TO_EJECT_CDROM
]);
1010 sprintf(message
, ctr
[TR_CONGRATULATIONS_LONG
],
1011 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
1012 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
1017 fprintf(flog
, "Install program ended.\n");
1022 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
1026 freekeyvalues(ethernetkv
);
1028 if (allok
&& !allok_fastexit
)
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.");
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");
1045 system("/bin/swapoff /harddisk/swapfile");
1046 system("/sbin/umount /harddisk/var/log");
1047 system("/sbin/umount /harddisk/boot");
1048 system("/sbin/umount /harddisk");
1050 system("/etc/halt");