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