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
26 extern char url
[STRING_SIZE
];
49 int main(int argc
, char *argv
[])
52 char *langnames
[] = { "English", NULL
};
53 char *shortlangnames
[] = { "en", NULL
};
54 char **langtrs
[] = { en_tr
, NULL
};
56 char *langnames
[] = { "Deutsch", "English", NULL
};
57 char *shortlangnames
[] = { "de", "en", NULL
};
58 char **langtrs
[] = { de_tr
, en_tr
, NULL
};
60 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
};
61 char *shortlangnames
[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "so", "fi", "sv", "tr", "vi", NULL
};
62 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
};
65 char hdletter
, cdletter
;
66 char harddrive
[5], cdromdrive
[5]; /* Device holder. */
67 struct devparams hdparams
, cdromparams
; /* Params for CDROM and HD */
68 int cdmounted
= 0; /* Loop flag for inserting a cd. */
70 char commandstring
[STRING_SIZE
];
71 char *installtypes
[] = { "CDROM", "HTTP/FTP", NULL
};
72 int installtype
= CDROM_INSTALL
;
73 char insertmessage
[STRING_SIZE
];
74 char insertdevnode
[STRING_SIZE
];
76 char shortlangname
[10];
78 char title
[STRING_SIZE
];
82 struct keyvalue
*ethernetkv
= initkeyvalues();
83 FILE *handle
, *cmdfile
;
84 char line
[STRING_SIZE
];
85 char string
[STRING_SIZE
];
86 int maximum_free
= 0, current_free
;
88 int log_partition
, boot_partition
, root_partition
, swap_file
;
97 setlocale (LC_ALL
, "");
98 sethostname( SNAME
, 10);
100 memset(&hdparams
, 0, sizeof(struct devparams
));
101 memset(&cdromparams
, 0, sizeof(struct devparams
));
103 /* Log file/terminal stuff. */
106 if (!(flog
= fopen(argv
[1], "w+")))
114 fprintf(flog
, "Install program started.\n");
119 /* Do usb detection first for usb keyboard */
120 if (! (cmdfile
= fopen("/proc/cmdline", "r")))
122 fprintf(flog
, "Couldn't open commandline: /proc/cmdline\n");
124 fgets(line
, STRING_SIZE
, cmdfile
);
125 if (strstr (line
, "fdisk") != NULL
) {
126 fprintf(flog
, "Manual FDISK selected.\n");
129 if (strstr (line
, "nopcmcia") == NULL
) {
130 fprintf(flog
, "Initializing PCMCIA controllers.\n");
131 pcmcia
= initialize_pcmcia();
133 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
134 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
135 mysystem("/sbin/modprobe pcmcia_core");
136 mysystem(commandstring
);
137 mysystem("/sbin/modprobe ds");
138 /* pcmcia netcard drivers are not available from Boot floppy,
139 * they will be loaded from Drivers floppy later */
141 fprintf (flog
, "Detected No PCMCIA Controller.\n");
144 fprintf(flog
, "Skipping PCMCIA detection.\n");
146 if (strstr (line
, "nousb") == NULL
) {
147 fprintf(flog
, "Initializing USB controllers.\n");
150 fprintf(flog
, "Skipping USB detection.\n");
154 /* Deutsch is the default */
155 for (choice
= 0; langnames
[choice
]; choice
++)
157 if (strcmp(langnames
[choice
], "Deutsch") == 0)
160 if (!langnames
[choice
])
164 /* No need to ask. "choice" already has the index for English */
166 rc
= newtWinMenu("Language selection",
167 "Select the language you wish to use for the " NAME
".", 50, 5, 5, 8,
168 langnames
, &choice
, "Ok", NULL
);
170 ctr
= langtrs
[choice
];
171 strcpy(shortlangname
, shortlangnames
[choice
]);
172 if (strcmp(shortlangname
, "el") == 0)
173 mysystem("/bin/setfont iso07u-16");
174 else if (strcmp(shortlangname
, "pt") == 0)
175 mysystem("/bin/setfont lat1-16");
176 else if (strcmp(shortlangname
, "bz") == 0)
177 mysystem("/bin/setfont lat1-16");
178 else if (strcmp(shortlangname
, "cs") == 0)
179 mysystem("/bin/setfont lat2-16");
180 else if (strcmp(shortlangname
, "hu") == 0)
181 mysystem("/bin/setfont lat2-16");
182 else if (strcmp(shortlangname
, "pl") == 0)
183 mysystem("/bin/setfont lat2-16");
184 else if (strcmp(shortlangname
, "tr") == 0)
185 mysystem("/bin/setfont lat5-16");
186 else if (strcmp(shortlangname
, "vi") == 0)
187 mysystem("/bin/setfont viscii10-8x16");
189 mysystem("/bin/setfont lat0-16");
191 newtDrawRootText(14, 0, NAME
" v" VERSION
" - " SLOGAN
);
192 newtPushHelpLine(ctr
[TR_HELPLINE
]);
194 sprintf(message
, ctr
[TR_WELCOME
], NAME
);
195 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
196 newtWinMessage(title
, ctr
[TR_OK
], message
);
198 sprintf(message
, ctr
[TR_SELECT_INSTALLATION_MEDIA_LONG
], NAME
);
199 rc
= newtWinMenu(ctr
[TR_SELECT_INSTALLATION_MEDIA
], message
,
200 50, 5, 5, 6, installtypes
, &installtype
, ctr
[TR_OK
],
201 ctr
[TR_CANCEL
], NULL
);
206 if (installtype
== CDROM_INSTALL
)
208 /* First look for an IDE CDROM. */
209 if (!(cdletter
= findidetype(IDE_CDROM
)))
211 /* If we have a USB attached CDROM then it will
212 * have already appeared at /dev/scd0, so we
213 * try to access it first, before asking for the
216 if (!(try_scsi("scd0"))) {
217 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
218 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
221 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
225 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
227 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
233 /* trying to support SCSI pcmcia :-) */
234 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
235 ctr
[TR_LOADING_PCMCIA
]);
236 if (try_scsi("scd0"))
240 /* try loading all SCSI modules with default options */
241 /* Should expand this to allow options later though */
243 runcommandwithstatus("/bin/probescsi.sh",
244 ctr
[TR_PROBING_SCSI
]);
246 /* If it fails, give up. */
247 if (!(try_scsi("scd0"))) {
248 errorbox(ctr
[TR_NO_CDROM
]);
253 sprintf(cdromdrive
, "scd0");
256 sprintf(cdromdrive
, "hd%c", cdletter
);
260 snprintf(cdromparams
.devnode
, STRING_SIZE
, "/dev/%s", cdromdrive
);
261 cdromparams
.module
= 0;
263 sprintf(insertmessage
, ctr
[TR_INSERT_CDROM
], NAME
);
264 strcpy (insertdevnode
, cdromparams
.devnode
);
268 /* If we've done a PXE boot, we can skip the Drivers floppy,
269 * as we've already got the modules in our instroot.gz */
270 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
271 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
);
272 strcpy (insertdevnode
, "/dev/floppy");
280 if (scsi_cdrom
|| ide_cdrom
) {
281 /* Try to mount /cdrom in a loop. */
282 snprintf(commandstring
, STRING_SIZE
, "/bin/mount -o ro %s /cdrom", insertdevnode
);
285 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
288 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
291 if (!(mysystem(commandstring
))) {
292 handle
= fopen ("/cdrom/" SNAME
"-" VERSION
".tgz", "r");
293 if (handle
!= NULL
) {
296 /* If we've booted from CDROM, then
297 * we've already got the drivers,
298 * so we can skip this unpack. */
299 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
300 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/drivers-%s.img", VERSION
);
301 if (runcommandwithprogress(60, 4, title
,
303 175, ctr
[TR_EXTRACTING_MODULES
]))
305 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
312 mysystem ("/bin/umount /cdrom");
317 snprintf(commandstring
, STRING_SIZE
, "/bin/tar -C / -xvzf /dev/floppy");
320 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
323 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
326 if (runcommandwithprogress(60, 4, title
,
328 175, ctr
[TR_EXTRACTING_MODULES
]))
330 #if 0 /* disable this, so we allow for people putting in the wrong disk */
331 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
337 handle
= fopen ("/bin/mke2fs", "r");
338 if (handle
!= NULL
) {
346 /* PCMCIA controller is already detected
347 * On Boot floppy, we didn't have the PCMCIA drivers
348 * so load them now because they are installed from Drivers. */
349 if (!(handle
= fopen("/CDROMBOOT", "r"))) {
350 if (strstr (line
, "nopcmcia") == NULL
) {
351 fprintf(flog
,"Floppy boot detected, loading PCMCIA drivers.\n");
353 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
354 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
355 mysystem("/sbin/modprobe pcmcia_core");
356 mysystem(commandstring
);
357 mysystem("/sbin/modprobe ds");
359 fprintf (flog
, "Detected No PCMCIA Controller.\n");
362 fprintf(flog
, "Skipping PCMCIA detection.\n");
364 if (strstr (line
, "nousb") == NULL
) {
365 fprintf(flog
, "Initializing USB controllers.\n");
368 fprintf(flog
, "Skipping USB detection.\n");
373 /* Configure the network now! */
374 if (installtype
== URL_INSTALL
)
376 /* Network driver and params. */
377 if (!(networkmenu(ethernetkv
)))
379 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
383 /* Check for ipcop-<VERSION>.tgz */
384 if (!(checktarball(SNAME
"-" VERSION
".tgz")))
386 errorbox(ctr
[TR_NO_IPCOP_TARBALL_FOUND
]);
391 /* Get device for the HD. This has to succeed. */
392 if (!(hdletter
= findidetype(IDE_HD
)))
394 if (installtype
== URL_INSTALL
)
396 /* If we've done a PXE boot, we can skip the SCSI
397 * floppy as we've already got the modules in our
399 if (!(handle
= fopen("/CDROMBOOT", "r")))
401 /* search img where it is on a mounted loop iso */
402 sprintf(string
, "images/scsidrv-%s.img", VERSION
);
403 if (!(checktarball(string
)))
405 /* Couldn't find the SCSI drivers on the URL page,
406 * so after 3 failed attempts, ask the user for the
407 * SCSI drivers floppy disk. */
408 errorbox(ctr
[TR_NO_SCSI_IMAGE_FOUND
]);
409 sprintf(insertmessage
, ctr
[TR_INSERT_FLOPPY
], NAME
" SCSI");
410 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], insertmessage
);
413 errorbox(ctr
[TR_INSTALLATION_CANCELED
]);
417 if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr
[TR_EXTRACTING_MODULES
]))
419 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
424 snprintf(commandstring
, STRING_SIZE
,
425 "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -",
427 if (runcommandwithprogress(60, 4, title
, commandstring
,
428 4500, ctr
[TR_INSTALLING_FILES
]))
430 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
438 sprintf(string
, "/bin/tar -C / -xvzf /cdrom/images/scsidrv-%s.img", VERSION
);
439 if (runcommandwithstatus(string
, ctr
[TR_EXTRACTING_MODULES
]))
441 errorbox(ctr
[TR_UNABLE_TO_EXTRACT_MODULES
]);
452 /* trying to support SCSI pcmcia :-) */
453 runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi",
454 ctr
[TR_LOADING_PCMCIA
]);
460 /* try loading all SCSI modules with default options */
461 /* Should expand this to allow options later though */
463 runcommandwithstatus("/bin/probescsi.sh",
464 ctr
[TR_PROBING_SCSI
]);
467 /* Need to clean this up at some point */
468 if (!try_scsi("sda")) {
469 if (!try_scsi("ida/c0d0")) {
470 if (!try_scsi("cciss/c0d0")) {
471 if (!try_scsi("rd/c0d0")) {
472 if (!try_scsi("ataraid/d0")) {
473 errorbox(ctr
[TR_NO_HARDDISK
]);
477 sprintf(harddrive
, "ataraid/d0");
481 sprintf(harddrive
, "rd/c0d0");
485 sprintf(harddrive
, "cciss/c0d0");
489 sprintf(harddrive
, "ida/c0d0");
492 sprintf(harddrive
, "sda");
496 sprintf(harddrive
, "hd%c", hdletter
);
498 /* Make the hdparms struct and print the contents. */
499 snprintf(hdparams
.devnode
, STRING_SIZE
, "/dev/%s", harddrive
);
502 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
],
503 ctr
[TR_PREPARE_HARDDISK
], hdparams
.devnode
);
507 /* Calculate amount of memory in machine */
508 if ((handle
= fopen("/proc/meminfo", "r")))
510 while (fgets(line
, STRING_SIZE
-1, handle
)) {
511 if (sscanf (line
, "MemTotal: %s kB", string
)) {
512 memory
= atoi(string
) / 1024 ;
518 /* Partition, mkswp, mkfs.
519 * before partitioning, first determine the sizes of each
520 * partition. In order to do that we need to know the size of
523 /* Don't use mysystem here so we can redirect output */
524 sprintf(commandstring
, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive
);
525 system(commandstring
);
527 /* Calculate amount of disk space */
528 if ((handle
= fopen("/disksize", "r")))
530 fgets(line
, STRING_SIZE
-1, handle
);
531 if (sscanf (line
, "%s", string
)) {
532 maximum_free
= atoi(string
) / 1024;
537 fprintf(flog
, "maximum_free = %d, memory = %d",
538 maximum_free
, memory
);
540 /* If you need more than this, you should really add physical memory */
541 /* Minimum: 192 = 64 real + 128 swap */
542 swap_file
= memory
< 64 ? 2 * memory
: 192 - memory
;
543 swap_file
= swap_file
< 32 ? 32 : swap_file
;
545 if (maximum_free
< 135 + swap_file
)
547 if (maximum_free
< 135) {
548 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
552 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], ctr
[TR_CONTINUE_NO_SWAP
]);
558 boot_partition
= 8; /* in MB */
559 current_free
= maximum_free
- boot_partition
- swap_file
;
561 /* Give more place for add-on, extend root to 25% of current_free, upper limit to 8 gigas */
562 root_partition
= current_free
/ 4 ;
563 root_partition
= root_partition
> 8192 ? 8192 : root_partition
;
564 root_partition
= current_free
< 860 ? 235 : root_partition
;
565 root_partition
= current_free
< 380 ? 110 : root_partition
;
567 current_free
= current_free
- root_partition
;
568 root_partition
= root_partition
+ swap_file
;
570 log_partition
= current_free
;
572 fprintf(flog
, "boot = %d, swap = %d, mylog = %d, root = %d\n",
573 boot_partition
, swap_file
, log_partition
, root_partition
);
581 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], "NOW FDISK");
586 handle
= fopen("/tmp/partitiontable", "w");
588 fprintf(handle
, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n",
589 boot_partition
, log_partition
);
593 snprintf(commandstring
, STRING_SIZE
, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams
.devnode
);
594 if (runcommandwithstatus(commandstring
, ctr
[TR_PARTITIONING_DISK
]))
596 errorbox(ctr
[TR_UNABLE_TO_PARTITION
]);
603 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %sp1", hdparams
.devnode
);
605 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 0 -j %s1", hdparams
.devnode
);
606 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_BOOT_FILESYSTEM
]))
608 errorbox(ctr
[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM
]);
612 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %sp2", hdparams
.devnode
);
614 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -j %s2", hdparams
.devnode
);
615 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_LOG_FILESYSTEM
]))
617 errorbox(ctr
[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM
]);
621 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %sp4", hdparams
.devnode
);
623 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -m 1 -j %s4", hdparams
.devnode
);
625 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_ROOT_FILESYSTEM
]))
627 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
630 /* Mount harddisk. */
632 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp4 /harddisk", hdparams
.devnode
);
634 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s4 /harddisk", hdparams
.devnode
);
635 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_ROOT_FILESYSTEM
]))
637 errorbox(ctr
[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM
]);
642 snprintf(commandstring
, STRING_SIZE
, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file
);
643 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
645 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
648 snprintf(commandstring
, STRING_SIZE
, "/bin/mkswap /harddisk/swapfile");
649 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
651 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
655 mkdir("/harddisk/boot", S_IRWXU
|S_IRWXG
|S_IRWXO
);
656 mkdir("/harddisk/var", S_IRWXU
|S_IRWXG
|S_IRWXO
);
657 mkdir("/harddisk/var/log", S_IRWXU
|S_IRWXG
|S_IRWXO
);
660 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp1 /harddisk/boot", hdparams
.devnode
);
662 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams
.devnode
);
664 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_BOOT_FILESYSTEM
]))
666 errorbox(ctr
[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM
]);
670 snprintf(commandstring
, STRING_SIZE
, "/bin/swapon /harddisk/swapfile");
671 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_SWAP_PARTITION
]))
673 errorbox(ctr
[TR_UNABLE_TO_MOUNT_SWAP_PARTITION
]);
678 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %sp2 /harddisk/var/log", hdparams
.devnode
);
680 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams
.devnode
);
681 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_LOG_FILESYSTEM
]))
683 errorbox(ctr
[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM
]);
687 /* Either use tarball from cdrom or download. */
688 if (installtype
== CDROM_INSTALL
)
689 snprintf(commandstring
, STRING_SIZE
,
690 "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME
"-" VERSION
".tgz");
692 snprintf(commandstring
, STRING_SIZE
,
693 "/bin/wget -O - %s/" SNAME
"-" VERSION
".tgz | /bin/tar -C /harddisk -xvzf -", url
);
695 if (runcommandwithprogress(60, 4, title
, commandstring
, 4600,
696 ctr
[TR_INSTALLING_FILES
]))
698 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
702 /* Save USB controller type to modules.conf */
703 write_usb_modules_conf();
705 /* touch the modules.dep files */
706 snprintf(commandstring
, STRING_SIZE
,
707 "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep",
709 mysystem(commandstring
);
711 snprintf(commandstring
, STRING_SIZE
,
712 "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep",
714 mysystem(commandstring
);
718 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
720 /* Write PCMCIA Config */
722 handle
= fopen("/harddisk/etc/modules.conf", "a");
723 if (handle
!= NULL
) {
724 fprintf (handle
, "# PCMCIA Settings\n");
725 fprintf (handle
, "alias pcmcia-controller %s\n", pcmcia
);
730 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
731 if (handle
!= NULL
) {
733 fprintf (handle
, "PCMCIA=yes\n");
734 fprintf (handle
, "PCIC=%s\n", pcmcia
);
736 fprintf (handle
, "PCMCIA=no\n");
737 fprintf (handle
, "PCIC=\n");
739 fprintf (handle
, "CARDMGR_OPTS=\n");
740 fprintf (handle
, "SCHEME=\n");
744 /* *always* write disk configuration */
745 if (!(write_disk_configs(&hdparams
))){
746 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
751 Allow the user to restore their configuration from a floppy.
752 It uses tar. If the tar fails for any reason, show user an
753 error and go back to the restore/skip question. This gives
754 the user the chance to have another go. */
756 #ifdef OLD_RESTORECFG
758 /* set status variables to nonsense values */
760 /* loop until floppy succeeds or user skips out */
763 sprintf(message
, ctr
[TR_RESTORE_CONFIGURATION
], NAME
);
764 if (newtWinChoice(title
, ctr
[TR_RESTORE
], ctr
[TR_SKIP
], message
) == 1)
766 /* Temporarily mount /proc under /harddisk/proc,
767 * run updfstab to locate the floppy, and unmount /harddisk/proc
768 * again. This should be run each time the user tries to restore
769 * so it can properly detect removable devices */
770 if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
771 errorbox(ctr
[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM
]);
774 if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
775 errorbox(ctr
[TR_UNABLE_TO_WRITE_ETC_FSTAB
]);
778 mysystem("/bin/umount /harddisk/proc");
780 mkdir("/harddisk/tmp/ipcop", S_IRWXU
|S_IRWXG
|S_IRWXO
);
782 /* Always extract to /tmp/ipcop for temporary extraction
783 * just in case floppy fails */
785 /* try a compressed backup first because it's quicker to fail.
786 * In exclude.system, files name must be without leading / or
787 * on extraction, name will never match */
788 snprintf(commandstring
, STRING_SIZE
,
789 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog
);
791 statuswindow(45, 4, title
, ctr
[TR_INSTALLING_FILES
]);
792 rc
= system(commandstring
);
795 /* if it's not compressed, try uncompressed first before failing*/
796 snprintf(commandstring
, STRING_SIZE
,
797 "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT
"/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog
);
798 rc
= system(commandstring
);
801 /* command failed trying to read from floppy */
802 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
804 /* remove badly restored files */
805 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
808 /* Now copy to correct location */
809 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
810 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
814 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
817 break; /* out of loop at this point because floppy has
818 successfully restored */
822 /* Now copy to correct location */
823 mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /");
824 mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop");
828 /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
831 break; /* out of loop at this point because floppy has
832 successfully restored */
835 else{ /* user chose to skip install from floppy */
836 if (installtype
== CDROM_INSTALL
){
837 /* if we installed from CD ROM then we didn't set up the
838 network interface yet. Therefore, set up Network
839 driver and params just before we need them. */
841 if (!(networkmenu(ethernetkv
))){
842 /* network setup failed, tell the world */
843 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
847 break; /* out of loop because we succeeded with ethernet
848 set up and user is notrestarting from floppy*/
852 if (installtype
== CDROM_INSTALL
){
853 /* if we installed from CD ROM then we didn't set up the
854 network interface yet. Therefore, set up Network
855 driver and params just before we need them. */
857 if (!(networkmenu(ethernetkv
))){
858 /* network setup failed, tell the world */
859 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
865 /* Check the SQUID acl file exists, if not use our 1.4 copy */
869 if (!(aclreadfile
= fopen ("/harddisk" CONFIG_ROOT
"/proxy/acl", "r"))) {
870 rename ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4",
871 "/harddisk" CONFIG_ROOT
"/proxy/acl");
873 unlink ("/harddisk" CONFIG_ROOT
"/proxy/acl-1.4");
876 chown ("/harddisk" CONFIG_ROOT
"/proxy/acl", 99, 99);
879 /* Build cache lang file */
880 mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
882 if (!allok_fastexit
){
883 /* write ethernet and lang configs only if they have not
884 been restored from floppy already. */
885 if (!(write_ethernet_configs( ethernetkv
))||
886 !(write_lang_configs(shortlangname
))){
887 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
892 /* if we detected SCSI then fixup */
893 if ((handle
= fopen("/scsidriver", "r")))
896 fgets(line
, STRING_SIZE
-1, handle
);
898 line
[strlen(line
) - 1] = 0;
899 driver
= strtok(line
, ".");
900 fprintf(flog
, "Detected SCSI driver %s\n",driver
);
901 if (strlen(driver
) > 1) {
902 fprintf(flog
, "Fixing up ipcoprd.img\n");
903 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
904 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
905 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
);
906 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
908 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
);
909 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
910 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
913 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
914 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
922 fprintf(flog
, "Detected SCSI driver PCMCIA\n");
923 fprintf(flog
, "Fixing up ipcoprd.img\n");
924 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
925 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
926 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipcoprd.img", KERNEL_VERSION
);
927 mysystem(commandstring
);
929 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
932 mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf");
938 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode
);
939 /* restore permissions */
940 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
943 sprintf(string
, "root=%sp4", hdparams
.devnode
);
945 sprintf(string
, "root=%s4", hdparams
.devnode
);
946 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
948 mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc");
950 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /boot/grub/grubbatch");
952 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_GRUB
]))
954 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
957 mysystem("/bin/chroot /harddisk /bin/umount -n /proc");
960 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams
.devnode
);
961 mysystem(commandstring
);
962 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams
.devnode
);
963 mysystem(commandstring
);
965 sprintf(string
, "root=%sp4", hdparams
.devnode
);
967 sprintf(string
, "root=%s4", hdparams
.devnode
);
968 replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string
);
971 /* unmounting happens everywhere because there are places
972 which require device is to be unmounted under certain
973 circumstances. This is the last place we can unmount
974 anything and still succeed. */
976 if (!unmount_before
&& installtype
== CDROM_INSTALL
){
977 if (mysystem("/sbin/umount /cdrom"))
979 errorbox(ctr
[TR_UNABLE_TO_UNMOUNT_CDROM
]);
984 if (installtype
== CDROM_INSTALL
)
987 if (!(ejectcdrom(cdromparams
.devnode
)))
989 errorbox(ctr
[TR_UNABLE_TO_EJECT_CDROM
]);
995 sprintf(message
, ctr
[TR_CONGRATULATIONS_LONG
],
996 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
997 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
1002 fprintf(flog
, "Install program ended.\n");
1007 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
1011 freekeyvalues(ethernetkv
);
1013 if (allok
&& !allok_fastexit
)
1015 /* /proc is needed by the module checker. We have to mount it
1016 * so it can be seen by setup, which is run chrooted. */
1017 if (system("/sbin/mount proc -t proc /harddisk/proc"))
1018 printf("Unable to mount proc in /harddisk.");
1021 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
1022 printf("Unable to run setup.\n");
1023 if (system("/sbin/umount /harddisk/proc"))
1024 printf("Unable to umount /harddisk/proc.\n");
1030 system("/bin/swapoff /harddisk/swapfile");
1031 system("/sbin/umount /harddisk/var/log");
1032 system("/sbin/umount /harddisk/boot");
1033 system("/sbin/umount /harddisk");
1035 system("/etc/halt");