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