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