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