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.
13 #define CDROM_INSTALL 0
23 extern char url
[STRING_SIZE
];
28 int main(int argc
, char *argv
[])
31 char *langnames
[] = { "English", NULL
};
32 char *shortlangnames
[] = { "en", NULL
};
33 char **langtrs
[] = { en_tr
, NULL
};
35 char *langnames
[] = { "Deutsch", "English", NULL
};
36 char *shortlangnames
[] = { "de", "en", NULL
};
37 char **langtrs
[] = { de_tr
, en_tr
, NULL
};
39 char hdletter
, cdletter
;
40 char harddrive
[5], cdromdrive
[5]; /* Device holder. */
41 struct devparams hdparams
, cdromparams
; /* Params for CDROM and HD */
42 int cdmounted
= 0; /* Loop flag for inserting a cd. */
44 char commandstring
[STRING_SIZE
];
45 char *installtypes
[] = { "CDROM", "HTTP/FTP", NULL
};
46 int installtype
= CDROM_INSTALL
;
47 char insertmessage
[STRING_SIZE
];
48 char insertdevnode
[STRING_SIZE
];
50 char shortlangname
[10];
52 char title
[STRING_SIZE
];
56 struct keyvalue
*ethernetkv
= initkeyvalues();
57 FILE *handle
, *cmdfile
;
58 char line
[STRING_SIZE
];
59 char string
[STRING_SIZE
];
60 int maximum_free
= 0, current_free
;
62 int log_partition
, boot_partition
, root_partition
, swap_file
;
71 setlocale (LC_ALL
, "");
72 sethostname( SNAME
, 10);
74 memset(&hdparams
, 0, sizeof(struct devparams
));
75 memset(&cdromparams
, 0, sizeof(struct devparams
));
77 /* Log file/terminal stuff. */
80 if (!(flog
= fopen(argv
[1], "w+")))
88 fprintf(flog
, "Install program started.\n");
93 /* Do usb detection first for usb keyboard */
94 if (! (cmdfile
= fopen("/proc/cmdline", "r")))
96 fprintf(flog
, "Couldn't open commandline: /proc/cmdline\n");
98 fgets(line
, STRING_SIZE
, cmdfile
);
99 if (strstr (line
, "fdisk") != NULL
) {
100 fprintf(flog
, "Manual FDISK selected.\n");
103 if (strstr (line
, "nopcmcia") == NULL
) {
104 fprintf(flog
, "Initializing PCMCIA controllers.\n");
105 pcmcia
= initialize_pcmcia();
107 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
108 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
109 mysystem("/sbin/modprobe pcmcia_core");
110 mysystem(commandstring
);
111 mysystem("/sbin/modprobe ds");
112 /* pcmcia netcard drivers are not available from Boot floppy,
113 * they will be loaded from Drivers floppy later */
115 fprintf (flog
, "Detected No PCMCIA Controller.\n");
118 fprintf(flog
, "Skipping PCMCIA detection.\n");
120 if (strstr (line
, "nousb") == NULL
) {
121 fprintf(flog
, "Initializing USB controllers.\n");
124 fprintf(flog
, "Skipping USB detection.\n");
128 /* Deutsch is the default */
129 for (choice
= 0; langnames
[choice
]; choice
++)
131 if (strcmp(langnames
[choice
], "Deutsch") == 0)
134 if (!langnames
[choice
])
138 /* No need to ask. "choice" already has the index for English */
140 rc
= newtWinMenu("Language selection",
141 "Select the language you wish to use for your " NAME
".", 50, 5, 5, 8,
142 langnames
, &choice
, "OK", NULL
);
144 ctr
= langtrs
[choice
];
145 strcpy(shortlangname
, shortlangnames
[choice
]);
147 mysystem("/bin/setfont lat0-16");
149 newtDrawRootText(14, 0, NAME
" v" VERSION
" - " SLOGAN
);
150 newtPushHelpLine(ctr
[TR_HELPLINE
]);
152 sprintf(message
, ctr
[TR_WELCOME
], NAME
);
153 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
154 newtWinMessage(title
, ctr
[TR_OK
], message
);
156 sprintf(message
, ctr
[TR_SELECT_INSTALLATION_MEDIA_LONG
], NAME
);
157 rc
= newtWinMenu(ctr
[TR_SELECT_INSTALLATION_MEDIA
], message
,
158 50, 5, 5, 6, installtypes
, &installtype
, ctr
[TR_OK
],
159 ctr
[TR_CANCEL
], NULL
);
164 if (installtype
== CDROM_INSTALL
)
166 /* First look for an IDE CDROM. */
167 if (!(cdletter
= findidetype(IDE_CDROM
)))
169 /* If we have a USB attached CDROM then it will
170 * have already appeared at /dev/scd0, so we
171 * try to access it first, before asking for the
174 if (!(try_scsi("scd0"))) {
175 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
176 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
179 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
183 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
185 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
191 /* trying to support SCSI pcmcia :-) */
192 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
193 ctr
[TR_LOADING_PCMCIA
]);
194 if (try_scsi("scd0"))
198 /* try loading all SCSI modules with default options */
199 /* Should expand this to allow options later though */
201 runcommandwithstatus("/bin/probescsi.sh",
202 ctr
[TR_PROBING_SCSI
]);
204 /* If it fails, give up. */
205 if (!(try_scsi("scd0"))) {
206 errorbox(ctr
[TR_NO_CDROM
]);
211 sprintf(cdromdrive
, "scd0");
214 sprintf(cdromdrive
, "hd%c", cdletter
);
218 snprintf(cdromparams
.devnode
, STRING_SIZE
, "/dev/%s", cdromdrive
);
219 cdromparams
.module
= 0;
221 sprintf(insertmessage
, ctr
[TR_INSERT_CDROM
], NAME
);
222 strcpy (insertdevnode
, cdromparams
.devnode
);
226 /* If we've done a PXE boot, we can skip the Drivers floppy,
227 * as we've already got the modules in our instroot.gz */
228 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
229 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
);
230 strcpy (insertdevnode
, "/dev/floppy");
238 if (scsi_cdrom
|| ide_cdrom
) {
239 /* Try to mount /cdrom in a loop. */
240 snprintf(commandstring
, STRING_SIZE
, "/bin/mount -o ro %s /cdrom", insertdevnode
);
243 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
246 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
249 if (!(mysystem(commandstring
))) {
250 handle
= fopen ("/cdrom/" SNAME
"-" VERSION
".tgz", "r");
251 if (handle
!= NULL
) {
254 /* If we've booted from CDROM, then
255 * we've already got the drivers,
256 * so we can skip this unpack. */
257 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
258 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/drivers-%s.img", VERSION
);
259 if (runcommandwithprogress(60, 4, title
,
261 175, ctr
[TR_EXTRACTING_MODULES
]))
263 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
270 mysystem ("/bin/umount /cdrom");
275 snprintf(commandstring
, STRING_SIZE
, "/bin/tar -C / -xvzf /dev/floppy");
278 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
281 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
284 if (runcommandwithprogress(60, 4, title
,
286 175, ctr
[TR_EXTRACTING_MODULES
]))
288 #if 0 /* disable this, so we allow for people putting in the wrong disk */
289 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
295 handle
= fopen ("/bin/mke2fs", "r");
296 if (handle
!= NULL
) {
304 /* PCMCIA controller is already detected
305 * On Boot floppy, we didn't have the PCMCIA drivers
306 * so load them now because they are installed from Drivers. */
307 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
308 if (strstr (line
, "nopcmcia") == NULL
) {
309 fprintf(flog
,"Floppy boot detected, loading PCMCIA drivers.\n");
311 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
312 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
313 mysystem("/sbin/modprobe pcmcia_core");
314 mysystem(commandstring
);
315 mysystem("/sbin/modprobe ds");
317 fprintf (flog
, "Detected No PCMCIA Controller.\n");
320 fprintf(flog
, "Skipping PCMCIA detection.\n");
322 if (strstr (line
, "nousb") == NULL
) {
323 fprintf(flog
, "Initializing USB controllers.\n");
326 fprintf(flog
, "Skipping USB detection.\n");
331 /* Configure the network now! */
332 if (installtype
== URL_INSTALL
)
334 /* Network driver and params. */
335 if (!(networkmenu(ethernetkv
)))
337 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
341 /* Check for ipfire-<VERSION>.tgz */
342 if (!(checktarball(SNAME
"-" VERSION
".tgz")))
344 errorbox(ctr
[TR_NO_IPCOP_TARBALL_FOUND
]);
349 /* Get device for the HD. This has to succeed. */
350 if (!(hdletter
= findidetype(IDE_HD
)))
352 if (installtype
== URL_INSTALL
)
354 /* If we've done a PXE boot, we can skip the SCSI
355 * floppy as we've already got the modules in our
357 if (!(handle
= fopen("/CDROMBOOT", "r")))
359 /* search img where it is on a mounted loop iso */
360 sprintf(string
, "images/scsidrv-%s.img", VERSION
);
361 if (!(checktarball(string
)))
363 /* Couldn't find the SCSI drivers on the URL page,
364 * so after 3 failed attempts, ask the user for the
365 * SCSI drivers floppy disk. */
366 errorbox(ctr
[TR_NO_SCSI_IMAGE_FOUND
]);
367 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
368 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
371 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
375 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
377 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
382 snprintf(commandstring
, STRING_SIZE
,
383 "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -",
385 if (runcommandwithprogress(60, 4, title
, commandstring
,
386 4500, ctr
[TR_INSTALLING_FILES
]))
388 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
396 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/scsidrv-%s.img", VERSION
);
397 if (runcommandwithstatus(string
, ctr
[TR_EXTRACTING_MODULES
]))
399 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
410 /* trying to support SCSI pcmcia :-) */
411 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
412 ctr
[TR_LOADING_PCMCIA
]);
418 /* try loading all SCSI modules with default options */
419 /* Should expand this to allow options later though */
421 runcommandwithstatus("/bin/probescsi.sh",
422 ctr
[TR_PROBING_SCSI
]);
425 /* Need to clean this up at some point */
426 if (!try_scsi("sda")) {
427 if (!try_scsi("ida/c0d0")) {
428 if (!try_scsi("cciss/c0d0")) {
429 if (!try_scsi("rd/c0d0")) {
430 if (!try_scsi("ataraid/d0")) {
431 errorbox(ctr
[TR_NO_HARDDISK
]);
435 sprintf(harddrive
, "ataraid/d0");
439 sprintf(harddrive
, "rd/c0d0");
443 sprintf(harddrive
, "cciss/c0d0");
447 sprintf(harddrive
, "ida/c0d0");
450 sprintf(harddrive
, "sda");
454 sprintf(harddrive
, "hd%c", hdletter
);
456 /* Make the hdparms struct and print the contents. */
457 snprintf(hdparams
.devnode
, STRING_SIZE
, "/dev/%s", harddrive
);
460 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
],
461 ctr
[TR_PREPARE_HARDDISK
], hdparams
.devnode
);
465 /* Calculate amount of memory in machine */
466 if ((handle
= fopen("/proc/meminfo", "r")))
468 while (fgets(line
, STRING_SIZE
-1, handle
)) {
469 if (sscanf (line
, "MemTotal: %s kB", string
)) {
470 memory
= atoi(string
) / 1024 ;
476 /* Partition, mkswp, mkfs.
477 * before partitioning, first determine the sizes of each
478 * partition. In order to do that we need to know the size of
481 /* Don't use mysystem here so we can redirect output */
482 sprintf(commandstring
, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive
);
483 system(commandstring
);
485 /* Calculate amount of disk space */
486 if ((handle
= fopen("/disksize", "r")))
488 fgets(line
, STRING_SIZE
-1, handle
);
489 if (sscanf (line
, "%s", string
)) {
490 maximum_free
= atoi(string
) / 1024;
495 fprintf(flog
, "maximum_free = %d, memory = %d",
496 maximum_free
, memory
);
498 /* If you need more than this, you should really add physical memory */
499 /* Minimum: 192 = 64 real + 128 swap */
500 swap_file
= memory
< 64 ? 2 * memory
: 192 - memory
;
501 swap_file
= swap_file
< 32 ? 32 : swap_file
;
503 if (maximum_free
< 135 + swap_file
)
505 if (maximum_free
< 135) {
506 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
510 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], ctr
[TR_CONTINUE_NO_SWAP
]);
516 boot_partition
= 20; /* in MB */
517 current_free
= maximum_free
- boot_partition
- swap_file
;
519 /* Give more place for add-on, extend root to 25% of current_free, upper limit to 8 gigas */
520 root_partition
= current_free
/ 4 ;
521 root_partition
= root_partition
> 8192 ? 8192 : root_partition
;
522 root_partition
= current_free
< 860 ? 235 : root_partition
;
523 root_partition
= current_free
< 380 ? 110 : root_partition
;
525 current_free
= current_free
- root_partition
;
526 root_partition
= root_partition
+ swap_file
;
528 log_partition
= current_free
;
530 fprintf(flog
, "boot = %d, swap = %d, mylog = %d, root = %d\n",
531 boot_partition
, swap_file
, log_partition
, root_partition
);
539 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], "NOW FDISK");
544 handle
= fopen("/tmp/partitiontable", "w");
546 fprintf(handle
, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n",
547 boot_partition
, log_partition
);
551 snprintf(commandstring
, STRING_SIZE
, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams
.devnode
);
552 if (runcommandwithstatus(commandstring
, ctr
[TR_PARTITIONING_DISK
]))
554 errorbox(ctr
[TR_UNABLE_TO_PARTITION
]);
561 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %sp1", hdparams
.devnode
);
563 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %s1", hdparams
.devnode
);
564 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_BOOT_FILESYSTEM
]))
566 errorbox(ctr
[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM
]);
570 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %sp2", hdparams
.devnode
);
572 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %s2", hdparams
.devnode
);
573 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_LOG_FILESYSTEM
]))
575 errorbox(ctr
[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM
]);
579 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %sp4", hdparams
.devnode
);
581 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %s4", hdparams
.devnode
);
583 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_ROOT_FILESYSTEM
]))
585 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
588 /* Mount harddisk. */
590 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp4 /harddisk", hdparams
.devnode
);
592 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s4 /harddisk", hdparams
.devnode
);
593 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_ROOT_FILESYSTEM
]))
595 errorbox(ctr
[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM
]);
600 snprintf(commandstring
, STRING_SIZE
, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file
);
601 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
603 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
606 snprintf(commandstring
, STRING_SIZE
, "/bin/mkswap /harddisk/swapfile");
607 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
609 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
613 mkdir("/harddisk/boot", S_IRWXU
|S_IRWXG
|S_IRWXO
);
614 mkdir("/harddisk/var", S_IRWXU
|S_IRWXG
|S_IRWXO
);
615 mkdir("/harddisk/var/log", S_IRWXU
|S_IRWXG
|S_IRWXO
);
618 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp1 /harddisk/boot", hdparams
.devnode
);
620 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams
.devnode
);
622 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_BOOT_FILESYSTEM
]))
624 errorbox(ctr
[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM
]);
628 snprintf(commandstring
, STRING_SIZE
, "/bin/swapon /harddisk/swapfile");
629 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_SWAP_PARTITION
]))
631 errorbox(ctr
[TR_UNABLE_TO_MOUNT_SWAP_PARTITION
]);
636 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp2 /harddisk/var/log", hdparams
.devnode
);
638 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams
.devnode
);
639 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_LOG_FILESYSTEM
]))
641 errorbox(ctr
[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM
]);
645 /* Either use tarball from cdrom or download. */
646 if (installtype
== CDROM_INSTALL
)
647 snprintf(commandstring
, STRING_SIZE
,
648 "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME
"-" VERSION
".tgz");
650 snprintf(commandstring
, STRING_SIZE
,
651 "/bin/wget -O - %s/" SNAME
"-" VERSION
".tgz | /bin/tar -C /harddisk -xvzf -", url
);
653 /* if (runcommandwithprogress(60, 4, title, commandstring, 4600,
654 * ctr[TR_INSTALLING_FILES]))
656 * errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
661 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_FILES
]))
663 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
667 /* Save USB controller type to modules.conf */
668 write_usb_modules_conf();
670 /* touch the modules.dep files */
671 snprintf(commandstring
, STRING_SIZE
,
672 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
674 mysystem(commandstring
);
676 snprintf(commandstring
, STRING_SIZE
,
677 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
679 mysystem(commandstring
);
683 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
685 /* Write PCMCIA Config */
687 handle
= fopen("/harddisk/etc/modules.conf", "a");
688 if (handle
!= NULL
) {
689 fprintf (handle
, "# PCMCIA Settings\n");
690 fprintf (handle
, "alias pcmcia-controller %s\n", pcmcia
);
695 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
696 if (handle
!= NULL
) {
698 fprintf (handle
, "PCMCIA=yes\n");
699 fprintf (handle
, "PCIC=%s\n", pcmcia
);
701 fprintf (handle
, "PCMCIA=no\n");
702 fprintf (handle
, "PCIC=\n");
704 fprintf (handle
, "CARDMGR_OPTS=\n");
705 fprintf (handle
, "SCHEME=\n");
709 /* *always* write disk configuration */
710 if (!(write_disk_configs(&hdparams
))){
711 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
716 Allow the user to restore their configuration from a floppy.
717 It uses tar. If the tar fails for any reason, show user an
718 error and go back to the restore/skip question. This gives
719 the user the chance to have another go. */
721 #ifdef OLD_RESTORECFG
723 /* set status variables to nonsense values */
725 /* loop until floppy succeeds or user skips out */
728 sprintf(message
, ctr
[TR_RESTORE_CONFIGURATION
], NAME
);
729 if (newtWinChoice(title
, ctr
[TR_RESTORE
], ctr
[TR_SKIP
], message
) == 1)
731 /* Temporarily mount /proc under /harddisk/proc,
732 * run updfstab to locate the floppy, and unmount /harddisk/proc
733 * again. This should be run each time the user tries to restore
734 * so it can properly detect removable devices */
735 if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
736 errorbox(ctr
[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM
]);
739 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
740 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_FSTAB
]);
743 mysystem("/bin/umount /harddisk/proc");
745 mkdir("/harddisk/tmp/ipcop", S_IRWXU
|S_IRWXG
|S_IRWXO
);
747 /* Always extract to /tmp/ipcop for temporary extraction
748 * just in case floppy fails */
750 /* try a compressed backup first because it's quicker to fail.
751 * In exclude.system, files name must be without leading / or
752 * on extraction, name will never match */
753 snprintf(commandstring
, STRING_SIZE
,
754 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog
);
756 statuswindow(45, 4, title
, ctr
[TR_INSTALLING_FILES
]);
757 rc
= system(commandstring
);
760 /* if it's not compressed, try uncompressed first before failing*/
761 snprintf(commandstring
, STRING_SIZE
,
762 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog
);
763 rc
= system(commandstring
);
766 /* command failed trying to read from floppy */
767 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
769 /* remove badly restored files */
770 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
773 /* Now copy to correct location */
774 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
775 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
779 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
782 break; /* out of loop at this point because floppy has
783 successfully restored */
787 /* Now copy to correct location */
788 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
789 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
793 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
796 break; /* out of loop at this point because floppy has
797 successfully restored */
800 else{ /* user chose to skip install from floppy */
801 if (installtype
== CDROM_INSTALL
){
802 /* if we installed from CD ROM then we didn't set up the
803 network interface yet. Therefore, set up Network
804 driver and params just before we need them. */
806 if (!(networkmenu(ethernetkv
))){
807 /* network setup failed, tell the world */
808 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
812 break; /* out of loop because we succeeded with ethernet
813 set up and user is notrestarting from floppy*/
817 if (installtype
== CDROM_INSTALL
){
818 /* if we installed from CD ROM then we didn't set up the
819 network interface yet. Therefore, set up Network
820 driver and params just before we need them. */
822 if (!(networkmenu(ethernetkv
))){
823 /* network setup failed, tell the world */
824 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
830 /* Check the SQUID acl file exists, if not use our 1.4 copy */
834 if (!(aclreadfile
= fopen ("/harddisk" CONFIG_ROOT
"/proxy/acl", "r"))) {
835 rename ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4",
836 "/harddisk" CONFIG_ROOT
"/proxy/acl");
838 unlink ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4");
841 chown ("/harddisk" CONFIG_ROOT
"/proxy/acl", 99, 99);
844 /* Build cache lang file */
845 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
847 if (!allok_fastexit
){
848 /* write ethernet and lang configs only if they have not
849 been restored from floppy already. */
850 if (!(write_ethernet_configs( ethernetkv
))||
851 !(write_lang_configs(shortlangname
))){
852 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
857 /* if we detected SCSI then fixup */
858 if ((handle
= fopen("/scsidriver", "r")))
861 fgets(line
, STRING_SIZE
-1, handle
);
863 line
[strlen(line
) - 1] = 0;
864 driver
= strtok(line
, ".");
865 fprintf(flog
, "Detected SCSI driver %s\n",driver
);
866 if (strlen(driver
) > 1) {
867 fprintf(flog
, "Fixing up ipfirerd.img\n");
868 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
869 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
870 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
);
871 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
873 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
);
874 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
875 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
878 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
879 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
887 fprintf(flog
, "Detected SCSI driver PCMCIA\n");
888 fprintf(flog
, "Fixing up ipfirerd.img\n");
889 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
890 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
891 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipfirerd.img", KERNEL_VERSION
);
892 mysystem(commandstring
);
894 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
897 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
903 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode
);
904 /* restore permissions */
905 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
908 sprintf(string
, "root=%sp4", hdparams
.devnode
);
910 sprintf(string
, "root=%s4", hdparams
.devnode
);
911 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
913 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
915 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /boot/grub/grubbatch");
917 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_GRUB
]))
919 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
923 mysystem("/bin/installbootsplash.sh");
924 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
927 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams
.devnode
);
928 mysystem(commandstring
);
929 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams
.devnode
);
930 mysystem(commandstring
);
932 sprintf(string
, "root=%sp4", hdparams
.devnode
);
934 sprintf(string
, "root=%s4", hdparams
.devnode
);
935 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string
);
938 /* unmounting happens everywhere because there are places
939 which require device is to be unmounted under certain
940 circumstances. This is the last place we can unmount
941 anything and still succeed. */
943 if (!unmount_before
&& installtype
== CDROM_INSTALL
){
944 if (mysystem("/sbin/umount /cdrom"))
946 errorbox(ctr
[TR_UNABLE_TO_UNMOUNT_CDROM
]);
951 if (installtype
== CDROM_INSTALL
)
954 if (!(ejectcdrom(cdromparams
.devnode
)))
956 errorbox(ctr
[TR_UNABLE_TO_EJECT_CDROM
]);
962 sprintf(message
, ctr
[TR_CONGRATULATIONS_LONG
],
963 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
964 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
969 fprintf(flog
, "Install program ended.\n");
974 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
978 freekeyvalues(ethernetkv
);
980 if (allok
&& !allok_fastexit
)
982 /* /proc is needed by the module checker. We have to mount it
983 * so it can be seen by setup, which is run chrooted. */
984 if (system("/sbin/mount proc -t proc /harddisk/proc"))
985 printf("Unable to mount proc in /harddisk.");
988 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
989 printf("Unable to run setup.\n");
990 if (system("/sbin/umount /harddisk/proc"))
991 printf("Unable to umount /harddisk/proc.\n");
997 system("/bin/swapoff /harddisk/swapfile");
998 system("/sbin/umount /harddisk/var/log");
999 system("/sbin/umount /harddisk/boot");
1000 system("/sbin/umount /harddisk");
1002 system("/etc/halt");