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