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