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