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