]>
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]); | |
406f019f | 152 | fprintf(flog, "Selected language: %s\n", shortlangname); |
3d6e1202 MT |
153 | |
154 | mysystem("/bin/setfont lat0-16"); | |
72d80898 | 155 | |
33634aa8 | 156 | newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN ); |
d6aaa55d | 157 | newtPushHelpLine(ctr[TR_HELPLINE]); |
4809e64e | 158 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); |
d6aaa55d | 159 | |
72d80898 MT |
160 | if (!unattended) { |
161 | sprintf(message, ctr[TR_WELCOME], NAME); | |
72d80898 MT |
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); | |
330345c2 | 168 | } else { |
72d80898 MT |
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]); | |
59de0b00 | 178 | runcommandwithstatus("/bin/probenic.sh install", ctr[TR_PROBING_HARDWARE]); |
72d80898 | 179 | |
9607771a MT |
180 | /* CDROM INSTALL */ |
181 | if (installtype == CDROM_INSTALL) { | |
9607771a MT |
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 */ | |
0b59f25c | 196 | if ((handle = fopen("/tmp/source_device", "r")) == NULL) { |
33634aa8 MT |
197 | errorbox(ctr[TR_ERROR_PROBING_CDROM]); |
198 | goto EXIT; | |
9607771a MT |
199 | } |
200 | fgets(sourcedrive, 5, handle); | |
201 | fprintf(flog, "Source drive: %s\n", sourcedrive); | |
202 | fclose(handle); | |
203 | ||
1cdddb12 MT |
204 | //snprintf(cdromparams.devnode_disk, STRING_SIZE, "/dev/%s", sourcedrive); |
205 | fprintf(flog, "Source device: %s\n", sourcedrive); | |
72d80898 | 206 | } |
9607771a MT |
207 | |
208 | /* Configure the network now! */ | |
209 | if (installtype == URL_INSTALL) { | |
210 | /* Network driver and params. */ | |
211 | if (!(networkmenu(ethernetkv))) { | |
212 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
213 | goto EXIT; | |
214 | } | |
215 | ||
330345c2 | 216 | /* Check for ipfire-<VERSION>.tbz2 */ |
9607771a MT |
217 | if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) { |
218 | errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]); | |
219 | goto EXIT; | |
220 | } | |
72d80898 MT |
221 | } |
222 | ||
1cdddb12 MT |
223 | // Now try to find destination device... |
224 | if ((hdletter = findidetype(IDE_HD))) { | |
72d80898 | 225 | sprintf(harddrive, "hd%c", hdletter); |
1cdddb12 MT |
226 | goto FOUND_DESTINATION; |
227 | } | |
228 | ||
229 | /* Need to clean this up at some point | |
230 | scsi disk is sdb/sdc when sda/sdb is used for usb-key | |
231 | if scsi-disk is sdd or more, it is not discovered | |
232 | Support only 2 usb keys, none could be unplugged */ | |
233 | if (checkusb("sdb") && try_scsi("sdc")) { | |
234 | scsi_disk = 1; | |
235 | sprintf(harddrive, "sdc"); | |
236 | goto FOUND_DESTINATION; | |
237 | } | |
238 | if (checkusb("sda") && try_scsi("sdb")) { | |
239 | scsi_disk = 1; | |
240 | sprintf(harddrive, "sdb"); | |
241 | goto FOUND_DESTINATION; | |
242 | } | |
243 | if (try_scsi("sda")) { | |
244 | scsi_disk = 1; | |
245 | sprintf(harddrive, "sda"); | |
246 | goto FOUND_DESTINATION; | |
247 | } | |
248 | if (try_scsi("ida/c0d0")) { | |
249 | raid_disk = 1; | |
250 | sprintf(harddrive, "ida/c0d0"); | |
251 | goto FOUND_DESTINATION; | |
252 | } | |
253 | if (try_scsi("cciss/c0d0")) { | |
254 | raid_disk = 1; | |
255 | sprintf(harddrive, "cciss/c0d0"); | |
256 | goto FOUND_DESTINATION; | |
257 | } | |
258 | if (try_scsi("rd/c0d0")) { | |
259 | raid_disk = 1; | |
260 | sprintf(harddrive, "rd/c0d0"); | |
261 | goto FOUND_DESTINATION; | |
262 | } | |
263 | if (try_scsi("ataraid/d0")) { | |
264 | raid_disk = 1; | |
265 | sprintf(harddrive, "ataraid/d0"); | |
266 | goto FOUND_DESTINATION; | |
267 | } | |
268 | /* nothing worked, give up */ | |
269 | errorbox(ctr[TR_NO_HARDDISK]); | |
270 | goto EXIT; | |
271 | ||
272 | FOUND_DESTINATION: | |
72d80898 MT |
273 | /* load unattended configuration */ |
274 | if (unattended) { | |
275 | fprintf(flog, "unattended: Reading unattended.conf\n"); | |
276 | ||
277 | (void) readkeyvalues(unattendedkv, UNATTENDED_CONF); | |
278 | } | |
72d80898 | 279 | |
1cdddb12 MT |
280 | /* Make the hdparms struct and print the contents. |
281 | With USB-KEY install and SCSI disk, while installing, the disk | |
282 | is named 'sdb,sdc,...' (following keys) | |
283 | On reboot, it will become 'sda' | |
284 | To avoid many test, all names are built in the struct. | |
285 | */ | |
286 | sprintf(hdparams.devnode_disk, "/dev/%s", harddrive); | |
287 | /* Address the partition or raid partition (eg dev/sda or /dev/sdap1 */ | |
288 | sprintf(hdparams.devnode_part, "/dev/%s%s", harddrive,raid_disk ? "p" : ""); | |
289 | /* Now the names after the machine is booted. Only scsi is affected | |
290 | and we only install on the first scsi disk. */ | |
291 | { char tmp[30]; | |
292 | strcpy(tmp, scsi_disk ? "sda" : harddrive); | |
293 | sprintf(hdparams.devnode_disk_run, "/dev/%s", tmp); | |
294 | sprintf(hdparams.devnode_part_run, "/dev/%s%s", tmp, raid_disk ? "p" : ""); | |
295 | } | |
296 | ||
297 | fprintf(flog, "Destination drive: %s\n", hdparams.devnode_disk); | |
298 | ||
299 | sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode_disk); | |
72d80898 MT |
300 | if (unattended) { |
301 | hardyn = 1; | |
302 | } | |
72d80898 MT |
303 | while (! hardyn) { |
304 | rc = newtWinMenu(title, message, | |
305 | 50, 5, 5, 6, yesnoharddisk, | |
306 | &hardyn, ctr[TR_OK], | |
307 | ctr[TR_CANCEL], NULL); | |
308 | if (rc == 2) | |
309 | goto EXIT; | |
310 | } | |
5433e2c9 MT |
311 | if (rc == 2) |
312 | goto EXIT; | |
72d80898 MT |
313 | |
314 | /* Calculate amount of memory in machine */ | |
315 | if ((handle = fopen("/proc/meminfo", "r"))) | |
316 | { | |
317 | while (fgets(line, STRING_SIZE-1, handle)) { | |
318 | if (sscanf (line, "MemTotal: %s kB", string)) { | |
319 | memory = atoi(string) / 1024 ; | |
320 | } | |
321 | } | |
322 | fclose(handle); | |
323 | } | |
324 | ||
325 | /* Partition, mkswp, mkfs. | |
326 | * before partitioning, first determine the sizes of each | |
327 | * partition. In order to do that we need to know the size of | |
328 | * the disk. | |
329 | */ | |
330 | /* Don't use mysystem here so we can redirect output */ | |
0b59f25c | 331 | sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive); |
72d80898 MT |
332 | system(commandstring); |
333 | ||
334 | /* Calculate amount of disk space */ | |
0b59f25c | 335 | if ((handle = fopen("/tmp/disksize", "r"))) |
72d80898 MT |
336 | { |
337 | fgets(line, STRING_SIZE-1, handle); | |
338 | if (sscanf (line, "%s", string)) { | |
339 | maximum_free = atoi(string) / 1024; | |
340 | } | |
341 | fclose(handle); | |
342 | } | |
343 | ||
344 | fprintf(flog, "maximum_free = %ld, memory = %ld", | |
345 | maximum_free, memory); | |
346 | ||
347 | swap_file = calc_swapsize(memory, maximum_free); | |
348 | ||
349 | if (maximum_free < 512 + swap_file ) { | |
350 | if (maximum_free < 512) { | |
351 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
352 | goto EXIT; | |
353 | } | |
354 | ||
355 | if (!unattended) { | |
356 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
357 | } | |
358 | else { | |
359 | rc = 1; | |
360 | } | |
361 | ||
362 | if (rc != 1) | |
363 | goto EXIT; | |
364 | swap_file = 0; | |
365 | } | |
366 | ||
8e2e5cf3 | 367 | boot_partition = 20; /* in MB */ |
72d80898 MT |
368 | current_free = maximum_free - boot_partition - swap_file; |
369 | ||
8e2e5cf3 MT |
370 | root_partition = 2048 ; |
371 | if (current_free < 512) { | |
72d80898 MT |
372 | errorbox(ctr[TR_DISK_TOO_SMALL]); |
373 | goto EXIT; | |
374 | } | |
375 | ||
376 | current_free = current_free - root_partition; | |
377 | if (!swap_file) { | |
378 | root_partition = root_partition + swap_file; | |
379 | } | |
380 | ||
8e2e5cf3 | 381 | system_partition = current_free; |
72d80898 MT |
382 | |
383 | fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n", | |
8e2e5cf3 | 384 | boot_partition, swap_file, system_partition, root_partition); |
72d80898 MT |
385 | |
386 | handle = fopen("/tmp/partitiontable", "w"); | |
387 | ||
72d80898 MT |
388 | /* Make swapfile */ |
389 | if (swap_file) { | |
9607771a | 390 | fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n", |
72d80898 MT |
391 | boot_partition, swap_file, root_partition); |
392 | } else { | |
9607771a | 393 | fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n", |
72d80898 MT |
394 | boot_partition, root_partition); |
395 | } | |
396 | ||
397 | fclose(handle); | |
398 | ||
1cdddb12 | 399 | snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode_disk); |
72d80898 MT |
400 | if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK])) |
401 | { | |
402 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
403 | goto EXIT; | |
404 | } | |
405 | ||
532a3663 | 406 | mysystem("/sbin/udevstart"); |
72d80898 | 407 | |
1cdddb12 | 408 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode_part); |
72d80898 MT |
409 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM])) |
410 | { | |
411 | errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]); | |
412 | goto EXIT; | |
413 | } | |
414 | ||
415 | if (swap_file) { | |
1cdddb12 | 416 | snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode_part); |
72d80898 MT |
417 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) |
418 | { | |
419 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
420 | goto EXIT; | |
421 | } | |
422 | } | |
423 | ||
1cdddb12 | 424 | snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s3", hdparams.devnode_part); |
72d80898 MT |
425 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM])) |
426 | { | |
427 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
428 | goto EXIT; | |
429 | } | |
430 | ||
1cdddb12 | 431 | snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s4", hdparams.devnode_part); |
72d80898 MT |
432 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM])) |
433 | { | |
434 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
435 | goto EXIT; | |
9607771a | 436 | } |
72d80898 MT |
437 | |
438 | /* Mount harddisk. */ | |
1cdddb12 MT |
439 | |
440 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode_part); | |
72d80898 MT |
441 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM])) |
442 | { | |
443 | errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]); | |
444 | goto EXIT; | |
445 | } | |
446 | ||
447 | mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO); | |
448 | mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO); | |
449 | mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO); | |
450 | ||
1cdddb12 | 451 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode_part); |
72d80898 MT |
452 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM])) |
453 | { | |
454 | errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]); | |
455 | goto EXIT; | |
456 | } | |
457 | if (swap_file) { | |
1cdddb12 | 458 | snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode_part); |
72d80898 MT |
459 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION])) |
460 | { | |
461 | errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]); | |
462 | goto EXIT; | |
463 | } | |
464 | } | |
1cdddb12 | 465 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode_part); |
72d80898 MT |
466 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM])) |
467 | { | |
468 | errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]); | |
469 | goto EXIT; | |
9607771a | 470 | } |
c78a77eb MT |
471 | |
472 | if (installtype == URL_INSTALL) { | |
473 | snprintf(commandstring, STRING_SIZE, | |
474 | "/bin/wget -q -O - %s/" SNAME "-" VERSION ".tbz2 | /bin/tar -C /harddisk -xvjf -", url); | |
475 | } | |
476 | ||
1cdddb12 | 477 | if (installtype == CDROM_INSTALL) { |
c78a77eb MT |
478 | snprintf(commandstring, STRING_SIZE, |
479 | "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2"); | |
480 | } | |
d6aaa55d | 481 | |
edd536b6 MT |
482 | if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT, |
483 | ctr[TR_INSTALLING_FILES])) | |
d6aaa55d MT |
484 | { |
485 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
486 | goto EXIT; | |
487 | } | |
e57bc1fd | 488 | |
d6aaa55d MT |
489 | /* Save USB controller type to modules.conf */ |
490 | write_usb_modules_conf(); | |
406f019f MT |
491 | |
492 | /* Save language und local settings */ | |
493 | write_lang_configs(shortlangname); | |
d6aaa55d MT |
494 | |
495 | /* touch the modules.dep files */ | |
10bc6f06 | 496 | snprintf(commandstring, STRING_SIZE, |
c78a77eb | 497 | "/bin/touch /harddisk/lib/modules/%s-ipfire/modules.dep", |
10bc6f06 MT |
498 | KERNEL_VERSION); |
499 | mysystem(commandstring); | |
10bc6f06 | 500 | snprintf(commandstring, STRING_SIZE, |
c78a77eb | 501 | "/bin/touch /harddisk/lib/modules/%s-ipfire-smp/modules.dep", |
10bc6f06 MT |
502 | KERNEL_VERSION); |
503 | mysystem(commandstring); | |
d6aaa55d MT |
504 | |
505 | /* Rename uname */ | |
506 | rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname"); | |
507 | ||
9607771a MT |
508 | /* mount proc filesystem */ |
509 | mysystem("mkdir /harddisk/proc"); | |
510 | mysystem("/bin/mount -t proc none /harddisk/proc"); | |
511 | mysystem("/bin/mount --bind /dev /harddisk/dev"); | |
512 | ||
330345c2 MT |
513 | /* Build cache lang file */ |
514 | snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); | |
515 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE])) | |
516 | { | |
517 | errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]); | |
518 | goto EXIT; | |
519 | } | |
520 | ||
521 | /* Update /etc/fstab */ | |
1cdddb12 | 522 | replace("/harddisk/etc/fstab", "DEVICE", hdparams.devnode_part_run); |
73d9a908 | 523 | |
330345c2 | 524 | /* if we detected SCSI/USB then fixup */ |
406f019f | 525 | /* mysystem("/bin/probecntrl.sh"); |
330345c2 | 526 | if ((handle = fopen("/tmp/cntrldriver", "r"))) |
22b9e405 MT |
527 | { |
528 | char *driver; | |
330345c2 MT |
529 | fgets(line, STRING_SIZE-1, handle); |
530 | fclose(handle); | |
22b9e405 MT |
531 | line[strlen(line) - 1] = 0; |
532 | driver = strtok(line, "."); | |
22b9e405 MT |
533 | if (strlen(driver) > 1) { |
534 | fprintf(flog, "Fixing up ipfirerd.img\n"); | |
22b9e405 | 535 | mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); |
5fd30232 | 536 | 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 | 537 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); |
5fd30232 | 538 | 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 | 539 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); |
532a3663 | 540 | mysystem("/sbin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); |
9607771a | 541 | } |
406f019f | 542 | } */ |
edd536b6 | 543 | |
1cdddb12 | 544 | sprintf(string, "root=%s3", hdparams.devnode_part_run); |
edd536b6 | 545 | replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string); |
1cdddb12 | 546 | replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode_disk); |
fd0763dc | 547 | |
edd536b6 MT |
548 | /* restore permissions */ |
549 | chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); | |
550 | ||
edd536b6 | 551 | snprintf(commandstring, STRING_SIZE, |
532a3663 | 552 | "/sbin/chroot /harddisk /boot/grub/grubbatch"); |
edd536b6 MT |
553 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) { |
554 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
555 | goto EXIT; | |
556 | } | |
557 | ||
22b9e405 MT |
558 | /* Install bootsplash */ |
559 | mysystem("/bin/installbootsplash.sh"); | |
560 | ||
561 | mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst"); | |
562 | mysystem("umount /harddisk/proc"); | |
563 | mysystem("umount /harddisk/dev"); | |
564 | ||
73d9a908 MT |
565 | if (!unattended) { |
566 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
567 | NAME, SNAME, SNAME, NAME, NAME, NAME); | |
568 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message); | |
569 | } | |
22b9e405 MT |
570 | |
571 | allok = 1; | |
edd536b6 | 572 | |
d6aaa55d | 573 | EXIT: |
10bc6f06 | 574 | fprintf(flog, "Install program ended.\n"); |
d6aaa55d | 575 | |
10bc6f06 | 576 | if (!(allok)) |
d6aaa55d | 577 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); |
10bc6f06 | 578 | |
d6aaa55d | 579 | freekeyvalues(ethernetkv); |
d6aaa55d | 580 | |
10bc6f06 | 581 | if (allok && !allok_fastexit) |
d6aaa55d MT |
582 | { |
583 | /* /proc is needed by the module checker. We have to mount it | |
584 | * so it can be seen by setup, which is run chrooted. */ | |
532a3663 | 585 | if (system("/bin/mount proc -t proc /harddisk/proc")) |
d6aaa55d MT |
586 | printf("Unable to mount proc in /harddisk."); |
587 | else | |
588 | { | |
c78a77eb MT |
589 | if (unattended) { |
590 | fprintf(flog, "Entering unattended setup\n"); | |
591 | if (unattended_setup(unattendedkv)) { | |
592 | snprintf(commandstring, STRING_SIZE, "/bin/sleep 10"); | |
593 | runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot"); | |
594 | } else { | |
595 | errorbox("Unattended setup failed."); | |
596 | goto EXIT; | |
597 | } | |
598 | } | |
599 | ||
600 | newtFinished(); | |
601 | fflush(flog); | |
602 | fclose(flog); | |
3a1019f6 MT |
603 | |
604 | if (!unattended) { | |
59de0b00 MT |
605 | // Copy our scanned nics to the disk and lock because scan doesn't work in chroot |
606 | system("touch /harddisk/var/ipfire/ethernet/scan_lock"); | |
607 | system("cp -f /tmp/scanned_nics /harddisk/var/ipfire/ethernet/scanned_nics"); | |
069680ac | 608 | if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) |
3a1019f6 | 609 | printf("Unable to run setup.\n"); |
59de0b00 | 610 | system("rm -f /harddisk/var/ipfire/ethernet/scan_lock"); |
3a1019f6 | 611 | } |
3a1019f6 | 612 | |
532a3663 | 613 | if (system("/bin/umount /harddisk/proc")) |
c78a77eb | 614 | printf("Unable to umount /harddisk/proc.\n"); |
d6aaa55d MT |
615 | } |
616 | } | |
d6aaa55d MT |
617 | fcloseall(); |
618 | ||
3a1019f6 | 619 | if (swap_file) { |
1cdddb12 | 620 | snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode_part); |
3a1019f6 MT |
621 | } |
622 | ||
623 | newtFinished(); | |
624 | ||
532a3663 MT |
625 | system("/bin/umount /harddisk/var"); |
626 | system("/bin/umount /harddisk/boot"); | |
627 | system("/bin/umount /harddisk"); | |
10bc6f06 | 628 | |
d6aaa55d MT |
629 | system("/etc/halt"); |
630 | ||
631 | return 0; | |
632 | } |