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