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