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 ipfire-<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]);
701 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_FILES
]))
703 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
707 /* Save USB controller type to modules.conf */
708 write_usb_modules_conf();
710 /* touch the modules.dep files */
711 snprintf(commandstring
, STRING_SIZE
,
712 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
714 mysystem(commandstring
);
716 snprintf(commandstring
, STRING_SIZE
,
717 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
719 mysystem(commandstring
);
723 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
725 /* Write PCMCIA Config */
727 handle
= fopen("/harddisk/etc/modules.conf", "a");
728 if (handle
!= NULL
) {
729 fprintf (handle
, "# PCMCIA Settings\n");
730 fprintf (handle
, "alias pcmcia-controller %s\n", pcmcia
);
735 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
736 if (handle
!= NULL
) {
738 fprintf (handle
, "PCMCIA=yes\n");
739 fprintf (handle
, "PCIC=%s\n", pcmcia
);
741 fprintf (handle
, "PCMCIA=no\n");
742 fprintf (handle
, "PCIC=\n");
744 fprintf (handle
, "CARDMGR_OPTS=\n");
745 fprintf (handle
, "SCHEME=\n");
749 /* *always* write disk configuration */
750 if (!(write_disk_configs(&hdparams
))){
751 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
756 Allow the user to restore their configuration from a floppy.
757 It uses tar. If the tar fails for any reason, show user an
758 error and go back to the restore/skip question. This gives
759 the user the chance to have another go. */
761 #ifdef OLD_RESTORECFG
763 /* set status variables to nonsense values */
765 /* loop until floppy succeeds or user skips out */
768 sprintf(message
, ctr
[TR_RESTORE_CONFIGURATION
], NAME
);
769 if (newtWinChoice(title
, ctr
[TR_RESTORE
], ctr
[TR_SKIP
], message
) == 1)
771 /* Temporarily mount /proc under /harddisk/proc,
772 * run updfstab to locate the floppy, and unmount /harddisk/proc
773 * again. This should be run each time the user tries to restore
774 * so it can properly detect removable devices */
775 if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
776 errorbox(ctr
[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM
]);
779 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
780 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_FSTAB
]);
783 mysystem("/bin/umount /harddisk/proc");
785 mkdir("/harddisk/tmp/ipcop", S_IRWXU
|S_IRWXG
|S_IRWXO
);
787 /* Always extract to /tmp/ipcop for temporary extraction
788 * just in case floppy fails */
790 /* try a compressed backup first because it's quicker to fail.
791 * In exclude.system, files name must be without leading / or
792 * on extraction, name will never match */
793 snprintf(commandstring
, STRING_SIZE
,
794 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog
);
796 statuswindow(45, 4, title
, ctr
[TR_INSTALLING_FILES
]);
797 rc
= system(commandstring
);
800 /* if it's not compressed, try uncompressed first before failing*/
801 snprintf(commandstring
, STRING_SIZE
,
802 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog
);
803 rc
= system(commandstring
);
806 /* command failed trying to read from floppy */
807 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
809 /* remove badly restored files */
810 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
813 /* Now copy to correct location */
814 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
815 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
819 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
822 break; /* out of loop at this point because floppy has
823 successfully restored */
827 /* Now copy to correct location */
828 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
829 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
833 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
836 break; /* out of loop at this point because floppy has
837 successfully restored */
840 else{ /* user chose to skip install from floppy */
841 if (installtype
== CDROM_INSTALL
){
842 /* if we installed from CD ROM then we didn't set up the
843 network interface yet. Therefore, set up Network
844 driver and params just before we need them. */
846 if (!(networkmenu(ethernetkv
))){
847 /* network setup failed, tell the world */
848 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
852 break; /* out of loop because we succeeded with ethernet
853 set up and user is notrestarting from floppy*/
857 if (installtype
== CDROM_INSTALL
){
858 /* if we installed from CD ROM then we didn't set up the
859 network interface yet. Therefore, set up Network
860 driver and params just before we need them. */
862 if (!(networkmenu(ethernetkv
))){
863 /* network setup failed, tell the world */
864 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
870 /* Check the SQUID acl file exists, if not use our 1.4 copy */
874 if (!(aclreadfile
= fopen ("/harddisk" CONFIG_ROOT
"/proxy/acl", "r"))) {
875 rename ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4",
876 "/harddisk" CONFIG_ROOT
"/proxy/acl");
878 unlink ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4");
881 chown ("/harddisk" CONFIG_ROOT
"/proxy/acl", 99, 99);
884 /* Build cache lang file */
885 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
887 if (!allok_fastexit
){
888 /* write ethernet and lang configs only if they have not
889 been restored from floppy already. */
890 if (!(write_ethernet_configs( ethernetkv
))||
891 !(write_lang_configs(shortlangname
))){
892 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
897 /* if we detected SCSI then fixup */
898 if ((handle
= fopen("/scsidriver", "r")))
901 fgets(line
, STRING_SIZE
-1, handle
);
903 line
[strlen(line
) - 1] = 0;
904 driver
= strtok(line
, ".");
905 fprintf(flog
, "Detected SCSI driver %s\n",driver
);
906 if (strlen(driver
) > 1) {
907 fprintf(flog
, "Fixing up ipfirerd.img\n");
908 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
909 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
910 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
);
911 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
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-smp.img %s-smp", driver
, KERNEL_VERSION
);
914 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
915 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
918 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
919 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
927 fprintf(flog
, "Detected SCSI driver PCMCIA\n");
928 fprintf(flog
, "Fixing up ipfirerd.img\n");
929 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
930 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
931 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipfirerd.img", KERNEL_VERSION
);
932 mysystem(commandstring
);
934 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
937 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
943 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode
);
944 /* restore permissions */
945 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
948 sprintf(string
, "root=%sp4", hdparams
.devnode
);
950 sprintf(string
, "root=%s4", hdparams
.devnode
);
951 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
953 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
955 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /boot/grub/grubbatch");
957 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_GRUB
]))
959 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
963 mysystem("/bin/installbootsplash.sh");
964 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
967 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams
.devnode
);
968 mysystem(commandstring
);
969 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams
.devnode
);
970 mysystem(commandstring
);
972 sprintf(string
, "root=%sp4", hdparams
.devnode
);
974 sprintf(string
, "root=%s4", hdparams
.devnode
);
975 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string
);
978 /* unmounting happens everywhere because there are places
979 which require device is to be unmounted under certain
980 circumstances. This is the last place we can unmount
981 anything and still succeed. */
983 if (!unmount_before
&& installtype
== CDROM_INSTALL
){
984 if (mysystem("/sbin/umount /cdrom"))
986 errorbox(ctr
[TR_UNABLE_TO_UNMOUNT_CDROM
]);
991 if (installtype
== CDROM_INSTALL
)
994 if (!(ejectcdrom(cdromparams
.devnode
)))
996 errorbox(ctr
[TR_UNABLE_TO_EJECT_CDROM
]);
1002 sprintf(message
, ctr
[TR_CONGRATULATIONS_LONG
],
1003 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
1004 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
1009 fprintf(flog
, "Install program ended.\n");
1014 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
1018 freekeyvalues(ethernetkv
);
1020 if (allok
&& !allok_fastexit
)
1022 /* /proc is needed by the module checker. We have to mount it
1023 * so it can be seen by setup, which is run chrooted. */
1024 if (system("/sbin/mount proc -t proc /harddisk/proc"))
1025 printf("Unable to mount proc in /harddisk.");
1028 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
1029 printf("Unable to run setup.\n");
1030 if (system("/sbin/umount /harddisk/proc"))
1031 printf("Unable to umount /harddisk/proc.\n");
1037 system("/bin/swapoff /harddisk/swapfile");
1038 system("/sbin/umount /harddisk/var/log");
1039 system("/sbin/umount /harddisk/boot");
1040 system("/sbin/umount /harddisk");
1042 system("/etc/halt");