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.
14 #define CDROM_INSTALL 0
16 #define DISK_INSTALL 2
17 #define INST_FILECOUNT 6600
18 #define UNATTENDED_CONF "/cdrom/data/unattended.conf"
27 extern char url
[STRING_SIZE
];
34 char line
[STRING_SIZE
];
37 if ((fd
= fopen("/proc/cpuinfo", "r")) == NULL
) {
40 while (fgets(line
, STRING_SIZE
, fd
) != NULL
) {
41 if (strstr(line
, "processor") == line
) {
46 return (cpu_count
> 1);
49 int generate_packages_list(char *packages
, const char *rpmdir
, const char *source
) {
52 char buffer
[STRING_SIZE
];
53 bzero(buffer
, sizeof(buffer
));
55 if ((fd
= fopen(source
, "r")) == NULL
) {
56 (void) fprintf(flog
, "Packages file %s not found\n", source
);
59 while (fgets(buffer
, sizeof(buffer
), fd
) != NULL
) {
61 length
= strlen(buffer
)-1;
65 if (buffer
[length
] == '\n') {
68 length
= snprintf(packages
, STRING_SIZE
, "%s %s/%s", strdup(packages
), rpmdir
, buffer
);
69 if ((length
<0) || (length
>STRING_SIZE
)) {
70 (void) fprintf(flog
, "rpm command line too long: %d\n%s", length
, packages
);
75 (void) fprintf(flog
, "Error reading file\n");
83 long calc_swapsize(long memory
, long disk
) {
94 int unattended_setup(struct keyvalue
*unattendedkv
) {
95 struct keyvalue
*mainsettings
= initkeyvalues();
96 struct keyvalue
*ethernetkv
= initkeyvalues();
98 char commandstring
[STRING_SIZE
];
100 char domainname
[STRING_SIZE
];
101 char hostname
[STRING_SIZE
];
102 char keymap
[STRING_SIZE
];
103 char language
[STRING_SIZE
];
104 char timezone
[STRING_SIZE
];
105 char green_address
[STRING_SIZE
];
106 char green_netmask
[STRING_SIZE
];
107 char green_netaddress
[STRING_SIZE
];
108 char green_broadcast
[STRING_SIZE
];
109 char root_password
[STRING_SIZE
];
110 char admin_password
[STRING_SIZE
];
111 char serial_console
[STRING_SIZE
];
112 char reversesort
[STRING_SIZE
];
114 findkey(unattendedkv
, "DOMAINNAME", domainname
);
115 findkey(unattendedkv
, "HOSTNAME", hostname
);
116 findkey(unattendedkv
, "KEYMAP", keymap
);
117 findkey(unattendedkv
, "LANGUAGE", language
);
118 findkey(unattendedkv
, "TIMEZONE", timezone
);
119 findkey(unattendedkv
, "GREEN_ADDRESS", green_address
);
120 findkey(unattendedkv
, "GREEN_NETMASK", green_netmask
);
121 findkey(unattendedkv
, "GREEN_NETADDRESS", green_netaddress
);
122 findkey(unattendedkv
, "GREEN_BROADCAST", green_broadcast
);
123 findkey(unattendedkv
, "ROOT_PASSWORD", root_password
);
124 findkey(unattendedkv
, "ADMIN_PASSWORD", admin_password
);
125 findkey(unattendedkv
, "SERIAL_CONSOLE", serial_console
);
126 findkey(unattendedkv
, "REVERSE_NICS", reversesort
);
128 /* write main/settings. */
129 replacekeyvalue(mainsettings
, "DOMAINNAME", domainname
);
130 replacekeyvalue(mainsettings
, "HOSTNAME", hostname
);
131 replacekeyvalue(mainsettings
, "KEYMAP", keymap
);
132 replacekeyvalue(mainsettings
, "LANGUAGE", language
);
133 replacekeyvalue(mainsettings
, "TIMEZONE", timezone
);
134 writekeyvalues(mainsettings
, "/harddisk" CONFIG_ROOT
"/main/settings");
135 freekeyvalues(mainsettings
);
138 fprintf(flog
, "unattended: Starting setup\n");
142 fprintf(flog
, "unattended: setting up network configuration\n");
144 (void) readkeyvalues(ethernetkv
, "/harddisk" CONFIG_ROOT
"/ethernet/settings");
145 replacekeyvalue(ethernetkv
, "GREEN_ADDRESS", green_address
);
146 replacekeyvalue(ethernetkv
, "GREEN_NETMASK", green_netmask
);
147 replacekeyvalue(ethernetkv
, "GREEN_NETADDRESS", green_netaddress
);
148 replacekeyvalue(ethernetkv
, "GREEN_BROADCAST", green_broadcast
);
149 replacekeyvalue(ethernetkv
, "CONFIG_TYPE", "0");
150 replacekeyvalue(ethernetkv
, "GREEN_DEV", "eth0");
151 write_ethernet_configs(ethernetkv
);
152 freekeyvalues(ethernetkv
);
155 unlink("/harddisk/etc/localtime");
156 snprintf(commandstring
, STRING_SIZE
, "/harddisk/%s", timezone
);
157 link(commandstring
, "/harddisk/etc/localtime");
160 fprintf(flog
, "unattended: writing hostname.conf\n");
161 if (!(file
= fopen("/harddisk" CONFIG_ROOT
"/main/hostname.conf", "w")))
163 errorbox("unattended: ERROR writing hostname.conf");
166 fprintf(file
, "ServerName %s\n", hostname
);
169 fprintf(flog
, "unattended: writing hosts\n");
170 if (!(hosts
= fopen("/harddisk/etc/hosts", "w")))
172 errorbox("unattended: ERROR writing hosts");
175 fprintf(hosts
, "127.0.0.1\tlocalhost\n");
176 fprintf(hosts
, "%s\t%s.%s\t%s\n", green_address
, hostname
, domainname
, hostname
);
179 fprintf(flog
, "unattended: writing hosts.allow\n");
180 if (!(file
= fopen("/harddisk/etc/hosts.allow", "w")))
182 errorbox("unattended: ERROR writing hosts.allow");
185 fprintf(file
, "sshd : ALL\n");
186 fprintf(file
, "ALL : localhost\n");
187 fprintf(file
, "ALL : %s/%s\n", green_netaddress
, green_netmask
);
190 fprintf(flog
, "unattended: writing hosts.deny\n");
191 if (!(file
= fopen("/harddisk/etc/hosts.deny", "w")))
193 errorbox("unattended: ERROR writing hosts.deny");
196 fprintf(file
, "ALL : ALL\n");
199 if (strcmp(serial_console
, "yes") != 0) {
200 snprintf(commandstring
, STRING_SIZE
,
201 "/bin/chroot /harddisk /bin/sed -i -e \"s/^s0/#s0/\" /etc/inittab");
202 if (mysystem(commandstring
)) {
203 errorbox("unattended: ERROR modifying inittab");
207 snprintf(commandstring
, STRING_SIZE
,
208 "/bin/chroot /harddisk /bin/sed -i -e \"s/^serial/#serial/; s/^terminal/#terminal/\" /boot/grub/grub.conf");
209 if (mysystem(commandstring
)) {
210 errorbox("unattended: ERROR modifying inittab");
215 /* set reverse sorting of interfaces */
216 if (strcmp(reversesort
, "yes") == 0) {
217 mysystem("/bin/touch /harddisk/var/ipfire/ethernet/reverse_nics");
220 /* set root password */
221 fprintf(flog
, "unattended: setting root password\n");
223 snprintf(commandstring
, STRING_SIZE
,
224 "/bin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password
);
225 if (mysystem(commandstring
)) {
226 errorbox("unattended: ERROR setting root password");
230 /* set admin password */
231 fprintf(flog
, "unattended: setting admin password\n");
232 snprintf(commandstring
, STRING_SIZE
,
233 "/bin/chroot /harddisk /usr/bin/htpasswd -c -m -b " CONFIG_ROOT
"/auth/users admin '%s'", admin_password
);
234 if (mysystem(commandstring
)) {
235 errorbox("unattended: ERROR setting admin password");
242 int main(int argc
, char *argv
[])
244 char *langnames
[] = { "Deutsch", "English", NULL
};
245 char *shortlangnames
[] = { "de", "en", NULL
};
246 char **langtrs
[] = { de_tr
, en_tr
, NULL
};
247 char hdletter
, cdletter
;
248 char harddrive
[5], sourcedrive
[5]; /* Device holder. */
249 struct devparams hdparams
, cdromparams
; /* Params for CDROM and HD */
250 int cdmounted
= 0; /* Loop flag for inserting a cd. */
252 char commandstring
[STRING_SIZE
];
253 char *installtypes
[] = { "CDROM", "HTTP/FTP", NULL
};
254 int installtype
= CDROM_INSTALL
;
255 char insertmessage
[STRING_SIZE
];
256 char insertdevnode
[STRING_SIZE
];
258 char shortlangname
[10];
260 char title
[STRING_SIZE
];
262 int allok_fastexit
=0;
263 int unmount_before
=0;
264 struct keyvalue
*ethernetkv
= initkeyvalues();
265 FILE *handle
, *cmdfile
;
266 char line
[STRING_SIZE
];
267 char string
[STRING_SIZE
];
268 long maximum_free
= 0, current_free
;
270 long system_partition
, boot_partition
, root_partition
, swap_file
;
273 int pcmcia_cdrom
= 0;
278 char *yesnoharddisk
[] = { "NO", "YES", NULL
};
279 char *yesno
[] = { "NO", "YES", NULL
};
280 char green
[STRING_SIZE
];
282 struct keyvalue
*unattendedkv
= initkeyvalues();
283 char packages
[STRING_SIZE
];
284 int serial_console
= 0;
285 char megabridge
[STRING_SIZE
];
287 setlocale (LC_ALL
, "");
288 sethostname( SNAME
, 10);
290 memset(&hdparams
, 0, sizeof(struct devparams
));
291 memset(&cdromparams
, 0, sizeof(struct devparams
));
293 /* Log file/terminal stuff. */
296 if (!(flog
= fopen(argv
[1], "w+")))
304 fprintf(flog
, "Install program started.\n");
309 /* Do usb detection first for usb keyboard */
310 if (! (cmdfile
= fopen("/proc/cmdline", "r")))
312 fprintf(flog
, "Couldn't open commandline: /proc/cmdline\n");
314 fgets(line
, STRING_SIZE
, cmdfile
);
315 if (strstr (line
, "fdisk") != NULL
) {
316 fprintf(flog
, "Manual FDISK selected.\n");
319 if (strstr (line
, "nopcmcia") == NULL
) {
320 fprintf(flog
, "Initializing PCMCIA controllers.\n");
321 pcmcia
= initialize_pcmcia();
323 fprintf (flog
, "Detected PCMCIA Controller: %s.\n", pcmcia
);
324 sprintf(commandstring
, "/sbin/modprobe %s", pcmcia
);
325 mysystem("/sbin/modprobe pcmcia_core");
326 mysystem(commandstring
);
327 mysystem("/sbin/modprobe ds");
328 /* pcmcia netcard drivers are not available from Boot floppy,
329 * they will be loaded from Drivers floppy later */
331 fprintf (flog
, "Detected No PCMCIA Controller.\n");
334 fprintf(flog
, "Skipping PCMCIA detection.\n");
336 if (strstr (line
, "nousb") == NULL
) {
337 fprintf(flog
, "Initializing USB controllers.\n");
340 fprintf(flog
, "Skipping USB detection.\n");
342 // check if we have to make an unattended install
343 if (strstr (line
, "unattended") != NULL
) {
348 // make some beeps before wiping the system :)
350 runcommandwithstatus("/bin/beep -f 450 -r 10 -D 800 -n -f 900 -l 1000", "WARNING: Unattended installation will start in 10 seconds...");
353 /* German is the default */
354 for (choice
= 0; langnames
[choice
]; choice
++)
356 if (strcmp(langnames
[choice
], "Deutsch") == 0)
359 if (!langnames
[choice
])
363 rc
= newtWinMenu("Language selection",
364 "Select the language you wish to use for the " NAME
".", 50, 5, 5, 8,
365 langnames
, &choice
, "Ok", NULL
);
368 ctr
= langtrs
[choice
];
369 strcpy(shortlangname
, shortlangnames
[choice
]);
371 mysystem("/bin/setfont lat0-16");
373 newtDrawRootText(14, 0, NAME
" v" VERSION
" - " SLOGAN
);
374 newtPushHelpLine(ctr
[TR_HELPLINE
]);
377 sprintf(message
, ctr
[TR_WELCOME
], NAME
);
378 sprintf (title
, "%s %s - %s", NAME
, VERSION
, SLOGAN
);
379 newtWinMessage(title
, ctr
[TR_OK
], message
);
381 sprintf(message
, ctr
[TR_SELECT_INSTALLATION_MEDIA_LONG
], NAME
);
382 rc
= newtWinMenu(ctr
[TR_SELECT_INSTALLATION_MEDIA
], message
,
383 50, 5, 5, 6, installtypes
, &installtype
, ctr
[TR_OK
],
384 ctr
[TR_CANCEL
], NULL
);
388 installtype
= CDROM_INSTALL
;
394 // Starting hardware detection
395 runcommandwithstatus("/bin/probehw.sh", ctr
[TR_PROBING_HARDWARE
]);
398 if (installtype
== CDROM_INSTALL
) {
400 switch (mysystem("/bin/mountsource.sh")) {
402 installtype
= CDROM_INSTALL
;
406 installtype
= DISK_INSTALL
;
409 errorbox(ctr
[TR_NO_CDROM
]);
413 /* read source drive letter */
414 if ((handle
= fopen("/source_device", "r")) == NULL
) {
415 errorbox("ERROR reading source_device");
417 fgets(sourcedrive
, 5, handle
);
418 fprintf(flog
, "Source drive: %s\n", sourcedrive
);
421 snprintf(cdromparams
.devnode
, STRING_SIZE
, "/dev/%s", sourcedrive
);
422 cdromparams
.module
= 0;
423 fprintf(flog
, "Source device: %s\n", cdromparams
.devnode
);
426 /* Configure the network now! */
427 if (installtype
== URL_INSTALL
) {
428 /* Network driver and params. */
429 if (!(networkmenu(ethernetkv
))) {
430 errorbox(ctr
[TR_NETWORK_SETUP_FAILED
]);
434 /* Check for ipcop-<VERSION>.tbz2 */
435 if (checktarball(SNAME
"-" VERSION
".tbz2", ctr
[TR_ENTER_URL
])) {
436 errorbox(ctr
[TR_NO_IPCOP_TARBALL_FOUND
]);
441 /* Get device for the HD. This has to succeed. */
442 if (!(hdletter
= findidetype(IDE_HD
)))
444 /* Need to clean this up at some point */
445 if (!try_scsi("sda") || strstr(sourcedrive
, "sda") != NULL
) {
446 if (!try_scsi("ida/c0d0")) {
447 if (!try_scsi("cciss/c0d0")) {
448 if (!try_scsi("rd/c0d0")) {
449 if (!try_scsi("ataraid/d0")) {
450 errorbox(ctr
[TR_NO_HARDDISK
]);
454 sprintf(harddrive
, "ataraid/d0");
458 sprintf(harddrive
, "rd/c0d0");
462 sprintf(harddrive
, "cciss/c0d0");
466 sprintf(harddrive
, "ida/c0d0");
469 if (strstr(sourcedrive
, "sda") != NULL
) {
470 // probably installing from usb stick, try sdb
471 if (try_scsi("sdb")) {
472 sprintf(harddrive
, "sdb");
475 errorbox(ctr
[TR_NO_HARDDISK
]);
480 sprintf(harddrive
, "sda");
485 sprintf(harddrive
, "hd%c", hdletter
);
487 fprintf(flog
, "Destination drive: %s\n", harddrive
);
489 /* load unattended configuration */
491 fprintf(flog
, "unattended: Reading unattended.conf\n");
493 (void) readkeyvalues(unattendedkv
, UNATTENDED_CONF
);
496 /* Make the hdparms struct and print the contents. */
497 snprintf(hdparams
.devnode
, STRING_SIZE
, "/dev/%s", harddrive
);
500 sprintf(message
, ctr
[TR_PREPARE_HARDDISK
], hdparams
.devnode
);
507 rc
= newtWinMenu(title
, message
,
508 50, 5, 5, 6, yesnoharddisk
,
510 ctr
[TR_CANCEL
], NULL
);
518 /* Calculate amount of memory in machine */
519 if ((handle
= fopen("/proc/meminfo", "r")))
521 while (fgets(line
, STRING_SIZE
-1, handle
)) {
522 if (sscanf (line
, "MemTotal: %s kB", string
)) {
523 memory
= atoi(string
) / 1024 ;
529 /* Partition, mkswp, mkfs.
530 * before partitioning, first determine the sizes of each
531 * partition. In order to do that we need to know the size of
534 /* Don't use mysystem here so we can redirect output */
535 sprintf(commandstring
, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive
);
536 system(commandstring
);
538 /* Calculate amount of disk space */
539 if ((handle
= fopen("/disksize", "r")))
541 fgets(line
, STRING_SIZE
-1, handle
);
542 if (sscanf (line
, "%s", string
)) {
543 maximum_free
= atoi(string
) / 1024;
548 fprintf(flog
, "maximum_free = %ld, memory = %ld",
549 maximum_free
, memory
);
551 swap_file
= calc_swapsize(memory
, maximum_free
);
553 if (maximum_free
< 512 + swap_file
) {
554 if (maximum_free
< 512) {
555 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
560 rc
= newtWinChoice(title
, ctr
[TR_OK
], ctr
[TR_CANCEL
], ctr
[TR_CONTINUE_NO_SWAP
]);
571 boot_partition
= 20; /* in MB */
572 current_free
= maximum_free
- boot_partition
- swap_file
;
574 root_partition
= 2048 ;
575 if (current_free
< 512) {
576 errorbox(ctr
[TR_DISK_TOO_SMALL
]);
580 current_free
= current_free
- root_partition
;
582 root_partition
= root_partition
+ swap_file
;
585 system_partition
= current_free
;
587 fprintf(flog
, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
588 boot_partition
, swap_file
, system_partition
, root_partition
);
590 handle
= fopen("/tmp/partitiontable", "w");
594 fprintf(handle
, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
595 boot_partition
, swap_file
, root_partition
);
597 fprintf(handle
, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
598 boot_partition
, root_partition
);
603 snprintf(commandstring
, STRING_SIZE
, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams
.devnode
);
604 if (runcommandwithstatus(commandstring
, ctr
[TR_PARTITIONING_DISK
]))
606 errorbox(ctr
[TR_UNABLE_TO_PARTITION
]);
610 mysystem("/bin/udevstart");
613 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -T ext2 -c %sp1", hdparams
.devnode
);
615 snprintf(commandstring
, STRING_SIZE
, "/bin/mke2fs -T ext2 -c %s1", hdparams
.devnode
);
616 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_BOOT_FILESYSTEM
]))
618 errorbox(ctr
[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM
]);
624 snprintf(commandstring
, STRING_SIZE
, "/bin/mkswap %sp2", hdparams
.devnode
);
626 snprintf(commandstring
, STRING_SIZE
, "/bin/mkswap %s2", hdparams
.devnode
);
627 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_SWAPSPACE
]))
629 errorbox(ctr
[TR_UNABLE_TO_MAKE_SWAPSPACE
]);
635 snprintf(commandstring
, STRING_SIZE
, "/bin/mkreiserfs -f %sp3", hdparams
.devnode
);
637 snprintf(commandstring
, STRING_SIZE
, "/bin/mkreiserfs -f %s3", hdparams
.devnode
);
639 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_ROOT_FILESYSTEM
]))
641 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
646 snprintf(commandstring
, STRING_SIZE
, "/bin/mkreiserfs -f %sp4", hdparams
.devnode
);
648 snprintf(commandstring
, STRING_SIZE
, "/bin/mkreiserfs -f %s4", hdparams
.devnode
);
650 if (runcommandwithstatus(commandstring
, ctr
[TR_MAKING_LOG_FILESYSTEM
]))
652 errorbox(ctr
[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM
]);
656 /* Mount harddisk. */
658 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount %sp3 /harddisk", hdparams
.devnode
);
660 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount %s3 /harddisk", hdparams
.devnode
);
661 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_ROOT_FILESYSTEM
]))
663 errorbox(ctr
[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM
]);
667 mkdir("/harddisk/boot", S_IRWXU
|S_IRWXG
|S_IRWXO
);
668 mkdir("/harddisk/var", S_IRWXU
|S_IRWXG
|S_IRWXO
);
669 mkdir("/harddisk/var/log", S_IRWXU
|S_IRWXG
|S_IRWXO
);
672 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount %sp1 /harddisk/boot", hdparams
.devnode
);
674 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount %s1 /harddisk/boot", hdparams
.devnode
);
676 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_BOOT_FILESYSTEM
]))
678 errorbox(ctr
[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM
]);
683 snprintf(commandstring
, STRING_SIZE
, "/bin/swapon %sp2", hdparams
.devnode
);
685 snprintf(commandstring
, STRING_SIZE
, "/bin/swapon %s2", hdparams
.devnode
);
686 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_SWAP_PARTITION
]))
688 errorbox(ctr
[TR_UNABLE_TO_MOUNT_SWAP_PARTITION
]);
693 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount %sp4 /harddisk/var", hdparams
.devnode
);
695 snprintf(commandstring
, STRING_SIZE
, "/sbin/mount %s4 /harddisk/var", hdparams
.devnode
);
696 if (runcommandwithstatus(commandstring
, ctr
[TR_MOUNTING_LOG_FILESYSTEM
]))
698 errorbox(ctr
[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM
]);
702 snprintf(commandstring
, STRING_SIZE
, "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME
"-" VERSION
".tbz2");
704 if (runcommandwithprogress(60, 4, title
, commandstring
, INST_FILECOUNT
,
705 ctr
[TR_INSTALLING_FILES
]))
707 errorbox(ctr
[TR_UNABLE_TO_INSTALL_FILES
]);
711 /* Save USB controller type to modules.conf */
712 write_usb_modules_conf();
714 /* touch the modules.dep files */
715 snprintf(commandstring
, STRING_SIZE
,
716 "/bin/chroot /harddisk /usr/bin/touch /lib/modules/%s/modules.dep",
718 mysystem(commandstring
);
719 snprintf(commandstring
, STRING_SIZE
,
720 "/bin/chroot /harddisk /usr/bin/touch /lib/modules/%s-smp/modules.dep",
722 mysystem(commandstring
);
725 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
727 /* Write PCMCIA Config */
729 handle
= fopen("/harddisk/etc/modules.conf", "a");
730 if (handle
!= NULL
) {
731 fprintf (handle
, "# PCMCIA Settings\n");
732 fprintf (handle
, "alias pcmcia-controller %s\n", pcmcia
);
737 handle
= fopen("/harddisk/etc/pcmcia.conf", "w");
738 if (handle
!= NULL
) {
740 fprintf (handle
, "PCMCIA=yes\n");
741 fprintf (handle
, "PCIC=%s\n", pcmcia
);
743 fprintf (handle
, "PCMCIA=no\n");
744 fprintf (handle
, "PCIC=\n");
746 fprintf (handle
, "CARDMGR_OPTS=\n");
747 fprintf (handle
, "SCHEME=\n");
751 /* *always* write disk configuration */
752 if (!(write_disk_configs(&hdparams
))){
753 errorbox(ctr
[TR_ERROR_WRITING_CONFIG
]);
757 /* mount proc filesystem */
758 mysystem("mkdir /harddisk/proc");
759 mysystem("/bin/mount -t proc none /harddisk/proc");
760 mysystem("/bin/mount --bind /dev /harddisk/dev");
762 /* if we detected SCSI then fixup */
763 mysystem("/bin/probecntrl.sh");
764 if ((handle
= fopen("/cntrldriver", "r")))
767 fgets(line
, STRING_SIZE
-1, handle
);
769 line
[strlen(line
) - 1] = 0;
770 driver
= strtok(line
, ".");
771 fprintf(flog
, "Detected SCSI driver %s\n",driver
);
772 if (strlen(driver
) > 1) {
773 fprintf(flog
, "Fixing up ipfirerd.img\n");
774 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
775 mkdir("/harddisk/initrd", S_IRWXU
|S_IRWXG
|S_IRWXO
);
776 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata /boot/ipfirerd.img %s", driver
, KERNEL_VERSION
);
777 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
778 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata /boot/ipfirerd-smp.img %s-smp", driver
, KERNEL_VERSION
);
779 runcommandwithstatus(commandstring
, ctr
[TR_BUILDING_INITRD
]);
780 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
784 /* Build cache lang file */
785 snprintf(commandstring
, STRING_SIZE
, "/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
786 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_LANG_CACHE
]))
788 errorbox(ctr
[TR_UNABLE_TO_INSTALL_LANG_CACHE
]);
793 sprintf(string
, "root=%sp3", hdparams
.devnode
);
795 sprintf(string
, "root=%s3", hdparams
.devnode
);
796 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string
);
797 mysystem( "sed -i \"s|KVERSION|$(/bin/uname -r)|\" /harddisk/boot/grub/grub.conf" );
799 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams
.devnode
);
800 /* restore permissions */
801 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR
| S_IRUSR
| S_IXGRP
| S_IRGRP
| S_IXOTH
| S_IROTH
);
803 snprintf(commandstring
, STRING_SIZE
,
804 "/bin/chroot /harddisk /boot/grub/grubbatch");
805 if (runcommandwithstatus(commandstring
, ctr
[TR_INSTALLING_GRUB
])) {
806 errorbox(ctr
[TR_UNABLE_TO_INSTALL_GRUB
]);
810 /* Install bootsplash */
811 mysystem("/bin/installbootsplash.sh");
813 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
814 mysystem("umount /harddisk/proc");
815 mysystem("umount /harddisk/dev");
817 sprintf(message
, ctr
[TR_CONGRATULATIONS_LONG
],
818 NAME
, SNAME
, SNAME
, NAME
, NAME
, NAME
);
819 newtWinMessage(ctr
[TR_CONGRATULATIONS
], ctr
[TR_OK
], message
);
824 fprintf(flog
, "Install program ended.\n");
829 newtWinMessage(title
, ctr
[TR_OK
], ctr
[TR_PRESS_OK_TO_REBOOT
]);
833 freekeyvalues(ethernetkv
);
835 if (allok
&& !allok_fastexit
)
837 /* /proc is needed by the module checker. We have to mount it
838 * so it can be seen by setup, which is run chrooted. */
839 if (system("/sbin/mount proc -t proc /harddisk/proc"))
840 printf("Unable to mount proc in /harddisk.");
843 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
844 printf("Unable to run setup.\n");
845 if (system("/sbin/umount /harddisk/proc"))
846 printf("Unable to umount /harddisk/proc.\n");
852 system("/bin/swapoff /harddisk/swapfile");
853 system("/sbin/umount /harddisk/var");
854 system("/sbin/umount /harddisk/boot");
855 system("/sbin/umount /harddisk");