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