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