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