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 hdletter
, cdletter
;
60 char harddrive
[5], cdromdrive
[5]; /* Device holder. */
61 struct devparams hdparams
, cdromparams
; /* Params for CDROM and HD */
62 int cdmounted
= 0; /* Loop flag for inserting a cd. */
64 char commandstring
[STRING_SIZE
];
65 char *installtypes
[] = { "CDROM", "HTTP/FTP", NULL
};
66 int installtype
= CDROM_INSTALL
;
67 char insertmessage
[STRING_SIZE
];
68 char insertdevnode
[STRING_SIZE
];
70 char shortlangname
[10];
72 char title
[STRING_SIZE
];
76 struct keyvalue
*ethernetkv
= initkeyvalues();
77 FILE *handle
, *cmdfile
;
78 char line
[STRING_SIZE
];
79 char string
[STRING_SIZE
];
80 int maximum_free
= 0, current_free
;
82 int log_partition
, boot_partition
, root_partition
, swap_file
;
91 setlocale (LC_ALL
, "");
92 sethostname( SNAME
, 10);
94 memset(&hdparams
, 0, sizeof(struct devparams
));
95 memset(&cdromparams
, 0, sizeof(struct devparams
));
97 /* Log file/terminal stuff. */
100 if (!(flog
= fopen(argv
[1], "w+")))
108 fprintf(flog
, "Install program started.\n");
113 /* Do usb detection first for usb keyboard */
114 if (! (cmdfile
= fopen("/proc/cmdline", "r")))
116 fprintf(flog
, "Couldn't open commandline: /proc/cmdline\n");
118 fgets(line
, STRING_SIZE
, cmdfile
);
119 if (strstr (line
, "fdisk") != NULL
) {
120 fprintf(flog
, "Manual FDISK selected.\n");
123 if (strstr (line
, "nopcmcia") == NULL
) {
124 fprintf(flog
, "Initializing PCMCIA controllers.\n");
125 pcmcia
= initialize_pcmcia();
127 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
128 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
129 mysystem("/sbin/modprobe pcmcia_core");
130 mysystem(commandstring
);
131 mysystem("/sbin/modprobe ds");
132 /* pcmcia netcard drivers are not available from Boot floppy,
133 * they will be loaded from Drivers floppy later */
135 fprintf (flog
, "Detected No PCMCIA Controller.\n");
138 fprintf(flog
, "Skipping PCMCIA detection.\n");
140 if (strstr (line
, "nousb") == NULL
) {
141 fprintf(flog
, "Initializing USB controllers.\n");
144 fprintf(flog
, "Skipping USB detection.\n");
148 /* English is the default */
149 for (choice
= 0; langnames
[choice
]; choice
++)
151 if (strcmp(langnames
[choice
], "English") == 0)
154 if (!langnames
[choice
])
158 /* No need to ask. "choice" already has the index for English */
160 rc
= newtWinMenu("Language selection",
161 "Select the language you wish to use for the " NAME
".", 50, 5, 5, 8,
162 langnames
, &choice
, "Ok", NULL
);
164 ctr
= langtrs
[choice
];
165 strcpy(shortlangname
, shortlangnames
[choice
]);
166 if (strcmp(shortlangname
, "el") == 0)
167 mysystem("/bin/setfont iso07u-16");
168 else if (strcmp(shortlangname
, "pt") == 0)
169 mysystem("/bin/setfont lat1-16");
170 else if (strcmp(shortlangname
, "bz") == 0)
171 mysystem("/bin/setfont lat1-16");
172 else if (strcmp(shortlangname
, "cs") == 0)
173 mysystem("/bin/setfont lat2-16");
174 else if (strcmp(shortlangname
, "hu") == 0)
175 mysystem("/bin/setfont lat2-16");
176 else if (strcmp(shortlangname
, "pl") == 0)
177 mysystem("/bin/setfont lat2-16");
178 else if (strcmp(shortlangname
, "tr") == 0)
179 mysystem("/bin/setfont lat5-16");
180 else if (strcmp(shortlangname
, "vi") == 0)
181 mysystem("/bin/setfont viscii10-8x16");
183 mysystem("/bin/setfont lat0-16");
185 newtDrawRootText(14, 0, NAME
" v" VERSION
" - " SLOGAN
);
186 newtPushHelpLine(ctr
[TR_HELPLINE
]);
188 sprintf(message
, ctr
[TR_WELCOME
], NAME
);
189 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
190 newtWinMessage(title
, ctr
[TR_OK
], message
);
192 sprintf(message
, ctr
[TR_SELECT_INSTALLATION_MEDIA_LONG
], NAME
);
193 rc
= newtWinMenu(ctr
[TR_SELECT_INSTALLATION_MEDIA
], message
,
194 50, 5, 5, 6, installtypes
, &installtype
, ctr
[TR_OK
],
195 ctr
[TR_CANCEL
], NULL
);
200 if (installtype
== CDROM_INSTALL
)
202 /* First look for an IDE CDROM. */
203 if (!(cdletter
= findidetype(IDE_CDROM
)))
205 /* If we have a USB attached CDROM then it will
206 * have already appeared at /dev/scd0, so we
207 * try to access it first, before asking for the
210 if (!(try_scsi("scd0"))) {
211 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
212 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
215 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
219 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
221 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
227 /* trying to support SCSI pcmcia :-) */
228 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
229 ctr
[TR_LOADING_PCMCIA
]);
230 if (try_scsi("scd0"))
234 /* try loading all SCSI modules with default options */
235 /* Should expand this to allow options later though */
237 runcommandwithstatus("/bin/probescsi.sh",
238 ctr
[TR_PROBING_SCSI
]);
240 /* If it fails, give up. */
241 if (!(try_scsi("scd0"))) {
242 errorbox(ctr
[TR_NO_CDROM
]);
247 sprintf(cdromdrive
, "scd0");
250 sprintf(cdromdrive
, "hd%c", cdletter
);
254 snprintf(cdromparams
.devnode
, STRING_SIZE
, "/dev/%s", cdromdrive
);
255 cdromparams
.module
= 0;
257 sprintf(insertmessage
, ctr
[TR_INSERT_CDROM
], NAME
);
258 strcpy (insertdevnode
, cdromparams
.devnode
);
262 /* If we've done a PXE boot, we can skip the Drivers floppy,
263 * as we've already got the modules in our instroot.gz */
264 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
265 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
);
266 strcpy (insertdevnode
, "/dev/floppy");
274 if (scsi_cdrom
|| ide_cdrom
) {
275 /* Try to mount /cdrom in a loop. */
276 snprintf(commandstring
, STRING_SIZE
, "/bin/mount -o ro %s /cdrom", insertdevnode
);
279 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
282 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
285 if (!(mysystem(commandstring
))) {
286 handle
= fopen ("/cdrom/" SNAME
"-" VERSION
".tgz", "r");
287 if (handle
!= NULL
) {
290 /* If we've booted from CDROM, then
291 * we've already got the drivers,
292 * so we can skip this unpack. */
293 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
294 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/drivers-%s.img", VERSION
);
295 if (runcommandwithprogress(60, 4, title
,
297 175, ctr
[TR_EXTRACTING_MODULES
]))
299 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
306 mysystem ("/bin/umount /cdrom");
311 snprintf(commandstring
, STRING_SIZE
, "/bin/tar -C / -xvzf /dev/floppy");
314 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
317 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
320 if (runcommandwithprogress(60, 4, title
,
322 175, ctr
[TR_EXTRACTING_MODULES
]))
324 #if 0 /* disable this, so we allow for people putting in the wrong disk */
325 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
331 handle
= fopen ("/bin/mke2fs", "r");
332 if (handle
!= NULL
) {
340 /* PCMCIA controller is already detected
341 * On Boot floppy, we didn't have the PCMCIA drivers
342 * so load them now because they are installed from Drivers. */
343 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
344 if (strstr (line
, "nopcmcia") == NULL
) {
345 fprintf(flog
,"Floppy boot detected, loading PCMCIA drivers.\n");
347 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
348 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
349 mysystem("/sbin/modprobe pcmcia_core");
350 mysystem(commandstring
);
351 mysystem("/sbin/modprobe ds");
353 fprintf (flog
, "Detected No PCMCIA Controller.\n");
356 fprintf(flog
, "Skipping PCMCIA detection.\n");
358 if (strstr (line
, "nousb") == NULL
) {
359 fprintf(flog
, "Initializing USB controllers.\n");
362 fprintf(flog
, "Skipping USB detection.\n");
367 /* Configure the network now! */
368 if (installtype
== URL_INSTALL
)
370 /* Network driver and params. */
371 if (!(networkmenu(ethernetkv
)))
373 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
377 /* Check for ipcop-<VERSION>.tgz */
378 if (!(checktarball(SNAME
"-" VERSION
".tgz")))
380 errorbox(ctr
[TR_NO_IPCOP_TARBALL_FOUND
]);
385 /* Get device for the HD. This has to succeed. */
386 if (!(hdletter
= findidetype(IDE_HD
)))
388 if (installtype
== URL_INSTALL
)
390 /* If we've done a PXE boot, we can skip the SCSI
391 * floppy as we've already got the modules in our
393 if (!(handle
= fopen("/CDROMBOOT", "r")))
395 /* search img where it is on a mounted loop iso */
396 sprintf(string
, "images/scsidrv-%s.img", VERSION
);
397 if (!(checktarball(string
)))
399 /* Couldn't find the SCSI drivers on the URL page,
400 * so after 3 failed attempts, ask the user for the
401 * SCSI drivers floppy disk. */
402 errorbox(ctr
[TR_NO_SCSI_IMAGE_FOUND
]);
403 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
404 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
407 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
411 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
413 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
418 snprintf(commandstring
, STRING_SIZE
,
419 "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -",
421 if (runcommandwithprogress(60, 4, title
, commandstring
,
422 4500, ctr
[TR_INSTALLING_FILES
]))
424 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
432 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/scsidrv-%s.img", VERSION
);
433 if (runcommandwithstatus(string
, ctr
[TR_EXTRACTING_MODULES
]))
435 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
446 /* trying to support SCSI pcmcia :-) */
447 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
448 ctr
[TR_LOADING_PCMCIA
]);
454 /* try loading all SCSI modules with default options */
455 /* Should expand this to allow options later though */
457 runcommandwithstatus("/bin/probescsi.sh",
458 ctr
[TR_PROBING_SCSI
]);
461 /* Need to clean this up at some point */
462 if (!try_scsi("sda")) {
463 if (!try_scsi("ida/c0d0")) {
464 if (!try_scsi("cciss/c0d0")) {
465 if (!try_scsi("rd/c0d0")) {
466 if (!try_scsi("ataraid/d0")) {
467 errorbox(ctr
[TR_NO_HARDDISK
]);
471 sprintf(harddrive
, "ataraid/d0");
475 sprintf(harddrive
, "rd/c0d0");
479 sprintf(harddrive
, "cciss/c0d0");
483 sprintf(harddrive
, "ida/c0d0");
486 sprintf(harddrive
, "sda");
490 sprintf(harddrive
, "hd%c", hdletter
);
492 /* Make the hdparms struct and print the contents. */
493 snprintf(hdparams
.devnode
, STRING_SIZE
, "/dev/%s", harddrive
);
496 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
],
497 ctr
[TR_PREPARE_HARDDISK
], hdparams
.devnode
);
501 /* Calculate amount of memory in machine */
502 if ((handle
= fopen("/proc/meminfo", "r")))
504 while (fgets(line
, STRING_SIZE
-1, handle
)) {
505 if (sscanf (line
, "MemTotal: %s kB", string
)) {
506 memory
= atoi(string
) / 1024 ;
512 /* Partition, mkswp, mkfs.
513 * before partitioning, first determine the sizes of each
514 * partition. In order to do that we need to know the size of
517 /* Don't use mysystem here so we can redirect output */
518 sprintf(commandstring
, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive
);
519 system(commandstring
);
521 /* Calculate amount of disk space */
522 if ((handle
= fopen("/disksize", "r")))
524 fgets(line
, STRING_SIZE
-1, handle
);
525 if (sscanf (line
, "%s", string
)) {
526 maximum_free
= atoi(string
) / 1024;
531 fprintf(flog
, "maximum_free = %d, memory = %d",
532 maximum_free
, memory
);
534 /* If you need more than this, you should really add physical memory */
535 /* Minimum: 192 = 64 real + 128 swap */
536 swap_file
= memory
< 64 ? 2 * memory
: 192 - memory
;
537 swap_file
= swap_file
< 32 ? 32 : swap_file
;
539 if (maximum_free
< 135 + swap_file
)
541 if (maximum_free
< 135) {
542 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
546 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], ctr
[TR_CONTINUE_NO_SWAP
]);
552 boot_partition
= 8; /* in MB */
553 current_free
= maximum_free
- boot_partition
- swap_file
;
555 /* Give more place for add-on, extend root to 25% of current_free, upper limit to 8 gigas */
556 root_partition
= current_free
/ 4 ;
557 root_partition
= root_partition
> 8192 ? 8192 : root_partition
;
558 root_partition
= current_free
< 860 ? 235 : root_partition
;
559 root_partition
= current_free
< 380 ? 110 : root_partition
;
561 current_free
= current_free
- root_partition
;
562 root_partition
= root_partition
+ swap_file
;
564 log_partition
= current_free
;
566 fprintf(flog
, "boot = %d, swap = %d, mylog = %d, root = %d\n",
567 boot_partition
, swap_file
, log_partition
, root_partition
);
575 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], "NOW FDISK");
580 handle
= fopen("/tmp/partitiontable", "w");
582 fprintf(handle
, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n",
583 boot_partition
, log_partition
);
587 snprintf(commandstring
, STRING_SIZE
, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams
.devnode
);
588 if (runcommandwithstatus(commandstring
, ctr
[TR_PARTITIONING_DISK
]))
590 errorbox(ctr
[TR_UNABLE_TO_PARTITION
]);
597 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %sp1", hdparams
.devnode
);
599 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %s1", hdparams
.devnode
);
600 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_BOOT_FILESYSTEM
]))
602 errorbox(ctr
[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM
]);
606 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %sp2", hdparams
.devnode
);
608 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %s2", hdparams
.devnode
);
609 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_LOG_FILESYSTEM
]))
611 errorbox(ctr
[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM
]);
615 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %sp4", hdparams
.devnode
);
617 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %s4", hdparams
.devnode
);
619 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_ROOT_FILESYSTEM
]))
621 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
624 /* Mount harddisk. */
626 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp4 /harddisk", hdparams
.devnode
);
628 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s4 /harddisk", hdparams
.devnode
);
629 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_ROOT_FILESYSTEM
]))
631 errorbox(ctr
[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM
]);
636 snprintf(commandstring
, STRING_SIZE
, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file
);
637 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
639 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
642 snprintf(commandstring
, STRING_SIZE
, "/bin/mkswap /harddisk/swapfile");
643 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
645 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
649 mkdir("/harddisk/boot", S_IRWXU
|S_IRWXG
|S_IRWXO
);
650 mkdir("/harddisk/var", S_IRWXU
|S_IRWXG
|S_IRWXO
);
651 mkdir("/harddisk/var/log", S_IRWXU
|S_IRWXG
|S_IRWXO
);
654 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp1 /harddisk/boot", hdparams
.devnode
);
656 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams
.devnode
);
658 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_BOOT_FILESYSTEM
]))
660 errorbox(ctr
[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM
]);
664 snprintf(commandstring
, STRING_SIZE
, "/bin/swapon /harddisk/swapfile");
665 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_SWAP_PARTITION
]))
667 errorbox(ctr
[TR_UNABLE_TO_MOUNT_SWAP_PARTITION
]);
672 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp2 /harddisk/var/log", hdparams
.devnode
);
674 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams
.devnode
);
675 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_LOG_FILESYSTEM
]))
677 errorbox(ctr
[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM
]);
681 /* Either use tarball from cdrom or download. */
682 if (installtype
== CDROM_INSTALL
)
683 snprintf(commandstring
, STRING_SIZE
,
684 "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME
"-" VERSION
".tgz");
686 snprintf(commandstring
, STRING_SIZE
,
687 "/bin/wget -O - %s/" SNAME
"-" VERSION
".tgz | /bin/tar -C /harddisk -xvzf -", url
);
689 if (runcommandwithprogress(60, 4, title
, commandstring
, 4600,
690 ctr
[TR_INSTALLING_FILES
]))
692 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
696 /* Save USB controller type to modules.conf */
697 write_usb_modules_conf();
699 /* touch the modules.dep files */
700 snprintf(commandstring
, STRING_SIZE
,
701 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
703 mysystem(commandstring
);
705 snprintf(commandstring
, STRING_SIZE
,
706 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
708 mysystem(commandstring
);
712 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
714 /* Write PCMCIA Config */
716 handle
= fopen("/harddisk/etc/modules.conf", "a");
717 if (handle
!= NULL
) {
718 fprintf (handle
, "# PCMCIA Settings\n");
719 fprintf (handle
, "alias pcmcia-controller %s\n", pcmcia
);
724 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
725 if (handle
!= NULL
) {
727 fprintf (handle
, "PCMCIA=yes\n");
728 fprintf (handle
, "PCIC=%s\n", pcmcia
);
730 fprintf (handle
, "PCMCIA=no\n");
731 fprintf (handle
, "PCIC=\n");
733 fprintf (handle
, "CARDMGR_OPTS=\n");
734 fprintf (handle
, "SCHEME=\n");
738 /* *always* write disk configuration */
739 if (!(write_disk_configs(&hdparams
))){
740 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
745 Allow the user to restore their configuration from a floppy.
746 It uses tar. If the tar fails for any reason, show user an
747 error and go back to the restore/skip question. This gives
748 the user the chance to have another go. */
751 /* set status variables to nonsense values */
753 /* loop until floppy succeeds or user skips out */
756 sprintf(message
, ctr
[TR_RESTORE_CONFIGURATION
], NAME
);
757 if (newtWinChoice(title
, ctr
[TR_RESTORE
], ctr
[TR_SKIP
], message
) == 1)
759 /* Temporarily mount /proc under /harddisk/proc,
760 * run updfstab to locate the floppy, and unmount /harddisk/proc
761 * again. This should be run each time the user tries to restore
762 * so it can properly detect removable devices */
763 if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
764 errorbox(ctr
[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM
]);
767 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
768 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_FSTAB
]);
771 mysystem("/bin/umount /harddisk/proc");
773 mkdir("/harddisk/tmp/ipcop", S_IRWXU
|S_IRWXG
|S_IRWXO
);
775 /* Always extract to /tmp/ipcop for temporary extraction
776 * just in case floppy fails */
778 /* try a compressed backup first because it's quicker to fail.
779 * In exclude.system, files name must be without leading / or
780 * on extraction, name will never match */
781 snprintf(commandstring
, STRING_SIZE
,
782 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog
);
784 statuswindow(45, 4, title
, ctr
[TR_INSTALLING_FILES
]);
785 rc
= system(commandstring
);
788 /* if it's not compressed, try uncompressed first before failing*/
789 snprintf(commandstring
, STRING_SIZE
,
790 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog
);
791 rc
= system(commandstring
);
794 /* command failed trying to read from floppy */
795 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
797 /* remove badly restored files */
798 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
801 /* Now copy to correct location */
802 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
803 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
807 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
810 break; /* out of loop at this point because floppy has
811 successfully restored */
815 /* Now copy to correct location */
816 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
817 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
821 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
824 break; /* out of loop at this point because floppy has
825 successfully restored */
828 else{ /* user chose to skip install from floppy */
829 if (installtype
== CDROM_INSTALL
){
830 /* if we installed from CD ROM then we didn't set up the
831 network interface yet. Therefore, set up Network
832 driver and params just before we need them. */
834 if (!(networkmenu(ethernetkv
))){
835 /* network setup failed, tell the world */
836 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
840 break; /* out of loop because we succeeded with ethernet
841 set up and user is notrestarting from floppy*/
845 /* Check the SQUID acl file exists, if not use our 1.4 copy */
849 if (!(aclreadfile
= fopen ("/harddisk" CONFIG_ROOT
"/proxy/acl", "r"))) {
850 rename ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4",
851 "/harddisk" CONFIG_ROOT
"/proxy/acl");
853 unlink ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4");
856 chown ("/harddisk" CONFIG_ROOT
"/proxy/acl", 99, 99);
859 /* Build cache lang file */
860 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
862 if (!allok_fastexit
){
863 /* write ethernet and lang configs only if they have not
864 been restored from floppy already. */
865 if (!(write_ethernet_configs( ethernetkv
))||
866 !(write_lang_configs(shortlangname
))){
867 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
872 /* if we detected SCSI then fixup */
873 if ((handle
= fopen("/scsidriver", "r")))
876 fgets(line
, STRING_SIZE
-1, handle
);
878 line
[strlen(line
) - 1] = 0;
879 driver
= strtok(line
, ".");
880 fprintf(flog
, "Detected SCSI driver %s\n",driver
);
881 if (strlen(driver
) > 1) {
882 fprintf(flog
, "Fixing up ipcoprd.img\n");
883 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
884 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
885 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/ipcoprd.img %s", driver
, KERNEL_VERSION
);
886 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
888 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/ipcoprd-smp.img %s-smp", driver
, KERNEL_VERSION
);
889 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
890 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
893 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
894 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
902 fprintf(flog
, "Detected SCSI driver PCMCIA\n");
903 fprintf(flog
, "Fixing up ipcoprd.img\n");
904 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
905 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
906 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipcoprd.img", KERNEL_VERSION
);
907 mysystem(commandstring
);
909 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
912 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
918 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode
);
919 /* restore permissions */
920 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
923 sprintf(string
, "root=%sp4", hdparams
.devnode
);
925 sprintf(string
, "root=%s4", hdparams
.devnode
);
926 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
928 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
930 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /boot/grub/grubbatch");
932 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_GRUB
]))
934 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
937 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
940 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams
.devnode
);
941 mysystem(commandstring
);
942 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams
.devnode
);
943 mysystem(commandstring
);
945 sprintf(string
, "root=%sp4", hdparams
.devnode
);
947 sprintf(string
, "root=%s4", hdparams
.devnode
);
948 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string
);
951 /* unmounting happens everywhere because there are places
952 which require device is to be unmounted under certain
953 circumstances. This is the last place we can unmount
954 anything and still succeed. */
956 if (!unmount_before
&& installtype
== CDROM_INSTALL
){
957 if (mysystem("/sbin/umount /cdrom"))
959 errorbox(ctr
[TR_UNABLE_TO_UNMOUNT_CDROM
]);
964 if (installtype
== CDROM_INSTALL
)
967 if (!(ejectcdrom(cdromparams
.devnode
)))
969 errorbox(ctr
[TR_UNABLE_TO_EJECT_CDROM
]);
975 sprintf(message
, ctr
[TR_CONGRATULATIONS_LONG
],
976 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
977 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
982 fprintf(flog
, "Install program ended.\n");
987 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
991 freekeyvalues(ethernetkv
);
993 if (allok
&& !allok_fastexit
)
995 /* /proc is needed by the module checker. We have to mount it
996 * so it can be seen by setup, which is run chrooted. */
997 if (system("/sbin/mount proc -t proc /harddisk/proc"))
998 printf("Unable to mount proc in /harddisk.");
1001 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
1002 printf("Unable to run setup.\n");
1003 if (system("/sbin/umount /harddisk/proc"))
1004 printf("Unable to umount /harddisk/proc.\n");
1010 system("/bin/swapoff /harddisk/swapfile");
1011 system("/sbin/umount /harddisk/var/log");
1012 system("/sbin/umount /harddisk/boot");
1013 system("/sbin/umount /harddisk");
1015 system("/etc/halt");