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