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