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