]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/install+setup/install/main.c
Updated kernel to 2.6.25.17
[people/pmueller/ipfire-2.x.git] / src / install+setup / install / main.c
CommitLineData
d6aaa55d
MT
1/* SmoothWall install program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
f9cc0d70 7 * Contains main entry point, and misc functions.6
d6aaa55d 8 *
d6aaa55d 9 */
10bc6f06 10
d6aaa55d 11#include "install.h"
72d80898
MT
12#define _GNU_SOURCE
13
0a0bdf6e 14#define INST_FILECOUNT 6200
33634aa8 15#define UNATTENDED_CONF "/cdrom/boot/unattended.conf"
d6aaa55d 16
cd8dd8dd
MT
17#define REISER4 0
18#define REISERFS 1
19#define EXT3 2
20
d6aaa55d
MT
21FILE *flog = NULL;
22char *mylog;
10bc6f06 23
d6aaa55d
MT
24char **ctr;
25
d6aaa55d
MT
26extern char url[STRING_SIZE];
27
f9cc0d70
HS
28struct nic nics[20] = { { "" , "" , "" } }; // only defined for compile
29struct knic knics[20] = { { "" , "" , "" , "" } }; // only defined for compile
5057b611 30
10bc6f06 31extern char *en_tr[];
10bc6f06 32extern char *de_tr[];
d6aaa55d
MT
33
34int main(int argc, char *argv[])
35{
b4e3cd7f
HS
36 char *langnames[] = { "Deutsch", "English", NULL };
37 char *shortlangnames[] = { "de", "en", NULL };
38 char **langtrs[] = { de_tr, en_tr, NULL };
c78a77eb 39 char hdletter;
77f1c55f 40 char harddrive[30], sourcedrive[5]; /* Device holder. */
72d80898 41 struct devparams hdparams, cdromparams; /* Params for CDROM and HD */
72d80898 42 int rc = 0;
d6aaa55d 43 char commandstring[STRING_SIZE];
cd8dd8dd
MT
44 char mkfscommand[STRING_SIZE];
45 char *fstypes[] = { "Reiser4", "ReiserFS", "ext3", NULL };
cfff20e5 46 int fstype = REISERFS;
d6aaa55d 47 int choice;
ee78a5ef
MT
48 int i;
49 int found = 0;
50 int firstrun = 0;
d6aaa55d
MT
51 char shortlangname[10];
52 char message[1000];
53 char title[STRING_SIZE];
54 int allok = 0;
10bc6f06 55 int allok_fastexit=0;
56b548f1 56 int raid_disk = 0;
d6aaa55d
MT
57 struct keyvalue *ethernetkv = initkeyvalues();
58 FILE *handle, *cmdfile;
59 char line[STRING_SIZE];
60 char string[STRING_SIZE];
66294b69 61 long memory = 0, disk = 0, free;
8e2e5cf3 62 long system_partition, boot_partition, root_partition, swap_file;
d6aaa55d 63 int scsi_disk = 0;
5057b611
HS
64 char *yesnoharddisk[3]; // char *yesnoharddisk = { "NO", "YES", NULL };
65
72d80898
MT
66 int unattended = 0;
67 struct keyvalue *unattendedkv = initkeyvalues();
c78a77eb 68 int hardyn = 0;
d6aaa55d
MT
69
70 setlocale (LC_ALL, "");
10bc6f06 71 sethostname( SNAME , 10);
72d80898 72
d6aaa55d
MT
73 memset(&hdparams, 0, sizeof(struct devparams));
74 memset(&cdromparams, 0, sizeof(struct devparams));
75
76 /* Log file/terminal stuff. */
77 if (argc >= 2)
78 {
79 if (!(flog = fopen(argv[1], "w+")))
80 return 0;
81 }
82 else
83 return 0;
84
85 mylog = argv[1];
86
87 fprintf(flog, "Install program started.\n");
88
89 newtInit();
90 newtCls();
91
92 /* Do usb detection first for usb keyboard */
93 if (! (cmdfile = fopen("/proc/cmdline", "r")))
94 {
95 fprintf(flog, "Couldn't open commandline: /proc/cmdline\n");
96 } else {
97 fgets(line, STRING_SIZE, cmdfile);
61e3d218 98
72d80898 99 // check if we have to make an unattended install
ee78a5ef 100 if (strstr (line, "unattended") != NULL) {
72d80898 101 unattended = 1;
bba7212c
MT
102 runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds...");
103 }
d6aaa55d 104 }
0db33b56 105
bba7212c
MT
106 mysystem("/sbin/modprobe ide-generic");
107 mysystem("/sbin/modprobe generic");
9c534116 108 mysystem("/sbin/modprobe ide-cd_mod");
bba7212c 109 mysystem("/sbin/modprobe ide-disk");
3485f9a2
CS
110 mysystem("/sbin/modprobe uhci-hcd");
111 mysystem("/sbin/modprobe ohci-hcd");
112 mysystem("/sbin/modprobe ehci-hcd");
149a26a8 113 mysystem("/sbin/modprobe ohci1394");
bba7212c
MT
114 mysystem("/sbin/modprobe sd_mod");
115 mysystem("/sbin/modprobe sr_mod");
116 mysystem("/sbin/modprobe usb-storage");
117 mysystem("/sbin/modprobe usbhid");
118
119 mysystem("/sbin/modprobe iso9660"); // CDROM
120 mysystem("/sbin/modprobe ext2"); // Boot patition
121 mysystem("/sbin/modprobe vfat"); // USB key
d6aaa55d 122
72d80898 123 /* German is the default */
d6aaa55d
MT
124 for (choice = 0; langnames[choice]; choice++)
125 {
b4e3cd7f 126 if (strcmp(langnames[choice], "Deutsch") == 0)
d6aaa55d
MT
127 break;
128 }
129 if (!langnames[choice])
130 goto EXIT;
131
72d80898 132 if (!unattended) {
51f3b7f5 133 rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8,
72d80898
MT
134 langnames, &choice, "Ok", NULL);
135 }
136
d6aaa55d
MT
137 ctr = langtrs[choice];
138 strcpy(shortlangname, shortlangnames[choice]);
3d6e1202 139
33634aa8 140 newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
d6aaa55d 141 newtPushHelpLine(ctr[TR_HELPLINE]);
4809e64e 142 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
d6aaa55d 143
0db33b56
MT
144 // Starting hardware detection
145 runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]);
146
03d956be
MT
147 sprintf(message, ctr[TR_WELCOME], NAME);
148 newtWinMessage(title, ctr[TR_OK], message);
72d80898 149
03d956be
MT
150 switch (mysystem("/bin/mountsource.sh")) {
151 case 0:
152 break;
153 case 10:
154 errorbox(ctr[TR_NO_CDROM]);
72d80898 155 goto EXIT;
72d80898 156 }
9607771a 157
03d956be
MT
158 /* read source drive letter */
159 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
160 errorbox(ctr[TR_ERROR_PROBING_CDROM]);
161 goto EXIT;
72d80898 162 }
03d956be
MT
163 fgets(sourcedrive, 5, handle);
164 fprintf(flog, "Source drive: %s\n", sourcedrive);
165 fclose(handle);
1cdddb12 166
ee78a5ef
MT
167 i = 0;
168 while (found == 0) {
169 i++;
170 fprintf(flog, "Harddisk scan pass %i\n", i);
171
aee3027d 172 switch (mysystem("/bin/mountdest.sh") % 255) {
ee78a5ef
MT
173 case 0: // Found IDE disk
174 scsi_disk = 0;
56b548f1 175 raid_disk = 0;
ee78a5ef
MT
176 found = 1;
177 break;
178 case 1: // Found SCSI disk
179 scsi_disk = 1;
56b548f1
MT
180 raid_disk = 0;
181 found = 1;
182 break;
183 case 2: // Found RAID disk
184 scsi_disk = 0;
185 raid_disk= 1;
ee78a5ef
MT
186 found = 1;
187 break;
188 case 10: // No harddisk found
189 if (firstrun == 1) {
190 errorbox(ctr[TR_NO_HARDDISK]);
191 goto EXIT;
192 }
193 // Do this if the kudzu-scan fails...
194 runcommandwithstatus("/bin/probehw.sh deep-scan", ctr[TR_PROBING_HARDWARE]);
195 firstrun = 1;
aee3027d 196 }
ee78a5ef
MT
197 }
198
ee78a5ef
MT
199 if ((handle = fopen("/tmp/dest_device", "r")) == NULL) {
200 errorbox(ctr[TR_NO_HARDDISK]);
201 goto EXIT;
202 }
77f1c55f 203 fgets(harddrive, 30, handle);
ee78a5ef
MT
204 fclose(handle);
205
72d80898
MT
206 /* load unattended configuration */
207 if (unattended) {
208 fprintf(flog, "unattended: Reading unattended.conf\n");
209
210 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
211 }
72d80898 212
1cdddb12
MT
213 /* Make the hdparms struct and print the contents.
214 With USB-KEY install and SCSI disk, while installing, the disk
215 is named 'sdb,sdc,...' (following keys)
216 On reboot, it will become 'sda'
217 To avoid many test, all names are built in the struct.
218 */
219 sprintf(hdparams.devnode_disk, "/dev/%s", harddrive);
220 /* Address the partition or raid partition (eg dev/sda or /dev/sdap1 */
221 sprintf(hdparams.devnode_part, "/dev/%s%s", harddrive,raid_disk ? "p" : "");
222 /* Now the names after the machine is booted. Only scsi is affected
223 and we only install on the first scsi disk. */
224 { char tmp[30];
225 strcpy(tmp, scsi_disk ? "sda" : harddrive);
226 sprintf(hdparams.devnode_disk_run, "/dev/%s", tmp);
227 sprintf(hdparams.devnode_part_run, "/dev/%s%s", tmp, raid_disk ? "p" : "");
228 }
229
230 fprintf(flog, "Destination drive: %s\n", hdparams.devnode_disk);
231
232 sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode_disk);
72d80898
MT
233 if (unattended) {
234 hardyn = 1;
be91126f
MT
235 } else {
236 yesnoharddisk[0] = ctr[TR_NO];
237 yesnoharddisk[1] = ctr[TR_YES];
238 yesnoharddisk[2] = NULL;
72d80898 239 }
5057b611 240
72d80898
MT
241 while (! hardyn) {
242 rc = newtWinMenu(title, message,
243 50, 5, 5, 6, yesnoharddisk,
244 &hardyn, ctr[TR_OK],
245 ctr[TR_CANCEL], NULL);
246 if (rc == 2)
247 goto EXIT;
248 }
5433e2c9
MT
249 if (rc == 2)
250 goto EXIT;
72d80898 251
cd8dd8dd 252 if (!unattended) {
1700769c
CS
253 sprintf(message, ctr[TR_CHOOSE_FILESYSTEM]);
254 rc = newtWinMenu( ctr[TR_CHOOSE_FILESYSTEM], message,
cd8dd8dd
MT
255 50, 5, 5, 6, fstypes, &fstype, ctr[TR_OK],
256 ctr[TR_CANCEL], NULL);
257 } else {
258 rc = 1;
cfff20e5 259 fstype = REISERFS;
cd8dd8dd
MT
260 }
261 if (rc == 2)
262 goto EXIT;
263
72d80898
MT
264 /* Calculate amount of memory in machine */
265 if ((handle = fopen("/proc/meminfo", "r")))
266 {
267 while (fgets(line, STRING_SIZE-1, handle)) {
268 if (sscanf (line, "MemTotal: %s kB", string)) {
269 memory = atoi(string) / 1024 ;
270 }
271 }
272 fclose(handle);
273 }
274
275 /* Partition, mkswp, mkfs.
276 * before partitioning, first determine the sizes of each
277 * partition. In order to do that we need to know the size of
278 * the disk.
279 */
280 /* Don't use mysystem here so we can redirect output */
0b59f25c 281 sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive);
72d80898
MT
282 system(commandstring);
283
284 /* Calculate amount of disk space */
d3fb18db
MT
285 if ((handle = fopen("/tmp/disksize", "r"))) {
286 fgets(line, STRING_SIZE-1, handle);
287 if (sscanf (line, "%s", string)) {
ffd4d196 288 disk = atoi(string) / 1024;
d3fb18db
MT
289 }
290 fclose(handle);
291 }
72d80898 292
ffd4d196 293 fprintf(flog, "Disksize = %ld, memory = %ld", disk, memory);
72d80898 294
ffd4d196 295 /* Calculating Swap-Size dependend of Ram Size */
66294b69
MT
296 if (memory < 128)
297 swap_file = 32;
58c7871a 298 else if (memory >= 1024)
66294b69
MT
299 swap_file = 512;
300 else
301 swap_file = memory;
ffd4d196
CS
302
303 /* Calculating Root-Size dependend of Max Disk Space */
a5997a4c 304 if ( disk < 756 )
25943d3b
CS
305 root_partition = 200;
306 else if ( disk >= 756 && disk <= 3072 )
66294b69
MT
307 root_partition = 512;
308 else
309 root_partition = 2048;
310
ffd4d196
CS
311
312 /* Calculating the amount of free space */
313 boot_partition = 20; /* in MB */
314 system_partition = disk - ( root_partition + swap_file + boot_partition );
d3fb18db 315
66294b69
MT
316 fprintf(flog, ", boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
317 boot_partition, swap_file, system_partition, root_partition);
9cd0c7fd 318 rc = 0;
66294b69 319
9cd0c7fd 320 if ( (!unattended) && (((disk - (root_partition + swap_file + boot_partition)) < 256 ) && ((disk - (root_partition + boot_partition )) > 256)) ) {
a5997a4c 321 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
9cd0c7fd
MT
322 if (rc == 1){
323 swap_file = 0;
a5997a4c 324 system_partition = disk - ( root_partition + swap_file + boot_partition );
9cd0c7fd 325 fprintf(flog, "Changing Swap Size to 0 MB.\n");
a5997a4c 326 }
9cd0c7fd 327 else if (rc == 2){
a5997a4c
MT
328 fprintf(flog, "Disk is too small.\n");
329 errorbox(ctr[TR_DISK_TOO_SMALL]);goto EXIT;
330 }
66294b69 331 }
58c7871a 332 else if (disk - (root_partition + swap_file + boot_partition) >= 256) {
66294b69
MT
333
334 }
335 else {
336 fprintf(flog, "Disk is too small.\n");
337 errorbox(ctr[TR_DISK_TOO_SMALL]);goto EXIT;
338 }
a5997a4c 339
72d80898
MT
340 handle = fopen("/tmp/partitiontable", "w");
341
72d80898 342 /* Make swapfile */
9cd0c7fd
MT
343 if (swap_file) {
344 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
345 boot_partition, swap_file, root_partition);
346 } else {
347 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
348 boot_partition, root_partition);
349 }
72d80898
MT
350
351 fclose(handle);
352
1cdddb12 353 snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode_disk);
72d80898
MT
354 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
355 {
356 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
357 goto EXIT;
358 }
cd8dd8dd
MT
359
360 if (fstype == REISER4) {
361 mysystem("/sbin/modprobe reiser4");
362 sprintf(mkfscommand, "/sbin/mkfs.reiser4 -y");
363 } else if (fstype == REISERFS) {
364 mysystem("/sbin/modprobe reiserfs");
365 sprintf(mkfscommand, "/sbin/mkreiserfs -f");
366 } else if (fstype == EXT3) {
367 mysystem("/sbin/modprobe ext3");
6027d6b8 368 sprintf(mkfscommand, "/sbin/mke2fs -T ext3 -c");
cd8dd8dd 369 }
72d80898 370
6027d6b8 371 snprintf(commandstring, STRING_SIZE, "/sbin/mke2fs -T ext2 -c %s1", hdparams.devnode_part);
72d80898
MT
372 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
373 {
374 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
375 goto EXIT;
376 }
377
378 if (swap_file) {
1cdddb12 379 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode_part);
72d80898
MT
380 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
381 {
382 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
383 goto EXIT;
384 }
385 }
386
cd8dd8dd 387 snprintf(commandstring, STRING_SIZE, "%s %s3", mkfscommand, hdparams.devnode_part);
72d80898
MT
388 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
389 {
390 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
391 goto EXIT;
392 }
393
cd8dd8dd 394 snprintf(commandstring, STRING_SIZE, "%s %s4", mkfscommand, hdparams.devnode_part);
72d80898
MT
395 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
396 {
cd8dd8dd 397 errorbox(ctr[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM]);
72d80898 398 goto EXIT;
9607771a 399 }
72d80898 400
1cdddb12 401 snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode_part);
72d80898
MT
402 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
403 {
404 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
405 goto EXIT;
406 }
407
408 mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
409 mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
410 mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
411
1cdddb12 412 snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode_part);
72d80898
MT
413 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
414 {
415 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
416 goto EXIT;
417 }
418 if (swap_file) {
1cdddb12 419 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode_part);
72d80898
MT
420 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
421 {
422 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
423 goto EXIT;
424 }
425 }
1cdddb12 426 snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode_part);
72d80898
MT
427 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
428 {
429 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
430 goto EXIT;
9607771a 431 }
c78a77eb 432
03d956be
MT
433 snprintf(commandstring, STRING_SIZE,
434 "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
d6aaa55d 435
edd536b6
MT
436 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
437 ctr[TR_INSTALLING_FILES]))
d6aaa55d
MT
438 {
439 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
440 goto EXIT;
441 }
406f019f
MT
442
443 /* Save language und local settings */
444 write_lang_configs(shortlangname);
d6aaa55d
MT
445
446 /* touch the modules.dep files */
10bc6f06 447 snprintf(commandstring, STRING_SIZE,
c78a77eb 448 "/bin/touch /harddisk/lib/modules/%s-ipfire/modules.dep",
10bc6f06
MT
449 KERNEL_VERSION);
450 mysystem(commandstring);
fd383f41 451/* snprintf(commandstring, STRING_SIZE,
c78a77eb 452 "/bin/touch /harddisk/lib/modules/%s-ipfire-smp/modules.dep",
10bc6f06
MT
453 KERNEL_VERSION);
454 mysystem(commandstring);
fd383f41 455*/
d6aaa55d
MT
456 /* Rename uname */
457 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
458
9607771a
MT
459 /* mount proc filesystem */
460 mysystem("mkdir /harddisk/proc");
ee78a5ef
MT
461 mysystem("/bin/mount --bind /proc /harddisk/proc");
462 mysystem("/bin/mount --bind /dev /harddisk/dev");
463 mysystem("/bin/mount --bind /sys /harddisk/sys");
9607771a 464
330345c2
MT
465 /* Build cache lang file */
466 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
467 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
468 {
469 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
470 goto EXIT;
471 }
472
473 /* Update /etc/fstab */
1cdddb12 474 replace("/harddisk/etc/fstab", "DEVICE", hdparams.devnode_part_run);
cd8dd8dd
MT
475
476 if (fstype == REISER4) {
477 replace("/harddisk/etc/fstab", "FSTYPE", "reiser4");
d3fb18db 478 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "rw");
cd8dd8dd
MT
479 } else if (fstype == REISERFS) {
480 replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs");
d3fb18db 481 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
cd8dd8dd 482 } else if (fstype == EXT3) {
db101f0c 483 snprintf(commandstring, STRING_SIZE, "tune2fs -j %s3", hdparams.devnode_part);
1700769c 484 if (runcommandwithstatus(commandstring, ctr[TR_JOURNAL_EXT3]))
db101f0c 485 {
1700769c 486 errorbox(ctr[TR_JOURNAL_ERROR]);
db101f0c
MT
487 replace("/harddisk/etc/fstab", "FSTYPE", "ext2");
488 goto NOJOURNAL;
489 }
490 snprintf(commandstring, STRING_SIZE, "tune2fs -j %s4", hdparams.devnode_part);
1700769c 491 if (runcommandwithstatus(commandstring, ctr[TR_JOURNAL_EXT3]))
db101f0c 492 {
1700769c 493 errorbox(ctr[TR_JOURNAL_ERROR]);
db101f0c
MT
494 replace("/harddisk/etc/fstab", "FSTYPE", "ext2");
495 goto NOJOURNAL;
496 }
cd8dd8dd 497 replace("/harddisk/etc/fstab", "FSTYPE", "ext3");
db101f0c 498 NOJOURNAL:
d3fb18db 499 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
cd8dd8dd 500 }
73d9a908 501
a869b064
AF
502 replace("/harddisk/boot/grub/grub.conf", "KVER", KERNEL_VERSION);
503
edd66ab6
AF
504 /* Build the emergency ramdisk with all drivers */
505 mysystem("cp -f /harddisk/etc/mkinitcpio.conf /harddisk/etc/mkinitcpio.conf.org");
506
507 replace("/harddisk/etc/mkinitcpio.conf", " autodetect ", " ");
508 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitcpio -g /boot/ipfirerd-%s-emergency.img -k %s-ipfire", KERNEL_VERSION, KERNEL_VERSION);
509 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
510
511 mysystem("cp -f /harddisk/etc/mkinitcpio.conf.org /harddisk/etc/mkinitcpio.conf");
512
e62ab04d 513 /* mkinitcpio has a problem if ide and pata are included */
a6e9d42e 514 if ( scsi_disk==1 ) {
e62ab04d
MT
515 /* Remove the ide hook if we install sda */
516 replace("/harddisk/etc/mkinitcpio.conf", " ide ", " ");
517 } else {
2e95c21c 518 /* Remove the pata & sata hook if we install hda */
e62ab04d 519 replace("/harddisk/etc/mkinitcpio.conf", " pata ", " ");
2e95c21c 520 replace("/harddisk/etc/mkinitcpio.conf", " sata ", " ");
a6e9d42e 521 }
ee78a5ef 522 /* Going to make our initrd... */
a869b064 523 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitcpio -g /boot/ipfirerd-%s.img -k %s-ipfire", KERNEL_VERSION, KERNEL_VERSION);
ee78a5ef 524 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
fd383f41 525/* snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitcpio -g /boot/ipfirerd-%s-smp.img -k %s-ipfire-smp", KERNEL_VERSION, KERNEL_VERSION );
ee78a5ef 526 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
fd383f41 527*/
1cdddb12 528 sprintf(string, "root=%s3", hdparams.devnode_part_run);
edd536b6 529 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
f4e27420 530 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
fd0763dc 531
f4e27420 532 system("sed -e 's#harddisk\\/##g' < /proc/mounts > /harddisk/etc/mtab");
edd536b6 533
edd536b6 534 snprintf(commandstring, STRING_SIZE,
03d956be 535 "/sbin/chroot /harddisk /usr/sbin/grub-install --no-floppy %s", hdparams.devnode_disk);
edd536b6
MT
536 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
537 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
538 goto EXIT;
539 }
8de160ff
MT
540
541 mysystem("umount /cdrom");
3ef6c343
MT
542 snprintf(commandstring, STRING_SIZE, "eject /dev/%s", sourcedrive);
543 mysystem(commandstring);
22b9e405 544
73d9a908
MT
545 if (!unattended) {
546 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
3ad8835c 547 NAME, SNAME, NAME);
73d9a908
MT
548 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
549 }
cd8dd8dd 550
22b9e405 551 allok = 1;
edd536b6 552
d6aaa55d 553EXIT:
10bc6f06 554 fprintf(flog, "Install program ended.\n");
d6aaa55d 555
10bc6f06 556 if (!(allok))
d6aaa55d 557 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
10bc6f06 558
d6aaa55d 559 freekeyvalues(ethernetkv);
d6aaa55d 560
10bc6f06 561 if (allok && !allok_fastexit)
d6aaa55d 562 {
ee78a5ef
MT
563 if (unattended) {
564 fprintf(flog, "Entering unattended setup\n");
565 if (unattended_setup(unattendedkv)) {
c78a77eb
MT
566 snprintf(commandstring, STRING_SIZE, "/bin/sleep 10");
567 runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot");
ee78a5ef 568 } else {
c78a77eb
MT
569 errorbox("Unattended setup failed.");
570 goto EXIT;
c78a77eb 571 }
ee78a5ef 572 }
c78a77eb 573
ee78a5ef
MT
574 fflush(flog);
575 fclose(flog);
576 newtFinished();
577
578 if (!unattended) {
ee78a5ef
MT
579 if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
580 printf("Unable to run setup.\n");
ee78a5ef 581 }
3a1019f6 582
ee78a5ef
MT
583 if (system("/bin/umount /harddisk/proc"))
584 printf("Unable to umount /harddisk/proc.\n");
5057b611
HS
585 } else {
586 fflush(flog);
587 fclose(flog);
588 newtFinished();
d6aaa55d 589 }
5057b611 590
d6aaa55d
MT
591 fcloseall();
592
3a1019f6 593 if (swap_file) {
1cdddb12 594 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode_part);
3a1019f6
MT
595 }
596
597 newtFinished();
598
5057b611
HS
599 system("/bin/umount /harddisk/proc");
600 system("/bin/umount /harddisk/dev");
ee78a5ef 601 system("/bin/umount /harddisk/sys");
5057b611 602
532a3663
MT
603 system("/bin/umount /harddisk/var");
604 system("/bin/umount /harddisk/boot");
605 system("/bin/umount /harddisk");
10bc6f06 606
d6aaa55d
MT
607 system("/etc/halt");
608
609 return 0;
610}