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