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