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