]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/install+setup/install/main.c
Merge branch 'kernel-update' of ssh://git.ipfire.org/pub/git/ipfire-2.x into kernel...
[people/teissler/ipfire-2.x.git] / src / install+setup / install / main.c
1
2 /* SmoothWall install program.
3 *
4 * This program is distributed under the terms of the GNU General Public
5 * Licence. See the file COPYING for details.
6 *
7 * (c) Lawrence Manning, 2001
8 * Contains main entry point, and misc functions.6
9 *
10 */
11
12 #include "install.h"
13 #define _GNU_SOURCE
14
15 #define INST_FILECOUNT 10700
16 #define UNATTENDED_CONF "/cdrom/boot/unattended.conf"
17
18 #define EXT2 0
19 #define EXT3 1
20 #define EXT4 2
21 #define REISERFS 3
22
23 FILE *flog = NULL;
24 char *mylog;
25
26 char **ctr;
27
28 extern char url[STRING_SIZE];
29
30 struct nic nics[20] = { { "" , "" , "" } }; // only defined for compile
31 struct knic knics[20] = { { "" , "" , "" , "" } }; // only defined for compile
32
33 extern char *en_tr[];
34 extern char *es_tr[];
35 extern char *de_tr[];
36 extern char *fr_tr[];
37 extern char *pl_tr[];
38 extern char *ru_tr[];
39
40 int main(int argc, char *argv[])
41 {
42
43 char discl_msg[40000] = "Disclaimer\n";
44
45 char *langnames[] = { "Deutsch", "English", "Français", "Español", "Polski", "Русский", NULL };
46 char *shortlangnames[] = { "de", "en", "fr", "es", "pl", "ru", NULL };
47 char **langtrs[] = { de_tr, en_tr, fr_tr, es_tr, pl_tr, ru_tr, NULL };
48 char hdletter;
49 char harddrive[30], sourcedrive[5]; /* Device holder. */
50 struct devparams hdparams, cdromparams; /* Params for CDROM and HD */
51 int rc = 0;
52 char commandstring[STRING_SIZE];
53 char mkfscommand[STRING_SIZE];
54 char *fstypes[] = { "ext2", "ext3", "ext4", "ReiserFS", NULL };
55 int fstype = EXT4;
56 int choice;
57 int i;
58 int found = 0;
59 int firstrun = 0;
60 char shortlangname[10];
61 char message[1000];
62 char title[STRING_SIZE];
63 int allok = 0;
64 int allok_fastexit=0;
65 int raid_disk = 0;
66 struct keyvalue *ethernetkv = initkeyvalues();
67 FILE *handle, *cmdfile, *copying;
68 char line[STRING_SIZE];
69 char string[STRING_SIZE];
70 long memory = 0, disk = 0, free;
71 long system_partition, boot_partition, root_partition, swap_file;
72 int scsi_disk = 0;
73 char *yesnoharddisk[3]; // char *yesnoharddisk = { "NO", "YES", NULL };
74
75 int unattended = 0;
76 int serialconsole = 0;
77 struct keyvalue *unattendedkv = initkeyvalues();
78 int hardyn = 0;
79 char restore_file[STRING_SIZE] = "";
80
81 setlocale (LC_ALL, "");
82 sethostname( SNAME , 10);
83
84 memset(&hdparams, 0, sizeof(struct devparams));
85 memset(&cdromparams, 0, sizeof(struct devparams));
86
87 /* Log file/terminal stuff. */
88 if (argc >= 2)
89 {
90 if (!(flog = fopen(argv[1], "w+")))
91 return 0;
92 }
93 else
94 return 0;
95
96 mylog = argv[1];
97
98 fprintf(flog, "Install program started.\n");
99
100 newtInit();
101 newtCls();
102
103 newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
104 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
105
106 if (! (cmdfile = fopen("/proc/cmdline", "r")))
107 {
108 fprintf(flog, "Couldn't open commandline: /proc/cmdline\n");
109 } else {
110 fgets(line, STRING_SIZE, cmdfile);
111
112 // check if we have to make an unattended install
113 if (strstr (line, "unattended") != NULL) {
114 unattended = 1;
115 runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds...");
116 }
117 // check if we have to patch for serial console
118 if (strstr (line, "console=ttyS0") != NULL) {
119 serialconsole = 1;
120 }
121 }
122
123 // Read gpl ...
124 if (! (copying = fopen("/COPYING", "r")))
125 {
126 fprintf(flog, "Couldn't open gpl (/COPYING)\n");
127 sprintf(discl_msg, "Couldn't open gpl (/COPYING)\n");
128 } else {
129 fread(discl_msg, 1, 40000, copying);
130 fclose(copying);
131 }
132
133 // Load common modules
134 mysystem("/sbin/modprobe iso9660"); // CDROM
135 // mysystem("/sbin/modprobe ext2"); // Boot patition
136 mysystem("/sbin/modprobe vfat"); // USB key
137
138 /* German is the default */
139 for (choice = 0; langnames[choice]; choice++)
140 {
141 if (strcmp(langnames[choice], "English") == 0)
142 break;
143 }
144 if (!langnames[choice])
145 goto EXIT;
146
147 if (!unattended) {
148 rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8,
149 langnames, &choice, "Ok", NULL);
150 }
151
152 ctr = langtrs[choice];
153 strcpy(shortlangname, shortlangnames[choice]);
154
155 newtPushHelpLine(ctr[TR_HELPLINE]);
156
157 if (!unattended) {
158 sprintf(message, ctr[TR_WELCOME], NAME);
159 newtWinMessage(title, ctr[TR_OK], message);
160
161 if (disclaimerbox(discl_msg)==0) {
162 errorbox(ctr[TR_LICENSE_NOT_ACCEPTED]);
163 goto EXIT;
164 }
165 }
166
167 mysystem("/bin/mountsource.sh");
168
169 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
170 newtWinMessage(title, ctr[TR_OK], ctr[TR_NO_LOCAL_SOURCE]);
171 runcommandwithstatus("/bin/downloadsource.sh",ctr[TR_DOWNLOADING_ISO]);
172 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
173 errorbox(ctr[TR_DOWNLOAD_ERROR]);
174 goto EXIT;
175 }
176 }
177
178 fgets(sourcedrive, 5, handle);
179 fprintf(flog, "Source drive: %s\n", sourcedrive);
180 fclose(handle);
181
182 i = 0;
183 while (found == 0) {
184 i++;
185 fprintf(flog, "Harddisk scan pass %i\n", i);
186
187 switch (mysystem("/bin/mountdest.sh") % 255) {
188 case 0: // Found IDE disk
189 scsi_disk = 0;
190 raid_disk = 0;
191 found = 1;
192 break;
193 case 1: // Found SCSI disk
194 scsi_disk = 1;
195 raid_disk = 0;
196 found = 1;
197 break;
198 case 2: // Found RAID disk
199 scsi_disk = 0;
200 raid_disk= 1;
201 found = 1;
202 break;
203 case 10: // No harddisk found
204 if (firstrun == 1) {
205 errorbox(ctr[TR_NO_HARDDISK]);
206 goto EXIT;
207 }
208 // Do this if the kudzu-scan fails...
209 runcommandwithstatus("/bin/probehw.sh deep-scan", ctr[TR_PROBING_HARDWARE]);
210 firstrun = 1;
211 }
212 }
213
214 if ((handle = fopen("/tmp/dest_device", "r")) == NULL) {
215 errorbox(ctr[TR_NO_HARDDISK]);
216 goto EXIT;
217 }
218 fgets(harddrive, 30, handle);
219 fclose(handle);
220
221 /* load unattended configuration */
222 if (unattended) {
223 fprintf(flog, "unattended: Reading unattended.conf\n");
224
225 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
226 findkey(unattendedkv, "RESTORE_FILE", restore_file);
227 }
228
229 /* Make the hdparms struct and print the contents.
230 With USB-KEY install and SCSI disk, while installing, the disk
231 is named 'sdb,sdc,...' (following keys)
232 On reboot, it will become 'sda'
233 To avoid many test, all names are built in the struct.
234 */
235 sprintf(hdparams.devnode_disk, "/dev/%s", harddrive);
236 /* Address the partition or raid partition (eg dev/sda or /dev/sdap1 */
237 sprintf(hdparams.devnode_part, "/dev/%s%s", harddrive,raid_disk ? "p" : "");
238 /* Now the names after the machine is booted. Only scsi is affected
239 and we only install on the first scsi disk. */
240
241 fprintf(flog, "Destination drive: %s\n", hdparams.devnode_disk);
242
243 sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode_disk);
244 if (unattended) {
245 hardyn = 1;
246 } else {
247 yesnoharddisk[0] = ctr[TR_NO];
248 yesnoharddisk[1] = ctr[TR_YES];
249 yesnoharddisk[2] = NULL;
250 }
251
252 while (! hardyn) {
253 rc = newtWinMenu(title, message,
254 50, 5, 5, 6, yesnoharddisk,
255 &hardyn, ctr[TR_OK],
256 ctr[TR_CANCEL], NULL);
257 if (rc == 2)
258 goto EXIT;
259 }
260 if (rc == 2)
261 goto EXIT;
262
263 fstypes[0]=ctr[TR_EXT2FS_DESCR];
264 fstypes[1]=ctr[TR_EXT3FS_DESCR];
265 fstypes[2]=ctr[TR_EXT4FS_DESCR];
266 fstypes[3]=ctr[TR_REISERFS_DESCR];
267 fstypes[4]=NULL;
268
269 if (!unattended) {
270 sprintf(message, ctr[TR_CHOOSE_FILESYSTEM]);
271 rc = newtWinMenu( ctr[TR_CHOOSE_FILESYSTEM], message,
272 50, 5, 5, 6, fstypes, &fstype, ctr[TR_OK],
273 ctr[TR_CANCEL], NULL);
274 } else {
275 rc = 1;
276 fstype = EXT3;
277 }
278 if (rc == 2)
279 goto EXIT;
280
281 /* Calculate amount of memory in machine */
282 if ((handle = fopen("/proc/meminfo", "r")))
283 {
284 while (fgets(line, STRING_SIZE-1, handle)) {
285 if (sscanf (line, "MemTotal: %s kB", string)) {
286 memory = atoi(string) / 1024 ;
287 }
288 }
289 fclose(handle);
290 }
291
292 /* Partition, mkswp, mkfs.
293 * before partitioning, first determine the sizes of each
294 * partition. In order to do that we need to know the size of
295 * the disk.
296 */
297 /* Don't use mysystem here so we can redirect output */
298 sprintf(commandstring, "/sbin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive);
299 system(commandstring);
300
301 /* Calculate amount of disk space */
302 if ((handle = fopen("/tmp/disksize", "r"))) {
303 fgets(line, STRING_SIZE-1, handle);
304 if (sscanf (line, "%s", string)) {
305 disk = atoi(string) / 1024;
306 }
307 fclose(handle);
308 }
309
310 fprintf(flog, "Disksize = %ld, memory = %ld", disk, memory);
311
312 /* Calculating Swap-Size dependend of Ram Size */
313 if (memory <= 256)
314 swap_file = 128;
315 else if (memory <= 1024 && memory > 256)
316 swap_file = 256;
317 else
318 swap_file = memory / 4;
319
320 /* Calculating Root-Size dependend of Max Disk Space */
321 if ( disk < 756 )
322 root_partition = 200;
323 else if ( disk >= 756 && disk <= 3072 )
324 root_partition = 512;
325 else
326 root_partition = 2048;
327
328
329 /* Calculating the amount of free space */
330 boot_partition = 20; /* in MB */
331 system_partition = disk - ( root_partition + swap_file + boot_partition );
332
333 fprintf(flog, ", boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
334 boot_partition, swap_file, system_partition, root_partition);
335 rc = 0;
336
337 if ( (!unattended) && (((disk - (root_partition + swap_file + boot_partition)) < 256 ) && ((disk - (root_partition + boot_partition )) > 256)) ) {
338 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
339 if (rc == 1){
340 swap_file = 0;
341 system_partition = disk - ( root_partition + swap_file + boot_partition );
342 fprintf(flog, "Changing Swap Size to 0 MB.\n");
343 }
344 else if (rc == 2){
345 fprintf(flog, "Disk is too small.\n");
346 errorbox(ctr[TR_DISK_TOO_SMALL]);goto EXIT;
347 }
348 }
349 else if (disk - (root_partition + swap_file + boot_partition) >= 256) {
350
351 }
352 else {
353 fprintf(flog, "Disk is too small.\n");
354 errorbox(ctr[TR_DISK_TOO_SMALL]);goto EXIT;
355 }
356
357 handle = fopen("/tmp/partitiontable", "w");
358
359 /* Make swapfile */
360 if (swap_file) {
361 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
362 boot_partition, swap_file, root_partition);
363 } else {
364 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
365 boot_partition, root_partition);
366 }
367
368 fclose(handle);
369
370 snprintf(commandstring, STRING_SIZE, "/sbin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode_disk);
371 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
372 {
373 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
374 goto EXIT;
375 }
376
377 if (fstype == EXT2) {
378 // mysystem("/sbin/modprobe ext2");
379 sprintf(mkfscommand, "/sbin/mke2fs -T ext2");
380 } else if (fstype == REISERFS) {
381 mysystem("/sbin/modprobe reiserfs");
382 sprintf(mkfscommand, "/sbin/mkreiserfs -f");
383 } else if (fstype == EXT3) {
384 // mysystem("/sbin/modprobe ext3");
385 sprintf(mkfscommand, "/sbin/mke2fs -T ext3");
386 } else if (fstype == EXT4) {
387 // mysystem("/sbin/modprobe ext4");
388 sprintf(mkfscommand, "/sbin/mke2fs -T ext4");
389 }
390
391 snprintf(commandstring, STRING_SIZE, "/sbin/mke2fs -T ext2 -I 128 %s1", hdparams.devnode_part);
392 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
393 {
394 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
395 goto EXIT;
396 }
397
398 if (swap_file) {
399 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode_part);
400 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
401 {
402 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
403 goto EXIT;
404 }
405 }
406
407 snprintf(commandstring, STRING_SIZE, "%s %s3", mkfscommand, hdparams.devnode_part);
408 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
409 {
410 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
411 goto EXIT;
412 }
413
414 snprintf(commandstring, STRING_SIZE, "%s %s4", mkfscommand, hdparams.devnode_part);
415 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
416 {
417 errorbox(ctr[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM]);
418 goto EXIT;
419 }
420
421 snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode_part);
422 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
423 {
424 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
425 goto EXIT;
426 }
427
428 mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
429 mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
430 mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
431
432 snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode_part);
433 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
434 {
435 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
436 goto EXIT;
437 }
438 if (swap_file) {
439 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode_part);
440 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
441 {
442 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
443 goto EXIT;
444 }
445 }
446 snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode_part);
447 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
448 {
449 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
450 goto EXIT;
451 }
452
453 snprintf(commandstring, STRING_SIZE,
454 "/bin/tar -C /harddisk -xvf /cdrom/" SNAME "-" VERSION ".tlz --lzma 2>/dev/null");
455
456 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
457 ctr[TR_INSTALLING_FILES]))
458 {
459 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
460 goto EXIT;
461 }
462
463 /* Save language und local settings */
464 write_lang_configs(shortlangname);
465
466 /* mount proc filesystem */
467 mysystem("mkdir /harddisk/proc");
468 mysystem("/bin/mount --bind /proc /harddisk/proc");
469 mysystem("/bin/mount --bind /dev /harddisk/dev");
470 mysystem("/bin/mount --bind /sys /harddisk/sys");
471
472 /* Build cache lang file */
473 snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
474 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
475 {
476 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
477 goto EXIT;
478 }
479
480 /* Update /etc/fstab */
481 snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE1#UUID=$(/sbin/blkid %s1 -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", hdparams.devnode_part);
482 system(commandstring);
483 snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE2#UUID=$(/sbin/blkid %s2 -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", hdparams.devnode_part);
484 system(commandstring);
485 snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE3#UUID=$(/sbin/blkid %s3 -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", hdparams.devnode_part);
486 system(commandstring);
487 snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE4#UUID=$(/sbin/blkid %s4 -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", hdparams.devnode_part);
488 system(commandstring);
489
490 if (fstype == EXT2) {
491 replace("/harddisk/etc/fstab", "FSTYPE", "ext2");
492 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
493 } else if (fstype == REISERFS) {
494 replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs");
495 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
496 } else if (fstype == EXT3) {
497 replace("/harddisk/etc/fstab", "FSTYPE", "ext3");
498 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
499 } else if (fstype == EXT4) {
500 replace("/harddisk/etc/fstab", "FSTYPE", "ext4");
501 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
502 }
503
504 replace("/harddisk/boot/grub/grub.conf", "KVER", KERNEL_VERSION);
505
506 snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#root=ROOT#root=UUID=$(/sbin/blkid %s3 -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/boot/grub/grub.conf", hdparams.devnode_part);
507 system(commandstring);
508
509 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
510
511 system("/bin/sed -e 's#/harddisk#/#g' -e 's#//#/#g' < /proc/mounts > /harddisk/etc/mtab");
512
513 /*
514 * Generate device.map to help grub finding the device to install itself on.
515 */
516 FILE *f = NULL;
517 if (f = fopen("/harddisk/boot/grub/device.map", "w")) {
518 fprintf(f, "(hd0) %s\n", hdparams.devnode_part);
519 fclose(f);
520 }
521
522 snprintf(commandstring, STRING_SIZE,
523 "/usr/sbin/chroot /harddisk /usr/sbin/grub-install --no-floppy %s", hdparams.devnode_disk);
524 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
525 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
526 goto EXIT;
527 }
528
529 /* Serial console ? */
530 if (serialconsole) {
531 /* grub */
532 replace("/harddisk/boot/grub/grub.conf", "splashimage", "#splashimage");
533 replace("/harddisk/boot/grub/grub.conf", "#serial", "serial");
534 replace("/harddisk/boot/grub/grub.conf", "#terminal", "terminal");
535 replace("/harddisk/boot/grub/grub.conf", " panic=10 ", " console=ttyS0,38400n8 panic=10 ");
536
537 /*inittab*/
538 replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:");
539 replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:");
540 replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:");
541 replace("/harddisk/etc/inittab", "4:2345:respawn:", "#4:2345:respawn:");
542 replace("/harddisk/etc/inittab", "5:2345:respawn:", "#5:2345:respawn:");
543 replace("/harddisk/etc/inittab", "6:2345:respawn:", "#6:2345:respawn:");
544 replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:");
545 }
546
547 /* Set marker that the user has already accepted the gpl */
548 mysystem("/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");
549
550 /* Copy restore file from cdrom */
551 if (unattended && (strlen(restore_file) > 0)) {
552 fprintf(flog, "unattended: Copy restore file\n");
553 snprintf(commandstring, STRING_SIZE,
554 "cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file);
555 mysystem(commandstring);
556 }
557
558 mysystem("umount /cdrom");
559 snprintf(commandstring, STRING_SIZE, "/usr/bin/eject /dev/%s", sourcedrive);
560 mysystem(commandstring);
561
562 if (!unattended) {
563 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
564 NAME, SNAME, NAME);
565 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_PRESS_OK_TO_REBOOT], message);
566 }
567
568 allok = 1;
569
570 EXIT:
571 fprintf(flog, "Install program ended.\n");
572
573 if (!(allok))
574 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
575
576 freekeyvalues(ethernetkv);
577
578 if (allok && !allok_fastexit)
579 {
580 if (unattended) {
581 fprintf(flog, "Entering unattended setup\n");
582 if (unattended_setup(unattendedkv)) {
583 snprintf(commandstring, STRING_SIZE, "/bin/sleep 10");
584 runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot");
585 } else {
586 errorbox("Unattended setup failed.");
587 goto EXIT;
588 }
589 }
590
591 fflush(flog);
592 fclose(flog);
593 newtFinished();
594
595 if (unattended) {
596 // Remove Setup autorun after boot
597 if (system("rm -f /harddisk/etc/rc.d/rcsysinit.d/S75firstsetup"))
598 printf("Unable to disable setup autorun.\n");
599 }
600
601 if (system("/bin/umount /harddisk/proc"))
602 printf("Unable to umount /harddisk/proc.\n");
603 } else {
604 fflush(flog);
605 fclose(flog);
606 newtFinished();
607 }
608
609 fcloseall();
610
611 if (swap_file) {
612 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode_part);
613 }
614
615 newtFinished();
616
617 system("/bin/umount /harddisk/proc >/dev/null 2>&1");
618 system("/bin/umount /harddisk/dev >/dev/null 2>&1");
619 system("/bin/umount /harddisk/sys >/dev/null 2>&1");
620
621 system("/bin/umount /harddisk/var >/dev/null 2>&1");
622 system("/bin/umount /harddisk/boot >/dev/null 2>&1");
623 system("/bin/umount /harddisk >/dev/null 2>&1");
624
625 if (!(allok))
626 system("/etc/halt");
627
628 return 0;
629 }