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