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