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
);
204 if (installtype
== CDROM_INSTALL
)
206 /* First look for an IDE CDROM. */
207 if (!(cdletter
= findidetype(IDE_CDROM
)))
209 /* If we have a USB attached CDROM then it will
210 * have already appeared at /dev/scd0, so we
211 * try to access it first, before asking for the
214 if (!(try_scsi("scd0"))) {
215 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
216 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
219 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
223 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
225 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
231 /* trying to support SCSI pcmcia :-) */
232 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
233 ctr
[TR_LOADING_PCMCIA
]);
234 if (try_scsi("scd0"))
238 /* try loading all SCSI modules with default options */
239 /* Should expand this to allow options later though */
241 runcommandwithstatus("/bin/probescsi.sh",
242 ctr
[TR_PROBING_SCSI
]);
244 /* If it fails, give up. */
245 if (!(try_scsi("scd0"))) {
246 errorbox(ctr
[TR_NO_CDROM
]);
251 sprintf(cdromdrive
, "scd0");
254 sprintf(cdromdrive
, "hd%c", cdletter
);
258 snprintf(cdromparams
.devnode
, STRING_SIZE
, "/dev/%s", cdromdrive
);
259 cdromparams
.module
= 0;
261 sprintf(insertmessage
, ctr
[TR_INSERT_CDROM
], NAME
);
262 strcpy (insertdevnode
, cdromparams
.devnode
);
266 /* If we've done a PXE boot, we can skip the Drivers floppy,
267 * as we've already got the modules in our instroot.gz */
268 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
269 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
);
270 strcpy (insertdevnode
, "/dev/floppy");
278 if (scsi_cdrom
|| ide_cdrom
) {
279 /* Try to mount /cdrom in a loop. */
280 snprintf(commandstring
, STRING_SIZE
, "/bin/mount -o ro %s /cdrom", insertdevnode
);
283 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
286 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
289 if (!(mysystem(commandstring
))) {
290 handle
= fopen ("/cdrom/" SNAME
"-" VERSION
".tgz", "r");
291 if (handle
!= NULL
) {
294 /* If we've booted from CDROM, then
295 * we've already got the drivers,
296 * so we can skip this unpack. */
297 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
298 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/drivers-%s.img", VERSION
);
299 if (runcommandwithprogress(60, 4, title
,
301 175, ctr
[TR_EXTRACTING_MODULES
]))
303 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
310 mysystem ("/bin/umount /cdrom");
315 snprintf(commandstring
, STRING_SIZE
, "/bin/tar -C / -xvzf /dev/floppy");
318 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
321 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
324 if (runcommandwithprogress(60, 4, title
,
326 175, ctr
[TR_EXTRACTING_MODULES
]))
328 #if 0 /* disable this, so we allow for people putting in the wrong disk */
329 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
335 handle
= fopen ("/bin/mke2fs", "r");
336 if (handle
!= NULL
) {
344 /* PCMCIA controller is already detected
345 * On Boot floppy, we didn't have the PCMCIA drivers
346 * so load them now because they are installed from Drivers. */
347 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
348 if (strstr (line
, "nopcmcia") == NULL
) {
349 fprintf(flog
,"Floppy boot detected, loading PCMCIA drivers.\n");
351 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
352 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
353 mysystem("/sbin/modprobe pcmcia_core");
354 mysystem(commandstring
);
355 mysystem("/sbin/modprobe ds");
357 fprintf (flog
, "Detected No PCMCIA Controller.\n");
360 fprintf(flog
, "Skipping PCMCIA detection.\n");
362 if (strstr (line
, "nousb") == NULL
) {
363 fprintf(flog
, "Initializing USB controllers.\n");
366 fprintf(flog
, "Skipping USB detection.\n");
371 /* Configure the network now! */
372 if (installtype
== URL_INSTALL
)
374 /* Network driver and params. */
375 if (!(networkmenu(ethernetkv
)))
377 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
381 /* Check for ipcop-<VERSION>.tgz */
382 if (!(checktarball(SNAME
"-" VERSION
".tgz")))
384 errorbox(ctr
[TR_NO_IPCOP_TARBALL_FOUND
]);
389 /* Get device for the HD. This has to succeed. */
390 if (!(hdletter
= findidetype(IDE_HD
)))
392 if (installtype
== URL_INSTALL
)
394 /* If we've done a PXE boot, we can skip the SCSI
395 * floppy as we've already got the modules in our
397 if (!(handle
= fopen("/CDROMBOOT", "r")))
399 /* search img where it is on a mounted loop iso */
400 sprintf(string
, "images/scsidrv-%s.img", VERSION
);
401 if (!(checktarball(string
)))
403 /* Couldn't find the SCSI drivers on the URL page,
404 * so after 3 failed attempts, ask the user for the
405 * SCSI drivers floppy disk. */
406 errorbox(ctr
[TR_NO_SCSI_IMAGE_FOUND
]);
407 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
408 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
411 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
415 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
417 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
422 snprintf(commandstring
, STRING_SIZE
,
423 "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -",
425 if (runcommandwithprogress(60, 4, title
, commandstring
,
426 4500, ctr
[TR_INSTALLING_FILES
]))
428 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
436 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/scsidrv-%s.img", VERSION
);
437 if (runcommandwithstatus(string
, ctr
[TR_EXTRACTING_MODULES
]))
439 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
450 /* trying to support SCSI pcmcia :-) */
451 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
452 ctr
[TR_LOADING_PCMCIA
]);
458 /* try loading all SCSI modules with default options */
459 /* Should expand this to allow options later though */
461 runcommandwithstatus("/bin/probescsi.sh",
462 ctr
[TR_PROBING_SCSI
]);
465 /* Need to clean this up at some point */
466 if (!try_scsi("sda")) {
467 if (!try_scsi("ida/c0d0")) {
468 if (!try_scsi("cciss/c0d0")) {
469 if (!try_scsi("rd/c0d0")) {
470 if (!try_scsi("ataraid/d0")) {
471 errorbox(ctr
[TR_NO_HARDDISK
]);
475 sprintf(harddrive
, "ataraid/d0");
479 sprintf(harddrive
, "rd/c0d0");
483 sprintf(harddrive
, "cciss/c0d0");
487 sprintf(harddrive
, "ida/c0d0");
490 sprintf(harddrive
, "sda");
494 sprintf(harddrive
, "hd%c", hdletter
);
496 /* Make the hdparms struct and print the contents. */
497 snprintf(hdparams
.devnode
, STRING_SIZE
, "/dev/%s", harddrive
);
500 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
],
501 ctr
[TR_PREPARE_HARDDISK
], hdparams
.devnode
);
505 /* Calculate amount of memory in machine */
506 if ((handle
= fopen("/proc/meminfo", "r")))
508 while (fgets(line
, STRING_SIZE
-1, handle
)) {
509 if (sscanf (line
, "MemTotal: %s kB", string
)) {
510 memory
= atoi(string
) / 1024 ;
516 /* Partition, mkswp, mkfs.
517 * before partitioning, first determine the sizes of each
518 * partition. In order to do that we need to know the size of
521 /* Don't use mysystem here so we can redirect output */
522 sprintf(commandstring
, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive
);
523 system(commandstring
);
525 /* Calculate amount of disk space */
526 if ((handle
= fopen("/disksize", "r")))
528 fgets(line
, STRING_SIZE
-1, handle
);
529 if (sscanf (line
, "%s", string
)) {
530 maximum_free
= atoi(string
) / 1024;
535 fprintf(flog
, "maximum_free = %d, memory = %d",
536 maximum_free
, memory
);
538 /* If you need more than this, you should really add physical memory */
539 /* Minimum: 192 = 64 real + 128 swap */
540 swap_file
= memory
< 64 ? 2 * memory
: 192 - memory
;
541 swap_file
= swap_file
< 32 ? 32 : swap_file
;
543 if (maximum_free
< 135 + swap_file
)
545 if (maximum_free
< 135) {
546 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
550 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], ctr
[TR_CONTINUE_NO_SWAP
]);
556 boot_partition
= 8; /* in MB */
557 current_free
= maximum_free
- boot_partition
- swap_file
;
559 /* Give more place for add-on, extend root to 25% of current_free, upper limit to 8 gigas */
560 root_partition
= current_free
/ 4 ;
561 root_partition
= root_partition
> 8192 ? 8192 : root_partition
;
562 root_partition
= current_free
< 860 ? 235 : root_partition
;
563 root_partition
= current_free
< 380 ? 110 : root_partition
;
565 current_free
= current_free
- root_partition
;
566 root_partition
= root_partition
+ swap_file
;
568 log_partition
= current_free
;
570 fprintf(flog
, "boot = %d, swap = %d, mylog = %d, root = %d\n",
571 boot_partition
, swap_file
, log_partition
, root_partition
);
579 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], "NOW FDISK");
584 handle
= fopen("/tmp/partitiontable", "w");
586 fprintf(handle
, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n",
587 boot_partition
, log_partition
);
591 snprintf(commandstring
, STRING_SIZE
, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams
.devnode
);
592 if (runcommandwithstatus(commandstring
, ctr
[TR_PARTITIONING_DISK
]))
594 errorbox(ctr
[TR_UNABLE_TO_PARTITION
]);
601 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %sp1", hdparams
.devnode
);
603 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %s1", hdparams
.devnode
);
604 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_BOOT_FILESYSTEM
]))
606 errorbox(ctr
[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM
]);
610 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %sp2", hdparams
.devnode
);
612 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %s2", hdparams
.devnode
);
613 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_LOG_FILESYSTEM
]))
615 errorbox(ctr
[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM
]);
619 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %sp4", hdparams
.devnode
);
621 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %s4", hdparams
.devnode
);
623 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_ROOT_FILESYSTEM
]))
625 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
628 /* Mount harddisk. */
630 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp4 /harddisk", hdparams
.devnode
);
632 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s4 /harddisk", hdparams
.devnode
);
633 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_ROOT_FILESYSTEM
]))
635 errorbox(ctr
[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM
]);
640 snprintf(commandstring
, STRING_SIZE
, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file
);
641 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
643 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
646 snprintf(commandstring
, STRING_SIZE
, "/bin/mkswap /harddisk/swapfile");
647 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
649 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
653 mkdir("/harddisk/boot", S_IRWXU
|S_IRWXG
|S_IRWXO
);
654 mkdir("/harddisk/var", S_IRWXU
|S_IRWXG
|S_IRWXO
);
655 mkdir("/harddisk/var/log", S_IRWXU
|S_IRWXG
|S_IRWXO
);
658 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp1 /harddisk/boot", hdparams
.devnode
);
660 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams
.devnode
);
662 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_BOOT_FILESYSTEM
]))
664 errorbox(ctr
[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM
]);
668 snprintf(commandstring
, STRING_SIZE
, "/bin/swapon /harddisk/swapfile");
669 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_SWAP_PARTITION
]))
671 errorbox(ctr
[TR_UNABLE_TO_MOUNT_SWAP_PARTITION
]);
676 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp2 /harddisk/var/log", hdparams
.devnode
);
678 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams
.devnode
);
679 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_LOG_FILESYSTEM
]))
681 errorbox(ctr
[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM
]);
685 /* Either use tarball from cdrom or download. */
686 if (installtype
== CDROM_INSTALL
)
687 snprintf(commandstring
, STRING_SIZE
,
688 "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME
"-" VERSION
".tgz");
690 snprintf(commandstring
, STRING_SIZE
,
691 "/bin/wget -O - %s/" SNAME
"-" VERSION
".tgz | /bin/tar -C /harddisk -xvzf -", url
);
693 if (runcommandwithprogress(60, 4, title
, commandstring
, 4600,
694 ctr
[TR_INSTALLING_FILES
]))
696 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
700 /* Save USB controller type to modules.conf */
701 write_usb_modules_conf();
703 /* touch the modules.dep files */
704 snprintf(commandstring
, STRING_SIZE
,
705 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
707 mysystem(commandstring
);
709 snprintf(commandstring
, STRING_SIZE
,
710 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
712 mysystem(commandstring
);
716 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
718 /* Write PCMCIA Config */
720 handle
= fopen("/harddisk/etc/modules.conf", "a");
721 if (handle
!= NULL
) {
722 fprintf (handle
, "# PCMCIA Settings\n");
723 fprintf (handle
, "alias pcmcia-controller %s\n", pcmcia
);
728 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
729 if (handle
!= NULL
) {
731 fprintf (handle
, "PCMCIA=yes\n");
732 fprintf (handle
, "PCIC=%s\n", pcmcia
);
734 fprintf (handle
, "PCMCIA=no\n");
735 fprintf (handle
, "PCIC=\n");
737 fprintf (handle
, "CARDMGR_OPTS=\n");
738 fprintf (handle
, "SCHEME=\n");
742 /* *always* write disk configuration */
743 if (!(write_disk_configs(&hdparams
))){
744 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
749 Allow the user to restore their configuration from a floppy.
750 It uses tar. If the tar fails for any reason, show user an
751 error and go back to the restore/skip question. This gives
752 the user the chance to have another go. */
754 #ifdef OLD_RESTORECFG
756 /* set status variables to nonsense values */
758 /* loop until floppy succeeds or user skips out */
761 sprintf(message
, ctr
[TR_RESTORE_CONFIGURATION
], NAME
);
762 if (newtWinChoice(title
, ctr
[TR_RESTORE
], ctr
[TR_SKIP
], message
) == 1)
764 /* Temporarily mount /proc under /harddisk/proc,
765 * run updfstab to locate the floppy, and unmount /harddisk/proc
766 * again. This should be run each time the user tries to restore
767 * so it can properly detect removable devices */
768 if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
769 errorbox(ctr
[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM
]);
772 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
773 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_FSTAB
]);
776 mysystem("/bin/umount /harddisk/proc");
778 mkdir("/harddisk/tmp/ipcop", S_IRWXU
|S_IRWXG
|S_IRWXO
);
780 /* Always extract to /tmp/ipcop for temporary extraction
781 * just in case floppy fails */
783 /* try a compressed backup first because it's quicker to fail.
784 * In exclude.system, files name must be without leading / or
785 * on extraction, name will never match */
786 snprintf(commandstring
, STRING_SIZE
,
787 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog
);
789 statuswindow(45, 4, title
, ctr
[TR_INSTALLING_FILES
]);
790 rc
= system(commandstring
);
793 /* if it's not compressed, try uncompressed first before failing*/
794 snprintf(commandstring
, STRING_SIZE
,
795 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog
);
796 rc
= system(commandstring
);
799 /* command failed trying to read from floppy */
800 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
802 /* remove badly restored files */
803 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
806 /* Now copy to correct location */
807 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
808 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
812 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
815 break; /* out of loop at this point because floppy has
816 successfully restored */
820 /* Now copy to correct location */
821 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
822 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
826 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
829 break; /* out of loop at this point because floppy has
830 successfully restored */
833 else{ /* user chose to skip install from floppy */
834 if (installtype
== CDROM_INSTALL
){
835 /* if we installed from CD ROM then we didn't set up the
836 network interface yet. Therefore, set up Network
837 driver and params just before we need them. */
839 if (!(networkmenu(ethernetkv
))){
840 /* network setup failed, tell the world */
841 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
845 break; /* out of loop because we succeeded with ethernet
846 set up and user is notrestarting from floppy*/
850 if (installtype
== CDROM_INSTALL
){
851 /* if we installed from CD ROM then we didn't set up the
852 network interface yet. Therefore, set up Network
853 driver and params just before we need them. */
855 if (!(networkmenu(ethernetkv
))){
856 /* network setup failed, tell the world */
857 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
863 /* Check the SQUID acl file exists, if not use our 1.4 copy */
867 if (!(aclreadfile
= fopen ("/harddisk" CONFIG_ROOT
"/proxy/acl", "r"))) {
868 rename ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4",
869 "/harddisk" CONFIG_ROOT
"/proxy/acl");
871 unlink ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4");
874 chown ("/harddisk" CONFIG_ROOT
"/proxy/acl", 99, 99);
877 /* Build cache lang file */
878 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
880 if (!allok_fastexit
){
881 /* write ethernet and lang configs only if they have not
882 been restored from floppy already. */
883 if (!(write_ethernet_configs( ethernetkv
))||
884 !(write_lang_configs(shortlangname
))){
885 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
890 /* if we detected SCSI then fixup */
891 if ((handle
= fopen("/scsidriver", "r")))
894 fgets(line
, STRING_SIZE
-1, handle
);
896 line
[strlen(line
) - 1] = 0;
897 driver
= strtok(line
, ".");
898 fprintf(flog
, "Detected SCSI driver %s\n",driver
);
899 if (strlen(driver
) > 1) {
900 fprintf(flog
, "Fixing up ipfirerd.img\n");
901 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
902 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
903 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
);
904 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
906 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
);
907 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
908 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
911 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
912 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
920 fprintf(flog
, "Detected SCSI driver PCMCIA\n");
921 fprintf(flog
, "Fixing up ipfirerd.img\n");
922 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
923 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
924 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipfirerd.img", KERNEL_VERSION
);
925 mysystem(commandstring
);
927 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
930 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
936 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode
);
937 /* restore permissions */
938 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
941 sprintf(string
, "root=%sp4", hdparams
.devnode
);
943 sprintf(string
, "root=%s4", hdparams
.devnode
);
944 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
946 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
948 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /boot/grub/grubbatch");
950 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_GRUB
]))
952 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
956 if ((handle
= fopen("/scsidriver", "r")))
958 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf >> /harddisk/boot/ipfirerd.img");
959 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf >> /harddisk/boot/ipfirerd-smp.img");
963 mysystem("/bin/chroot /harddisk /sbin/splash -s -f /boot/splash/config/bootsplash-1024x768.cgf > /harddisk/boot/initrd.splash");
965 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
968 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams
.devnode
);
969 mysystem(commandstring
);
970 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams
.devnode
);
971 mysystem(commandstring
);
973 sprintf(string
, "root=%sp4", hdparams
.devnode
);
975 sprintf(string
, "root=%s4", hdparams
.devnode
);
976 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string
);
979 /* unmounting happens everywhere because there are places
980 which require device is to be unmounted under certain
981 circumstances. This is the last place we can unmount
982 anything and still succeed. */
984 if (!unmount_before
&& installtype
== CDROM_INSTALL
){
985 if (mysystem("/sbin/umount /cdrom"))
987 errorbox(ctr
[TR_UNABLE_TO_UNMOUNT_CDROM
]);
992 if (installtype
== CDROM_INSTALL
)
995 if (!(ejectcdrom(cdromparams
.devnode
)))
997 errorbox(ctr
[TR_UNABLE_TO_EJECT_CDROM
]);
1003 sprintf(message
, ctr
[TR_CONGRATULATIONS_LONG
],
1004 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
1005 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
1010 fprintf(flog
, "Install program ended.\n");
1015 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
1019 freekeyvalues(ethernetkv
);
1021 if (allok
&& !allok_fastexit
)
1023 /* /proc is needed by the module checker. We have to mount it
1024 * so it can be seen by setup, which is run chrooted. */
1025 if (system("/sbin/mount proc -t proc /harddisk/proc"))
1026 printf("Unable to mount proc in /harddisk.");
1029 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
1030 printf("Unable to run setup.\n");
1031 if (system("/sbin/umount /harddisk/proc"))
1032 printf("Unable to umount /harddisk/proc.\n");
1038 system("/bin/swapoff /harddisk/swapfile");
1039 system("/sbin/umount /harddisk/var/log");
1040 system("/sbin/umount /harddisk/boot");
1041 system("/sbin/umount /harddisk");
1043 system("/etc/halt");