]>
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. | |
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 7000 | |
18 | #define UNATTENDED_CONF "/cdrom/boot/unattended.conf" | |
19 | ||
20 | int raid_disk = 0; | |
21 | FILE *flog = NULL; | |
22 | char *mylog; | |
23 | ||
24 | char **ctr; | |
25 | ||
26 | extern char url[STRING_SIZE]; | |
27 | ||
28 | extern char *en_tr[]; | |
29 | extern char *de_tr[]; | |
30 | ||
31 | int detect_smp() { | |
32 | FILE *fd = NULL; | |
33 | char line[STRING_SIZE]; | |
34 | int cpu_count = 0; | |
35 | ||
36 | if ((fd = fopen("/proc/cpuinfo", "r")) == NULL) { | |
37 | return 0; | |
38 | } | |
39 | while (fgets(line, STRING_SIZE, fd) != NULL) { | |
40 | if (strstr(line, "processor") == line) { | |
41 | cpu_count++; | |
42 | } | |
43 | } | |
44 | (void)fclose(fd); | |
45 | return (cpu_count > 1); | |
46 | } | |
47 | ||
48 | long calc_swapsize(long memory, long disk) { | |
49 | if (memory < 128) { | |
50 | return 256; | |
51 | } | |
52 | if (memory > 1024) { | |
53 | return 512; | |
54 | } | |
55 | ||
56 | return memory*2; | |
57 | } | |
58 | ||
59 | int main(int argc, char *argv[]) | |
60 | { | |
61 | char *langnames[] = { "Deutsch", "English", NULL }; | |
62 | char *shortlangnames[] = { "de", "en", NULL }; | |
63 | char **langtrs[] = { de_tr, en_tr, NULL }; | |
64 | char hdletter; | |
65 | char harddrive[5], sourcedrive[5]; /* Device holder. */ | |
66 | struct devparams hdparams, cdromparams; /* Params for CDROM and HD */ | |
67 | int cdmounted = 0; /* Loop flag for inserting a cd. */ | |
68 | int rc = 0; | |
69 | char commandstring[STRING_SIZE]; | |
70 | char *installtypes[] = { "CDROM/USB", "HTTP/FTP", NULL }; | |
71 | int installtype = CDROM_INSTALL; | |
72 | int choice; | |
73 | char shortlangname[10]; | |
74 | char message[1000]; | |
75 | char title[STRING_SIZE]; | |
76 | int allok = 0; | |
77 | int allok_fastexit=0; | |
78 | struct keyvalue *ethernetkv = initkeyvalues(); | |
79 | FILE *handle, *cmdfile; | |
80 | char line[STRING_SIZE]; | |
81 | char string[STRING_SIZE]; | |
82 | long maximum_free = 0, current_free; | |
83 | long memory = 0; | |
84 | long system_partition, boot_partition, root_partition, swap_file; | |
85 | int scsi_disk = 0; | |
86 | char *yesnoharddisk[] = { "NO", "YES", NULL }; | |
87 | int unattended = 0; | |
88 | struct keyvalue *unattendedkv = initkeyvalues(); | |
89 | int hardyn = 0; | |
90 | ||
91 | setlocale (LC_ALL, ""); | |
92 | sethostname( SNAME , 10); | |
93 | ||
94 | memset(&hdparams, 0, sizeof(struct devparams)); | |
95 | memset(&cdromparams, 0, sizeof(struct devparams)); | |
96 | ||
97 | /* Log file/terminal stuff. */ | |
98 | if (argc >= 2) | |
99 | { | |
100 | if (!(flog = fopen(argv[1], "w+"))) | |
101 | return 0; | |
102 | } | |
103 | else | |
104 | return 0; | |
105 | ||
106 | mylog = argv[1]; | |
107 | ||
108 | fprintf(flog, "Install program started.\n"); | |
109 | ||
110 | newtInit(); | |
111 | newtCls(); | |
112 | ||
113 | /* Do usb detection first for usb keyboard */ | |
114 | if (! (cmdfile = fopen("/proc/cmdline", "r"))) | |
115 | { | |
116 | fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); | |
117 | } else { | |
118 | fgets(line, STRING_SIZE, cmdfile); | |
119 | if (strstr (line, "nousb") == NULL) { | |
120 | fprintf(flog, "Initializing USB controllers.\n"); | |
121 | initialize_usb(); | |
122 | } else { | |
123 | fprintf(flog, "Skipping USB detection.\n"); | |
124 | } | |
125 | // check if we have to make an unattended install | |
126 | if (strstr (line, "unattended") != NULL) { | |
127 | unattended = 1; | |
128 | } | |
129 | } | |
130 | ||
131 | if (unattended) { | |
132 | runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds..."); | |
133 | } | |
134 | ||
135 | /* German is the default */ | |
136 | for (choice = 0; langnames[choice]; choice++) | |
137 | { | |
138 | if (strcmp(langnames[choice], "Deutsch") == 0) | |
139 | break; | |
140 | } | |
141 | if (!langnames[choice]) | |
142 | goto EXIT; | |
143 | ||
144 | if (!unattended) { | |
145 | rc = newtWinMenu("Language selection", | |
146 | "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, | |
147 | langnames, &choice, "Ok", NULL); | |
148 | } | |
149 | ||
150 | ctr = langtrs[choice]; | |
151 | strcpy(shortlangname, shortlangnames[choice]); | |
152 | fprintf(flog, "Selected language: %s\n", shortlangname); | |
153 | ||
154 | mysystem("/bin/setfont lat0-16"); | |
155 | ||
156 | newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN ); | |
157 | newtPushHelpLine(ctr[TR_HELPLINE]); | |
158 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
159 | ||
160 | if (!unattended) { | |
161 | sprintf(message, ctr[TR_WELCOME], NAME); | |
162 | newtWinMessage(title, ctr[TR_OK], message); | |
163 | ||
164 | sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME); | |
165 | rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message, | |
166 | 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK], | |
167 | ctr[TR_CANCEL], NULL); | |
168 | } else { | |
169 | rc = 1; | |
170 | installtype = CDROM_INSTALL; | |
171 | } | |
172 | ||
173 | if (rc == 2) | |
174 | goto EXIT; | |
175 | ||
176 | // Starting hardware detection | |
177 | runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]); | |
178 | runcommandwithstatus("/bin/probenic.sh install", ctr[TR_PROBING_HARDWARE]); | |
179 | ||
180 | /* CDROM INSTALL */ | |
181 | if (installtype == CDROM_INSTALL) { | |
182 | switch (mysystem("/bin/mountsource.sh")) { | |
183 | case 0: | |
184 | installtype = CDROM_INSTALL; | |
185 | cdmounted = 1; | |
186 | break; | |
187 | case 1: | |
188 | installtype = DISK_INSTALL; | |
189 | break; | |
190 | case 10: | |
191 | errorbox(ctr[TR_NO_CDROM]); | |
192 | goto EXIT; | |
193 | } | |
194 | ||
195 | /* read source drive letter */ | |
196 | if ((handle = fopen("/tmp/source_device", "r")) == NULL) { | |
197 | errorbox(ctr[TR_ERROR_PROBING_CDROM]); | |
198 | goto EXIT; | |
199 | } | |
200 | fgets(sourcedrive, 5, handle); | |
201 | fprintf(flog, "Source drive: %s\n", sourcedrive); | |
202 | fclose(handle); | |
203 | ||
204 | snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive); | |
205 | cdromparams.module = 0; | |
206 | fprintf(flog, "Source device: %s\n", cdromparams.devnode); | |
207 | } | |
208 | ||
209 | /* Configure the network now! */ | |
210 | if (installtype == URL_INSTALL) { | |
211 | /* Network driver and params. */ | |
212 | if (!(networkmenu(ethernetkv))) { | |
213 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
214 | goto EXIT; | |
215 | } | |
216 | ||
217 | /* Check for ipfire-<VERSION>.tbz2 */ | |
218 | if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) { | |
219 | errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]); | |
220 | goto EXIT; | |
221 | } | |
222 | } | |
223 | ||
224 | /* Get device for the HD. This has to succeed. */ | |
225 | if (!(hdletter = findidetype(IDE_HD))) | |
226 | { | |
227 | /* Need to clean this up at some point */ | |
228 | if (!try_scsi("sda") || strstr(sourcedrive, "sda") != NULL) { | |
229 | if (!try_scsi("ida/c0d0")) { | |
230 | if (!try_scsi("cciss/c0d0")) { | |
231 | if (!try_scsi("rd/c0d0")) { | |
232 | if (!try_scsi("ataraid/d0")) { | |
233 | errorbox(ctr[TR_NO_HARDDISK]); | |
234 | goto EXIT; | |
235 | } else { | |
236 | raid_disk = 1; | |
237 | sprintf(harddrive, "ataraid/d0"); | |
238 | } | |
239 | } else { | |
240 | raid_disk = 1; | |
241 | sprintf(harddrive, "rd/c0d0"); | |
242 | } | |
243 | } else { | |
244 | raid_disk = 1; | |
245 | sprintf(harddrive, "cciss/c0d0"); | |
246 | } | |
247 | } else { | |
248 | raid_disk = 1; | |
249 | sprintf(harddrive, "ida/c0d0"); | |
250 | } | |
251 | } else { | |
252 | if (strstr(sourcedrive, "sda") != NULL) { | |
253 | // probably installing from usb stick, try sdb | |
254 | if (try_scsi("sdb")) { | |
255 | sprintf(harddrive, "sdb"); | |
256 | } | |
257 | else { | |
258 | errorbox(ctr[TR_NO_HARDDISK]); | |
259 | goto EXIT; | |
260 | } | |
261 | } | |
262 | else { | |
263 | sprintf(harddrive, "sda"); | |
264 | } | |
265 | } | |
266 | scsi_disk = 1; | |
267 | } else | |
268 | sprintf(harddrive, "hd%c", hdletter); | |
269 | ||
270 | fprintf(flog, "Destination drive: %s\n", harddrive); | |
271 | ||
272 | /* load unattended configuration */ | |
273 | if (unattended) { | |
274 | fprintf(flog, "unattended: Reading unattended.conf\n"); | |
275 | ||
276 | (void) readkeyvalues(unattendedkv, UNATTENDED_CONF); | |
277 | } | |
278 | ||
279 | /* Make the hdparms struct and print the contents. */ | |
280 | snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive); | |
281 | hdparams.module = 0; | |
282 | ||
283 | sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode); | |
284 | ||
285 | if (unattended) { | |
286 | hardyn = 1; | |
287 | } | |
288 | ||
289 | while (! hardyn) { | |
290 | rc = newtWinMenu(title, message, | |
291 | 50, 5, 5, 6, yesnoharddisk, | |
292 | &hardyn, ctr[TR_OK], | |
293 | ctr[TR_CANCEL], NULL); | |
294 | if (rc == 2) | |
295 | goto EXIT; | |
296 | } | |
297 | ||
298 | if (rc == 2) | |
299 | goto EXIT; | |
300 | ||
301 | /* Calculate amount of memory in machine */ | |
302 | if ((handle = fopen("/proc/meminfo", "r"))) | |
303 | { | |
304 | while (fgets(line, STRING_SIZE-1, handle)) { | |
305 | if (sscanf (line, "MemTotal: %s kB", string)) { | |
306 | memory = atoi(string) / 1024 ; | |
307 | } | |
308 | } | |
309 | fclose(handle); | |
310 | } | |
311 | ||
312 | /* Partition, mkswp, mkfs. | |
313 | * before partitioning, first determine the sizes of each | |
314 | * partition. In order to do that we need to know the size of | |
315 | * the disk. | |
316 | */ | |
317 | /* Don't use mysystem here so we can redirect output */ | |
318 | sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive); | |
319 | system(commandstring); | |
320 | ||
321 | /* Calculate amount of disk space */ | |
322 | if ((handle = fopen("/tmp/disksize", "r"))) | |
323 | { | |
324 | fgets(line, STRING_SIZE-1, handle); | |
325 | if (sscanf (line, "%s", string)) { | |
326 | maximum_free = atoi(string) / 1024; | |
327 | } | |
328 | fclose(handle); | |
329 | } | |
330 | ||
331 | fprintf(flog, "maximum_free = %ld, memory = %ld", | |
332 | maximum_free, memory); | |
333 | ||
334 | swap_file = calc_swapsize(memory, maximum_free); | |
335 | ||
336 | if (maximum_free < 512 + swap_file ) { | |
337 | if (maximum_free < 512) { | |
338 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
339 | goto EXIT; | |
340 | } | |
341 | ||
342 | if (!unattended) { | |
343 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
344 | } | |
345 | else { | |
346 | rc = 1; | |
347 | } | |
348 | ||
349 | if (rc != 1) | |
350 | goto EXIT; | |
351 | swap_file = 0; | |
352 | } | |
353 | ||
354 | boot_partition = 20; /* in MB */ | |
355 | current_free = maximum_free - boot_partition - swap_file; | |
356 | ||
357 | root_partition = 2048 ; | |
358 | if (current_free < 512) { | |
359 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
360 | goto EXIT; | |
361 | } | |
362 | ||
363 | current_free = current_free - root_partition; | |
364 | if (!swap_file) { | |
365 | root_partition = root_partition + swap_file; | |
366 | } | |
367 | ||
368 | system_partition = current_free; | |
369 | ||
370 | fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n", | |
371 | boot_partition, swap_file, system_partition, root_partition); | |
372 | ||
373 | handle = fopen("/tmp/partitiontable", "w"); | |
374 | ||
375 | /* Make swapfile */ | |
376 | if (swap_file) { | |
377 | fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n", | |
378 | boot_partition, swap_file, root_partition); | |
379 | } else { | |
380 | fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n", | |
381 | boot_partition, root_partition); | |
382 | } | |
383 | ||
384 | fclose(handle); | |
385 | ||
386 | snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode); | |
387 | if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK])) | |
388 | { | |
389 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
390 | goto EXIT; | |
391 | } | |
392 | ||
393 | mysystem("/sbin/udevstart"); | |
394 | ||
395 | if (raid_disk) | |
396 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %sp1", hdparams.devnode); | |
397 | else | |
398 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode); | |
399 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM])) | |
400 | { | |
401 | errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]); | |
402 | goto EXIT; | |
403 | } | |
404 | ||
405 | if (swap_file) { | |
406 | if (raid_disk) | |
407 | snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %sp2", hdparams.devnode); | |
408 | else | |
409 | snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode); | |
410 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) | |
411 | { | |
412 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
413 | goto EXIT; | |
414 | } | |
415 | } | |
416 | ||
417 | if (raid_disk) | |
418 | snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp3", hdparams.devnode); | |
419 | else | |
420 | snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s3", hdparams.devnode); | |
421 | ||
422 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM])) | |
423 | { | |
424 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
425 | goto EXIT; | |
426 | } | |
427 | ||
428 | if (raid_disk) | |
429 | snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp4", hdparams.devnode); | |
430 | else | |
431 | snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s4", hdparams.devnode); | |
432 | ||
433 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM])) | |
434 | { | |
435 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
436 | goto EXIT; | |
437 | } | |
438 | ||
439 | /* Mount harddisk. */ | |
440 | if (raid_disk) | |
441 | snprintf(commandstring, STRING_SIZE, "/bin/mount %sp3 /harddisk", hdparams.devnode); | |
442 | else | |
443 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode); | |
444 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM])) | |
445 | { | |
446 | errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]); | |
447 | goto EXIT; | |
448 | } | |
449 | ||
450 | mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO); | |
451 | mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO); | |
452 | mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO); | |
453 | ||
454 | if (raid_disk) | |
455 | snprintf(commandstring, STRING_SIZE, "/bin/mount %sp1 /harddisk/boot", hdparams.devnode); | |
456 | else | |
457 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode); | |
458 | ||
459 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM])) | |
460 | { | |
461 | errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]); | |
462 | goto EXIT; | |
463 | } | |
464 | if (swap_file) { | |
465 | if (raid_disk) | |
466 | snprintf(commandstring, STRING_SIZE, "/sbin/swapon %sp2", hdparams.devnode); | |
467 | else | |
468 | snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode); | |
469 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION])) | |
470 | { | |
471 | errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]); | |
472 | goto EXIT; | |
473 | } | |
474 | } | |
475 | if (raid_disk) | |
476 | snprintf(commandstring, STRING_SIZE, "/bin/mount %sp4 /harddisk/var", hdparams.devnode); | |
477 | else | |
478 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode); | |
479 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM])) | |
480 | { | |
481 | errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]); | |
482 | goto EXIT; | |
483 | } | |
484 | ||
485 | if (installtype == URL_INSTALL) { | |
486 | snprintf(commandstring, STRING_SIZE, | |
487 | "/bin/wget -q -O - %s/" SNAME "-" VERSION ".tbz2 | /bin/tar -C /harddisk -xvjf -", url); | |
488 | } | |
489 | ||
490 | if (installtype == CDROM_INSTALL) { | |
491 | snprintf(commandstring, STRING_SIZE, | |
492 | "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2"); | |
493 | } | |
494 | ||
495 | if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT, | |
496 | ctr[TR_INSTALLING_FILES])) | |
497 | { | |
498 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
499 | goto EXIT; | |
500 | } | |
501 | ||
502 | /* Save USB controller type to modules.conf */ | |
503 | write_usb_modules_conf(); | |
504 | ||
505 | /* Save language und local settings */ | |
506 | write_lang_configs(shortlangname); | |
507 | ||
508 | /* touch the modules.dep files */ | |
509 | snprintf(commandstring, STRING_SIZE, | |
510 | "/bin/touch /harddisk/lib/modules/%s-ipfire/modules.dep", | |
511 | KERNEL_VERSION); | |
512 | mysystem(commandstring); | |
513 | snprintf(commandstring, STRING_SIZE, | |
514 | "/bin/touch /harddisk/lib/modules/%s-ipfire-smp/modules.dep", | |
515 | KERNEL_VERSION); | |
516 | mysystem(commandstring); | |
517 | ||
518 | /* Rename uname */ | |
519 | rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname"); | |
520 | ||
521 | /* mount proc filesystem */ | |
522 | mysystem("mkdir /harddisk/proc"); | |
523 | mysystem("/bin/mount -t proc none /harddisk/proc"); | |
524 | mysystem("/bin/mount --bind /dev /harddisk/dev"); | |
525 | ||
526 | /* Build cache lang file */ | |
527 | snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); | |
528 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE])) | |
529 | { | |
530 | errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]); | |
531 | goto EXIT; | |
532 | } | |
533 | ||
534 | /* Update /etc/fstab */ | |
535 | replace("/harddisk/etc/fstab", "DEVICE", hdparams.devnode); | |
536 | ||
537 | /* if we detected SCSI/USB then fixup */ | |
538 | /* mysystem("/bin/probecntrl.sh"); | |
539 | if ((handle = fopen("/tmp/cntrldriver", "r"))) | |
540 | { | |
541 | char *driver; | |
542 | fgets(line, STRING_SIZE-1, handle); | |
543 | fclose(handle); | |
544 | line[strlen(line) - 1] = 0; | |
545 | driver = strtok(line, "."); | |
546 | if (strlen(driver) > 1) { | |
547 | fprintf(flog, "Fixing up ipfirerd.img\n"); | |
548 | mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); | |
549 | snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod %s --with=sd_mod --with=sr_mod /boot/ipfirerd.img %s-ipfire", driver, KERNEL_VERSION); | |
550 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); | |
551 | snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod %s --with=sd_mod --with=sr_mod /boot/ipfirerd-smp.img %s-ipfire-smp", driver, KERNEL_VERSION); | |
552 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); | |
553 | mysystem("/sbin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); | |
554 | } | |
555 | } */ | |
556 | ||
557 | if (raid_disk) | |
558 | sprintf(string, "root=%sp3", hdparams.devnode); | |
559 | else | |
560 | sprintf(string, "root=%s3", hdparams.devnode); | |
561 | replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string); | |
562 | replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode); | |
563 | ||
564 | /* restore permissions */ | |
565 | chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); | |
566 | ||
567 | snprintf(commandstring, STRING_SIZE, | |
568 | "/sbin/chroot /harddisk /boot/grub/grubbatch"); | |
569 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) { | |
570 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
571 | goto EXIT; | |
572 | } | |
573 | ||
574 | /* Install bootsplash */ | |
575 | mysystem("/bin/installbootsplash.sh"); | |
576 | ||
577 | mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst"); | |
578 | mysystem("umount /harddisk/proc"); | |
579 | mysystem("umount /harddisk/dev"); | |
580 | ||
581 | if (!unattended) { | |
582 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
583 | NAME, SNAME, SNAME, NAME, NAME, NAME); | |
584 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message); | |
585 | } | |
586 | ||
587 | allok = 1; | |
588 | ||
589 | EXIT: | |
590 | fprintf(flog, "Install program ended.\n"); | |
591 | ||
592 | if (!(allok)) | |
593 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); | |
594 | ||
595 | freekeyvalues(ethernetkv); | |
596 | ||
597 | if (allok && !allok_fastexit) | |
598 | { | |
599 | /* /proc is needed by the module checker. We have to mount it | |
600 | * so it can be seen by setup, which is run chrooted. */ | |
601 | if (system("/bin/mount proc -t proc /harddisk/proc")) | |
602 | printf("Unable to mount proc in /harddisk."); | |
603 | else | |
604 | { | |
605 | if (unattended) { | |
606 | fprintf(flog, "Entering unattended setup\n"); | |
607 | if (unattended_setup(unattendedkv)) { | |
608 | snprintf(commandstring, STRING_SIZE, "/bin/sleep 10"); | |
609 | runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot"); | |
610 | } else { | |
611 | errorbox("Unattended setup failed."); | |
612 | goto EXIT; | |
613 | } | |
614 | } | |
615 | ||
616 | newtFinished(); | |
617 | fflush(flog); | |
618 | fclose(flog); | |
619 | ||
620 | if (!unattended) { | |
621 | // Copy our scanned nics to the disk and lock because scan doesn't work in chroot | |
622 | system("touch /harddisk/var/ipfire/ethernet/scan_lock"); | |
623 | system("cp -f /tmp/scanned_nics /harddisk/var/ipfire/ethernet/scanned_nics"); | |
624 | if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) | |
625 | printf("Unable to run setup.\n"); | |
626 | system("rm -f /harddisk/var/ipfire/ethernet/scan_lock"); | |
627 | } | |
628 | ||
629 | if (system("/bin/umount /harddisk/proc")) | |
630 | printf("Unable to umount /harddisk/proc.\n"); | |
631 | } | |
632 | } | |
633 | fcloseall(); | |
634 | ||
635 | if (swap_file) { | |
636 | if (raid_disk) | |
637 | snprintf(commandstring, STRING_SIZE, "/bin/swapoff %sp2", hdparams.devnode); | |
638 | else | |
639 | snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode); | |
640 | } | |
641 | ||
642 | newtFinished(); | |
643 | ||
644 | system("/bin/umount /harddisk/var"); | |
645 | system("/bin/umount /harddisk/boot"); | |
646 | system("/bin/umount /harddisk"); | |
647 | ||
648 | system("/etc/halt"); | |
649 | ||
650 | return 0; | |
651 | } |