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