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

Last change on this file since 3849 was 3839, checked in by Bruno Cornec, 4 months ago

Fix compiler errors

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