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