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