]>
Commit | Line | Data |
---|---|---|
2bb7b134 | 1 | |
d6aaa55d MT |
2 | /* SmoothWall install program. |
3 | * | |
4 | * This program is distributed under the terms of the GNU General Public | |
5 | * Licence. See the file COPYING for details. | |
6 | * | |
7 | * (c) Lawrence Manning, 2001 | |
f9cc0d70 | 8 | * Contains main entry point, and misc functions.6 |
d6aaa55d | 9 | * |
d6aaa55d | 10 | */ |
10bc6f06 | 11 | |
72d80898 | 12 | #define _GNU_SOURCE |
f0fa1795 MT |
13 | |
14 | #include <assert.h> | |
15 | #include <errno.h> | |
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
18 | #include <sys/mount.h> | |
19 | ||
20 | #include "hw.h" | |
21 | #include "install.h" | |
72d80898 | 22 | |
68561214 | 23 | #define INST_FILECOUNT 21000 |
33634aa8 | 24 | #define UNATTENDED_CONF "/cdrom/boot/unattended.conf" |
918546e2 | 25 | #define LICENSE_FILE "/cdrom/COPYING" |
d6aaa55d | 26 | |
d6aaa55d MT |
27 | FILE *flog = NULL; |
28 | char *mylog; | |
10bc6f06 | 29 | |
d6aaa55d MT |
30 | char **ctr; |
31 | ||
d6aaa55d MT |
32 | extern char url[STRING_SIZE]; |
33 | ||
f9cc0d70 HS |
34 | struct nic nics[20] = { { "" , "" , "" } }; // only defined for compile |
35 | struct knic knics[20] = { { "" , "" , "" , "" } }; // only defined for compile | |
5057b611 | 36 | |
10bc6f06 | 37 | extern char *en_tr[]; |
cf4dd3c0 | 38 | extern char *es_tr[]; |
10bc6f06 | 39 | extern char *de_tr[]; |
462515e4 | 40 | extern char *fr_tr[]; |
1d76272b | 41 | extern char *nl_tr[]; |
b6c9668f | 42 | extern char *pl_tr[]; |
2bb7b134 | 43 | extern char *ru_tr[]; |
910193da | 44 | extern char *tr_tr[]; |
d6aaa55d | 45 | |
d7dd283b MT |
46 | static int newtChecklist(const char* title, const char* message, |
47 | unsigned int width, unsigned int height, unsigned int num_entries, | |
48 | const char** entries, int* states) { | |
49 | int ret; | |
50 | const int list_height = 4; | |
51 | ||
52 | char cbstates[num_entries]; | |
53 | ||
54 | for (unsigned int i = 0; i < num_entries; i++) { | |
55 | cbstates[i] = states[i] ? '*' : ' '; | |
56 | } | |
57 | ||
58 | newtCenteredWindow(width, height, title); | |
59 | ||
60 | newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6 - list_height, | |
61 | NEWT_FLAG_WRAP); | |
62 | newtTextboxSetText(textbox, message); | |
63 | ||
64 | int top = newtTextboxGetNumLines(textbox) + 2; | |
65 | ||
66 | newtComponent form = newtForm(NULL, NULL, 0); | |
67 | ||
68 | newtComponent sb = NULL; | |
69 | if (list_height < num_entries) { | |
70 | sb = newtVerticalScrollbar( | |
71 | width - 4, top + 1, list_height, | |
72 | NEWT_COLORSET_CHECKBOX, NEWT_COLORSET_ACTCHECKBOX); | |
73 | ||
74 | newtFormAddComponent(form, sb); | |
75 | } | |
76 | ||
77 | newtComponent subform = newtForm(sb, NULL, 0); | |
78 | newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX); | |
79 | ||
80 | newtFormSetHeight(subform, list_height); | |
81 | newtFormSetWidth(subform, width - 10); | |
82 | ||
83 | for (unsigned int i = 0; i < num_entries; i++) { | |
84 | newtComponent cb = newtCheckbox(4, top + i, entries[i], cbstates[i], | |
85 | NULL, &cbstates[i]); | |
86 | ||
87 | newtFormAddComponent(subform, cb); | |
88 | } | |
89 | ||
90 | newtFormAddComponents(form, textbox, subform, NULL); | |
91 | ||
92 | newtComponent btn_okay = newtButton((width - 18) / 3, height - 4, ctr[TR_OK]); | |
93 | newtComponent btn_cancel = newtButton((width - 18) / 3 * 2 + 9, height - 4, ctr[TR_CANCEL]); | |
94 | newtFormAddComponents(form, btn_okay, btn_cancel, NULL); | |
95 | ||
96 | newtComponent answer = newtRunForm(form); | |
97 | ||
98 | if ((answer == NULL) || (answer == btn_cancel)) { | |
99 | ret = -1; | |
100 | } else { | |
101 | ret = 0; | |
102 | ||
103 | for (unsigned int i = 0; i < num_entries; i++) { | |
104 | states[i] = (cbstates[i] != ' '); | |
105 | ||
106 | if (states[i]) | |
107 | ret++; | |
108 | } | |
109 | } | |
110 | ||
111 | newtFormDestroy(form); | |
112 | newtPopWindow(); | |
113 | ||
114 | return ret; | |
115 | } | |
116 | ||
117 | static int newtWinOkCancel(const char* title, const char* message, int width, int height, | |
118 | const char* btn_txt_ok, const char* btn_txt_cancel) { | |
119 | int ret = 1; | |
120 | ||
121 | newtCenteredWindow(width, height, title); | |
122 | ||
123 | newtComponent form = newtForm(NULL, NULL, 0); | |
124 | ||
125 | newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6, NEWT_FLAG_WRAP); | |
126 | newtTextboxSetText(textbox, message); | |
127 | newtFormAddComponent(form, textbox); | |
128 | ||
129 | newtComponent btn_ok = newtButton((width - 16) / 3, height - 4, btn_txt_ok); | |
130 | newtComponent btn_cancel = newtButton((width - 16) / 3 * 2 + 9, height - 4, | |
131 | btn_txt_cancel); | |
132 | ||
133 | newtFormAddComponents(form, btn_ok, btn_cancel, NULL); | |
134 | ||
135 | newtComponent answer = newtRunForm(form); | |
136 | ||
137 | if (answer == btn_ok) { | |
138 | ret = 0; | |
139 | } | |
140 | ||
141 | newtFormDestroy(form); | |
142 | newtPopWindow(); | |
143 | ||
144 | return ret; | |
145 | } | |
146 | ||
f0fa1795 MT |
147 | int main(int argc, char *argv[]) { |
148 | struct hw* hw = hw_init(); | |
e0bbaf87 AF |
149 | |
150 | char discl_msg[40000] = "Disclaimer\n"; | |
151 | ||
910193da EY |
152 | char *langnames[] = { "Deutsch", "English", "Français", "Español", "Nederlands", "Polski", "Русский", "Türkçe", NULL }; |
153 | char *shortlangnames[] = { "de", "en", "fr", "es", "nl", "pl", "ru", "tr", NULL }; | |
154 | char **langtrs[] = { de_tr, en_tr, fr_tr, es_tr, nl_tr, pl_tr, ru_tr, tr_tr, NULL }; | |
f0fa1795 | 155 | char* sourcedrive = NULL; |
72d80898 | 156 | int rc = 0; |
d6aaa55d | 157 | char commandstring[STRING_SIZE]; |
d6aaa55d MT |
158 | int choice; |
159 | char shortlangname[10]; | |
d7dd283b | 160 | char message[STRING_SIZE]; |
d6aaa55d MT |
161 | char title[STRING_SIZE]; |
162 | int allok = 0; | |
e0bbaf87 | 163 | FILE *handle, *cmdfile, *copying; |
d6aaa55d | 164 | char line[STRING_SIZE]; |
5057b611 | 165 | |
72d80898 | 166 | int unattended = 0; |
5faa66cf | 167 | int serialconsole = 0; |
72d80898 | 168 | struct keyvalue *unattendedkv = initkeyvalues(); |
66335974 | 169 | char restore_file[STRING_SIZE] = ""; |
d6aaa55d MT |
170 | |
171 | setlocale (LC_ALL, ""); | |
10bc6f06 | 172 | sethostname( SNAME , 10); |
72d80898 | 173 | |
d6aaa55d MT |
174 | /* Log file/terminal stuff. */ |
175 | if (argc >= 2) | |
176 | { | |
177 | if (!(flog = fopen(argv[1], "w+"))) | |
178 | return 0; | |
179 | } | |
180 | else | |
181 | return 0; | |
182 | ||
183 | mylog = argv[1]; | |
184 | ||
185 | fprintf(flog, "Install program started.\n"); | |
186 | ||
187 | newtInit(); | |
188 | newtCls(); | |
189 | ||
7ea444c8 AF |
190 | newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN ); |
191 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
192 | ||
d6aaa55d MT |
193 | if (! (cmdfile = fopen("/proc/cmdline", "r"))) |
194 | { | |
195 | fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); | |
196 | } else { | |
197 | fgets(line, STRING_SIZE, cmdfile); | |
61e3d218 | 198 | |
72d80898 | 199 | // check if we have to make an unattended install |
ee78a5ef | 200 | if (strstr (line, "unattended") != NULL) { |
72d80898 | 201 | unattended = 1; |
bba7212c MT |
202 | runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds..."); |
203 | } | |
5faa66cf AF |
204 | // check if we have to patch for serial console |
205 | if (strstr (line, "console=ttyS0") != NULL) { | |
206 | serialconsole = 1; | |
207 | } | |
d6aaa55d | 208 | } |
0db33b56 | 209 | |
7ea444c8 | 210 | // Load common modules |
bba7212c | 211 | mysystem("/sbin/modprobe vfat"); // USB key |
d6aaa55d | 212 | |
72d80898 | 213 | /* German is the default */ |
d6aaa55d MT |
214 | for (choice = 0; langnames[choice]; choice++) |
215 | { | |
215bd18d | 216 | if (strcmp(langnames[choice], "English") == 0) |
d6aaa55d MT |
217 | break; |
218 | } | |
219 | if (!langnames[choice]) | |
220 | goto EXIT; | |
221 | ||
72d80898 | 222 | if (!unattended) { |
51f3b7f5 | 223 | rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, |
72d80898 MT |
224 | langnames, &choice, "Ok", NULL); |
225 | } | |
226 | ||
d6aaa55d MT |
227 | ctr = langtrs[choice]; |
228 | strcpy(shortlangname, shortlangnames[choice]); | |
3d6e1202 | 229 | |
d6aaa55d | 230 | newtPushHelpLine(ctr[TR_HELPLINE]); |
0db33b56 | 231 | |
e0bbaf87 | 232 | if (!unattended) { |
c5685c24 MT |
233 | sprintf(message, ctr[TR_WELCOME], NAME); |
234 | newtWinMessage(title, ctr[TR_OK], message); | |
e0bbaf87 AF |
235 | } |
236 | ||
f0fa1795 MT |
237 | /* Search for a source drive that holds the right |
238 | * version of the image we are going to install. */ | |
239 | sourcedrive = hw_find_source_medium(hw); | |
9607771a | 240 | |
f0fa1795 MT |
241 | fprintf(flog, "Source drive: %s\n", sourcedrive); |
242 | if (!sourcedrive) { | |
0f680bcc | 243 | newtWinMessage(title, ctr[TR_OK], ctr[TR_NO_LOCAL_SOURCE]); |
f0fa1795 | 244 | runcommandwithstatus("/bin/downloadsource.sh", ctr[TR_DOWNLOADING_ISO]); |
0f680bcc AF |
245 | if ((handle = fopen("/tmp/source_device", "r")) == NULL) { |
246 | errorbox(ctr[TR_DOWNLOAD_ERROR]); | |
247 | goto EXIT; | |
248 | } | |
f0fa1795 MT |
249 | |
250 | fgets(sourcedrive, 5, handle); | |
251 | fclose(handle); | |
72d80898 | 252 | } |
0f680bcc | 253 | |
f0fa1795 MT |
254 | assert(sourcedrive); |
255 | ||
25fcce25 | 256 | int r = hw_mount(sourcedrive, SOURCE_MOUNT_PATH, "iso9660", MS_RDONLY); |
f0fa1795 MT |
257 | if (r) { |
258 | fprintf(flog, "Could not mount %s to %s\n", sourcedrive, SOURCE_MOUNT_PATH); | |
259 | fprintf(flog, strerror(errno)); | |
260 | exit(1); | |
261 | } | |
918546e2 | 262 | |
d7dd283b MT |
263 | /* load unattended configuration */ |
264 | if (unattended) { | |
265 | fprintf(flog, "unattended: Reading unattended.conf\n"); | |
266 | ||
267 | (void) readkeyvalues(unattendedkv, UNATTENDED_CONF); | |
268 | findkey(unattendedkv, "RESTORE_FILE", restore_file); | |
269 | } | |
270 | ||
918546e2 MT |
271 | if (!unattended) { |
272 | // Read the license file. | |
273 | if (!(copying = fopen(LICENSE_FILE, "r"))) { | |
274 | sprintf(discl_msg, "Could not open license file: %s\n", LICENSE_FILE); | |
275 | fprintf(flog, discl_msg); | |
276 | } else { | |
277 | fread(discl_msg, 1, 40000, copying); | |
278 | fclose(copying); | |
279 | ||
280 | if (disclaimerbox(discl_msg)==0) { | |
281 | errorbox(ctr[TR_LICENSE_NOT_ACCEPTED]); | |
282 | goto EXIT; | |
283 | } | |
284 | } | |
285 | } | |
286 | ||
d7dd283b | 287 | int part_type = HW_PART_TYPE_NORMAL; |
ee78a5ef | 288 | |
d7dd283b MT |
289 | // Scan for disks to install on. |
290 | struct hw_disk** disks = hw_find_disks(hw); | |
291 | ||
292 | struct hw_disk** selected_disks = NULL; | |
293 | unsigned int num_selected_disks = 0; | |
294 | ||
295 | // Check how many disks have been found and what | |
296 | // we can do with them. | |
297 | unsigned int num_disks = hw_count_disks(disks); | |
298 | ||
299 | while (1) { | |
300 | // no harddisks found | |
301 | if (num_disks == 0) { | |
302 | errorbox(ctr[TR_NO_HARDDISK]); | |
303 | goto EXIT; | |
304 | ||
305 | // exactly one disk has been found | |
306 | } else if (num_disks == 1) { | |
307 | selected_disks = hw_select_disks(disks, NULL); | |
308 | ||
309 | // more than one usable disk has been found and | |
310 | // the user needs to choose what to do with them | |
311 | } else { | |
312 | const char* disk_names[num_disks]; | |
313 | int disk_selection[num_disks]; | |
314 | ||
315 | for (unsigned int i = 0; i < num_disks; i++) { | |
316 | disk_names[i] = &disks[i]->description; | |
317 | disk_selection[i] = 0; | |
318 | } | |
319 | ||
320 | while (!selected_disks) { | |
321 | rc = newtChecklist(ctr[TR_DISK_SELECTION], ctr[TR_DISK_SELECTION_MSG], | |
322 | 50, 20, num_disks, disk_names, disk_selection); | |
323 | ||
324 | // Error | |
325 | if (rc < 0) { | |
326 | goto EXIT; | |
327 | ||
328 | // Nothing has been selected | |
329 | } else if (rc == 0) { | |
330 | errorbox(ctr[TR_NO_DISK_SELECTED]); | |
331 | ||
332 | } else { | |
333 | selected_disks = hw_select_disks(disks, disk_selection); | |
334 | } | |
335 | } | |
336 | } | |
337 | ||
338 | num_selected_disks = hw_count_disks(selected_disks); | |
339 | ||
340 | if (num_selected_disks == 1) { | |
341 | snprintf(message, sizeof(message), ctr[TR_DISK_SETUP_DESC], (*selected_disks)->description); | |
342 | rc = newtWinOkCancel(ctr[TR_DISK_SETUP], message, 50, 10, | |
343 | ctr[TR_DELETE_ALL_DATA], ctr[TR_CANCEL]); | |
344 | ||
345 | if (rc == 0) | |
56b548f1 | 346 | break; |
d7dd283b MT |
347 | |
348 | } else if (num_selected_disks == 2) { | |
349 | snprintf(message, sizeof(message), ctr[TR_RAID_SETUP_DESC], | |
350 | (*selected_disks)->description, (*selected_disks + 1)->description); | |
351 | rc = newtWinOkCancel(ctr[TR_RAID_SETUP], message, 50, 10, | |
352 | ctr[TR_DELETE_ALL_DATA], ctr[TR_CANCEL]); | |
353 | ||
354 | if (rc == 0) { | |
355 | part_type = HW_PART_TYPE_RAID1; | |
356 | ||
ee78a5ef | 357 | break; |
d7dd283b MT |
358 | } |
359 | ||
360 | // Currently not supported | |
361 | } else { | |
362 | errorbox(ctr[TR_DISK_CONFIGURATION_NOT_SUPPORTED]); | |
aee3027d | 363 | } |
ee78a5ef | 364 | |
d7dd283b MT |
365 | if (selected_disks) { |
366 | hw_free_disks(selected_disks); | |
367 | selected_disks = NULL; | |
368 | } | |
212cab4f | 369 | } |
212cab4f | 370 | |
d7dd283b | 371 | hw_free_disks(disks); |
72d80898 | 372 | |
d7dd283b | 373 | struct hw_destination* destination = hw_make_destination(part_type, selected_disks); |
5057b611 | 374 | |
25fcce25 MT |
375 | if (!destination) { |
376 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
cd8dd8dd | 377 | goto EXIT; |
25fcce25 | 378 | } |
cd8dd8dd | 379 | |
25fcce25 MT |
380 | fprintf(flog, "Destination drive: %s\n", destination->path); |
381 | fprintf(flog, " boot: %s (%lluMB)\n", destination->part_boot, BYTES2MB(destination->size_boot)); | |
382 | fprintf(flog, " swap: %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap)); | |
383 | fprintf(flog, " root: %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root)); | |
384 | fprintf(flog, " data: %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data)); | |
72d80898 | 385 | |
25fcce25 MT |
386 | // Warn the user if there is not enough space to create a swap partition |
387 | if (!unattended && !*destination->part_swap) { | |
388 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
4f26ff7f | 389 | |
25fcce25 MT |
390 | if (rc != 1) |
391 | goto EXIT; | |
72d80898 | 392 | } |
9a3d3d95 | 393 | |
25fcce25 MT |
394 | // Filesystem selection |
395 | if (!unattended) { | |
396 | struct filesystems { | |
397 | int fstype; | |
398 | const char* description; | |
399 | } filesystems[] = { | |
400 | { HW_FS_EXT4, ctr[TR_EXT4FS] }, | |
401 | { HW_FS_EXT4_WO_JOURNAL, ctr[TR_EXT4FS_WO_JOURNAL] }, | |
402 | { HW_FS_REISERFS, ctr[TR_REISERFS] }, | |
403 | { 0, NULL }, | |
404 | }; | |
405 | unsigned int num_filesystems = sizeof(filesystems) / sizeof(*filesystems); | |
406 | ||
407 | char* fs_names[num_filesystems]; | |
408 | int fs_choice = 0; | |
409 | for (unsigned int i = 0; i < num_filesystems; i++) { | |
410 | if (HW_FS_DEFAULT == filesystems[i].fstype) | |
411 | fs_choice = i; | |
412 | ||
413 | fs_names[i] = filesystems[i].description; | |
414 | } | |
72d80898 | 415 | |
25fcce25 MT |
416 | rc = newtWinMenu(ctr[TR_CHOOSE_FILESYSTEM], ctr[TR_CHOOSE_FILESYSTEM], |
417 | 50, 5, 5, 6, fs_names, &fs_choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
418 | ||
419 | if (rc == 0) | |
420 | destination->filesystem = filesystems[fs_choice].fstype; | |
72d80898 | 421 | |
25fcce25 | 422 | else |
72d80898 | 423 | goto EXIT; |
72d80898 MT |
424 | } |
425 | ||
25fcce25 MT |
426 | // Execute the partitioning... |
427 | statuswindow(60, 4, title, ctr[TR_PARTITIONING_DISK]); | |
72d80898 | 428 | |
25fcce25 MT |
429 | rc = hw_create_partitions(destination); |
430 | if (rc) { | |
431 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
72d80898 | 432 | goto EXIT; |
9607771a | 433 | } |
72d80898 | 434 | |
25fcce25 | 435 | newtPopWindow(); |
72d80898 | 436 | |
25fcce25 MT |
437 | // Execute the formatting... |
438 | statuswindow(60, 4, title, ctr[TR_CREATING_FILESYSTEMS]); | |
b8e2d108 | 439 | |
25fcce25 MT |
440 | rc = hw_create_filesystems(destination); |
441 | if (rc) { | |
442 | errorbox(ctr[TR_UNABLE_TO_CREATE_FILESYSTEMS]); | |
72d80898 MT |
443 | goto EXIT; |
444 | } | |
25fcce25 MT |
445 | |
446 | rc = hw_mount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
447 | if (rc) { | |
448 | errorbox(ctr[TR_UNABLE_TO_MOUNT_FILESYSTEMS]); | |
72d80898 | 449 | goto EXIT; |
9607771a | 450 | } |
c78a77eb | 451 | |
25fcce25 MT |
452 | newtPopWindow(); |
453 | ||
454 | // Extract files... | |
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 | |
330345c2 | 468 | /* Build cache lang file */ |
6cf9e770 | 469 | snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); |
330345c2 MT |
470 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE])) |
471 | { | |
472 | errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]); | |
473 | goto EXIT; | |
474 | } | |
475 | ||
476 | /* Update /etc/fstab */ | |
d7dd283b | 477 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE1#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_boot); |
a9a26c5a | 478 | system(commandstring); |
d7dd283b | 479 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE2#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_swap); |
a9a26c5a | 480 | system(commandstring); |
d7dd283b | 481 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE3#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_root); |
a9a26c5a | 482 | system(commandstring); |
d7dd283b | 483 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE4#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_data); |
a9a26c5a AF |
484 | system(commandstring); |
485 | ||
25fcce25 MT |
486 | switch (destination->filesystem) { |
487 | case HW_FS_REISERFS: | |
488 | replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs"); | |
489 | replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro"); | |
490 | break; | |
491 | ||
492 | case HW_FS_EXT4: | |
493 | case HW_FS_EXT4_WO_JOURNAL: | |
494 | replace("/harddisk/etc/fstab", "FSTYPE", "ext4"); | |
495 | replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro"); | |
496 | break; | |
497 | ||
498 | default: | |
499 | assert(0); | |
cd8dd8dd | 500 | } |
73d9a908 | 501 | |
a869b064 AF |
502 | replace("/harddisk/boot/grub/grub.conf", "KVER", KERNEL_VERSION); |
503 | ||
d7dd283b | 504 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#root=ROOT#root=UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/boot/grub/grub.conf", destination->part_root); |
a9a26c5a AF |
505 | system(commandstring); |
506 | ||
f4e27420 | 507 | mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst"); |
fd0763dc | 508 | |
a9a26c5a | 509 | system("/bin/sed -e 's#/harddisk#/#g' -e 's#//#/#g' < /proc/mounts > /harddisk/etc/mtab"); |
edd536b6 | 510 | |
423400cf MT |
511 | /* |
512 | * Generate device.map to help grub finding the device to install itself on. | |
513 | */ | |
514 | FILE *f = NULL; | |
515 | if (f = fopen("/harddisk/boot/grub/device.map", "w")) { | |
d7dd283b | 516 | fprintf(f, "(hd0) %s\n", destination->path); |
423400cf MT |
517 | fclose(f); |
518 | } | |
519 | ||
edd536b6 | 520 | snprintf(commandstring, STRING_SIZE, |
d7dd283b | 521 | "/usr/sbin/chroot /harddisk /usr/sbin/grub-install --no-floppy %s", destination->path); |
edd536b6 MT |
522 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) { |
523 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
524 | goto EXIT; | |
525 | } | |
5faa66cf AF |
526 | |
527 | /* Serial console ? */ | |
528 | if (serialconsole) { | |
529 | /* grub */ | |
530 | replace("/harddisk/boot/grub/grub.conf", "splashimage", "#splashimage"); | |
531 | replace("/harddisk/boot/grub/grub.conf", "#serial", "serial"); | |
532 | replace("/harddisk/boot/grub/grub.conf", "#terminal", "terminal"); | |
1445c9e0 | 533 | replace("/harddisk/boot/grub/grub.conf", " panic=10 ", " console=ttyS0,115200n8 panic=10 "); |
5faa66cf AF |
534 | |
535 | /*inittab*/ | |
536 | replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:"); | |
537 | replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:"); | |
538 | replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:"); | |
539 | replace("/harddisk/etc/inittab", "4:2345:respawn:", "#4:2345:respawn:"); | |
540 | replace("/harddisk/etc/inittab", "5:2345:respawn:", "#5:2345:respawn:"); | |
541 | replace("/harddisk/etc/inittab", "6:2345:respawn:", "#6:2345:respawn:"); | |
542 | replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:"); | |
543 | } | |
544 | ||
dfa59dbd AF |
545 | /* Set marker that the user has already accepted the gpl */ |
546 | mysystem("/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted"); | |
547 | ||
c25a0343 | 548 | /* Copy restore file from cdrom */ |
7062cecd | 549 | if (unattended && (strlen(restore_file) > 0)) { |
c25a0343 | 550 | fprintf(flog, "unattended: Copy restore file\n"); |
dca095e1 | 551 | snprintf(commandstring, STRING_SIZE, |
c25a0343 | 552 | "cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file); |
dca095e1 | 553 | mysystem(commandstring); |
c25a0343 | 554 | } |
2c9c458c MT |
555 | |
556 | // Umount source drive and eject | |
557 | hw_umount(SOURCE_MOUNT_PATH); | |
558 | ||
559 | snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive); | |
3ef6c343 | 560 | mysystem(commandstring); |
22b9e405 | 561 | |
73d9a908 MT |
562 | if (!unattended) { |
563 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
3ad8835c | 564 | NAME, SNAME, NAME); |
fac85ccd | 565 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_PRESS_OK_TO_REBOOT], message); |
73d9a908 | 566 | } |
cd8dd8dd | 567 | |
22b9e405 | 568 | allok = 1; |
edd536b6 | 569 | |
d6aaa55d | 570 | EXIT: |
10bc6f06 | 571 | fprintf(flog, "Install program ended.\n"); |
d6aaa55d | 572 | |
10bc6f06 | 573 | if (!(allok)) |
d6aaa55d | 574 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); |
d6aaa55d | 575 | |
25fcce25 | 576 | if (allok) { |
ee78a5ef MT |
577 | fflush(flog); |
578 | fclose(flog); | |
3a1019f6 MT |
579 | } |
580 | ||
581 | newtFinished(); | |
582 | ||
f0fa1795 MT |
583 | // Free resources |
584 | free(sourcedrive); | |
25fcce25 MT |
585 | |
586 | if (destination) { | |
587 | hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
588 | free(destination); | |
589 | } | |
d7dd283b MT |
590 | |
591 | if (selected_disks) | |
592 | hw_free_disks(selected_disks); | |
593 | ||
594 | hw_free(hw); | |
f0fa1795 | 595 | |
25fcce25 MT |
596 | fcloseall(); |
597 | ||
598 | if (!(allok)) | |
599 | system("/etc/halt"); | |
600 | ||
d6aaa55d MT |
601 | return 0; |
602 | } |