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