source: MondoRescue/branches/3.3/mondo/src/mondorestore/mondo-rstr-tools.c@ 3854

Last change on this file since 3854 was 3854, checked in by Bruno Cornec, 3 months ago

Fix mr_popup_and_get_string proto

  • Property svn:keywords set to Id
File size: 76.3 KB
Line 
1/***************************************************************************
2$Id: mondo-rstr-tools.c 3854 2024-03-06 02:42:16Z bruno $
3***************************************************************************/
4
5#include <pthread.h>
6#include <linux/fd.h>
7#include "my-stuff.h"
8#include "mr_mem.h"
9#include "mr_str.h"
10#include "mr_file.h"
11#include "mr_sys.h"
12#include "../common/mondostructures.h"
13#include "../common/libmondo.h"
14#include "mr-externs.h"
15#include "mondo-rstr-tools.h"
16#include "libmondo-mountlist-EXT.h"
17
18/**
19 * The biggielist stub (appended to the directory where all.tar.gz was unpacked).
20 */
21#define BIGGIELIST_TXT_STUB "tmp/biggielist.txt"
22
23/**
24 * The filelist stub (appended to the directory where all.tar.gz was unpacked).
25 */
26#define FILELIST_FULL_STUB "tmp/filelist.full.gz"
27
28/**
29 * The mountlist stub (appended to the directory where all.tar.gz was unpacked).
30 */
31#define MOUNTLIST_FNAME_STUB "tmp/mountlist.txt"
32
33/**
34 * The mondorestore.cfg stub (appended to the directory where all.tar.gz was unpacked).
35 */
36#define MONDO_CFG_FILE_STUB "tmp/mondorestore.cfg"
37/**
38 * The i-want-my-lvm stub
39 */
40#define IWANTMYLVM_STUB "tmp/i-want-my-lvm"
41
42extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
43extern bool g_I_have_just_nuked;
44/*
45extern char *g_tmpfs_mountpt;
46*/
47
48/**
49 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
50 */
51char *g_isodir_device;
52
53
54/**
55 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
56 */
57char *g_isodir_format;
58
59extern long g_current_progress, g_maximum_progress;
60extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir;
61 // biggielist.txt is the list of big files stored on the
62 // backup media set in question
63extern char *g_filelist_full; // filelist.full.gz is the list of all regular files
64 // (excluding big files) stored on the backup media set
65extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the
66 // user chooses them
67extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
68 // were archived as images, not just /dev entries
69 // ... e.g. NTFS, BeOS partitions
70extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
71 // restore only these
72extern char *g_mondo_cfg_file; // where mondorestore.cfg (the config file) is stored
73extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
74extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo
75
76extern t_bkptype g_backup_media_type;
77
78extern int g_partition_table_locked_up;
79extern char *MONDO_LOGFILE;
80
81/* Reference to global bkpinfo */
82extern struct s_bkpinfo *bkpinfo;
83
84/* Should we use or not extended attributes and acl when restoring */
85extern char *g_getfattr;
86extern char *g_getfacl;
87
88extern void kill_anything_like_this(char *str);
89extern int skip_obdr(void);
90extern int mount_media();
91extern int set_tape_block_size_with_mt(long internal_tape_block_size);
92
93/**
94* @addtogroup restoreUtilityGroup
95* @{
96*/
97/**
98* Free the malloc()s for the filename variables.
99*/
100void free_MR_global_filenames(void)
101{
102paranoid_free(g_biggielist_txt);
103paranoid_free(g_filelist_full);
104paranoid_free(g_filelist_imagedevs);
105paranoid_free(g_imagedevs_restthese);
106paranoid_free(g_mondo_cfg_file);
107paranoid_free(g_mountlist_fname);
108paranoid_free(g_mondo_home);
109/*
110paranoid_free(g_tmpfs_mountpt);
111*/
112paranoid_free(g_isodir_device);
113paranoid_free(g_isodir_format);
114
115}
116
117
118
119/**
120* Ask the user which imagedevs from the list contained in @p infname should
121* actually be restored.
122* @param infname The file containing a list of all imagedevs.
123* @param outfname The location of the output file containing the imagedevs the user wanted to restore.
124* @ingroup restoreUtilityGroup
125*/
126void ask_about_these_imagedevs(char *infname, char *outfname) {
127
128FILE *fin;
129FILE *fout;
130char *incoming = NULL;
131char *p = NULL;
132char *question = NULL;
133
134assert_string_is_neither_NULL_nor_zerolength(infname);
135assert_string_is_neither_NULL_nor_zerolength(outfname);
136
137if (!(fin = fopen(infname, "r"))) {
138 fatal_error("Cannot openin infname");
139}
140if (!(fout = fopen(outfname, "w"))) {
141 fatal_error("Cannot openin outfname");
142}
143for (mr_getline(p, fin); !feof(fin) && (p != NULL); mr_getline(p, fin)) {
144 incoming = mr_strip_spaces(p);
145 mr_free(p);
146
147 if (incoming[0] == '\0') {
148 mr_free(incoming);
149 continue;
150 }
151
152 mr_asprintf(question, "Should I restore the image of %s ?", incoming);
153
154 if (ask_me_yes_or_no(question)) {
155 fprintf(fout, "%s\n", incoming);
156 }
157 mr_free(incoming);
158}
159mr_free(incoming);
160mr_free(question);
161paranoid_fclose(fout);
162paranoid_fclose(fin);
163}
164
165/**************************************************************************
166*ASK_ABOUT_THESE_IMAGEDEVS *
167**************************************************************************/
168
169
170
171
172
173
174
175
176/**
177* Extract @c mondorestore.cfg and @c mountlist.txt from @p ramdisk_fname.
178* @param bkpinfo The backup information structure. @c tmpdir is the only field used.
179* @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
180* @param output_cfg_file Where to put the configuration file extracted.
181* @param output_mountlist_file Where to put the mountlist file extracted.
182* @return 0 for success, nonzero for failure.
183* @ingroup restoreUtilityGroup
184*/
185
186/**
187* Keep trying to get mondorestore.cfg from the archive, until the user gives up.
188*/
189void get_cfg_file_from_archive_or_bust()
190{
191while (get_cfg_file_from_archive()) {
192 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) {
193 fatal_error("Could not find config file/archives. Aborting.");
194 }
195 interactively_obtain_media_parameters_from_user(FALSE);
196 }
197}
198
199
200/**
201* Determine whether @p list_fname contains a line containing @p f.
202* @param f The line to search for.
203* @param list_fname The file to search in.
204* @param preamble Ignore this beginning part of @p f ("" to disable).
205* @return TRUE if it's in the list, FALSE if it's not.
206*/
207bool is_file_in_list(char *f, char *list_fname, char *preamble)
208{
209
210char *command = NULL;
211char *file = NULL;
212char *tmp = NULL;
213int res;
214
215assert_string_is_neither_NULL_nor_zerolength(f);
216assert_string_is_neither_NULL_nor_zerolength(list_fname);
217assert(preamble != NULL);
218
219if (strncmp(preamble, f, strlen(preamble)) == 0) {
220 mr_asprintf(file, "%s", f + strlen(preamble));
221} else {
222 mr_asprintf(file, "%s", f);
223}
224if (file[0] == '/' && file[1] == '/') {
225 tmp = file;
226
227 mr_asprintf(file, "%s", tmp + 1);
228 mr_free(tmp);
229}
230log_msg(2, "Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file);
231mr_asprintf(command, "grep -E '^%s$' %s", file, list_fname);
232mr_free(file);
233
234res = run_program_and_log_output(command, FALSE);
235mr_free(command);
236if (res) {
237 return (FALSE);
238} else {
239 return (TRUE);
240}
241}
242
243/**************************************************************************
244*END_IS_FILE_IN_LIST *
245**************************************************************************/
246
247/**
248 * Get information about the location of ISO images from the user.
249 * @param isodir_device Where to put the device (e.g. /dev/hda4) the user enters.
250 * @param isodir_format Where to put the format (e.g. ext2) the user enters.
251 * @param nuke_me_please Whether we're planning on nuking or not.
252 * @return TRUE if OK was pressed, FALSE otherwise.
253 */
254bool get_isodir_info(char *isodir_device, char *isodir_format,
255 struct s_bkpinfo *bkpinfo, bool nuke_me_please)
256{
257
258 bool HDD = FALSE;
259 char *tmp = NULL;
260 /** initialize ********************************************************/
261
262 assert(isodir_device != NULL);
263 assert(isodir_format != NULL);
264 assert(bkpinfo->isodir != NULL);
265
266 log_it("bkpinfo->isodir = %s", bkpinfo->isodir);
267 isodir_format[0] = '\0';
268 if (isodir_device[0] == '\0') {
269 strcpy(isodir_device, "/dev/");
270 }
271 if (bkpinfo->isodir == NULL) {
272 mr_asprintf(bkpinfo->isodir, "%s", "/");
273 }
274 // TODO: Are we sure it does what it's expected to do here ?
275 if (does_file_exist("/tmp/NETFS-SERVER-MOUNT")) {
276 strcpy(isodir_device, last_line_of_file("/tmp/NETFS-SERVER-MOUNT"));
277 strcpy(isodir_format, "netfs");
278 mr_asprintf(bkpinfo->isodir, "%s", last_line_of_file("/tmp/ISO-DIR"));
279 }
280 if (nuke_me_please) {
281 return (TRUE);
282 }
283
284 if (popup_and_get_string("ISO Mode - device", "On what device do the ISO files live?", isodir_device, MAX_STR_LEN / 4)) {
285 if (popup_and_get_string ("ISO Mode - format", "What is the disk format of the device? (Hit ENTER if you don't know.)", isodir_format, 16)) {
286 if (popup_with_buttons("Are you restoring from an external hard drive ?", "Yes", "No")) {
287 HDD = TRUE;
288 }
289 tmp = mr_popup_and_get_string ("ISO Mode - path", "At what path on this device can the ISO files be found ?", bkpinfo->isodir);
290 if (tmp) {
291 strip_spaces(isodir_device);
292 strip_spaces(isodir_format);
293 bkpinfo->isodir = mr_strip_spaces(tmp);
294 mr_free(tmp);
295 log_it("isodir_device = %s - isodir_format = %s - bkpinfo->isodir = %s", isodir_device, isodir_format, bkpinfo->isodir);
296 if (HDD) {
297 /* We need an additional param */
298 mr_asprintf(bkpinfo->subdir, "%s", bkpinfo->isodir);
299 mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
300 log_it("Now bkpinfo->isodir = %s and subdir = ", bkpinfo->isodir, bkpinfo->subdir);
301 }
302 return (TRUE);
303 }
304 }
305 }
306 return (FALSE);
307}
308
309
310/**
311* Set up an ISO backup.
312* @param bkpinfo The backup information structure. Fields used:
313* - @c bkpinfo->backup_media_type
314* - @c bkpinfo->disaster_recovery
315* - @c bkpinfo->isodir
316* @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
317* @return 0 for success, nonzero for failure.
318*/
319int iso_fiddly_bits(bool nuke_me_please) {
320
321char *mount_isodir_command = NULL;
322char *command = NULL;
323char *mds = NULL;
324int retval = 0, i;
325
326g_ISO_restore_mode = TRUE;
327read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
328if (bkpinfo->disaster_recovery) {
329 /* Don't let this clobber an existing bkpinfo->isodir */
330 if (bkpinfo->isodir == NULL) {
331 mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
332 }
333 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
334 run_program_and_log_output(command, 5);
335 mr_free(command);
336 log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
337}
338
339if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo, nuke_me_please)) {
340 return (1);
341}
342paranoid_system("umount -d " MNT_CDROM " 2> /dev/null"); /* just in case */
343
344if (is_this_device_mounted(g_isodir_device)) {
345 log_to_screen("WARNING - isodir is already mounted");
346} else {
347 mr_asprintf(mount_isodir_command, "mount %s", g_isodir_device);
348 if (strlen(g_isodir_format) > 1) {
349 mr_strcat(mount_isodir_command, " -t %s", g_isodir_format);
350 }
351
352 mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir);
353 run_program_and_log_output("df -m -P -T", FALSE);
354 log_msg(1, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command);
355 if (run_program_and_log_output(mount_isodir_command, FALSE)) {
356 popup_and_OK("Cannot mount the device where the ISO files are stored.");
357 return (1);
358 }
359 paranoid_free(mount_isodir_command);
360 log_to_screen("I have mounted the device where the ISO files are stored.");
361}
362if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
363 mount_media();
364}
365i = what_number_cd_is_this(); /* has the side-effect of calling mount_media() */
366mds = media_descriptor_string(bkpinfo->backup_media_type);
367mr_free(mds);
368
369log_msg(1, "%s #%d has been mounted via loopback mount", mds, i);
370if (i < 0) {
371 popup_and_OK("Cannot find ISO images in the directory you specified.");
372 retval = 1;
373}
374log_msg(2, "bkpinfo->isodir is now %s", bkpinfo->isodir);
375return (retval);
376}
377
378
379
380
381/**
382* Kill all Petris processes.
383*/
384void kill_petris(void) {
385 kill_anything_like_this("petris");
386}
387
388/**************************************************************************
389*END_KILL_PETRIS *
390**************************************************************************/
391
392
393/**
394 * Mount @p device at @p mpt as @p format.
395 * @param device The device (/dev entry) to mount.
396 * @param mpt The directory to mount it on.
397 * @param format The filesystem type of @p device.
398 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
399 * @return 0 for success, nonzero for failure.
400 */
401int mount_device(char *device, char *mpt, char *format, bool writeable)
402{
403int res = 0;
404
405/** malloc **/
406char *tmp = NULL;
407char *command = NULL;
408char *mountdir = NULL;
409char *mountpoint = NULL;
410char *additional_parameters = NULL;
411
412assert_string_is_neither_NULL_nor_zerolength(device);
413assert_string_is_neither_NULL_nor_zerolength(mpt);
414assert(format != NULL);
415
416 if (!strcmp(mpt, "/1")) {
417 mr_asprintf(mountpoint, "/");
418 log_msg(3, "Mommm! SME is being a dildo!");
419 } else {
420 mr_asprintf(mountpoint, "%s", mpt);
421 }
422
423 if (!strcmp(mountpoint, "lvm")) {
424 return (0);
425 }
426 if (!strcmp(mountpoint, "image")) {
427 return (0);
428 }
429 mr_asprintf(tmp, "Mounting device %s ", device);
430 log_msg(1, tmp);
431 /* Deal with additional params only if not /proc or /sys */
432 mr_asprintf(additional_parameters, "");
433 if (strcmp(format, "proc") && strcmp(format, "sys")) {
434 if (writeable) {
435 mr_strcat(additional_parameters, "-o rw");
436 } else {
437 mr_strcat(additional_parameters, "-o ro");
438 }
439 if (find_home_of_exe("setfattr")) {
440 mr_strcat(additional_parameters, ",user_xattr");
441 }
442 if (find_home_of_exe("setfacl")) {
443 mr_strcat(additional_parameters, ",acl");
444 }
445 }
446
447 if (!strcmp(mountpoint, "swap")) {
448 mr_asprintf(command, "swapon %s", device);
449 mr_asprintf(mountdir, "swap");
450 } else {
451 if (!strcmp(mountpoint, "/")) {
452 mr_asprintf(mountdir, "%s", MNT_RESTORING);
453 } else {
454 mr_asprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
455 }
456 mr_asprintf(command, "mkdir -p %s", mountdir);
457 run_program_and_log_output(command, FALSE);
458 mr_free(command);
459
460 mr_asprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE);
461 log_msg(2, "command='%s'", command);
462 }
463 mr_free(additional_parameters);
464
465 res = run_program_and_log_output(command, TRUE);
466 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
467 log_msg(1, "Re-trying without the fancy extra parameters");
468 mr_free(command);
469 mr_asprintf(command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE);
470 res = run_program_and_log_output(command, TRUE);
471 }
472 if (res) {
473 log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir);
474 log_msg(1, "command was '%s'", command);
475 if (!strcmp(mountpoint, "swap")) {
476 log_to_screen(tmp);
477 } else {
478 log_msg(2, "Retrying w/o the '-t' switch");
479 mr_free(command);
480 mr_asprintf(command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE);
481 log_msg(2, "2nd command = '%s'", command);
482 res = run_program_and_log_output(command, TRUE);
483 if (res == 0) {
484 log_msg(1,
485 "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
486 } else {
487 log_to_screen(tmp);
488 }
489 }
490 }
491
492 if (res && !strcmp(mountpoint, "swap")) {
493 log_msg(2, "That's ok. It's just a swap partition.");
494 log_msg(2, "Non-fatal error. Returning 0.");
495 res = 0;
496 }
497
498mr_free(tmp);
499mr_free(command);
500mr_free(mountdir);
501mr_free(mountpoint);
502
503return (res);
504}
505/**************************************************************************
506 *END_MOUNT_DEVICE *
507**************************************************************************/
508
509
510/**
511 * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
512 * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
513 * @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
514 * @return The number of errors encountered (0 for success).
515 */
516int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable)
517{
518int retval = 0, lino, res;
519char *tmp = NULL;
520char *these_failed = NULL;
521struct mountlist_itself *mountlist = NULL;
522
523assert(p_external_copy_of_mountlist != NULL);
524mountlist = malloc(sizeof(struct mountlist_itself));
525memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
526 sizeof(struct mountlist_itself));
527 sort_mountlist_by_mountpoint(mountlist, 0);
528
529
530 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices ");
531 open_progress_form("Mounting devices", "I am now mounting all the drives.", "This should not take long.", "", mountlist->entries);
532
533 mr_asprintf(these_failed, "");
534 for (lino = 0; lino < mountlist->entries; lino++) {
535 if (!strcmp(mountlist->el[lino].device, "/proc")) {
536 log_msg(1, "Again with the /proc - why is this in your mountlist?");
537 } else if (is_this_device_mounted(mountlist->el[lino].device)) {
538 log_to_screen("%s is already mounted", mountlist->el[lino].device);
539 } else if (strcmp(mountlist->el[lino].mountpoint, "none")
540 && strcmp(mountlist->el[lino].mountpoint, "lvm")
541 && strcmp(mountlist->el[lino].mountpoint, "raid")
542 && strcmp(mountlist->el[lino].mountpoint, "image")) {
543 mr_asprintf(tmp, "Mounting %s", mountlist->el[lino].device);
544 update_progress_form(tmp);
545 mr_free(tmp);
546 res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable);
547 retval += res;
548 if (res) {
549 mr_strcat(these_failed, "%s ",mountlist->el[lino].device);
550 }
551 }
552 g_current_progress++;
553 }
554 close_progress_form();
555 if (retval) {
556 if (g_partition_table_locked_up > 0) {
557 log_to_screen("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
558 log_to_screen("lock up the partition table. You might have to reboot and use Interactive Mode to");
559 log_to_screen("format and restore *without* partitioning first. Sorry for the inconvenience.");
560 }
561 mr_asprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed);
562
563 if (!ask_me_yes_or_no(tmp)) {
564 retval = 0;
565 log_to_screen("Continuing, although some device(s) failed to be mounted");
566 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
567 } else {
568 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
569 log_to_screen("Unable to mount some or all of your partitions.");
570 }
571 mr_free(tmp);
572 } else {
573 log_to_screen("All partitions were mounted OK.");
574 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
575 }
576 paranoid_free(these_failed);
577
578 /* Also mounting under MNT_RESTORING special FS */
579 (void)mount_device("/proc","/proc","proc",TRUE);
580 (void)mount_device("/sys","/sys","sysfs",TRUE);
581 /* BR#852: we need to create BTRFS subvols now */
582 /* Creating potential btrfs subvolumes */
583 if (does_file_exist("/tmp/create-btrfs-subvol")) {
584 run_program_and_log_output("/tmp/create-btrfs-subvol",3);
585 }
586 /* Mounting potential btrfs subvolumes */
587 if (does_file_exist("/tmp/mount-btrfs-subvol")) {
588 run_program_and_log_output("/tmp/mount-btrfs-subvol",3);
589 }
590 run_program_and_log_output("df -m -P -T", 3);
591 paranoid_free(mountlist);
592 return (retval);
593}
594/**************************************************************************
595*END_MOUNT_ALL_DEVICES *
596**************************************************************************/
597
598
599/**
600* Fix some miscellaneous things in the filesystem so the system will come
601* up correctly on the first boot.
602*/
603void protect_against_braindead_sysadmins() {
604
605run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct", 0);
606run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct", 0);
607
608/* Log the status of the boot area */
609run_program_and_log_output("ls -alR " MNT_RESTORING "/boot", 0);
610
611if (run_program_and_log_output("ls -al " MNT_RESTORING " /tmp", 0)) {
612 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp", 0);
613}
614run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run/console", 0);
615run_program_and_log_output("chmod 666 " MNT_RESTORING "/dev/null", 0);
616/* This doesn't work as the mkdir should be done in home ! Maybe time to remove
617 run_program_and_log_output("cd " MNT_RESTORING "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done", 1);
618 */
619run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid", 1);
620run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*", 1);
621}
622
623/**************************************************************************
624*END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS *
625**************************************************************************/
626
627
628
629
630/**
631* Fill out @p bkpinfo based on @p cfg_file.
632* @param cfg_file The mondorestore.cfg file to read into @p bkpinfo.
633* @param bkpinfo The backup information structure to fill out with information
634* from @p cfg_file.
635* @return 0 for success, nonzero for failure.
636*/
637int read_cfg_file_into_bkpinfo(char *cfgf)
638{
639/** add mallocs **/
640char value[MAX_STR_LEN];
641char *tmp1 = NULL;
642char *envtmp1 = NULL;
643char *envtmp2 = NULL;
644char *command = NULL;
645char iso_mnt[MAX_STR_LEN];
646char iso_path[MAX_STR_LEN];
647char *old_isodir = NULL;
648char *cfg_file = NULL;
649t_bkptype media_specified_by_user;
650
651// assert_string_is_neither_NULL_nor_zerolength(cfg_file);
652assert(bkpinfo != NULL);
653assert(cfgf != NULL);
654log_it("Entering read_cfg_file_into_bkpinfo");
655
656if (!cfgf) {
657 mr_asprintf(cfg_file, "%s", g_mondo_cfg_file);
658} else {
659 mr_asprintf(cfg_file, "%s", cfgf);
660}
661
662media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
663
664if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
665 if (!strcmp(value, "cdstream")) {
666 bkpinfo->backup_media_type = cdstream;
667 } else if (!strcmp(value, "cdr")) {
668 bkpinfo->backup_media_type = cdr;
669 } else if (!strcmp(value, "cdrw")) {
670 bkpinfo->backup_media_type = cdrw;
671 } else if (!strcmp(value, "dvd")) {
672 bkpinfo->backup_media_type = dvd;
673 } else if (!strcmp(value, "usb")) {
674 bkpinfo->backup_media_type = usb;
675 bkpinfo->please_dont_eject = TRUE;
676 } else if (!strcmp(value, "iso")) {
677 bkpinfo->backup_media_type = iso;
678 if (am_I_in_disaster_recovery_mode()) {
679 /* Check to see if CD is already mounted before mounting it... */
680 if (!is_this_device_mounted("/dev/cdrom")) {
681 log_msg(2, "NB: CDROM device not mounted, mounting...");
682 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);
683 }
684 if (does_file_exist(MNT_CDROM"/archives/filelist.0")) {
685 bkpinfo->backup_media_type = cdr;
686 run_program_and_log_output("umount -d "MNT_CDROM, 1);
687 log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
688 }
689 }
690 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
691 mr_asprintf(bkpinfo->prefix, "%s", value);
692 } else {
693 mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
694 }
695 log_it("Setting Prefix to %s", bkpinfo->prefix);
696 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
697 /* Stay compatible with previous versions by allowing nfs as an entry here */
698 bkpinfo->backup_media_type = netfs;
699 bkpinfo->please_dont_eject = TRUE;
700 if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) {
701 mr_asprintf(bkpinfo->netfs_proto,"%s", value);
702 } else {
703 /* For compatibility, force protocol in old nfs case to be transparent */
704 mr_asprintf(bkpinfo->netfs_proto, "nfs");
705 }
706 if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) {
707 mr_asprintf(bkpinfo->netfs_user,"%s", value);
708 }
709 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
710 mr_asprintf(bkpinfo->prefix, "%s", value);
711 } else {
712 mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
713 }
714 tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
715 if (strstr(tmp1, "pxe")) {
716 /* We need to override prefix value in PXE mode as it's
717 * already done in start-netfs */
718 envtmp1 = getenv("imgname");
719 if (envtmp1 == NULL) {
720 fatal_error("no imgname variable in environment");
721 }
722 mr_asprintf(bkpinfo->prefix, "%s", envtmp1);
723 }
724 mr_free(tmp1);
725 } else if (!strcmp(value, "tape")) {
726 bkpinfo->backup_media_type = tape;
727 } else if (!strcmp(value, "udev")) {
728 bkpinfo->backup_media_type = udev;
729 } else {
730 fatal_error("UNKNOWN bkp-media-type");
731 }
732} else {
733 fatal_error("backup-media-type not specified!");
734}
735
736if (bkpinfo->disaster_recovery) {
737 if (bkpinfo->backup_media_type == cdstream) {
738 mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom");
739 bkpinfo->media_size = 650; /* good guess */
740 } else if (bkpinfo->backup_media_type == usb) {
741 envtmp1 = getenv("MRUSBDEV");
742 if (envtmp1 == NULL) {
743 if (read_cfg_var(cfg_file, "usb-dev", value)) {
744 fatal_error("Cannot get USB device name from cfg file");
745 }
746 } else {
747 strcpy(value,envtmp1);
748 }
749 mr_asprintf(bkpinfo->media_device, "%s1", value);
750 log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
751 } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
752 if (read_cfg_var(cfg_file, "media-dev", value)) {
753 fatal_error("Cannot get tape device name from cfg file");
754 }
755 mr_asprintf(bkpinfo->media_device, "%s", value);
756 read_cfg_var(cfg_file, "media-size", value);
757 bkpinfo->media_size = atol(value);
758 log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device);
759 } else {
760 mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* we don't really need this var */
761 bkpinfo->media_size = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
762 log_msg(2, "Backup medium is similar to CD-R[W]");
763 }
764} else {
765 log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file.");
766}
767
768read_cfg_var(cfg_file, "use-star", value);
769if (strstr(value, "yes")) {
770 bkpinfo->use_star = TRUE;
771 log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
772}
773
774read_cfg_var(cfg_file, "obdr", value);
775if (strstr(value, "TRUE")) {
776 bkpinfo->use_obdr = TRUE;
777 log_msg(1, "OBDR mode activated");
778}
779
780read_cfg_var(cfg_file, "acl", value);
781if (strstr(value, "TRUE")) {
782 mr_asprintf(g_getfacl,"setfacl");
783 log_msg(1, "We will restore ACLs");
784 if (! find_home_of_exe("setfacl")) {
785 log_msg(1, "Unable to restore ACLs as no setfacl found");
786 }
787}
788read_cfg_var(cfg_file, "xattr", value);
789if (strstr(value, "TRUE")) {
790 mr_asprintf(g_getfattr,"setfattr");
791 log_msg(1, "We will restore XATTRs");
792 if (! find_home_of_exe("setfattr")) {
793 log_msg(1, "Unable to restore XATTRs as no setfattr found");
794 }
795}
796
797if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
798 bkpinfo->internal_tape_block_size = atol(value);
799} else {
800 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
801}
802log_msg(1, "Internal tape block size set to %ld", bkpinfo->internal_tape_block_size);
803
804read_cfg_var(cfg_file, "use-lzma", value);
805if (strstr(value, "yes")) {
806 bkpinfo->use_lzma = TRUE;
807 bkpinfo->use_lzo = FALSE;
808 bkpinfo->use_gzip = FALSE;
809 mr_asprintf(bkpinfo->zip_exe, "%s", "lzma");
810 mr_asprintf(bkpinfo->zip_suffix, "%s", "lzma");
811}
812
813read_cfg_var(cfg_file, "use-lzo", value);
814if (strstr(value, "yes")) {
815 bkpinfo->use_lzma = FALSE;
816 bkpinfo->use_lzo = TRUE;
817 bkpinfo->use_gzip = FALSE;
818 mr_asprintf(bkpinfo->zip_exe, "%s", "lzop");
819 mr_asprintf(bkpinfo->zip_suffix, "%s", "lzo");
820}
821
822read_cfg_var(cfg_file, "use-gzip", value);
823if (strstr(value, "yes")) {
824 bkpinfo->use_lzma = FALSE;
825 bkpinfo->use_lzo = FALSE;
826 bkpinfo->use_gzip = TRUE;
827 mr_asprintf(bkpinfo->zip_exe, "%s", "gzip");
828 mr_asprintf(bkpinfo->zip_suffix, "%s", "gz");
829}
830
831read_cfg_var(cfg_file, "use-comp", value);
832if (strstr(value, "yes")) {
833 bkpinfo->use_lzma = FALSE;
834 bkpinfo->use_lzo = FALSE;
835 bkpinfo->use_gzip = FALSE;
836 mr_asprintf(bkpinfo->zip_exe, "%s", "xz");
837 mr_asprintf(bkpinfo->zip_suffix, "%s", "xz");
838}
839
840value[0] = '\0';
841read_cfg_var(cfg_file, "differential", value);
842if (!strcmp(value, "yes") || !strcmp(value, "1")) {
843 bkpinfo->differential = TRUE;
844}
845log_msg(2, "differential var = '%s'", value);
846if (bkpinfo->differential) {
847 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
848} else {
849 log_msg(2, "This is a regular (full) backup");
850}
851
852read_cfg_var(cfg_file, "please-dont-eject", value);
853tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
854if (value[0] || strstr(tmp1, "donteject")) {
855 bkpinfo->please_dont_eject = TRUE;
856 log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
857}
858mr_free(tmp1);
859
860/* TODO: Read here the boot_* variables */
861read_cfg_var(cfg_file, "boot-type", value);
862if (!strcmp(value, "BIOS")) {
863 bkpinfo->boot_type = BIOS;
864} else if (!strcmp(value, "EFI")) {
865 bkpinfo->boot_type = EFI;
866} else if (!strcmp(value, "UEFI")) {
867 bkpinfo->boot_type = UEFI;
868} else {
869 log_msg(1, "No known boot type found");
870}
871log_msg(1, "Found %s boot type",value);
872
873if (bkpinfo->backup_media_type == netfs) {
874 if (!cfgf) {
875 if (bkpinfo->netfs_mount) {
876 log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount);
877 }
878 if (bkpinfo->netfs_remote_dir != NULL) {
879 log_msg(2, "netfs_remote_dir remains %s", bkpinfo->netfs_remote_dir);
880 }
881 log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
882 } else {
883 read_cfg_var(cfg_file, "netfs-server-mount", value);
884 mr_free(bkpinfo->netfs_mount);
885 mr_asprintf(bkpinfo->netfs_mount, "%s", value);
886 if (bkpinfo->netfs_mount != NULL) {
887 log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount);
888 }
889
890 read_cfg_var(cfg_file, "iso-dir", value);
891 mr_free(bkpinfo->netfs_remote_dir);
892 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", value);
893 if (bkpinfo->netfs_remote_dir != NULL) {
894 log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir);
895 }
896
897 if (bkpinfo->netfs_proto != NULL) {
898 log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto);
899 }
900 if (bkpinfo->netfs_user != NULL) {
901 log_msg(2, "netfs_user is %s", bkpinfo->netfs_user);
902 }
903 }
904 tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
905 if (strstr(tmp1, "pxe")) {
906 /* We need to override values in PXE mode as it's
907 * already done in start-netfs */
908 envtmp1 = getenv("netfsmount");
909 if (envtmp1 == NULL) {
910 fatal_error("no netfsmount variable in environment");
911 }
912 envtmp2 = getenv("dirimg");
913 if (envtmp2 == NULL) {
914 fatal_error("no dirimg variable in environment");
915 }
916 mr_free(bkpinfo->netfs_mount);
917 mr_asprintf(bkpinfo->netfs_mount, "%s", envtmp1);
918
919 mr_free(bkpinfo->netfs_remote_dir);
920 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", envtmp2);
921 }
922 mr_free(tmp1);
923} else if (bkpinfo->backup_media_type == iso) {
924 /* Patch by Conor Daly 23-june-2004
925 * to correctly mount iso-dev and set a sensible
926 * isodir in disaster recovery mode
927 */
928 mr_asprintf(old_isodir, "%s", bkpinfo->isodir);
929 if (read_cfg_var(cfg_file, "iso-mnt", iso_mnt) != 0) {
930 iso_mnt[0] = '\0';
931 }
932 if (read_cfg_var(cfg_file, "iso-dir", iso_path) != 0) {
933 iso_path[0] = '\0';
934 }
935 mr_asprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
936 if (!strcmp(bkpinfo->isodir,"")) {
937 mr_asprintf(bkpinfo->isodir, "%s", old_isodir);
938 }
939
940 if ((!bkpinfo->disaster_recovery) || (g_isodir_device[0] != '\0')) {
941 if (strcmp(old_isodir, bkpinfo->isodir)) {
942 log_it("user nominated isodir %s differs from archive, keeping user's choice: %s\n", bkpinfo->isodir, old_isodir );
943 mr_asprintf(bkpinfo->isodir, "%s", old_isodir);
944 }
945 }
946 mr_free(old_isodir);
947
948 if (g_isodir_device[0] == '\0') {
949 /* We don't want to loose our conf made earlier in iso_fiddly_bits
950 * so go here only if job not done already */
951 read_cfg_var(cfg_file, "iso-dev", g_isodir_device);
952 }
953
954 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
955
956 if (bkpinfo->disaster_recovery) {
957 if (is_this_device_mounted(g_isodir_device)) {
958 log_msg(2, "NB: isodir is already mounted");
959 /* Find out where it's mounted */
960 mr_asprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);
961 log_it("command = %s", command);
962 tmp1 = call_program_and_get_last_line_of_output(command);
963 log_it("res of it = %s", tmp1);
964 sprintf(iso_mnt, "%s", tmp1);
965 mr_free(command);
966 mr_free(tmp1);
967 } else {
968 sprintf(iso_mnt, "/tmp/isodir");
969 mr_asprintf(tmp1, "mkdir -p %s", iso_mnt);
970 run_program_and_log_output(tmp1, 5);
971 mr_free(tmp1);
972
973 mr_asprintf(tmp1, "mount %s %s", g_isodir_device, iso_mnt);
974 if (run_program_and_log_output(tmp1, 3)) {
975 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?");
976 bkpinfo->backup_media_type = cdr;
977 mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* superfluous */
978 mr_free(bkpinfo->isodir);
979 iso_mnt[0] = iso_path[0] = '\0';
980 if (mount_media()) {
981 mr_free(tmp1);
982 fatal_error("Unable to mount isodir. Failed to mount CD-ROM as well.");
983 } else {
984 log_msg(1, "You backed up to disk, then burned some CDs.");
985 }
986 }
987 mr_free(tmp1);
988 }
989 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
990 /* except when already done in iso_fiddly_bits */
991 if ((bkpinfo->backup_media_type == iso) && (g_isodir_device[0] == '\0')) {
992 mr_asprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
993 }
994 }
995}
996mr_free(cfg_file);
997
998if (media_specified_by_user != none) {
999 if (g_restoring_live_from_cd) {
1000 if (bkpinfo->backup_media_type != media_specified_by_user) {
1001 log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
1002 interactively_obtain_media_parameters_from_user(FALSE);
1003 media_specified_by_user = bkpinfo->backup_media_type;
1004 get_cfg_file_from_archive();
1005 }
1006 }
1007 bkpinfo->backup_media_type = media_specified_by_user;
1008}
1009g_backup_media_type = bkpinfo->backup_media_type;
1010return (0);
1011
1012}
1013
1014/**************************************************************************
1015*END_READ_CFG_FILE_INTO_BKPINFO *
1016**************************************************************************/
1017
1018
1019
1020
1021/**
1022 * Allow the user to edit the filelist and biggielist.
1023 * The filelist is unlinked after it is read.
1024 * @param bkpinfo The backup information structure. Fields used:
1025 * - @c bkpinfo->backup_media_type
1026 * - @c bkpinfo->isodir
1027 * - @c bkpinfo->media_device
1028 * - @c bkpinfo->tmpdir
1029 * @return The filelist structure containing the information read from disk.
1030 */
1031struct
1032s_node *process_filelist_and_biggielist()
1033{
1034struct s_node *filelist;
1035
1036char *command = NULL;
1037char *old_pwd = NULL;
1038char *q;
1039int res = 0;
1040pid_t pid;
1041bool extract_mountlist_stub = FALSE;
1042
1043assert(bkpinfo != NULL);
1044
1045/* If those files already exist, do not overwrite them later on */
1046if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
1047 extract_mountlist_stub = FALSE;
1048} else {
1049 extract_mountlist_stub = TRUE;
1050}
1051
1052if (does_file_exist(g_filelist_full)
1053&& does_file_exist(g_biggielist_txt)) {
1054 log_msg(1, "%s exists", g_filelist_full);
1055 log_msg(1, "%s exists", g_biggielist_txt);
1056 log_msg(2,
1057 "Filelist and biggielist already recovered from media. Yay!");
1058} else {
1059 old_pwd = mr_getcwd();
1060 if (chdir(bkpinfo->tmpdir)) {
1061 // FIXME
1062 }
1063 log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
1064 log_to_screen("Extracting filelist and biggielist from media...");
1065 unlink("/tmp/filelist.full");
1066 unlink(FILELIST_FULL_STUB);
1067 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1068 mr_asprintf(command, "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1069 log_msg(1, "tarcommand = %s", command);
1070 run_program_and_log_output(command, 1);
1071 mr_free(command);
1072
1073 if (!does_file_exist(FILELIST_FULL_STUB)) {
1074 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1075 log_msg(2, "pre-2.2.4 compatible mode on");
1076 mr_asprintf(command, "tar -b %ld -zxf %s %s %s %s %s %s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1077 log_msg(1, "tarcommand = %s", command);
1078 run_program_and_log_output(command, 1);
1079 mr_free(command);
1080 }
1081 } else {
1082 log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir);
1083 insist_on_this_cd_number(1);
1084 log_msg(2, "Back from iotcn");
1085 run_program_and_log_output("mount", 1);
1086 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1087
1088 log_msg(1, "tarcommand = %s", command);
1089 run_program_and_log_output(command, 1);
1090 mr_free(command);
1091
1092 if (!does_file_exist(FILELIST_FULL_STUB)) {
1093 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1094 log_msg(2, "pre-2.2.4 compatible mode on");
1095 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1096
1097 log_msg(1, "tarcommand = %s", command);
1098 run_program_and_log_output(command, 1);
1099 mr_free(command);
1100 }
1101 if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
1102 fatal_error("all.tar.gz did not include " BIGGIELIST_TXT_STUB);
1103 }
1104 if (!does_file_exist(FILELIST_FULL_STUB)) {
1105 fatal_error("all.tar.gz did not include " FILELIST_FULL_STUB);
1106 }
1107 }
1108 mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file);
1109 run_program_and_log_output(command, FALSE);
1110 mr_free(command);
1111
1112 mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt);
1113 log_msg(1, "command = %s", command);
1114 paranoid_system(command);
1115 mr_free(command);
1116
1117 mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full);
1118 log_msg(1, "command = %s", command);
1119 paranoid_system(command);
1120 mr_free(command);
1121 }
1122
1123 if (am_I_in_disaster_recovery_mode()
1124 &&
1125 /* If it was there, do not overwrite it */
1126 (extract_mountlist_stub)
1127 &&
1128 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
1129 {
1130 mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir);
1131 paranoid_system(command);
1132 mr_free(command);
1133 }
1134
1135 if (chdir(old_pwd)) {
1136 // FIXME
1137 }
1138 mr_free(old_pwd);
1139
1140 if (!does_file_exist(g_biggielist_txt)) {
1141 log_msg(1, "Warning - %s not found", g_biggielist_txt);
1142 }
1143 if (!does_file_exist(g_filelist_full)) {
1144 log_msg(1, "Warning - %s does not exist", g_filelist_full);
1145 }
1146
1147 log_msg(2, "Forking");
1148 pid = fork();
1149 switch (pid) {
1150 case -1:
1151 fatal_error("Forking error");
1152 break;
1153
1154 case 0:
1155 log_to_screen("Pre-processing filelist");
1156 if (!does_file_exist(g_biggielist_txt)) {
1157 mr_asprintf(command, "echo -n > %s", g_biggielist_txt);
1158 paranoid_system(command);
1159 mr_free(command);
1160 }
1161 mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs);
1162 paranoid_system(command);
1163 mr_free(command);
1164 exit(0);
1165 break;
1166
1167 default:
1168 open_evalcall_form("Pre-processing filelist");
1169 while (!waitpid(pid, (int *) 0, WNOHANG)) {
1170 usleep(100000);
1171 update_evalcall_form(0);
1172 }
1173 }
1174 close_evalcall_form();
1175
1176 log_msg(3, "loading filelist");
1177 filelist = load_filelist(g_filelist_full);
1178 log_msg(3, "deleting original filelist");
1179 unlink(g_filelist_full);
1180 if (g_text_mode) {
1181 q = NULL;
1182 while (q == NULL) {
1183 printf("Restore which directory? --> ");
1184 mr_getline(q, stdin);
1185 }
1186 toggle_path_selection(filelist, q, TRUE);
1187 if (strlen(q) == 0) {
1188 res = 1;
1189 } else {
1190 res = 0;
1191 }
1192 mr_free(q);
1193 } else {
1194 res = edit_filelist(filelist);
1195 }
1196 if (res) {
1197 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
1198 free_filelist(filelist);
1199 return (NULL);
1200 }
1201 ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
1202 close_evalcall_form();
1203
1204 // NB: It's not necessary to add g_biggielist_txt to the filelist.full
1205 // file. The filelist.full file already contains the filename of EVERY
1206 // file backed up - regular and biggie files.
1207
1208 // However, we do want to make sure the imagedevs selected by the user
1209 // are flagged for restoring.
1210 if (length_of_file(g_imagedevs_restthese) > 2) {
1211 add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
1212 TRUE);
1213 }
1214
1215 return (filelist);
1216}
1217
1218/**************************************************************************
1219 *END_ PROCESS_FILELIST_AND_BIGGIELIST *
1220 **************************************************************************/
1221
1222
1223
1224
1225/**
1226 * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
1227 * The backup filename is the filename of the original with ".pristine" added.
1228 * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
1229 * @param filename The filename (absolute path) within @p path_root.
1230 * @return 0 for success, nonzero for failure.
1231 */
1232int backup_crucial_file(char *path_root, char *filename)
1233{
1234 char *tmp = NULL;
1235 char *command = NULL;
1236 int res;
1237
1238 assert(path_root != NULL);
1239 assert_string_is_neither_NULL_nor_zerolength(filename);
1240
1241 mr_asprintf(tmp, "%s/%s", path_root, filename);
1242 mr_asprintf(command, "cp -f %s %s.pristine", tmp, tmp);
1243 mr_free(tmp);
1244
1245 res = run_program_and_log_output(command, 5);
1246 mr_free(command);
1247 return (res);
1248}
1249
1250void offer_to_make_initrd() {
1251
1252if (bkpinfo->restore_mode != nuke) {
1253 if (ask_me_yes_or_no
1254 ("You will now be able to re-generate your initrd.\nThis is especially useful if you changed of hardware configuration, cloned, made P2V, used multipath...\nDo you need to do it ?")) {
1255 log_msg(1,"Launching shell for manual initrd recreation");
1256 if (does_file_exist(MNT_RESTORING"/etc/arch-release")) {
1257 popup_and_OK("You'll now be chrooted under your future / partition.\nEdit /etc/mkinitcpio.conf if needed and rebuild your initrd with the kernel preset name e.g.\nmkinitcpio -p kernel26\nThen type exit to finish.\n");
1258 } else {
1259 popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your init(rd|ramfs) with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nor initramfs, dracut, ... Then type exit to finish.");
1260 }
1261 mvaddstr_and_log_it(g_currentY, 0, "Modifying initrd...");
1262 if (!g_text_mode) {
1263 newtSuspend();
1264 }
1265 paranoid_system("chroot " MNT_RESTORING);
1266 if (!g_text_mode) {
1267 newtResume();
1268 }
1269 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1270 } else {
1271 return;
1272 }
1273} else {
1274 log_to_screen("Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1275 log_msg(1,"Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1276}
1277}
1278
1279
1280/**
1281 * Install the user's boot loader in the MBR.
1282 * Currently LILO, ELILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
1283 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1284 * @return 0 for success, nonzero for failure.
1285 */
1286int run_boot_loader(bool offer_to_hack_scripts)
1287{
1288 int res;
1289 int retval = 0;
1290
1291 /** malloc *******/
1292 char *device = NULL;
1293 char *disk = NULL;
1294 char *name = NULL;
1295 char *type = NULL;
1296 char *cmd = NULL;
1297
1298 malloc_string(device);
1299 malloc_string(name);
1300 malloc_string(type);
1301
1302 /* In order to have a working bootloader, we need to have all devices
1303 * ready in the chroot. If they are not there (udev) then copy them from
1304 * the current /dev location
1305 */
1306 mr_asprintf(cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);
1307 run_program_and_log_output(cmd, 3);
1308 mr_free(cmd);
1309
1310 backup_crucial_file(MNT_RESTORING, "/etc/fstab");
1311 backup_crucial_file(MNT_RESTORING, "/boot/grub/menu.lst");
1312 backup_crucial_file(MNT_RESTORING, "/boot/grub/grub.cfg");
1313 backup_crucial_file(MNT_RESTORING, "/boot/grub2/grub.cfg");
1314 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
1315 backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
1316 backup_crucial_file(MNT_RESTORING, "/boot/grub/device.map");
1317 backup_crucial_file(MNT_RESTORING, "/boot/grub2/device.map");
1318 backup_crucial_file(MNT_RESTORING, "/etc/mtab");
1319 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
1320 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
1321 read_cfg_var(g_mondo_cfg_file, "boot-type", type);
1322 log_msg(2, "run_boot_loader: device='%s', name='%s', type='%s'", device, name, type);
1323 sync();
1324
1325 offer_to_make_initrd();
1326
1327 disk = truncate_to_drive_name(device);
1328 if (strcmp(type,"BIOS") == 0) {
1329 // Force installation of a MBR bootloader brought by mindi on the disk
1330 // in case none was available and we then start from a partition
1331 log_msg(2, "Reinstalling mbr.bin on %s", disk);
1332 mr_system("dd bs=440 count=1 conv=notrunc if=/tmp/mbr.bin of=%s &> /dev/null",disk);
1333 } else {
1334 // Same for GPT
1335 log_msg(2, "Reinstalling gptmbr.bin on %s", disk);
1336 mr_system("dd bs=440 count=1 conv=notrunc if=/tmp/gptmbr.bin of=%s &> /dev/null",disk);
1337 }
1338
1339 // Now reinstall bootloader
1340 if (!strcmp(name, "LILO")) {
1341 res = run_lilo(offer_to_hack_scripts);
1342 } else if (!strcmp(name, "ELILO")) {
1343 res = run_elilo(offer_to_hack_scripts);
1344 } else if (!strcmp(name, "GRUB")) {
1345 res = run_grub(offer_to_hack_scripts, device);
1346 } else if (!strcmp(name, "RAW")) {
1347 res = run_raw_mbr(offer_to_hack_scripts, device);
1348 }
1349#ifdef __FreeBSD__
1350 else if (!strcmp(name, "BOOT0")) {
1351 mr_asprintf(tmp, "boot0cfg -B %s", device);
1352 res = run_program_and_log_output(tmp, FALSE);
1353 paranoid_free(tmp);
1354 } else {
1355 mr_asprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
1356 if (!system(tmp)) {
1357 mr_free(tmp);
1358 mr_asprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
1359 res = run_program_and_log_output(tmp, 3);
1360 } else {
1361 log_msg(1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
1362 }
1363 mr_free(tmp);
1364 }
1365#else
1366 else {
1367 log_to_screen
1368 ("Unable to determine type of boot loader. Defaulting to LILO.");
1369 res = run_lilo(offer_to_hack_scripts);
1370 }
1371#endif
1372 retval += res;
1373 if (res) {
1374 log_to_screen("Your boot loader returned an error");
1375 } else {
1376 log_to_screen("Your boot loader ran OK");
1377 }
1378 paranoid_free(device);
1379 paranoid_free(name);
1380 return (retval);
1381}
1382
1383/**************************************************************************
1384 *END_ RUN_BOOT_LOADER *
1385 **************************************************************************/
1386
1387
1388
1389/**
1390 * Attempt to find the user's editor.
1391 * @return The editor found ("vi" if none could be found).
1392 * @note The returned string points to static storage that will be overwritten with each call.
1393 */
1394char *find_my_editor(void) {
1395
1396 static char output[MAX_STR_LEN];
1397 if (find_home_of_exe("pico")) {
1398 strcpy(output, "pico");
1399 } else if (find_home_of_exe("nano")) {
1400 strcpy(output, "nano");
1401 } else if (find_home_of_exe("e3em")) {
1402 strcpy(output, "e3em");
1403 } else if (find_home_of_exe("e3vi")) {
1404 strcpy(output, "e3vi");
1405 } else {
1406 strcpy(output, "vi");
1407 }
1408 if (!find_home_of_exe(output)) {
1409 log_msg(2, " (find_my_editor) --- warning - %s not found", output);
1410 }
1411 return (output);
1412}
1413
1414
1415/**
1416 * Install GRUB on @p bd.
1417 * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
1418 * @param bd The boot device where GRUB is installed.
1419 * @return 0 for success, nonzero for failure.
1420 */
1421int run_grub(bool offer_to_run_stabgrub, char *bd)
1422{
1423 /** malloc **/
1424 char *command = NULL;
1425 char *boot_device = NULL;
1426 char *tmp = NULL;
1427 char *editor = NULL;
1428
1429 bool done;
1430 int res = 0; /* FALSE */
1431 bool mntlistchg = FALSE;
1432 FILE *fin = NULL;
1433
1434 malloc_string(boot_device);
1435
1436 assert_string_is_neither_NULL_nor_zerolength(bd);
1437 strcpy(boot_device, bd);
1438
1439 if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
1440 /* interactive mode */
1441 mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab, mtab, device.map and menu.lst/grub.cfg, and running GRUB...");
1442 /* Did we changed the mountlist ? If yes, then force editing conf files */
1443 if ((fin = fopen(MONDO_MNTLISTCHG, "r")) != NULL) {
1444 mntlistchg = TRUE;
1445 }
1446 for (done = FALSE; !done;) {
1447 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/sda", boot_device, MAX_STR_LEN / 4);
1448 /* Only try to adapt grub here first if the mountlist wasn't changed before */
1449 if (! mntlistchg) {
1450 mr_asprintf(command, "mr-stabgrub-me %s", boot_device);
1451 res = run_program_and_log_output(command, 1);
1452 mr_free(command);
1453 }
1454
1455 if ((res) || (mntlistchg)) {
1456 if (res) {
1457 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
1458 } else {
1459 popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
1460 }
1461 if (!g_text_mode) {
1462 newtSuspend();
1463 }
1464 mr_asprintf(editor, "%s", find_my_editor());
1465 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
1466 paranoid_system(tmp);
1467 mr_free(tmp);
1468
1469 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
1470 paranoid_system(tmp);
1471 mr_free(tmp);
1472
1473 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
1474 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
1475 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
1476 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
1477 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
1478 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
1479 }
1480 paranoid_system(tmp);
1481 mr_free(tmp);
1482
1483 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
1484 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
1485 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
1486 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
1487 }
1488 paranoid_system(tmp);
1489 mr_free(tmp);
1490 mr_free(editor);
1491
1492 if (!g_text_mode) {
1493 newtResume();
1494 }
1495 mr_asprintf(command, "mr-stabgrub-me %s", boot_device);
1496 res = run_program_and_log_output(command, 1);
1497 mr_free(command);
1498
1499 if (res) {
1500 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
1501 newtSuspend();
1502 paranoid_system("chroot " MNT_RESTORING);
1503 newtResume();
1504 } else {
1505 popup_and_OK("GRUB is now installed correctly");
1506 done = TRUE;
1507 }
1508 } else {
1509 done = TRUE;
1510 }
1511 }
1512 } else {
1513 /* nuke mode */
1514 if (!run_program_and_log_output("which mr-grub", FALSE)) {
1515 log_msg(1, "Yay! mr-grub found...");
1516 mr_asprintf(command, "mr-grub %s /"MOUNTLIST_FNAME_STUB, boot_device);
1517 log_msg(1, "command = %s", command);
1518 } else {
1519 // Or grub2-install
1520 mr_asprintf(command, "chroot " MNT_RESTORING " grub-install %s", boot_device);
1521 log_msg(1, "WARNING - mr-grub not found; using grub-install");
1522 }
1523 mvaddstr_and_log_it(g_currentY, 0, "Running GRUB... ");
1524 log_it("%s",command);
1525 res = run_program_and_log_output(command, 1);
1526 mr_free(command);
1527
1528 if (res) {
1529 popup_and_OK("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
1530 newtSuspend();
1531 paranoid_system("chroot " MNT_RESTORING);
1532 newtResume();
1533 }
1534 }
1535 if (res) {
1536 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1537 log_to_screen
1538 ("GRUB ran w/error(s). See %s for more info.", MONDO_LOGFILE);
1539 log_msg(1, "Type:-");
1540 log_msg(1, " mr-mount-me");
1541 log_msg(1, " chroot " MNT_RESTORING);
1542 log_msg(1, " mount /boot if needed");
1543 log_msg(1, " grub-install '(hd0)'");
1544 log_msg(1, " exit");
1545 log_msg(1, " mr-unmount-me");
1546 log_msg(1,
1547 "If you're really stuck, please e-mail the mailing list.");
1548 } else {
1549 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1550 }
1551 paranoid_free(boot_device);
1552
1553 return (res);
1554}
1555
1556/**************************************************************************
1557 *END_RUN_GRUB *
1558 **************************************************************************/
1559
1560
1561/**
1562 * Install ELILO on the user's boot drive (determined by elilo.conf).
1563 * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
1564 * @return 0 for success, nonzero for failure.
1565 */
1566int run_elilo(bool offer_to_run_stabelilo)
1567{
1568 /** malloc **/
1569 char *command = NULL;
1570 char *tmp = NULL;
1571 char *editor = NULL;
1572
1573 int res;
1574 int done;
1575
1576 if (offer_to_run_stabelilo
1577 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
1578
1579 /* interactive mode */
1580 {
1581 mvaddstr_and_log_it(g_currentY,
1582 0,
1583 "Modifying fstab and elilo.conf... ");
1584 mr_asprintf(command, "mr-stabelilo-me");
1585 res = run_program_and_log_output(command, 3);
1586 mr_free(command);
1587
1588 if (res) {
1589 popup_and_OK
1590 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
1591 for (done = FALSE; !done;) {
1592 if (!g_text_mode) {
1593 newtSuspend();
1594 }
1595 mr_asprintf(editor, "%s", find_my_editor());
1596
1597 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
1598 paranoid_system(tmp);
1599 mr_free(tmp);
1600
1601 mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
1602 paranoid_system(tmp);
1603 mr_free(tmp);
1604 mr_free(editor);
1605
1606 if (!g_text_mode) {
1607 newtResume();
1608 }
1609// newtCls();
1610 if (ask_me_yes_or_no("Edit them again?")) {
1611 continue;
1612 }
1613 done = TRUE;
1614 }
1615 } else {
1616 log_to_screen("elilo.conf and fstab were modified OK");
1617 }
1618 } else
1619 /* nuke mode */
1620 {
1621 res = TRUE;
1622 }
1623 return (res);
1624}
1625
1626/**************************************************************************
1627 *END_RUN_ELILO *
1628 **************************************************************************/
1629
1630
1631/**
1632 * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
1633 * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
1634 * @return 0 for success, nonzero for failure.
1635 */
1636int run_lilo(bool offer_to_run_stablilo)
1637{
1638 /** malloc **/
1639 char *command = NULL;
1640 char *tmp = NULL;
1641 char *editor = NULL;
1642
1643 int res;
1644 int done;
1645 bool run_lilo_M = FALSE;
1646
1647 if (!run_program_and_log_output
1648 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
1649 run_lilo_M = TRUE;
1650 }
1651
1652 if (offer_to_run_stablilo
1653 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
1654
1655 /* interactive mode */
1656 {
1657 mvaddstr_and_log_it(g_currentY,
1658 0,
1659 "Modifying fstab and lilo.conf, and running LILO... ");
1660 mr_asprintf(command, "mr-stablilo-me");
1661 res = run_program_and_log_output(command, 3);
1662 mr_free(command);
1663
1664 if (res) {
1665 popup_and_OK
1666 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
1667 for (done = FALSE; !done;) {
1668 if (!g_text_mode) {
1669 newtSuspend();
1670 }
1671 mr_asprintf(editor, "%s", find_my_editor());
1672
1673 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1674 paranoid_system(tmp);
1675 mr_free(tmp);
1676
1677 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
1678 paranoid_system(tmp);
1679 mr_free(tmp);
1680 mr_free(editor);
1681
1682 if (!g_text_mode) {
1683 newtResume();
1684 }
1685// newtCls();
1686 if (ask_me_yes_or_no("Edit them again?")) {
1687 continue;
1688 }
1689 res =
1690 run_program_and_log_output("chroot " MNT_RESTORING
1691 " lilo -L", 3);
1692 if (res) {
1693 res =
1694 run_program_and_log_output("chroot " MNT_RESTORING
1695 " lilo", 3);
1696 }
1697 if (res) {
1698 done =
1699 ask_me_yes_or_no
1700 ("LILO failed. Re-edit system files?");
1701 } else {
1702 done = TRUE;
1703 }
1704 }
1705 } else {
1706 log_to_screen("lilo.conf and fstab were modified OK");
1707 }
1708 } else
1709 /* nuke mode */
1710 {
1711 mvaddstr_and_log_it(g_currentY,
1712 0,
1713 "Running LILO... ");
1714 res =
1715 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
1716 3);
1717 if (res) {
1718 res =
1719 run_program_and_log_output("chroot " MNT_RESTORING " lilo",
1720 3);
1721 }
1722 if (res) {
1723 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1724 log_to_screen
1725 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
1726 } else {
1727 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1728 }
1729 }
1730 if (run_lilo_M) {
1731 run_program_and_log_output("chroot " MNT_RESTORING
1732 " lilo -M /dev/hda", 3);
1733 run_program_and_log_output("chroot " MNT_RESTORING
1734 " lilo -M /dev/sda", 3);
1735 }
1736 return (res);
1737}
1738
1739/**************************************************************************
1740 *END_RUN_LILO *
1741 **************************************************************************/
1742
1743
1744/**
1745 * Install a raw MBR onto @p bd.
1746 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1747 * @param bd The device to copy the stored MBR to.
1748 * @return 0 for success, nonzero for failure.
1749 */
1750int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
1751{
1752 /** malloc **/
1753 char *command = NULL;
1754 char *boot_device = NULL;
1755 char *tmp = NULL;
1756 char *editor;
1757 int res;
1758 int done;
1759
1760 malloc_string(boot_device);
1761 assert_string_is_neither_NULL_nor_zerolength(bd);
1762
1763 strcpy(boot_device, bd);
1764
1765 if (offer_to_hack_scripts
1766 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
1767 /* interactive mode */
1768 mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab and restoring MBR... ");
1769 for (done = FALSE; !done;) {
1770 if (!run_program_and_log_output("which vi", FALSE)) {
1771 popup_and_OK("You will now edit fstab");
1772 if (!g_text_mode) {
1773 newtSuspend();
1774 }
1775 mr_asprintf(editor, "%s", find_my_editor());
1776 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1777 mr_free(editor);
1778
1779 paranoid_system(tmp);
1780 mr_free(tmp);
1781 if (!g_text_mode) {
1782 newtResume();
1783 }
1784 }
1785 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4);
1786 mr_asprintf(command, "mr-stabraw-me %s", boot_device);
1787 res = run_program_and_log_output(command, 3);
1788 mr_free(command);
1789
1790 if (res) {
1791 done = ask_me_yes_or_no("Modifications failed. Re-try?");
1792 } else {
1793 done = TRUE;
1794 }
1795 }
1796 } else {
1797 /* nuke mode */
1798 mr_asprintf(command, "mr-raw %s /"MOUNTLIST_FNAME_STUB, boot_device);
1799 log_msg(2, "run_raw_mbr() --- command='%s'", command);
1800
1801 mvaddstr_and_log_it(g_currentY, 0, "Restoring MBR... ");
1802 res = run_program_and_log_output(command, 3);
1803 mr_free(command);
1804 }
1805 if (res) {
1806 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1807 log_to_screen("MBR+fstab processed w/error(s). See %s for more info.", MONDO_LOGFILE);
1808 } else {
1809 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1810 }
1811 paranoid_free(boot_device);
1812 return (res);
1813}
1814
1815/**************************************************************************
1816 *END_RUN_RAW_MBR *
1817 **************************************************************************/
1818
1819
1820
1821/**
1822 * malloc() and set sensible defaults for the mondorestore filename variables.
1823 * @param bkpinfo The backup information structure. Fields used:
1824 * - @c bkpinfo->tmpdir
1825 * - @c bkpinfo->disaster_recovery
1826 */
1827void setup_MR_global_filenames()
1828{
1829 assert(bkpinfo != NULL);
1830
1831 malloc_string(g_biggielist_txt);
1832 malloc_string(g_filelist_full);
1833 malloc_string(g_filelist_imagedevs);
1834 malloc_string(g_imagedevs_restthese);
1835 malloc_string(g_mondo_cfg_file);
1836 malloc_string(g_mountlist_fname);
1837 malloc_string(g_mondo_home);
1838 malloc_string(g_isodir_device);
1839 malloc_string(g_isodir_format);
1840
1841 sprintf(g_biggielist_txt, "%s/%s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB);
1842 sprintf(g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB);
1843 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", bkpinfo->tmpdir);
1844// sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", bkpinfo->tmpdir);
1845 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
1846 bkpinfo->tmpdir);
1847 if (bkpinfo->disaster_recovery) {
1848 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
1849 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
1850 } else {
1851 sprintf(g_mondo_cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
1852 sprintf(g_mountlist_fname, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
1853 }
1854}
1855
1856/**************************************************************************
1857 *END_SET_GLOBAL_FILENAME *
1858 **************************************************************************/
1859
1860
1861/**
1862 * Copy @p input_file (containing the result of a compare) to @p output_file,
1863 * deleting spurious "changes" along the way.
1864 * @param output_file The output file to write with spurious changes removed.
1865 * @param input_file The input file, a list of changed files created by a compare.
1866 */
1867void streamline_changes_file(char *output_file, char *input_file)
1868{
1869 FILE *fin;
1870 FILE *fout;
1871 char *incoming = NULL;
1872
1873 assert_string_is_neither_NULL_nor_zerolength(output_file);
1874 assert_string_is_neither_NULL_nor_zerolength(input_file);
1875
1876 if (!(fin = fopen(input_file, "r"))) {
1877 log_OS_error(input_file);
1878 return;
1879 }
1880 if (!(fout = fopen(output_file, "w"))) {
1881 fatal_error("cannot open output_file");
1882 }
1883 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
1884 if (strncmp(incoming, "etc/adjtime", 11)
1885 && strncmp(incoming, "etc/mtab", 8)
1886 && strncmp(incoming, "tmp/", 4)
1887 && strncmp(incoming, "boot/map", 8)
1888 && !strstr(incoming, "incheckentry")
1889 && strncmp(incoming, "etc/mail/statistics", 19)
1890 && strncmp(incoming, "var/", 4))
1891 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
1892 mr_free(incoming);
1893 }
1894 mr_free(incoming);
1895 paranoid_fclose(fout);
1896 paranoid_fclose(fin);
1897}
1898
1899/**************************************************************************
1900 *END_STREAMLINE_CHANGES_FILE *
1901 **************************************************************************/
1902
1903
1904/**
1905 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
1906 */
1907void twenty_seconds_til_yikes()
1908{
1909 int i;
1910 /* MALLOC * */
1911 char *tmp = NULL;
1912
1913 if (does_file_exist("/tmp/NOPAUSE")) {
1914 return;
1915 }
1916 open_progress_form("CAUTION",
1917 "Be advised: I am about to ERASE your hard disk(s)!",
1918 "You may press Ctrl+Alt+Del to abort safely.",
1919 "", 20);
1920 for (i = 0; i < 20; i++) {
1921 g_current_progress = i;
1922 mr_asprintf(tmp, "You have %d seconds left to abort.", 20 - i);
1923 update_progress_form(tmp);
1924 mr_free(tmp);
1925 sleep(1);
1926 }
1927 close_progress_form();
1928}
1929
1930/**************************************************************************
1931 *END_TWENTY_SECONDS_TIL_YIKES *
1932 **************************************************************************/
1933
1934
1935/**
1936 * Unmount all devices in @p p_external_copy_of_mountlist.
1937 * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
1938 * @return 0 for success, nonzero for failure.
1939 */
1940int unmount_all_devices(struct mountlist_itself
1941 *p_external_copy_of_mountlist)
1942{
1943 struct mountlist_itself *mountlist;
1944 int retval = 0, lino, res = 0, i;
1945 char *command = NULL;
1946 char *tmp = NULL;
1947
1948 assert(p_external_copy_of_mountlist != NULL);
1949
1950 mountlist = malloc(sizeof(struct mountlist_itself));
1951 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
1952 sort_mountlist_by_mountpoint(mountlist, 0);
1953
1954 run_program_and_log_output("df -m -P -T", 3);
1955 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
1956 open_progress_form("Unmounting devices", "Unmounting all devices that were mounted,", "in preparation for the post-restoration reboot.", "", mountlist->entries);
1957 if (chdir("/")) {
1958 // FIXME
1959 }
1960 for (i = 0; i < 10 && run_program_and_log_output("ps | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++) {
1961 sleep(1);
1962 log_msg(2, "Waiting for buffer() to finish");
1963 }
1964
1965 sync();
1966
1967 /* after that what is logged is not copied on disk, typically the result of labelling */
1968 mr_asprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
1969 if (run_program_and_log_output(tmp, FALSE)) {
1970 log_msg(1, "Error. Failed to copy log to the machine's /var/log dir. (Mounted read-only?)");
1971 }
1972 paranoid_free(tmp);
1973 if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
1974 run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5);
1975 }
1976
1977 /* Unmounting the local /proc and /sys first */
1978 run_program_and_log_output("umount -d " MNT_RESTORING "/proc",3);
1979 run_program_and_log_output("umount -d " MNT_RESTORING "/sys",3);
1980
1981 /* Unmounting potential btrfs subvolumes */
1982 if (does_file_exist("/tmp/umount-btrfs-subvol")) {
1983 run_program_and_log_output("/tmp/umount-btrfs-subvol",3);
1984 }
1985
1986 for (lino = mountlist->entries - 1; lino >= 0; lino--) {
1987 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
1988 continue;
1989 }
1990 mr_asprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
1991 update_progress_form(tmp);
1992
1993 //TODO: this should be done in a certain order normally if there are cascading mount
1994 if (is_this_device_mounted(mountlist->el[lino].device)) {
1995 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
1996 mr_asprintf(command, "swapoff %s", mountlist->el[lino].device);
1997 } else {
1998 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
1999 mr_asprintf(command, "umount -d %s/", MNT_RESTORING);
2000 log_msg(3,
2001 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
2002 } else {
2003 mr_asprintf(command, "umount -d " MNT_RESTORING "%s", mountlist->el[lino].mountpoint);
2004
2005 /* To support latest Ubuntu where /var is a separate FS
2006 * Cf: http://linux.derkeiler.com/Mailing-Lists/Ubuntu/2007-04/msg01319.html
2007 * we need to create some dirs under the real / before unmounting it */
2008 if (!strcmp(mountlist->el[lino].mountpoint, "/")) {
2009 run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/lock", FALSE);
2010 run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run", FALSE);
2011 }
2012 }
2013 }
2014 log_msg(10, "The 'umount' command is '%s'", command);
2015 res = run_program_and_log_output(command, 3);
2016 mr_free(command);
2017 } else {
2018 mr_strcat(tmp, "...not mounted anyway :-) OK");
2019 res = 0;
2020 }
2021 g_current_progress++;
2022 if (res) {
2023 mr_strcat(tmp, "...Failed");
2024 retval++;
2025 log_to_screen(tmp);
2026 } else {
2027 log_msg(2, tmp);
2028 }
2029 paranoid_free(tmp);
2030 }
2031 close_progress_form();
2032 if (retval) {
2033 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2034 } else {
2035 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2036 }
2037 if (retval) {
2038 log_to_screen("Unable to unmount some of your partitions.");
2039 } else {
2040 log_to_screen("All partitions were unmounted OK.");
2041 }
2042 mr_asprintf(command, "mount");
2043 log_msg(4, "mount result after unmounting all FS", command);
2044 (void)run_program_and_log_output(command, 3);
2045 mr_free(command);
2046 free(mountlist);
2047 return (retval);
2048}
2049
2050/**************************************************************************
2051 *END_UNMOUNT_ALL_DEVICES *
2052 **************************************************************************/
2053
2054/**
2055 * Extract mondorestore.cfg and the mountlist from the tape inserted
2056 * to the ./tmp/ directory.
2057 * @param dev The tape device to read from.
2058 * @return 0 for success, nonzero for failure.
2059 */
2060int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
2061{
2062 char *command = NULL;
2063 int res = 0;
2064
2065 if (bkpinfo->use_obdr) {
2066 skip_obdr();
2067 } else {
2068 // TODO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
2069 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
2070 }
2071
2072 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
2073 log_msg(2, "command = '%s'", command);
2074 res = run_program_and_log_output(command, -1);
2075 mr_free(command);
2076
2077 if (res != 0) {
2078 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2079 res = 0;
2080 } else {
2081 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
2082 log_msg(2, "pre-2.2.4 compatible mode on");
2083 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
2084 log_msg(2, "command = '%s'", command);
2085 res = run_program_and_log_output(command, -1);
2086 mr_free(command);
2087 if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) {
2088 res = 0;
2089 }
2090 }
2091 }
2092 paranoid_free(command);
2093 return (res);
2094}
2095
2096
2097/**
2098 * Get the configuration file from the tape, or CD.
2099 * @param bkpinfo The backup information structure. Fields used:
2100 * - @c bkpinfo->backup_media_type
2101 * - @c bkpinfo->media_device
2102 * - @c bkpinfo->tmpdir
2103 * @return 0 for success, nonzero for failure.
2104 */
2105int get_cfg_file_from_archive()
2106{
2107 int retval = 0;
2108
2109 /** malloc *****/
2110 char *command = NULL;
2111 char *cfg_file = NULL;
2112 char *tmp = NULL;
2113 char *tmp1 = NULL;
2114 char *mountpt = NULL;
2115 char *mountlist_file = NULL;
2116 bool extract_mountlist_stub = FALSE;
2117 bool extract_i_want_my_lvm = FALSE;
2118
2119 bool try_plan_B;
2120
2121 assert(bkpinfo != NULL);
2122 log_msg(2, "gcffa --- starting");
2123 log_to_screen("I'm thinking...");
2124 mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
2125 if (chdir(bkpinfo->tmpdir)) {
2126 // FIXME
2127 }
2128 mr_asprintf(cfg_file, "%s", MONDO_CFG_FILE_STUB);
2129 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
2130 mr_free(cfg_file);
2131
2132 unlink(FILELIST_FULL_STUB);
2133 unlink(BIGGIELIST_TXT_STUB);
2134 mr_asprintf(command, "mkdir -p %s", mountpt);
2135 run_program_and_log_output(command, FALSE);
2136 mr_free(command);
2137
2138 mr_asprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
2139 mr_asprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2140 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
2141 mr_free(mountpt);
2142
2143 if (!does_file_exist(cfg_file)) {
2144 log_msg(2, "gcffa --- we don't have cfg file yet.");
2145 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2146 try_plan_B = TRUE;
2147 } else {
2148 log_msg(2, "gcffa --- calling mount_media now :)");
2149 if (!mount_media()) {
2150 log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B");
2151 try_plan_B = FALSE;
2152 } else {
2153 try_plan_B = TRUE;
2154 }
2155 if (what_number_cd_is_this() > 1) {
2156 insist_on_this_cd_number((g_current_media_number = 1));
2157 }
2158 }
2159 if (try_plan_B) {
2160 log_msg(2, "gcffa --- OK, switching to Plan B");
2161 if (chdir(bkpinfo->tmpdir)) {
2162 // FIXME
2163 }
2164 run_program_and_log_output("mkdir -p tmp", FALSE);
2165
2166 if (bkpinfo->media_device == NULL) {
2167 mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
2168 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device);
2169 }
2170 mr_asprintf(tmp, "%s", bkpinfo->media_device);
2171 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
2172 mr_free(bkpinfo->media_device);
2173 mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
2174 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
2175 mr_free(bkpinfo->media_device);
2176 mr_asprintf(bkpinfo->media_device, "%s", "/dev/osst0");
2177 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
2178 mr_free(bkpinfo->media_device);
2179 mr_asprintf(bkpinfo->media_device, "%s", "/dev/ht0");
2180 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
2181 log_msg(3, "I tried lots of devices but none worked.");
2182 mr_free(bkpinfo->media_device);
2183 }
2184 }
2185 }
2186 }
2187 if (bkpinfo->media_device == NULL) {
2188 bkpinfo->media_device = tmp;
2189 } else {
2190 mr_free(tmp);
2191 }
2192
2193 if (!does_file_exist("tmp/mondorestore.cfg")) {
2194 log_to_screen("Cannot find config info on media");
2195 return (1);
2196 }
2197 } else {
2198 if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
2199 extract_mountlist_stub = FALSE;
2200 } else {
2201 extract_mountlist_stub = TRUE;
2202 }
2203 if (does_file_exist("/"IWANTMYLVM_STUB)) {
2204 extract_i_want_my_lvm = FALSE;
2205 } else {
2206 extract_i_want_my_lvm = TRUE;
2207 }
2208
2209 log_msg(2, "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
2210 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
2211 run_program_and_log_output(command, TRUE);
2212 mr_free(command);
2213
2214 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2215 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
2216 log_msg(2, "pre-2.2.4 compatible mode on");
2217 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
2218 run_program_and_log_output(command, TRUE);
2219 mr_free(command);
2220 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2221 fatal_error
2222 ("Please reinsert the disk/CD and try again.");
2223 }
2224 }
2225 }
2226 }
2227 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2228 log_msg(1, "gcffa --- great! We've got the config file");
2229 tmp1 = call_program_and_get_last_line_of_output("pwd");
2230 mr_asprintf(tmp, "%s/%s", tmp1, MONDO_CFG_FILE_STUB);
2231 mr_asprintf(command, "cp -f %s %s", tmp, cfg_file);
2232 log_it("%s",command);
2233 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
2234 log_msg(1,
2235 "... but an error occurred when I tried to move it to %s",
2236 cfg_file);
2237 } else {
2238 log_msg(1, "... and I moved it successfully to %s", cfg_file);
2239 }
2240 mr_free(command);
2241
2242 mr_asprintf(command, "cp -f %s/%s %s", tmp1, MOUNTLIST_FNAME_STUB, mountlist_file);
2243 mr_free(tmp1);
2244 log_it("%s",command);
2245 if (extract_mountlist_stub) {
2246 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
2247 log_msg(1, "Failed to get mountlist");
2248 } else {
2249 log_msg(1, "Got mountlist too");
2250 mr_free(command);
2251 mr_asprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);
2252 if (run_program_and_log_output(command, 1)) {
2253 log_msg(1, "Failed to copy mountlist to /tmp");
2254 } else {
2255 log_msg(1, "Copied mountlist to /tmp as well OK");
2256 mr_free(command);
2257 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
2258 run_program_and_log_output(command, 1);
2259 }
2260 }
2261 }
2262 mr_free(command);
2263 mr_free(tmp);
2264 }
2265
2266 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2267 if (!does_file_exist(cfg_file)) {
2268 log_it("%s",cfg_file);
2269 log_msg(1, "%s not found", cfg_file);
2270 log_to_screen("Oh dear. Unable to recover configuration file from boot disk");
2271 return (1);
2272 }
2273
2274 log_to_screen("Recovered mondorestore.cfg");
2275 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
2276 log_to_screen("...but not mountlist.txt - a pity, really...");
2277 } else {
2278 /* Is this code really useful ??? */
2279 if (extract_mountlist_stub) {
2280 mr_asprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2281 run_program_and_log_output(command, FALSE);
2282 mr_free(command);
2283 }
2284 }
2285
2286 mr_asprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
2287 mr_free(cfg_file);
2288
2289 run_program_and_log_output(command, FALSE);
2290 mr_free(command);
2291
2292 if (extract_mountlist_stub) {
2293 mr_asprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
2294 run_program_and_log_output(command, FALSE);
2295 mr_free(command);
2296 }
2297 mr_free(mountlist_file);
2298
2299 mr_asprintf(command, "cp -f etc/raidtab /etc/");
2300 run_program_and_log_output(command, FALSE);
2301 mr_free(command);
2302
2303 if (extract_i_want_my_lvm) {
2304 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
2305 run_program_and_log_output(command, FALSE);
2306 mr_free(command);
2307 }
2308 g_backup_media_type = bkpinfo->backup_media_type;
2309 return (retval);
2310}
2311
2312/**************************************************************************
2313 *END_GET_CFG_FILE_FROM_ARCHIVE *
2314 **************************************************************************/
2315
2316/* @} - end restoreUtilityGroup */
2317
2318void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage)
2319{
2320 struct raidlist_itself *raidlist;
2321 int unfinished_mdstat_devices = 9999;
2322 int i = 0;
2323 char *screen_message = NULL;
2324
2325 raidlist = malloc(sizeof(struct raidlist_itself));
2326
2327 assert(wait_for_percentage <= 100);
2328 log_it("wait_until_software_raids_are_prepped");
2329 while (unfinished_mdstat_devices > 0) {
2330 // FIXME: Prefix '/dev/' should really be dynamic!
2331 if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
2332 log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
2333 log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
2334 return;
2335 }
2336 for (unfinished_mdstat_devices = 0; i <= raidlist->entries; i++) {
2337 if (raidlist->el[i].progress < wait_for_percentage) {
2338 unfinished_mdstat_devices++;
2339 if (raidlist->el[i].progress == -1) // delayed while another partition inits
2340 {
2341 continue;
2342 }
2343 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
2344 mr_asprintf(screen_message, "Sync'ing %s", raidlist->el[i].raid_device);
2345 open_evalcall_form(screen_message);
2346 mr_free(screen_message);
2347
2348 while (raidlist->el[i].progress < wait_for_percentage) {
2349 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
2350 update_evalcall_form(raidlist->el[i].progress);
2351 sleep(2);
2352 // FIXME: Prefix '/dev/' should really be dynamic!
2353 if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
2354 break;
2355 }
2356 }
2357 close_evalcall_form();
2358 }
2359 }
2360 }
2361 paranoid_free(raidlist);
2362}
Note: See TracBrowser for help on using the repository browser.