]>
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; | |
d6aaa55d | 163 | struct keyvalue *ethernetkv = initkeyvalues(); |
e0bbaf87 | 164 | FILE *handle, *cmdfile, *copying; |
d6aaa55d | 165 | char line[STRING_SIZE]; |
5057b611 | 166 | |
72d80898 | 167 | int unattended = 0; |
5faa66cf | 168 | int serialconsole = 0; |
72d80898 | 169 | struct keyvalue *unattendedkv = initkeyvalues(); |
66335974 | 170 | char restore_file[STRING_SIZE] = ""; |
d6aaa55d MT |
171 | |
172 | setlocale (LC_ALL, ""); | |
10bc6f06 | 173 | sethostname( SNAME , 10); |
72d80898 | 174 | |
d6aaa55d MT |
175 | /* Log file/terminal stuff. */ |
176 | if (argc >= 2) | |
177 | { | |
178 | if (!(flog = fopen(argv[1], "w+"))) | |
179 | return 0; | |
180 | } | |
181 | else | |
182 | return 0; | |
183 | ||
184 | mylog = argv[1]; | |
185 | ||
186 | fprintf(flog, "Install program started.\n"); | |
187 | ||
188 | newtInit(); | |
189 | newtCls(); | |
190 | ||
7ea444c8 AF |
191 | newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN ); |
192 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
193 | ||
d6aaa55d MT |
194 | if (! (cmdfile = fopen("/proc/cmdline", "r"))) |
195 | { | |
196 | fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); | |
197 | } else { | |
198 | fgets(line, STRING_SIZE, cmdfile); | |
61e3d218 | 199 | |
72d80898 | 200 | // check if we have to make an unattended install |
ee78a5ef | 201 | if (strstr (line, "unattended") != NULL) { |
72d80898 | 202 | unattended = 1; |
bba7212c MT |
203 | runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds..."); |
204 | } | |
5faa66cf AF |
205 | // check if we have to patch for serial console |
206 | if (strstr (line, "console=ttyS0") != NULL) { | |
207 | serialconsole = 1; | |
208 | } | |
d6aaa55d | 209 | } |
0db33b56 | 210 | |
7ea444c8 | 211 | // Load common modules |
bba7212c | 212 | mysystem("/sbin/modprobe vfat"); // USB key |
d6aaa55d | 213 | |
72d80898 | 214 | /* German is the default */ |
d6aaa55d MT |
215 | for (choice = 0; langnames[choice]; choice++) |
216 | { | |
215bd18d | 217 | if (strcmp(langnames[choice], "English") == 0) |
d6aaa55d MT |
218 | break; |
219 | } | |
220 | if (!langnames[choice]) | |
221 | goto EXIT; | |
222 | ||
72d80898 | 223 | if (!unattended) { |
51f3b7f5 | 224 | rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, |
72d80898 MT |
225 | langnames, &choice, "Ok", NULL); |
226 | } | |
227 | ||
d6aaa55d MT |
228 | ctr = langtrs[choice]; |
229 | strcpy(shortlangname, shortlangnames[choice]); | |
3d6e1202 | 230 | |
d6aaa55d | 231 | newtPushHelpLine(ctr[TR_HELPLINE]); |
0db33b56 | 232 | |
e0bbaf87 | 233 | if (!unattended) { |
c5685c24 MT |
234 | sprintf(message, ctr[TR_WELCOME], NAME); |
235 | newtWinMessage(title, ctr[TR_OK], message); | |
e0bbaf87 AF |
236 | } |
237 | ||
f0fa1795 MT |
238 | /* Search for a source drive that holds the right |
239 | * version of the image we are going to install. */ | |
240 | sourcedrive = hw_find_source_medium(hw); | |
9607771a | 241 | |
f0fa1795 MT |
242 | fprintf(flog, "Source drive: %s\n", sourcedrive); |
243 | if (!sourcedrive) { | |
0f680bcc | 244 | newtWinMessage(title, ctr[TR_OK], ctr[TR_NO_LOCAL_SOURCE]); |
f0fa1795 | 245 | runcommandwithstatus("/bin/downloadsource.sh", ctr[TR_DOWNLOADING_ISO]); |
0f680bcc AF |
246 | if ((handle = fopen("/tmp/source_device", "r")) == NULL) { |
247 | errorbox(ctr[TR_DOWNLOAD_ERROR]); | |
248 | goto EXIT; | |
249 | } | |
f0fa1795 MT |
250 | |
251 | fgets(sourcedrive, 5, handle); | |
252 | fclose(handle); | |
72d80898 | 253 | } |
0f680bcc | 254 | |
f0fa1795 MT |
255 | assert(sourcedrive); |
256 | ||
25fcce25 | 257 | int r = hw_mount(sourcedrive, SOURCE_MOUNT_PATH, "iso9660", MS_RDONLY); |
f0fa1795 MT |
258 | if (r) { |
259 | fprintf(flog, "Could not mount %s to %s\n", sourcedrive, SOURCE_MOUNT_PATH); | |
260 | fprintf(flog, strerror(errno)); | |
261 | exit(1); | |
262 | } | |
918546e2 | 263 | |
d7dd283b MT |
264 | /* load unattended configuration */ |
265 | if (unattended) { | |
266 | fprintf(flog, "unattended: Reading unattended.conf\n"); | |
267 | ||
268 | (void) readkeyvalues(unattendedkv, UNATTENDED_CONF); | |
269 | findkey(unattendedkv, "RESTORE_FILE", restore_file); | |
270 | } | |
271 | ||
918546e2 MT |
272 | if (!unattended) { |
273 | // Read the license file. | |
274 | if (!(copying = fopen(LICENSE_FILE, "r"))) { | |
275 | sprintf(discl_msg, "Could not open license file: %s\n", LICENSE_FILE); | |
276 | fprintf(flog, discl_msg); | |
277 | } else { | |
278 | fread(discl_msg, 1, 40000, copying); | |
279 | fclose(copying); | |
280 | ||
281 | if (disclaimerbox(discl_msg)==0) { | |
282 | errorbox(ctr[TR_LICENSE_NOT_ACCEPTED]); | |
283 | goto EXIT; | |
284 | } | |
285 | } | |
286 | } | |
287 | ||
d7dd283b | 288 | int part_type = HW_PART_TYPE_NORMAL; |
ee78a5ef | 289 | |
d7dd283b MT |
290 | // Scan for disks to install on. |
291 | struct hw_disk** disks = hw_find_disks(hw); | |
292 | ||
293 | struct hw_disk** selected_disks = NULL; | |
294 | unsigned int num_selected_disks = 0; | |
295 | ||
296 | // Check how many disks have been found and what | |
297 | // we can do with them. | |
298 | unsigned int num_disks = hw_count_disks(disks); | |
299 | ||
300 | while (1) { | |
301 | // no harddisks found | |
302 | if (num_disks == 0) { | |
303 | errorbox(ctr[TR_NO_HARDDISK]); | |
304 | goto EXIT; | |
305 | ||
306 | // exactly one disk has been found | |
307 | } else if (num_disks == 1) { | |
308 | selected_disks = hw_select_disks(disks, NULL); | |
309 | ||
310 | // more than one usable disk has been found and | |
311 | // the user needs to choose what to do with them | |
312 | } else { | |
313 | const char* disk_names[num_disks]; | |
314 | int disk_selection[num_disks]; | |
315 | ||
316 | for (unsigned int i = 0; i < num_disks; i++) { | |
317 | disk_names[i] = &disks[i]->description; | |
318 | disk_selection[i] = 0; | |
319 | } | |
320 | ||
321 | while (!selected_disks) { | |
322 | rc = newtChecklist(ctr[TR_DISK_SELECTION], ctr[TR_DISK_SELECTION_MSG], | |
323 | 50, 20, num_disks, disk_names, disk_selection); | |
324 | ||
325 | // Error | |
326 | if (rc < 0) { | |
327 | goto EXIT; | |
328 | ||
329 | // Nothing has been selected | |
330 | } else if (rc == 0) { | |
331 | errorbox(ctr[TR_NO_DISK_SELECTED]); | |
332 | ||
333 | } else { | |
334 | selected_disks = hw_select_disks(disks, disk_selection); | |
335 | } | |
336 | } | |
337 | } | |
338 | ||
339 | num_selected_disks = hw_count_disks(selected_disks); | |
340 | ||
341 | if (num_selected_disks == 1) { | |
342 | snprintf(message, sizeof(message), ctr[TR_DISK_SETUP_DESC], (*selected_disks)->description); | |
343 | rc = newtWinOkCancel(ctr[TR_DISK_SETUP], message, 50, 10, | |
344 | ctr[TR_DELETE_ALL_DATA], ctr[TR_CANCEL]); | |
345 | ||
346 | if (rc == 0) | |
56b548f1 | 347 | break; |
d7dd283b MT |
348 | |
349 | } else if (num_selected_disks == 2) { | |
350 | snprintf(message, sizeof(message), ctr[TR_RAID_SETUP_DESC], | |
351 | (*selected_disks)->description, (*selected_disks + 1)->description); | |
352 | rc = newtWinOkCancel(ctr[TR_RAID_SETUP], message, 50, 10, | |
353 | ctr[TR_DELETE_ALL_DATA], ctr[TR_CANCEL]); | |
354 | ||
355 | if (rc == 0) { | |
356 | part_type = HW_PART_TYPE_RAID1; | |
357 | ||
ee78a5ef | 358 | break; |
d7dd283b MT |
359 | } |
360 | ||
361 | // Currently not supported | |
362 | } else { | |
363 | errorbox(ctr[TR_DISK_CONFIGURATION_NOT_SUPPORTED]); | |
aee3027d | 364 | } |
ee78a5ef | 365 | |
d7dd283b MT |
366 | if (selected_disks) { |
367 | hw_free_disks(selected_disks); | |
368 | selected_disks = NULL; | |
369 | } | |
212cab4f | 370 | } |
212cab4f | 371 | |
d7dd283b | 372 | hw_free_disks(disks); |
72d80898 | 373 | |
d7dd283b | 374 | struct hw_destination* destination = hw_make_destination(part_type, selected_disks); |
5057b611 | 375 | |
25fcce25 MT |
376 | if (!destination) { |
377 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
cd8dd8dd | 378 | goto EXIT; |
25fcce25 | 379 | } |
cd8dd8dd | 380 | |
25fcce25 MT |
381 | fprintf(flog, "Destination drive: %s\n", destination->path); |
382 | fprintf(flog, " boot: %s (%lluMB)\n", destination->part_boot, BYTES2MB(destination->size_boot)); | |
383 | fprintf(flog, " swap: %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap)); | |
384 | fprintf(flog, " root: %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root)); | |
385 | fprintf(flog, " data: %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data)); | |
72d80898 | 386 | |
25fcce25 MT |
387 | // Warn the user if there is not enough space to create a swap partition |
388 | if (!unattended && !*destination->part_swap) { | |
389 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
4f26ff7f | 390 | |
25fcce25 MT |
391 | if (rc != 1) |
392 | goto EXIT; | |
72d80898 | 393 | } |
9a3d3d95 | 394 | |
25fcce25 MT |
395 | // Filesystem selection |
396 | if (!unattended) { | |
397 | struct filesystems { | |
398 | int fstype; | |
399 | const char* description; | |
400 | } filesystems[] = { | |
401 | { HW_FS_EXT4, ctr[TR_EXT4FS] }, | |
402 | { HW_FS_EXT4_WO_JOURNAL, ctr[TR_EXT4FS_WO_JOURNAL] }, | |
403 | { HW_FS_REISERFS, ctr[TR_REISERFS] }, | |
404 | { 0, NULL }, | |
405 | }; | |
406 | unsigned int num_filesystems = sizeof(filesystems) / sizeof(*filesystems); | |
407 | ||
408 | char* fs_names[num_filesystems]; | |
409 | int fs_choice = 0; | |
410 | for (unsigned int i = 0; i < num_filesystems; i++) { | |
411 | if (HW_FS_DEFAULT == filesystems[i].fstype) | |
412 | fs_choice = i; | |
413 | ||
414 | fs_names[i] = filesystems[i].description; | |
415 | } | |
72d80898 | 416 | |
25fcce25 MT |
417 | rc = newtWinMenu(ctr[TR_CHOOSE_FILESYSTEM], ctr[TR_CHOOSE_FILESYSTEM], |
418 | 50, 5, 5, 6, fs_names, &fs_choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
419 | ||
420 | if (rc == 0) | |
421 | destination->filesystem = filesystems[fs_choice].fstype; | |
72d80898 | 422 | |
25fcce25 | 423 | else |
72d80898 | 424 | goto EXIT; |
72d80898 MT |
425 | } |
426 | ||
25fcce25 MT |
427 | // Execute the partitioning... |
428 | statuswindow(60, 4, title, ctr[TR_PARTITIONING_DISK]); | |
72d80898 | 429 | |
25fcce25 MT |
430 | rc = hw_create_partitions(destination); |
431 | if (rc) { | |
432 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
72d80898 | 433 | goto EXIT; |
9607771a | 434 | } |
72d80898 | 435 | |
25fcce25 | 436 | newtPopWindow(); |
72d80898 | 437 | |
25fcce25 MT |
438 | // Execute the formatting... |
439 | statuswindow(60, 4, title, ctr[TR_CREATING_FILESYSTEMS]); | |
b8e2d108 | 440 | |
25fcce25 MT |
441 | rc = hw_create_filesystems(destination); |
442 | if (rc) { | |
443 | errorbox(ctr[TR_UNABLE_TO_CREATE_FILESYSTEMS]); | |
72d80898 MT |
444 | goto EXIT; |
445 | } | |
25fcce25 MT |
446 | |
447 | rc = hw_mount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
448 | if (rc) { | |
449 | errorbox(ctr[TR_UNABLE_TO_MOUNT_FILESYSTEMS]); | |
72d80898 | 450 | goto EXIT; |
9607771a | 451 | } |
c78a77eb | 452 | |
25fcce25 MT |
453 | newtPopWindow(); |
454 | ||
455 | // Extract files... | |
03d956be | 456 | snprintf(commandstring, STRING_SIZE, |
23ed79cb | 457 | "/bin/tar -C /harddisk -xvf /cdrom/" SNAME "-" VERSION ".tlz --lzma 2>/dev/null"); |
d6aaa55d | 458 | |
edd536b6 MT |
459 | if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT, |
460 | ctr[TR_INSTALLING_FILES])) | |
d6aaa55d MT |
461 | { |
462 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
463 | goto EXIT; | |
464 | } | |
406f019f MT |
465 | |
466 | /* Save language und local settings */ | |
467 | write_lang_configs(shortlangname); | |
d6aaa55d | 468 | |
330345c2 | 469 | /* Build cache lang file */ |
6cf9e770 | 470 | snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); |
330345c2 MT |
471 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE])) |
472 | { | |
473 | errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]); | |
474 | goto EXIT; | |
475 | } | |
476 | ||
477 | /* Update /etc/fstab */ | |
d7dd283b | 478 | 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 | 479 | system(commandstring); |
d7dd283b | 480 | 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 | 481 | system(commandstring); |
d7dd283b | 482 | 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 | 483 | system(commandstring); |
d7dd283b | 484 | 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 |
485 | system(commandstring); |
486 | ||
25fcce25 MT |
487 | switch (destination->filesystem) { |
488 | case HW_FS_REISERFS: | |
489 | replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs"); | |
490 | replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro"); | |
491 | break; | |
492 | ||
493 | case HW_FS_EXT4: | |
494 | case HW_FS_EXT4_WO_JOURNAL: | |
495 | replace("/harddisk/etc/fstab", "FSTYPE", "ext4"); | |
496 | replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro"); | |
497 | break; | |
498 | ||
499 | default: | |
500 | assert(0); | |
cd8dd8dd | 501 | } |
73d9a908 | 502 | |
a869b064 AF |
503 | replace("/harddisk/boot/grub/grub.conf", "KVER", KERNEL_VERSION); |
504 | ||
d7dd283b | 505 | 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 |
506 | system(commandstring); |
507 | ||
f4e27420 | 508 | mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst"); |
fd0763dc | 509 | |
a9a26c5a | 510 | system("/bin/sed -e 's#/harddisk#/#g' -e 's#//#/#g' < /proc/mounts > /harddisk/etc/mtab"); |
edd536b6 | 511 | |
423400cf MT |
512 | /* |
513 | * Generate device.map to help grub finding the device to install itself on. | |
514 | */ | |
515 | FILE *f = NULL; | |
516 | if (f = fopen("/harddisk/boot/grub/device.map", "w")) { | |
d7dd283b | 517 | fprintf(f, "(hd0) %s\n", destination->path); |
423400cf MT |
518 | fclose(f); |
519 | } | |
520 | ||
edd536b6 | 521 | snprintf(commandstring, STRING_SIZE, |
d7dd283b | 522 | "/usr/sbin/chroot /harddisk /usr/sbin/grub-install --no-floppy %s", destination->path); |
edd536b6 MT |
523 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) { |
524 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
525 | goto EXIT; | |
526 | } | |
5faa66cf AF |
527 | |
528 | /* Serial console ? */ | |
529 | if (serialconsole) { | |
530 | /* grub */ | |
531 | replace("/harddisk/boot/grub/grub.conf", "splashimage", "#splashimage"); | |
532 | replace("/harddisk/boot/grub/grub.conf", "#serial", "serial"); | |
533 | replace("/harddisk/boot/grub/grub.conf", "#terminal", "terminal"); | |
1445c9e0 | 534 | replace("/harddisk/boot/grub/grub.conf", " panic=10 ", " console=ttyS0,115200n8 panic=10 "); |
5faa66cf AF |
535 | |
536 | /*inittab*/ | |
537 | replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:"); | |
538 | replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:"); | |
539 | replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:"); | |
540 | replace("/harddisk/etc/inittab", "4:2345:respawn:", "#4:2345:respawn:"); | |
541 | replace("/harddisk/etc/inittab", "5:2345:respawn:", "#5:2345:respawn:"); | |
542 | replace("/harddisk/etc/inittab", "6:2345:respawn:", "#6:2345:respawn:"); | |
543 | replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:"); | |
544 | } | |
545 | ||
dfa59dbd AF |
546 | /* Set marker that the user has already accepted the gpl */ |
547 | mysystem("/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted"); | |
548 | ||
c25a0343 | 549 | /* Copy restore file from cdrom */ |
7062cecd | 550 | if (unattended && (strlen(restore_file) > 0)) { |
c25a0343 | 551 | fprintf(flog, "unattended: Copy restore file\n"); |
dca095e1 | 552 | snprintf(commandstring, STRING_SIZE, |
c25a0343 | 553 | "cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file); |
dca095e1 | 554 | mysystem(commandstring); |
c25a0343 DG |
555 | } |
556 | ||
8de160ff | 557 | mysystem("umount /cdrom"); |
23ed79cb | 558 | snprintf(commandstring, STRING_SIZE, "/usr/bin/eject /dev/%s", sourcedrive); |
3ef6c343 | 559 | mysystem(commandstring); |
22b9e405 | 560 | |
73d9a908 MT |
561 | if (!unattended) { |
562 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
3ad8835c | 563 | NAME, SNAME, NAME); |
fac85ccd | 564 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_PRESS_OK_TO_REBOOT], message); |
73d9a908 | 565 | } |
cd8dd8dd | 566 | |
22b9e405 | 567 | allok = 1; |
edd536b6 | 568 | |
d6aaa55d | 569 | EXIT: |
10bc6f06 | 570 | fprintf(flog, "Install program ended.\n"); |
d6aaa55d | 571 | |
10bc6f06 | 572 | if (!(allok)) |
d6aaa55d | 573 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); |
10bc6f06 | 574 | |
d6aaa55d | 575 | freekeyvalues(ethernetkv); |
d6aaa55d | 576 | |
25fcce25 | 577 | if (allok) { |
ee78a5ef MT |
578 | fflush(flog); |
579 | fclose(flog); | |
3a1019f6 MT |
580 | } |
581 | ||
582 | newtFinished(); | |
583 | ||
f0fa1795 MT |
584 | // Free resources |
585 | free(sourcedrive); | |
25fcce25 MT |
586 | |
587 | if (destination) { | |
588 | hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
589 | free(destination); | |
590 | } | |
d7dd283b MT |
591 | |
592 | if (selected_disks) | |
593 | hw_free_disks(selected_disks); | |
594 | ||
595 | hw_free(hw); | |
f0fa1795 | 596 | |
25fcce25 MT |
597 | fcloseall(); |
598 | ||
599 | if (!(allok)) | |
600 | system("/etc/halt"); | |
601 | ||
d6aaa55d MT |
602 | return 0; |
603 | } |