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