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