]>
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 | ||
26 | char *pcmcia = NULL; | |
27 | extern char url[STRING_SIZE]; | |
28 | ||
10bc6f06 | 29 | extern char *en_tr[]; |
10bc6f06 | 30 | extern char *de_tr[]; |
d6aaa55d | 31 | |
72d80898 MT |
32 | int detect_smp() { |
33 | FILE *fd = NULL; | |
34 | char line[STRING_SIZE]; | |
35 | int cpu_count = 0; | |
36 | ||
37 | if ((fd = fopen("/proc/cpuinfo", "r")) == NULL) { | |
38 | return 0; | |
39 | } | |
40 | while (fgets(line, STRING_SIZE, fd) != NULL) { | |
41 | if (strstr(line, "processor") == line) { | |
42 | cpu_count++; | |
43 | } | |
44 | } | |
45 | (void)fclose(fd); | |
46 | return (cpu_count > 1); | |
47 | } | |
48 | ||
72d80898 MT |
49 | long calc_swapsize(long memory, long disk) { |
50 | if (memory < 128) { | |
51 | return 256; | |
52 | } | |
53 | if (memory > 1024) { | |
54 | return 512; | |
55 | } | |
56 | ||
57 | return memory*2; | |
58 | } | |
59 | ||
60 | int unattended_setup(struct keyvalue *unattendedkv) { | |
61 | struct keyvalue *mainsettings = initkeyvalues(); | |
62 | struct keyvalue *ethernetkv = initkeyvalues(); | |
63 | FILE *file, *hosts; | |
64 | char commandstring[STRING_SIZE]; | |
65 | ||
66 | char domainname[STRING_SIZE]; | |
67 | char hostname[STRING_SIZE]; | |
68 | char keymap[STRING_SIZE]; | |
69 | char language[STRING_SIZE]; | |
70 | char timezone[STRING_SIZE]; | |
a1055a1c | 71 | char theme[STRING_SIZE]; |
72d80898 MT |
72 | char green_address[STRING_SIZE]; |
73 | char green_netmask[STRING_SIZE]; | |
74 | char green_netaddress[STRING_SIZE]; | |
75 | char green_broadcast[STRING_SIZE]; | |
76 | char root_password[STRING_SIZE]; | |
77 | char admin_password[STRING_SIZE]; | |
72d80898 MT |
78 | |
79 | findkey(unattendedkv, "DOMAINNAME", domainname); | |
80 | findkey(unattendedkv, "HOSTNAME", hostname); | |
81 | findkey(unattendedkv, "KEYMAP", keymap); | |
82 | findkey(unattendedkv, "LANGUAGE", language); | |
83 | findkey(unattendedkv, "TIMEZONE", timezone); | |
a1055a1c | 84 | findkey(unattendedkv, "THEME", theme); |
72d80898 MT |
85 | findkey(unattendedkv, "GREEN_ADDRESS", green_address); |
86 | findkey(unattendedkv, "GREEN_NETMASK", green_netmask); | |
87 | findkey(unattendedkv, "GREEN_NETADDRESS", green_netaddress); | |
88 | findkey(unattendedkv, "GREEN_BROADCAST", green_broadcast); | |
89 | findkey(unattendedkv, "ROOT_PASSWORD", root_password); | |
90 | findkey(unattendedkv, "ADMIN_PASSWORD", admin_password); | |
72d80898 MT |
91 | |
92 | /* write main/settings. */ | |
93 | replacekeyvalue(mainsettings, "DOMAINNAME", domainname); | |
94 | replacekeyvalue(mainsettings, "HOSTNAME", hostname); | |
95 | replacekeyvalue(mainsettings, "KEYMAP", keymap); | |
96 | replacekeyvalue(mainsettings, "LANGUAGE", language); | |
97 | replacekeyvalue(mainsettings, "TIMEZONE", timezone); | |
a1055a1c | 98 | replacekeyvalue(mainsettings, "THEME", theme); |
72d80898 MT |
99 | writekeyvalues(mainsettings, "/harddisk" CONFIG_ROOT "/main/settings"); |
100 | freekeyvalues(mainsettings); | |
101 | ||
102 | /* do setup stuff */ | |
103 | fprintf(flog, "unattended: Starting setup\n"); | |
104 | ||
105 | /* network */ | |
72d80898 MT |
106 | fprintf(flog, "unattended: setting up network configuration\n"); |
107 | ||
108 | (void) readkeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings"); | |
109 | replacekeyvalue(ethernetkv, "GREEN_ADDRESS", green_address); | |
110 | replacekeyvalue(ethernetkv, "GREEN_NETMASK", green_netmask); | |
111 | replacekeyvalue(ethernetkv, "GREEN_NETADDRESS", green_netaddress); | |
112 | replacekeyvalue(ethernetkv, "GREEN_BROADCAST", green_broadcast); | |
113 | replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0"); | |
8e2e5cf3 | 114 | replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0"); |
72d80898 MT |
115 | write_ethernet_configs(ethernetkv); |
116 | freekeyvalues(ethernetkv); | |
117 | ||
118 | /* timezone */ | |
119 | unlink("/harddisk/etc/localtime"); | |
120 | snprintf(commandstring, STRING_SIZE, "/harddisk/%s", timezone); | |
121 | link(commandstring, "/harddisk/etc/localtime"); | |
122 | ||
123 | /* hostname */ | |
124 | fprintf(flog, "unattended: writing hostname.conf\n"); | |
125 | if (!(file = fopen("/harddisk" CONFIG_ROOT "/main/hostname.conf", "w"))) | |
126 | { | |
127 | errorbox("unattended: ERROR writing hostname.conf"); | |
128 | return 0; | |
129 | } | |
130 | fprintf(file, "ServerName %s\n", hostname); | |
3a1019f6 | 131 | fclose(file); |
72d80898 MT |
132 | |
133 | fprintf(flog, "unattended: writing hosts\n"); | |
134 | if (!(hosts = fopen("/harddisk/etc/hosts", "w"))) | |
135 | { | |
136 | errorbox("unattended: ERROR writing hosts"); | |
137 | return 0; | |
138 | } | |
139 | fprintf(hosts, "127.0.0.1\tlocalhost\n"); | |
140 | fprintf(hosts, "%s\t%s.%s\t%s\n", green_address, hostname, domainname, hostname); | |
3a1019f6 | 141 | fclose(hosts); |
72d80898 MT |
142 | |
143 | fprintf(flog, "unattended: writing hosts.allow\n"); | |
144 | if (!(file = fopen("/harddisk/etc/hosts.allow", "w"))) | |
145 | { | |
146 | errorbox("unattended: ERROR writing hosts.allow"); | |
edd536b6 | 147 | return 0; |
72d80898 MT |
148 | } |
149 | fprintf(file, "sshd : ALL\n"); | |
150 | fprintf(file, "ALL : localhost\n"); | |
151 | fprintf(file, "ALL : %s/%s\n", green_netaddress, green_netmask); | |
152 | fclose(file); | |
153 | ||
154 | fprintf(flog, "unattended: writing hosts.deny\n"); | |
155 | if (!(file = fopen("/harddisk/etc/hosts.deny", "w"))) | |
156 | { | |
157 | errorbox("unattended: ERROR writing hosts.deny"); | |
158 | return 0; | |
159 | } | |
160 | fprintf(file, "ALL : ALL\n"); | |
161 | fclose(file); | |
162 | ||
72d80898 MT |
163 | /* set root password */ |
164 | fprintf(flog, "unattended: setting root password\n"); | |
72d80898 | 165 | snprintf(commandstring, STRING_SIZE, |
532a3663 | 166 | "/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password); |
72d80898 MT |
167 | if (mysystem(commandstring)) { |
168 | errorbox("unattended: ERROR setting root password"); | |
169 | return 0; | |
170 | } | |
3a1019f6 | 171 | |
72d80898 MT |
172 | /* set admin password */ |
173 | fprintf(flog, "unattended: setting admin password\n"); | |
174 | snprintf(commandstring, STRING_SIZE, | |
3a1019f6 | 175 | "/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", admin_password); |
72d80898 MT |
176 | if (mysystem(commandstring)) { |
177 | errorbox("unattended: ERROR setting admin password"); | |
3a1019f6 | 178 | return 0; |
72d80898 | 179 | } |
3a1019f6 | 180 | return 1; |
72d80898 MT |
181 | } |
182 | ||
d6aaa55d MT |
183 | int main(int argc, char *argv[]) |
184 | { | |
b4e3cd7f HS |
185 | char *langnames[] = { "Deutsch", "English", NULL }; |
186 | char *shortlangnames[] = { "de", "en", NULL }; | |
187 | char **langtrs[] = { de_tr, en_tr, NULL }; | |
d6aaa55d | 188 | char hdletter, cdletter; |
72d80898 MT |
189 | char harddrive[5], sourcedrive[5]; /* Device holder. */ |
190 | struct devparams hdparams, cdromparams; /* Params for CDROM and HD */ | |
191 | int cdmounted = 0; /* Loop flag for inserting a cd. */ | |
192 | int rc = 0; | |
d6aaa55d | 193 | char commandstring[STRING_SIZE]; |
aa2870e6 | 194 | char *installtypes[] = { "CDROM/USB", "HTTP/FTP", NULL }; |
72d80898 | 195 | int installtype = CDROM_INSTALL; |
d6aaa55d MT |
196 | char insertmessage[STRING_SIZE]; |
197 | char insertdevnode[STRING_SIZE]; | |
198 | int choice; | |
199 | char shortlangname[10]; | |
200 | char message[1000]; | |
201 | char title[STRING_SIZE]; | |
202 | int allok = 0; | |
10bc6f06 | 203 | int allok_fastexit=0; |
d6aaa55d MT |
204 | int unmount_before=0; |
205 | struct keyvalue *ethernetkv = initkeyvalues(); | |
206 | FILE *handle, *cmdfile; | |
207 | char line[STRING_SIZE]; | |
208 | char string[STRING_SIZE]; | |
72d80898 MT |
209 | long maximum_free = 0, current_free; |
210 | long memory = 0; | |
8e2e5cf3 | 211 | long system_partition, boot_partition, root_partition, swap_file; |
d6aaa55d MT |
212 | int scsi_disk = 0; |
213 | int pcmcia_disk = 0; | |
214 | int pcmcia_cdrom = 0; | |
215 | int scsi_cdrom = 0; | |
216 | int ide_cdrom = 0; | |
217 | int fdisk = 0; | |
72d80898 MT |
218 | int hardyn = 0; |
219 | char *yesnoharddisk[] = { "NO", "YES", NULL }; | |
220 | char *yesno[] = { "NO", "YES", NULL }; | |
221 | char green[STRING_SIZE]; | |
222 | int unattended = 0; | |
223 | struct keyvalue *unattendedkv = initkeyvalues(); | |
224 | char packages[STRING_SIZE]; | |
225 | int serial_console = 0; | |
226 | char megabridge[STRING_SIZE]; | |
d6aaa55d MT |
227 | |
228 | setlocale (LC_ALL, ""); | |
10bc6f06 | 229 | sethostname( SNAME , 10); |
72d80898 | 230 | |
d6aaa55d MT |
231 | memset(&hdparams, 0, sizeof(struct devparams)); |
232 | memset(&cdromparams, 0, sizeof(struct devparams)); | |
233 | ||
234 | /* Log file/terminal stuff. */ | |
235 | if (argc >= 2) | |
236 | { | |
237 | if (!(flog = fopen(argv[1], "w+"))) | |
238 | return 0; | |
239 | } | |
240 | else | |
241 | return 0; | |
242 | ||
243 | mylog = argv[1]; | |
244 | ||
245 | fprintf(flog, "Install program started.\n"); | |
246 | ||
247 | newtInit(); | |
248 | newtCls(); | |
249 | ||
250 | /* Do usb detection first for usb keyboard */ | |
251 | if (! (cmdfile = fopen("/proc/cmdline", "r"))) | |
252 | { | |
253 | fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); | |
254 | } else { | |
255 | fgets(line, STRING_SIZE, cmdfile); | |
256 | if (strstr (line, "fdisk") != NULL) { | |
257 | fprintf(flog, "Manual FDISK selected.\n"); | |
258 | fdisk = 1; | |
259 | } | |
d6aaa55d MT |
260 | if (strstr (line, "nousb") == NULL) { |
261 | fprintf(flog, "Initializing USB controllers.\n"); | |
262 | initialize_usb(); | |
263 | } else { | |
264 | fprintf(flog, "Skipping USB detection.\n"); | |
265 | } | |
72d80898 MT |
266 | // check if we have to make an unattended install |
267 | if (strstr (line, "unattended") != NULL) { | |
268 | unattended = 1; | |
269 | } | |
d6aaa55d | 270 | } |
72d80898 MT |
271 | |
272 | // make some beeps before wiping the system :) | |
273 | if (unattended) { | |
33634aa8 | 274 | runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds..."); |
72d80898 | 275 | } |
d6aaa55d | 276 | |
72d80898 | 277 | /* German is the default */ |
d6aaa55d MT |
278 | for (choice = 0; langnames[choice]; choice++) |
279 | { | |
b4e3cd7f | 280 | if (strcmp(langnames[choice], "Deutsch") == 0) |
d6aaa55d MT |
281 | break; |
282 | } | |
283 | if (!langnames[choice]) | |
284 | goto EXIT; | |
285 | ||
72d80898 MT |
286 | if (!unattended) { |
287 | rc = newtWinMenu("Language selection", | |
288 | "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, | |
289 | langnames, &choice, "Ok", NULL); | |
290 | } | |
291 | ||
d6aaa55d MT |
292 | ctr = langtrs[choice]; |
293 | strcpy(shortlangname, shortlangnames[choice]); | |
3d6e1202 MT |
294 | |
295 | mysystem("/bin/setfont lat0-16"); | |
72d80898 | 296 | |
33634aa8 | 297 | newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN ); |
d6aaa55d MT |
298 | newtPushHelpLine(ctr[TR_HELPLINE]); |
299 | ||
72d80898 MT |
300 | if (!unattended) { |
301 | sprintf(message, ctr[TR_WELCOME], NAME); | |
302 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
303 | newtWinMessage(title, ctr[TR_OK], message); | |
304 | ||
305 | sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME); | |
306 | rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message, | |
307 | 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK], | |
308 | ctr[TR_CANCEL], NULL); | |
309 | } | |
310 | else { | |
311 | rc = 1; | |
312 | installtype = CDROM_INSTALL; | |
313 | } | |
314 | ||
315 | if (rc == 2) | |
316 | goto EXIT; | |
317 | ||
318 | // Starting hardware detection | |
319 | runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]); | |
320 | ||
9607771a MT |
321 | /* CDROM INSTALL */ |
322 | if (installtype == CDROM_INSTALL) { | |
72d80898 | 323 | |
9607771a MT |
324 | switch (mysystem("/bin/mountsource.sh")) { |
325 | case 0: | |
326 | installtype = CDROM_INSTALL; | |
327 | cdmounted = 1; | |
328 | break; | |
329 | case 1: | |
330 | installtype = DISK_INSTALL; | |
331 | break; | |
332 | case 10: | |
333 | errorbox(ctr[TR_NO_CDROM]); | |
334 | goto EXIT; | |
335 | } | |
336 | ||
337 | /* read source drive letter */ | |
0b59f25c | 338 | if ((handle = fopen("/tmp/source_device", "r")) == NULL) { |
33634aa8 MT |
339 | errorbox(ctr[TR_ERROR_PROBING_CDROM]); |
340 | goto EXIT; | |
9607771a MT |
341 | } |
342 | fgets(sourcedrive, 5, handle); | |
343 | fprintf(flog, "Source drive: %s\n", sourcedrive); | |
344 | fclose(handle); | |
345 | ||
346 | snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive); | |
347 | cdromparams.module = 0; | |
348 | fprintf(flog, "Source device: %s\n", cdromparams.devnode); | |
72d80898 | 349 | } |
9607771a MT |
350 | |
351 | /* Configure the network now! */ | |
352 | if (installtype == URL_INSTALL) { | |
353 | /* Network driver and params. */ | |
354 | if (!(networkmenu(ethernetkv))) { | |
355 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
356 | goto EXIT; | |
357 | } | |
358 | ||
359 | /* Check for ipcop-<VERSION>.tbz2 */ | |
360 | if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) { | |
361 | errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]); | |
362 | goto EXIT; | |
363 | } | |
72d80898 MT |
364 | } |
365 | ||
366 | /* Get device for the HD. This has to succeed. */ | |
367 | if (!(hdletter = findidetype(IDE_HD))) | |
368 | { | |
369 | /* Need to clean this up at some point */ | |
370 | if (!try_scsi("sda") || strstr(sourcedrive, "sda") != NULL) { | |
371 | if (!try_scsi("ida/c0d0")) { | |
372 | if (!try_scsi("cciss/c0d0")) { | |
373 | if (!try_scsi("rd/c0d0")) { | |
374 | if (!try_scsi("ataraid/d0")) { | |
375 | errorbox(ctr[TR_NO_HARDDISK]); | |
376 | goto EXIT; | |
377 | } else { | |
378 | raid_disk = 1; | |
379 | sprintf(harddrive, "ataraid/d0"); | |
380 | } | |
381 | } else { | |
382 | raid_disk = 1; | |
383 | sprintf(harddrive, "rd/c0d0"); | |
384 | } | |
385 | } else { | |
386 | raid_disk = 1; | |
387 | sprintf(harddrive, "cciss/c0d0"); | |
388 | } | |
389 | } else { | |
390 | raid_disk = 1; | |
391 | sprintf(harddrive, "ida/c0d0"); | |
392 | } | |
393 | } else { | |
394 | if (strstr(sourcedrive, "sda") != NULL) { | |
395 | // probably installing from usb stick, try sdb | |
396 | if (try_scsi("sdb")) { | |
397 | sprintf(harddrive, "sdb"); | |
398 | } | |
399 | else { | |
400 | errorbox(ctr[TR_NO_HARDDISK]); | |
401 | goto EXIT; | |
402 | } | |
403 | } | |
404 | else { | |
405 | sprintf(harddrive, "sda"); | |
406 | } | |
407 | } | |
408 | scsi_disk = 1; | |
409 | } else | |
410 | sprintf(harddrive, "hd%c", hdletter); | |
411 | ||
9607771a | 412 | fprintf(flog, "Destination drive: %s\n", harddrive); |
d6aaa55d | 413 | |
72d80898 MT |
414 | /* load unattended configuration */ |
415 | if (unattended) { | |
416 | fprintf(flog, "unattended: Reading unattended.conf\n"); | |
417 | ||
418 | (void) readkeyvalues(unattendedkv, UNATTENDED_CONF); | |
419 | } | |
420 | ||
421 | /* Make the hdparms struct and print the contents. */ | |
422 | snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive); | |
423 | hdparams.module = 0; | |
424 | ||
425 | sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode); | |
426 | ||
427 | if (unattended) { | |
428 | hardyn = 1; | |
429 | } | |
430 | ||
431 | while (! hardyn) { | |
432 | rc = newtWinMenu(title, message, | |
433 | 50, 5, 5, 6, yesnoharddisk, | |
434 | &hardyn, ctr[TR_OK], | |
435 | ctr[TR_CANCEL], NULL); | |
436 | if (rc == 2) | |
437 | goto EXIT; | |
438 | } | |
5433e2c9 MT |
439 | |
440 | if (rc == 2) | |
441 | goto EXIT; | |
72d80898 MT |
442 | |
443 | /* Calculate amount of memory in machine */ | |
444 | if ((handle = fopen("/proc/meminfo", "r"))) | |
445 | { | |
446 | while (fgets(line, STRING_SIZE-1, handle)) { | |
447 | if (sscanf (line, "MemTotal: %s kB", string)) { | |
448 | memory = atoi(string) / 1024 ; | |
449 | } | |
450 | } | |
451 | fclose(handle); | |
452 | } | |
453 | ||
454 | /* Partition, mkswp, mkfs. | |
455 | * before partitioning, first determine the sizes of each | |
456 | * partition. In order to do that we need to know the size of | |
457 | * the disk. | |
458 | */ | |
459 | /* Don't use mysystem here so we can redirect output */ | |
0b59f25c | 460 | sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive); |
72d80898 MT |
461 | system(commandstring); |
462 | ||
463 | /* Calculate amount of disk space */ | |
0b59f25c | 464 | if ((handle = fopen("/tmp/disksize", "r"))) |
72d80898 MT |
465 | { |
466 | fgets(line, STRING_SIZE-1, handle); | |
467 | if (sscanf (line, "%s", string)) { | |
468 | maximum_free = atoi(string) / 1024; | |
469 | } | |
470 | fclose(handle); | |
471 | } | |
472 | ||
473 | fprintf(flog, "maximum_free = %ld, memory = %ld", | |
474 | maximum_free, memory); | |
475 | ||
476 | swap_file = calc_swapsize(memory, maximum_free); | |
477 | ||
478 | if (maximum_free < 512 + swap_file ) { | |
479 | if (maximum_free < 512) { | |
480 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
481 | goto EXIT; | |
482 | } | |
483 | ||
484 | if (!unattended) { | |
485 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
486 | } | |
487 | else { | |
488 | rc = 1; | |
489 | } | |
490 | ||
491 | if (rc != 1) | |
492 | goto EXIT; | |
493 | swap_file = 0; | |
494 | } | |
495 | ||
8e2e5cf3 | 496 | boot_partition = 20; /* in MB */ |
72d80898 MT |
497 | current_free = maximum_free - boot_partition - swap_file; |
498 | ||
8e2e5cf3 MT |
499 | root_partition = 2048 ; |
500 | if (current_free < 512) { | |
72d80898 MT |
501 | errorbox(ctr[TR_DISK_TOO_SMALL]); |
502 | goto EXIT; | |
503 | } | |
504 | ||
505 | current_free = current_free - root_partition; | |
506 | if (!swap_file) { | |
507 | root_partition = root_partition + swap_file; | |
508 | } | |
509 | ||
8e2e5cf3 | 510 | system_partition = current_free; |
72d80898 MT |
511 | |
512 | fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n", | |
8e2e5cf3 | 513 | boot_partition, swap_file, system_partition, root_partition); |
72d80898 MT |
514 | |
515 | handle = fopen("/tmp/partitiontable", "w"); | |
516 | ||
72d80898 MT |
517 | /* Make swapfile */ |
518 | if (swap_file) { | |
9607771a | 519 | fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n", |
72d80898 MT |
520 | boot_partition, swap_file, root_partition); |
521 | } else { | |
9607771a | 522 | fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n", |
72d80898 MT |
523 | boot_partition, root_partition); |
524 | } | |
525 | ||
526 | fclose(handle); | |
527 | ||
528 | snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode); | |
529 | if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK])) | |
530 | { | |
531 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
532 | goto EXIT; | |
533 | } | |
534 | ||
532a3663 | 535 | mysystem("/sbin/udevstart"); |
72d80898 MT |
536 | |
537 | if (raid_disk) | |
8e2e5cf3 | 538 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %sp1", hdparams.devnode); |
72d80898 | 539 | else |
8e2e5cf3 | 540 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode); |
72d80898 MT |
541 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM])) |
542 | { | |
543 | errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]); | |
544 | goto EXIT; | |
545 | } | |
546 | ||
547 | if (swap_file) { | |
548 | if (raid_disk) | |
532a3663 | 549 | snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %sp2", hdparams.devnode); |
72d80898 | 550 | else |
532a3663 | 551 | snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode); |
72d80898 MT |
552 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) |
553 | { | |
554 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
555 | goto EXIT; | |
556 | } | |
557 | } | |
558 | ||
559 | if (raid_disk) | |
376e42ce | 560 | snprintf(commandstring, STRING_SIZE, "/sbin/mkfs.reiser4 -y %sp3", hdparams.devnode); |
72d80898 | 561 | else |
376e42ce | 562 | snprintf(commandstring, STRING_SIZE, "/sbin/mkfs.reiser4 -y %s3", hdparams.devnode); |
72d80898 MT |
563 | |
564 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM])) | |
565 | { | |
566 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
567 | goto EXIT; | |
568 | } | |
569 | ||
9607771a | 570 | if (raid_disk) |
376e42ce | 571 | snprintf(commandstring, STRING_SIZE, "/sbin/mkfs.reiser4 -y %sp4", hdparams.devnode); |
72d80898 | 572 | else |
376e42ce | 573 | snprintf(commandstring, STRING_SIZE, "/sbin/mkfs.reiser4 -y %s4", hdparams.devnode); |
72d80898 MT |
574 | |
575 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM])) | |
576 | { | |
577 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
578 | goto EXIT; | |
9607771a | 579 | } |
72d80898 MT |
580 | |
581 | /* Mount harddisk. */ | |
582 | if (raid_disk) | |
532a3663 | 583 | snprintf(commandstring, STRING_SIZE, "/bin/mount %sp3 /harddisk", hdparams.devnode); |
72d80898 | 584 | else |
532a3663 | 585 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode); |
72d80898 MT |
586 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM])) |
587 | { | |
588 | errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]); | |
589 | goto EXIT; | |
590 | } | |
591 | ||
592 | mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO); | |
593 | mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO); | |
594 | mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO); | |
595 | ||
596 | if (raid_disk) | |
532a3663 | 597 | snprintf(commandstring, STRING_SIZE, "/bin/mount %sp1 /harddisk/boot", hdparams.devnode); |
72d80898 | 598 | else |
532a3663 | 599 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode); |
72d80898 MT |
600 | |
601 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM])) | |
602 | { | |
603 | errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]); | |
604 | goto EXIT; | |
605 | } | |
606 | if (swap_file) { | |
607 | if (raid_disk) | |
532a3663 | 608 | snprintf(commandstring, STRING_SIZE, "/sbin/swapon %sp2", hdparams.devnode); |
72d80898 | 609 | else |
532a3663 | 610 | snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode); |
72d80898 MT |
611 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION])) |
612 | { | |
613 | errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]); | |
614 | goto EXIT; | |
615 | } | |
616 | } | |
9607771a | 617 | if (raid_disk) |
532a3663 | 618 | snprintf(commandstring, STRING_SIZE, "/bin/mount %sp4 /harddisk/var", hdparams.devnode); |
72d80898 | 619 | else |
532a3663 | 620 | snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode); |
72d80898 MT |
621 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM])) |
622 | { | |
623 | errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]); | |
624 | goto EXIT; | |
9607771a | 625 | } |
10bc6f06 | 626 | |
8e2e5cf3 | 627 | snprintf(commandstring, STRING_SIZE, "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2"); |
d6aaa55d | 628 | |
edd536b6 MT |
629 | if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT, |
630 | ctr[TR_INSTALLING_FILES])) | |
d6aaa55d MT |
631 | { |
632 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
633 | goto EXIT; | |
634 | } | |
e57bc1fd | 635 | |
d6aaa55d MT |
636 | /* Save USB controller type to modules.conf */ |
637 | write_usb_modules_conf(); | |
638 | ||
639 | /* touch the modules.dep files */ | |
10bc6f06 | 640 | snprintf(commandstring, STRING_SIZE, |
532a3663 | 641 | "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s/modules.dep", |
10bc6f06 MT |
642 | KERNEL_VERSION); |
643 | mysystem(commandstring); | |
10bc6f06 | 644 | snprintf(commandstring, STRING_SIZE, |
532a3663 | 645 | "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s-smp/modules.dep", |
10bc6f06 MT |
646 | KERNEL_VERSION); |
647 | mysystem(commandstring); | |
d6aaa55d MT |
648 | |
649 | /* Rename uname */ | |
650 | rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname"); | |
651 | ||
d6aaa55d MT |
652 | /* *always* write disk configuration */ |
653 | if (!(write_disk_configs(&hdparams))){ | |
10bc6f06 MT |
654 | errorbox(ctr[TR_ERROR_WRITING_CONFIG]); |
655 | goto EXIT; | |
d6aaa55d MT |
656 | } |
657 | ||
9607771a MT |
658 | /* mount proc filesystem */ |
659 | mysystem("mkdir /harddisk/proc"); | |
660 | mysystem("/bin/mount -t proc none /harddisk/proc"); | |
661 | mysystem("/bin/mount --bind /dev /harddisk/dev"); | |
662 | ||
73d9a908 | 663 | |
22b9e405 | 664 | /* if we detected SCSI then fixup */ |
73d9a908 MT |
665 | /* doesn't really work cause it sometimes creates a ramdisk on ide systems */ |
666 | /* mysystem("/bin/probecntrl.sh"); | |
9607771a | 667 | if ((handle = fopen("/cntrldriver", "r"))) |
22b9e405 MT |
668 | { |
669 | char *driver; | |
670 | fgets(line, STRING_SIZE-1, handle); | |
671 | fclose(handle); | |
672 | line[strlen(line) - 1] = 0; | |
673 | driver = strtok(line, "."); | |
674 | fprintf(flog, "Detected SCSI driver %s\n",driver); | |
675 | if (strlen(driver) > 1) { | |
676 | fprintf(flog, "Fixing up ipfirerd.img\n"); | |
532a3663 | 677 | mysystem("/sbin/chroot /harddisk /sbin/modprobe loop"); |
22b9e405 | 678 | mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); |
532a3663 | 679 | snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata /boot/ipfirerd.img %s", driver, KERNEL_VERSION); |
22b9e405 | 680 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); |
532a3663 | 681 | snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata /boot/ipfirerd-smp.img %s-smp", driver, KERNEL_VERSION); |
22b9e405 | 682 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); |
532a3663 | 683 | mysystem("/sbin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); |
9607771a | 684 | } |
73d9a908 | 685 | } */ |
22b9e405 | 686 | |
9607771a | 687 | /* Build cache lang file */ |
532a3663 | 688 | snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); |
9607771a MT |
689 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE])) |
690 | { | |
691 | errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]); | |
692 | goto EXIT; | |
693 | } | |
edd536b6 MT |
694 | |
695 | if (raid_disk) | |
696 | sprintf(string, "root=%sp3", hdparams.devnode); | |
697 | else | |
698 | sprintf(string, "root=%s3", hdparams.devnode); | |
699 | replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string); | |
edd536b6 | 700 | replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode); |
fd0763dc | 701 | |
edd536b6 MT |
702 | /* restore permissions */ |
703 | chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); | |
704 | ||
edd536b6 | 705 | snprintf(commandstring, STRING_SIZE, |
532a3663 | 706 | "/sbin/chroot /harddisk /boot/grub/grubbatch"); |
edd536b6 MT |
707 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) { |
708 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
709 | goto EXIT; | |
710 | } | |
711 | ||
73d9a908 MT |
712 | /* Update /etc/fstab */ |
713 | replace( "/harddisk/etc/fstab", "DEVICE", hdparams.devnode); | |
714 | ||
22b9e405 MT |
715 | /* Install bootsplash */ |
716 | mysystem("/bin/installbootsplash.sh"); | |
717 | ||
718 | mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst"); | |
719 | mysystem("umount /harddisk/proc"); | |
720 | mysystem("umount /harddisk/dev"); | |
721 | ||
73d9a908 MT |
722 | if (!unattended) { |
723 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
724 | NAME, SNAME, SNAME, NAME, NAME, NAME); | |
725 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message); | |
726 | } | |
22b9e405 MT |
727 | |
728 | allok = 1; | |
edd536b6 | 729 | |
d6aaa55d | 730 | EXIT: |
10bc6f06 | 731 | fprintf(flog, "Install program ended.\n"); |
d6aaa55d MT |
732 | fflush(flog); |
733 | fclose(flog); | |
734 | ||
10bc6f06 | 735 | if (!(allok)) |
d6aaa55d | 736 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); |
10bc6f06 | 737 | |
d6aaa55d | 738 | newtFinished(); |
10bc6f06 | 739 | |
d6aaa55d | 740 | freekeyvalues(ethernetkv); |
d6aaa55d | 741 | |
10bc6f06 | 742 | if (allok && !allok_fastexit) |
d6aaa55d MT |
743 | { |
744 | /* /proc is needed by the module checker. We have to mount it | |
745 | * so it can be seen by setup, which is run chrooted. */ | |
532a3663 | 746 | if (system("/bin/mount proc -t proc /harddisk/proc")) |
d6aaa55d MT |
747 | printf("Unable to mount proc in /harddisk."); |
748 | else | |
749 | { | |
3a1019f6 MT |
750 | |
751 | if (!unattended) { | |
069680ac | 752 | if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) |
3a1019f6 MT |
753 | printf("Unable to run setup.\n"); |
754 | } | |
755 | else { | |
756 | fprintf(flog, "Entering unattended setup\n"); | |
757 | unattended_setup(unattendedkv); | |
758 | snprintf(commandstring, STRING_SIZE, "/bin/sleep 10"); | |
759 | runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot"); | |
760 | } | |
761 | ||
532a3663 | 762 | if (system("/bin/umount /harddisk/proc")) |
d6aaa55d MT |
763 | printf("Unable to umount /harddisk/proc.\n"); |
764 | } | |
765 | } | |
766 | ||
767 | fcloseall(); | |
768 | ||
3a1019f6 MT |
769 | if (swap_file) { |
770 | if (raid_disk) | |
771 | snprintf(commandstring, STRING_SIZE, "/bin/swapoff %sp2", hdparams.devnode); | |
772 | else | |
773 | snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode); | |
774 | } | |
775 | ||
776 | newtFinished(); | |
777 | ||
532a3663 MT |
778 | system("/bin/umount /harddisk/var"); |
779 | system("/bin/umount /harddisk/boot"); | |
780 | system("/bin/umount /harddisk"); | |
10bc6f06 | 781 | |
d6aaa55d MT |
782 | system("/etc/halt"); |
783 | ||
784 | return 0; | |
785 | } |