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