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