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