]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/install+setup/install/main.c
Nochmal was neues damit der endlich die CD auswirft...
[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
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
cd8dd8dd 17#define INST_FILECOUNT 6000
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;
69 if (root < 512) {
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
MT
179 if (!unattended) {
180 rc = newtWinMenu("Language selection",
181 "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8,
182 langnames, &choice, "Ok", NULL);
183 }
184
d6aaa55d
MT
185 ctr = langtrs[choice];
186 strcpy(shortlangname, shortlangnames[choice]);
406f019f 187 fprintf(flog, "Selected language: %s\n", shortlangname);
3d6e1202 188
33634aa8 189 newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
d6aaa55d 190 newtPushHelpLine(ctr[TR_HELPLINE]);
4809e64e 191 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
d6aaa55d 192
72d80898
MT
193 if (!unattended) {
194 sprintf(message, ctr[TR_WELCOME], NAME);
72d80898
MT
195 newtWinMessage(title, ctr[TR_OK], message);
196
197 sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME);
198 rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message,
199 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK],
200 ctr[TR_CANCEL], NULL);
330345c2 201 } else {
72d80898
MT
202 rc = 1;
203 installtype = CDROM_INSTALL;
204 }
205
206 if (rc == 2)
207 goto EXIT;
208
209 // Starting hardware detection
210 runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]);
59de0b00 211 runcommandwithstatus("/bin/probenic.sh install", ctr[TR_PROBING_HARDWARE]);
72d80898 212
9607771a
MT
213 /* CDROM INSTALL */
214 if (installtype == CDROM_INSTALL) {
9607771a
MT
215 switch (mysystem("/bin/mountsource.sh")) {
216 case 0:
cd8dd8dd
MT
217 installtype = CDROM_INSTALL;
218 cdmounted = 1;
9607771a
MT
219 break;
220 case 1:
cd8dd8dd 221 installtype = DISK_INSTALL;
9607771a
MT
222 break;
223 case 10:
cd8dd8dd 224 errorbox(ctr[TR_NO_CDROM]);
9607771a
MT
225 goto EXIT;
226 }
227
228 /* read source drive letter */
0b59f25c 229 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
33634aa8
MT
230 errorbox(ctr[TR_ERROR_PROBING_CDROM]);
231 goto EXIT;
9607771a
MT
232 }
233 fgets(sourcedrive, 5, handle);
234 fprintf(flog, "Source drive: %s\n", sourcedrive);
235 fclose(handle);
72d80898 236 }
9607771a
MT
237
238 /* Configure the network now! */
239 if (installtype == URL_INSTALL) {
240 /* Network driver and params. */
241 if (!(networkmenu(ethernetkv))) {
242 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
243 goto EXIT;
244 }
245
330345c2 246 /* Check for ipfire-<VERSION>.tbz2 */
9607771a
MT
247 if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) {
248 errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]);
249 goto EXIT;
250 }
72d80898 251 }
1cdddb12 252
ee78a5ef
MT
253 i = 0;
254 while (found == 0) {
255 i++;
256 fprintf(flog, "Harddisk scan pass %i\n", i);
257
aee3027d 258 switch (mysystem("/bin/mountdest.sh") % 255) {
ee78a5ef
MT
259 case 0: // Found IDE disk
260 scsi_disk = 0;
56b548f1 261 raid_disk = 0;
ee78a5ef
MT
262 found = 1;
263 break;
264 case 1: // Found SCSI disk
265 scsi_disk = 1;
56b548f1
MT
266 raid_disk = 0;
267 found = 1;
268 break;
269 case 2: // Found RAID disk
270 scsi_disk = 0;
271 raid_disk= 1;
ee78a5ef
MT
272 found = 1;
273 break;
274 case 10: // No harddisk found
275 if (firstrun == 1) {
276 errorbox(ctr[TR_NO_HARDDISK]);
277 goto EXIT;
278 }
279 // Do this if the kudzu-scan fails...
280 runcommandwithstatus("/bin/probehw.sh deep-scan", ctr[TR_PROBING_HARDWARE]);
281 firstrun = 1;
aee3027d 282 }
ee78a5ef
MT
283 }
284
ee78a5ef
MT
285 if ((handle = fopen("/tmp/dest_device", "r")) == NULL) {
286 errorbox(ctr[TR_NO_HARDDISK]);
287 goto EXIT;
288 }
56b548f1 289 fgets(harddrive, 11, handle);
ee78a5ef
MT
290 fclose(handle);
291
72d80898
MT
292 /* load unattended configuration */
293 if (unattended) {
294 fprintf(flog, "unattended: Reading unattended.conf\n");
295
296 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
297 }
72d80898 298
1cdddb12
MT
299 /* Make the hdparms struct and print the contents.
300 With USB-KEY install and SCSI disk, while installing, the disk
301 is named 'sdb,sdc,...' (following keys)
302 On reboot, it will become 'sda'
303 To avoid many test, all names are built in the struct.
304 */
305 sprintf(hdparams.devnode_disk, "/dev/%s", harddrive);
306 /* Address the partition or raid partition (eg dev/sda or /dev/sdap1 */
307 sprintf(hdparams.devnode_part, "/dev/%s%s", harddrive,raid_disk ? "p" : "");
308 /* Now the names after the machine is booted. Only scsi is affected
309 and we only install on the first scsi disk. */
310 { char tmp[30];
311 strcpy(tmp, scsi_disk ? "sda" : harddrive);
312 sprintf(hdparams.devnode_disk_run, "/dev/%s", tmp);
313 sprintf(hdparams.devnode_part_run, "/dev/%s%s", tmp, raid_disk ? "p" : "");
314 }
315
316 fprintf(flog, "Destination drive: %s\n", hdparams.devnode_disk);
317
318 sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode_disk);
72d80898
MT
319 if (unattended) {
320 hardyn = 1;
321 }
5057b611
HS
322
323 yesnoharddisk[0] = ctr[TR_NO];
324 yesnoharddisk[1] = ctr[TR_YES];
325 yesnoharddisk[2] = NULL;
326
72d80898
MT
327 while (! hardyn) {
328 rc = newtWinMenu(title, message,
329 50, 5, 5, 6, yesnoharddisk,
330 &hardyn, ctr[TR_OK],
331 ctr[TR_CANCEL], NULL);
332 if (rc == 2)
333 goto EXIT;
334 }
5433e2c9
MT
335 if (rc == 2)
336 goto EXIT;
72d80898 337
cd8dd8dd
MT
338 if (!unattended) {
339 sprintf(message, "(TR) Bitte waehlen Sie ihr Dateisystem aus:");
340 rc = newtWinMenu("(TR) Dateisystemauswahl", message,
341 50, 5, 5, 6, fstypes, &fstype, ctr[TR_OK],
342 ctr[TR_CANCEL], NULL);
343 } else {
344 rc = 1;
345 fstype = REISER4; // Reiser4 is our standard filesystem. Love it or shut up!
346 }
347 if (rc == 2)
348 goto EXIT;
349
72d80898
MT
350 /* Calculate amount of memory in machine */
351 if ((handle = fopen("/proc/meminfo", "r")))
352 {
353 while (fgets(line, STRING_SIZE-1, handle)) {
354 if (sscanf (line, "MemTotal: %s kB", string)) {
355 memory = atoi(string) / 1024 ;
356 }
357 }
358 fclose(handle);
359 }
360
361 /* Partition, mkswp, mkfs.
362 * before partitioning, first determine the sizes of each
363 * partition. In order to do that we need to know the size of
364 * the disk.
365 */
366 /* Don't use mysystem here so we can redirect output */
0b59f25c 367 sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive);
72d80898
MT
368 system(commandstring);
369
370 /* Calculate amount of disk space */
d3fb18db
MT
371 if ((handle = fopen("/tmp/disksize", "r"))) {
372 fgets(line, STRING_SIZE-1, handle);
373 if (sscanf (line, "%s", string)) {
72d80898 374 maximum_free = atoi(string) / 1024;
d3fb18db
MT
375 }
376 fclose(handle);
377 }
72d80898 378
d3fb18db 379 fprintf(flog, "maximum_free = %ld, memory = %ld", maximum_free, memory);
72d80898
MT
380
381 swap_file = calc_swapsize(memory, maximum_free);
382
d3fb18db
MT
383 if (maximum_free < 768 + swap_file ) {
384 if (maximum_free < 768) {
72d80898
MT
385 errorbox(ctr[TR_DISK_TOO_SMALL]);
386 goto EXIT;
387 }
388
389 if (!unattended) {
390 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
391 }
392 else {
393 rc = 1;
394 }
395
396 if (rc != 1)
397 goto EXIT;
398 swap_file = 0;
399 }
400
8e2e5cf3 401 boot_partition = 20; /* in MB */
72d80898
MT
402 current_free = maximum_free - boot_partition - swap_file;
403
d3fb18db 404 if (current_free < 768) {
72d80898
MT
405 errorbox(ctr[TR_DISK_TOO_SMALL]);
406 goto EXIT;
407 }
d3fb18db
MT
408
409 root_partition = calc_rootsize(current_free, maximum_free);
410
411 if (root_partition == 0) {
412 errorbox(ctr[TR_DISK_TOO_SMALL]);
413 goto EXIT;
414 } else {
415 current_free = current_free - root_partition;
416 }
417
418 if (current_free < 256) {
419 errorbox(ctr[TR_DISK_TOO_SMALL]);
420 goto EXIT;
72d80898
MT
421 }
422
8e2e5cf3 423 system_partition = current_free;
72d80898
MT
424
425 fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
8e2e5cf3 426 boot_partition, swap_file, system_partition, root_partition);
72d80898
MT
427
428 handle = fopen("/tmp/partitiontable", "w");
429
72d80898
MT
430 /* Make swapfile */
431 if (swap_file) {
9607771a 432 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
72d80898
MT
433 boot_partition, swap_file, root_partition);
434 } else {
9607771a 435 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
72d80898
MT
436 boot_partition, root_partition);
437 }
438
439 fclose(handle);
440
1cdddb12 441 snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode_disk);
72d80898
MT
442 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
443 {
444 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
445 goto EXIT;
446 }
cd8dd8dd
MT
447
448 if (fstype == REISER4) {
449 mysystem("/sbin/modprobe reiser4");
450 sprintf(mkfscommand, "/sbin/mkfs.reiser4 -y");
451 } else if (fstype == REISERFS) {
452 mysystem("/sbin/modprobe reiserfs");
453 sprintf(mkfscommand, "/sbin/mkreiserfs -f");
454 } else if (fstype == EXT3) {
455 mysystem("/sbin/modprobe ext3");
d3fb18db 456 sprintf(mkfscommand, "/bin/mke2fs -T ext3 -c");
cd8dd8dd 457 }
72d80898 458
1cdddb12 459 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode_part);
72d80898
MT
460 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
461 {
462 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
463 goto EXIT;
464 }
465
466 if (swap_file) {
1cdddb12 467 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode_part);
72d80898
MT
468 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
469 {
470 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
471 goto EXIT;
472 }
473 }
474
cd8dd8dd 475 snprintf(commandstring, STRING_SIZE, "%s %s3", mkfscommand, hdparams.devnode_part);
72d80898
MT
476 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
477 {
478 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
479 goto EXIT;
480 }
481
cd8dd8dd 482 snprintf(commandstring, STRING_SIZE, "%s %s4", mkfscommand, hdparams.devnode_part);
72d80898
MT
483 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
484 {
cd8dd8dd 485 errorbox(ctr[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM]);
72d80898 486 goto EXIT;
9607771a 487 }
72d80898 488
1cdddb12 489 snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode_part);
72d80898
MT
490 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
491 {
492 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
493 goto EXIT;
494 }
495
496 mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
497 mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
498 mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
499
1cdddb12 500 snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode_part);
72d80898
MT
501 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
502 {
503 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
504 goto EXIT;
505 }
506 if (swap_file) {
1cdddb12 507 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode_part);
72d80898
MT
508 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
509 {
510 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
511 goto EXIT;
512 }
513 }
1cdddb12 514 snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode_part);
72d80898
MT
515 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
516 {
517 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
518 goto EXIT;
9607771a 519 }
c78a77eb
MT
520
521 if (installtype == URL_INSTALL) {
522 snprintf(commandstring, STRING_SIZE,
523 "/bin/wget -q -O - %s/" SNAME "-" VERSION ".tbz2 | /bin/tar -C /harddisk -xvjf -", url);
524 }
525
1cdddb12 526 if (installtype == CDROM_INSTALL) {
c78a77eb
MT
527 snprintf(commandstring, STRING_SIZE,
528 "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
529 }
d6aaa55d 530
edd536b6
MT
531 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
532 ctr[TR_INSTALLING_FILES]))
d6aaa55d
MT
533 {
534 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
535 goto EXIT;
536 }
e57bc1fd 537
d6aaa55d
MT
538 /* Save USB controller type to modules.conf */
539 write_usb_modules_conf();
406f019f
MT
540
541 /* Save language und local settings */
542 write_lang_configs(shortlangname);
d6aaa55d
MT
543
544 /* touch the modules.dep files */
10bc6f06 545 snprintf(commandstring, STRING_SIZE,
c78a77eb 546 "/bin/touch /harddisk/lib/modules/%s-ipfire/modules.dep",
10bc6f06
MT
547 KERNEL_VERSION);
548 mysystem(commandstring);
10bc6f06 549 snprintf(commandstring, STRING_SIZE,
c78a77eb 550 "/bin/touch /harddisk/lib/modules/%s-ipfire-smp/modules.dep",
10bc6f06
MT
551 KERNEL_VERSION);
552 mysystem(commandstring);
d6aaa55d
MT
553
554 /* Rename uname */
555 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
556
9607771a
MT
557 /* mount proc filesystem */
558 mysystem("mkdir /harddisk/proc");
ee78a5ef
MT
559 mysystem("/bin/mount --bind /proc /harddisk/proc");
560 mysystem("/bin/mount --bind /dev /harddisk/dev");
561 mysystem("/bin/mount --bind /sys /harddisk/sys");
9607771a 562
330345c2
MT
563 /* Build cache lang file */
564 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
565 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
566 {
567 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
568 goto EXIT;
569 }
570
571 /* Update /etc/fstab */
1cdddb12 572 replace("/harddisk/etc/fstab", "DEVICE", hdparams.devnode_part_run);
cd8dd8dd
MT
573
574 if (fstype == REISER4) {
575 replace("/harddisk/etc/fstab", "FSTYPE", "reiser4");
576 replace("/harddisk/etc/mkinitcpio.conf", "MODULES=\"", "MODULES=\"reiser4 ");
d3fb18db 577 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "rw");
cd8dd8dd
MT
578 } else if (fstype == REISERFS) {
579 replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs");
d3fb18db 580 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
cd8dd8dd
MT
581 } else if (fstype == EXT3) {
582 replace("/harddisk/etc/fstab", "FSTYPE", "ext3");
d3fb18db 583 replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
cd8dd8dd 584 }
73d9a908 585
ee78a5ef
MT
586 /* Going to make our initrd... */
587 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitcpio -v -g /boot/ipfirerd.img -k %s-ipfire", KERNEL_VERSION);
588 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
aee3027d 589 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitcpio -v -g /boot/ipfirerd-smp.img -k %s-ipfire-smp", KERNEL_VERSION);
ee78a5ef 590 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
edd536b6 591
1cdddb12 592 sprintf(string, "root=%s3", hdparams.devnode_part_run);
edd536b6 593 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
1cdddb12 594 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode_disk);
fd0763dc 595
edd536b6
MT
596 /* restore permissions */
597 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
598
edd536b6 599 snprintf(commandstring, STRING_SIZE,
532a3663 600 "/sbin/chroot /harddisk /boot/grub/grubbatch");
edd536b6
MT
601 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
602 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
603 goto EXIT;
604 }
605
22b9e405 606 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
8de160ff
MT
607
608 mysystem("umount /cdrom");
609 ejectcdrom(sourcedrive);
22b9e405 610
73d9a908
MT
611 if (!unattended) {
612 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
3ad8835c 613 NAME, SNAME, NAME);
73d9a908
MT
614 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
615 }
cd8dd8dd 616
22b9e405 617 allok = 1;
edd536b6 618
d6aaa55d 619EXIT:
10bc6f06 620 fprintf(flog, "Install program ended.\n");
d6aaa55d 621
10bc6f06 622 if (!(allok))
d6aaa55d 623 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
10bc6f06 624
d6aaa55d 625 freekeyvalues(ethernetkv);
d6aaa55d 626
10bc6f06 627 if (allok && !allok_fastexit)
d6aaa55d 628 {
ee78a5ef
MT
629 if (unattended) {
630 fprintf(flog, "Entering unattended setup\n");
631 if (unattended_setup(unattendedkv)) {
c78a77eb
MT
632 snprintf(commandstring, STRING_SIZE, "/bin/sleep 10");
633 runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot");
ee78a5ef 634 } else {
c78a77eb
MT
635 errorbox("Unattended setup failed.");
636 goto EXIT;
c78a77eb 637 }
ee78a5ef 638 }
c78a77eb 639
ee78a5ef
MT
640 fflush(flog);
641 fclose(flog);
642 newtFinished();
643
644 if (!unattended) {
645 // Copy our scanned nics to the disk and lock because scan doesn't work in chroot
646 system("touch /harddisk/var/ipfire/ethernet/scan_lock");
647 system("cp -f /tmp/scanned_nics /harddisk/var/ipfire/ethernet/scanned_nics");
648 if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
649 printf("Unable to run setup.\n");
650 system("rm -f /harddisk/var/ipfire/ethernet/scan_lock");
651 }
3a1019f6 652
ee78a5ef
MT
653 if (system("/bin/umount /harddisk/proc"))
654 printf("Unable to umount /harddisk/proc.\n");
5057b611
HS
655 } else {
656 fflush(flog);
657 fclose(flog);
658 newtFinished();
d6aaa55d 659 }
5057b611 660
d6aaa55d
MT
661 fcloseall();
662
3a1019f6 663 if (swap_file) {
1cdddb12 664 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode_part);
3a1019f6
MT
665 }
666
667 newtFinished();
668
5057b611
HS
669 system("/bin/umount /harddisk/proc");
670 system("/bin/umount /harddisk/dev");
ee78a5ef 671 system("/bin/umount /harddisk/sys");
5057b611 672
532a3663
MT
673 system("/bin/umount /harddisk/var");
674 system("/bin/umount /harddisk/boot");
675 system("/bin/umount /harddisk");
10bc6f06 676
d6aaa55d
MT
677 system("/etc/halt");
678
679 return 0;
680}