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