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

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

remove differentiated support for cdrw

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