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