source: MondoRescue/trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c@ 127

Last change on this file since 127 was 127, checked in by bcornec, 18 years ago

merge -r 125:126 $SVN_M/branches/2.05

  • Property svn:keywords set to Id
File size: 80.5 KB
Line 
1/***************************************************************************
2mondo-rstr-tools.c - description
3-----------------
4
5begin: Sun Sep 21 16:40:35 EDT 2003
6copyright : (C) 2002 Mondo Hugo Rabson
7email : Hugo Rabson <hugorabson@msn.com>
8edited by : by Stan Benoit ?/2003
9email : troff@nakedsoul.org
10cvsid : $Id: mondo-rstr-tools.c
11***************************************************************************/
12
13/***************************************************************************
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
19 * *
20 ***************************************************************************/
21/* mondo-rstr-tools.c Hugo Rabson
22
23
2407/27
25- if the user is foolish enough to use /dev/md0 as boot device,
26 call lilo -M /dev/hda to make sure lilo does its job properly
27- better NFS+nuke support
28
2907/20
30- use backup's i-want-my-lvm file
31- be sure to use archives' raidtab when restoring
32
3307/18
34- use /tmp/isodir for NFS if DR mode
35- better support of users who boot from LVM CD and nuke-restore non-LVM backups
36
3707/12
38- bugfix to allow user to burn ISOs to CDs and restore from CDs (not original src)
39
4006/29
41- mount ext3 partitions as ext2, just in case :)
42
4306/26
44- delete make_relevant_partition_bootable()
45
4606/19
47- futzed with the call to mount floppy, to stop it from locking up on my AMD64 system
48
4906/14
50- shell out to /mnt/RESTORING chroot in order to let user install GRUB
51 manually if automatic GRUB installation fails
52
5306/15
54- Added check for different 'isodir' chosen by user than stored in the archive
55 Conor Daly <conor.daly@met.ie>
56
5704/17
58- replaced INTERNAL_TAPE_BLK_SIZE with bkpinfo->internal_tape_block_size
59
6004/09
61- don't try to mount CD if tape bkp
62
6304/03
64- trying to copy tmp/mondo-restore.cfg to itself - silly! - fixed
65
6604/02
67- when extracting cfg file and mountlist from all.tar.gz (tape copy),
68 use block size of INTERNAL_TAPE_BLK_SIZE, not TAPE_BLOCK_SIZE
69
7002/21
71- don't use 'mv -v' cos Busybox won't support it
72
7302/09
74- make hole for cfg file before moving it (line 2094 or so)
75
7602/03
77- changed a couple of refs to filelist.full, to filelist.full.gz
78
7901/16/2004
80- instead of copying filelist, use 'ln -sf' to link to original;
81 saves space
82
8311/20/2003
84- also retrieve /tmp/mountlist.txt if user wants
85
8611/16
87- fixed NFS path bug affecting the extractions of filelist/biggielist
88 during selective restore
89
9011/02
91- fixed mount_cdrom() to run properly w/ nfs restores
92- mount_device() returns 0 if swap mount fails cos swap isn't crucial
93
9410/17
95- run_grub() uses MNT_RESTORING instead of "/mnt/RESTORING"
96
9710/26
98- cleaned up run_grub()
99
10010/25
101- fixed mount_cdrom() to run properly w/ nfs restores
102
10310/21
104- mount_device() returns 0 if swap mount fails cos swap isn't crucial
105
10610/15
107- run_grub() now uses its initiative instead
108 of calling grub-install
109
11010/10
111- don't leave copies of filelist.full lying around, clogging up
112 the ramdisk, there's a good fellow :-)
113
11410/02
115- added 'dvd' to the range of media types I'll understand
116- fixed iso->cdr problem (thanks, Stan Benoit & Fred Beondo)
117
11809/24
119- try lots of tape devs if /dev/st0 fails
120
12109/23/2003
122- first incarnation
123*/
124
125
126#include "../common/my-stuff.h"
127#include "../common/mondostructures.h"
128#include "../common/libmondo.h"
129#include "mr-externs.h"
130//#include "mondo-restore.h"
131//#include "mondo-rstr-compare-EXT.h"
132#include "mondo-rstr-tools.h"
133#include <pthread.h>
134
135extern bool g_sigpipe_caught;
136extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
137extern bool g_I_have_just_nuked;
138extern char *g_tmpfs_mountpt;
139extern char *g_isodir_device;
140extern char *g_isodir_format;
141extern long g_current_progress, g_maximum_progress;
142extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir;
143 // biggielist.txt is the list of big files stored on the
144 // backup media set in question
145extern char *g_filelist_full; // filelist.full.gz is the list of all regular files
146 // (excluding big files) stored on the backup media set
147extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the
148 // user chooses them
149extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
150 // were archived as images, not just /dev entries
151 // ... e.g. NTFS, BeOS partitions
152extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
153 // restore only these
154extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored
155extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
156extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo
157extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS;
158
159extern t_bkptype g_backup_media_type;
160
161extern int g_partition_table_locked_up;
162
163/**
164 * @addtogroup restoreUtilityGroup
165 * @{
166 */
167/**
168 * Free the malloc()s for the filename variables.
169 */
170void free_MR_global_filenames()
171{
172 paranoid_free(g_biggielist_txt);
173 paranoid_free(g_filelist_full);
174 paranoid_free(g_filelist_imagedevs);
175// paranoid_free (g_imagedevs_pot );
176 paranoid_free(g_imagedevs_restthese);
177 paranoid_free(g_mondo_cfg_file);
178 paranoid_free(g_mountlist_fname);
179 paranoid_free(g_mondo_home);
180 paranoid_free(g_tmpfs_mountpt);
181 paranoid_free(g_isodir_device);
182 paranoid_free(g_isodir_format);
183
184}
185
186
187
188/**
189 * Ask the user which imagedevs from the list contained in @p infname should
190 * actually be restored.
191 * @param infname The file containing a list of all imagedevs.
192 * @param outfname The location of the output file containing the imagedevs the user wanted to restore.
193 * @ingroup restoreUtilityGroup
194 */
195void ask_about_these_imagedevs(char *infname, char *outfname)
196{
197 FILE *fin;
198 FILE *fout;
199 /************************************************************************
200 * allocate memory regions. test and set -sab 16 feb 2003 *
201 ************************************************************************/
202 char *incoming_ptr;
203 char *question_ptr;
204
205 char incoming[MAX_STR_LEN];
206 char question[MAX_STR_LEN];
207
208 assert_string_is_neither_NULL_nor_zerolength(infname);
209 assert_string_is_neither_NULL_nor_zerolength(outfname);
210
211 incoming_ptr = malloc(sizeof(incoming));
212 if (incoming_ptr == NULL) {
213 fprintf(stderr, "Out of Memory\n");
214 exit(EXIT_FAILURE);
215 }
216
217 question_ptr = malloc(sizeof(question));
218 if (question_ptr == NULL) {
219 fprintf(stderr, "Out of Memory\n");
220 exit(EXIT_FAILURE);
221 }
222
223 memset(incoming_ptr, '\0', sizeof(incoming));
224 memset(question_ptr, '\0', sizeof(question));
225
226
227
228 if (!(fin = fopen(infname, "r"))) {
229 fatal_error("Cannot openin infname");
230 }
231 if (!(fout = fopen(outfname, "w"))) {
232 fatal_error("Cannot openin outfname");
233 }
234 for (fgets(incoming_ptr, MAX_STR_LEN, fin);
235 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
236 strip_spaces(incoming_ptr);
237
238 if (incoming[0] == '\0') {
239 continue;
240 }
241
242 sprintf(question_ptr,
243 "Should I restore the image of %s ?", incoming_ptr);
244
245 if (ask_me_yes_or_no(question_ptr)) {
246 fprintf(fout, "%s\n", incoming_ptr);
247 }
248 }
249
250 /*** free memory ***********/
251 paranoid_free(incoming_ptr);
252 incoming_ptr = NULL;
253 paranoid_free(question_ptr);
254 question_ptr = NULL;
255
256
257 paranoid_fclose(fout);
258 paranoid_fclose(fin);
259}
260
261/**************************************************************************
262 *ASK_ABOUT_THESE_IMAGEDEVS *
263 **************************************************************************/
264
265
266
267
268
269
270
271
272/**
273 * Extract @c mondo-restore.cfg and @c mountlist.txt from @p ramdisk_fname.
274 * @param bkpinfo The backup information structure. @c tmpdir is the only field used.
275 * @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
276 * @param output_cfg_file Where to put the configuration file extracted.
277 * @param output_mountlist_file Where to put the mountlist file extracted.
278 * @return 0 for success, nonzero for failure.
279 * @ingroup restoreUtilityGroup
280 */
281int
282extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
283 char *ramdisk_fname,
284 char *output_cfg_file,
285 char *output_mountlist_file)
286{
287 char *mountpt;
288 char *command;
289 char *orig_fname;
290 int retval = 0;
291
292 assert(bkpinfo != NULL);
293 malloc_string(mountpt);
294 malloc_string(command);
295 malloc_string(orig_fname);
296 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
297 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
298 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
299 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
300 sprintf(command, "mkdir -p %s", mountpt);
301 run_program_and_log_output(command, FALSE);
302 sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
303 ramdisk_fname, bkpinfo->tmpdir);
304
305 run_program_and_log_output(command, FALSE);
306 sprintf(command, "umount %s", mountpt);
307
308 run_program_and_log_output(command, FALSE);
309
310 sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
311 bkpinfo->tmpdir, mountpt);
312
313 run_program_and_log_output(command, FALSE);
314
315 sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
316
317 run_program_and_log_output(command, FALSE);
318
319 sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
320 mountpt, g_mondo_cfg_file, output_cfg_file);
321 run_program_and_log_output(command, FALSE);
322
323 sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
324 if (does_file_exist(orig_fname)) {
325 sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
326 run_program_and_log_output(command, FALSE);
327 }
328 sprintf(command, "umount %s", mountpt);
329 run_program_and_log_output(command, FALSE);
330 if (!does_file_exist(output_cfg_file)
331 || (!does_file_exist(output_mountlist_file)
332 && does_file_exist(orig_fname))) {
333 log_msg(2, "Failed to extract %s and/or %s from ramdisk",
334 output_cfg_file, output_mountlist_file);
335 retval = 1;
336 } else {
337 retval = 0;
338 }
339 paranoid_free(mountpt);
340 paranoid_free(command);
341 paranoid_free(orig_fname);
342 return (retval);
343
344}
345
346
347
348
349/**
350 * Keep trying to get mondo-restore.cfg from the archive, until the user gives up.
351 * @param bkpinfo The backup information structure.
352 */
353void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *bkpinfo)
354{
355 while (get_cfg_file_from_archive(bkpinfo)) {
356 if (!ask_me_yes_or_no
357 ("Failed to find config file/archives. Choose another source?"))
358 {
359 fatal_error("Could not find config file/archives. Aborting.");
360 }
361 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
362 }
363}
364
365
366/**
367 * Determine whether @p list_fname contains a line containing @p f.
368 * @param f The line to search for.
369 * @param list_fname The file to search in.
370 * @param preamble Ignore this beginning part of @p f ("" to disable).
371 * @return TRUE if it's in the list, FALSE if it's not.
372 */
373bool is_file_in_list(char *f, char *list_fname, char *preamble)
374{
375
376 /** needs malloc **/
377 char *command;
378 char *file;
379 char *tmp;
380 int res;
381
382 malloc_string(command);
383 malloc_string(file);
384 malloc_string(tmp);
385 assert_string_is_neither_NULL_nor_zerolength(f);
386 assert_string_is_neither_NULL_nor_zerolength(list_fname);
387 assert(preamble != NULL);
388
389 if (strncmp(preamble, f, strlen(preamble)) == 0) {
390 strcpy(file, f + strlen(preamble));
391 } else {
392 strcpy(file, f);
393 }
394 if (file[0] == '/' && file[1] == '/') {
395 strcpy(tmp, file);
396 strcpy(file, tmp + 1);
397 }
398 sprintf(tmp,
399 "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
400 f, file);
401 log_msg(2, tmp);
402 sprintf(command, "cat %s | grep -x \"%s\"", list_fname, file);
403 res = run_program_and_log_output(command, FALSE);
404 paranoid_free(command);
405 paranoid_free(file);
406 paranoid_free(tmp);
407 if (res) {
408 return (FALSE);
409 } else {
410 return (TRUE);
411 }
412}
413
414/**************************************************************************
415 *END_IS_FILE_IN_LIST *
416 **************************************************************************/
417
418
419
420/**
421 * Set up an ISO backup.
422 * @param bkpinfo The backup information structure. Fields used:
423 * - @c bkpinfo->backup_media_type
424 * - @c bkpinfo->disaster_recovery
425 * - @c bkpinfo->isodir
426 * @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
427 * @return 0 for success, nonzero for failure.
428 */
429int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please)
430{
431 char *mount_isodir_command, *tmp, *command;
432 int retval = 0, i;
433 bool already_mounted = FALSE;
434
435 assert(bkpinfo != NULL);
436 malloc_string(mount_isodir_command);
437 malloc_string(tmp);
438 malloc_string(command);
439 g_ISO_restore_mode = TRUE;
440 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
441 if (bkpinfo->disaster_recovery) {
442/* Patch Conor Daly 26-june-2004
443 * Don't let this clobber an existing bkpinfo->isodir */
444 if (!bkpinfo->isodir[0]) {
445 strcpy(bkpinfo->isodir, "/tmp/isodir");
446 }
447/* End patch */
448 sprintf(command, "mkdir -p %s", bkpinfo->isodir);
449 run_program_and_log_output(command, 5);
450 log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
451 }
452
453 if (!get_isodir_info
454 (g_isodir_device, g_isodir_format, bkpinfo->isodir,
455 nuke_me_please)) {
456 return (1);
457 }
458 paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */
459
460 if (is_this_device_mounted(g_isodir_device)) {
461 log_to_screen("WARNING - isodir is already mounted");
462 already_mounted = TRUE;
463 } else {
464 sprintf(mount_isodir_command, "mount %s", g_isodir_device);
465 if (strlen(g_isodir_format) > 1) {
466 sprintf(mount_isodir_command + strlen(mount_isodir_command),
467 " -t %s", g_isodir_format);
468 }
469 strcat(mount_isodir_command, " -o ro ");
470 strcat(mount_isodir_command, bkpinfo->isodir);
471 run_program_and_log_output("df -m", FALSE);
472 sprintf(tmp,
473 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
474 mount_isodir_command);
475 log_msg(1, tmp);
476 if (run_program_and_log_output(mount_isodir_command, FALSE)) {
477 popup_and_OK
478 ("Cannot mount the device where the ISO files are stored.");
479 return (1);
480 }
481 log_to_screen
482 ("I have mounted the device where the ISO files are stored.");
483 }
484 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
485 mount_cdrom(bkpinfo);
486 }
487 i = what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */
488 sprintf(tmp, "%s #%d has been mounted via loopback mount",
489 media_descriptor_string(bkpinfo->backup_media_type), i);
490 log_msg(1, tmp);
491 if (i < 0) {
492 popup_and_OK
493 ("Cannot find ISO images in the directory you specified.");
494 retval = 1;
495 }
496 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
497 bkpinfo->isodir);
498 paranoid_free(mount_isodir_command);
499 paranoid_free(tmp);
500 paranoid_free(command);
501 return (retval);
502}
503
504
505
506
507/**
508 * Kill all Petris processes.
509 */
510void kill_petris(void)
511{
512 char *command;
513 malloc_string(command);
514 sprintf(command,
515 "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
516 paranoid_system(command);
517 paranoid_free(command);
518}
519
520/**************************************************************************
521 *END_KILL_PETRIS *
522 **************************************************************************/
523
524
525/**
526 * (Disabled) Modify rc.local to fix some things on first boot.
527 * This function currently doesn't do anything except make sure /tmp has the
528 * right permissions.
529 * @param path The path to /etc on the user's filesystem.
530 * @return 0 for success, nonzero for failure.
531 */
532int modify_rclocal_one_time(char *path)
533{
534 /** malloc **/
535 char *rclocal_fname;
536 char *newfile_fname;
537 char *tmp;
538
539 malloc_string(rclocal_fname);
540 malloc_string(newfile_fname);
541 malloc_string(tmp);
542 assert_string_is_neither_NULL_nor_zerolength(path);
543
544 sprintf(rclocal_fname, "%s/rc.local", path);
545
546// sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING);
547// run_program_and_log_output( tmp, FALSE );
548 return (0); /* remove this line to open the floodgates... */
549
550 if (!does_file_exist(rclocal_fname)) {
551 sprintf(rclocal_fname, "%s/rc.d/rc.local", path);
552 }
553 if (!does_file_exist(rclocal_fname)) {
554 paranoid_free(rclocal_fname);
555 paranoid_free(newfile_fname);
556 paranoid_free(tmp);
557 return (1);
558 }
559 sprintf(newfile_fname, "%s/rc.local.mondorescue", path);
560 sprintf(tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null",
561 rclocal_fname);
562 if (system(tmp)) {
563 sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",
564 newfile_fname, newfile_fname, rclocal_fname);
565
566 paranoid_system(tmp);
567 }
568 sprintf(tmp, "echo -en \"#!/bin/sh\
569\\n\
570\\n\
571cat %s | grep -v mondorescue > %s\\n\
572rm -f /var/lock/subsys/*xfs*\\n\
573rm -f /var/run/xfs.*\\n\
574killall xfs\\n\
575service xfs start\\n\
576yes | rm -f %s\\n\
577\" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname);
578 sprintf(tmp, "chmod +x \"%s\"", newfile_fname);
579 run_program_and_log_output(tmp, FALSE);
580 paranoid_free(rclocal_fname);
581 paranoid_free(newfile_fname);
582 paranoid_free(tmp);
583 return (0);
584}
585
586/**************************************************************************
587 *END_ MODIFY_RCLOCAL_ONE_TIME *
588 **************************************************************************/
589
590
591
592
593
594/**
595 * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
596 * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
597 * @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
598 * @return The number of errors encountered (0 for success).
599 */
600int mount_all_devices(struct mountlist_itself
601 *p_external_copy_of_mountlist, bool writeable)
602{
603 int retval = 0, lino, res;
604 char *tmp, *these_failed, *format;
605 struct mountlist_itself *mountlist;
606
607 malloc_string(tmp);
608 malloc_string(format);
609 malloc_string(these_failed);
610 assert(p_external_copy_of_mountlist != NULL);
611 mountlist = malloc(sizeof(struct mountlist_itself));
612 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
613 sizeof(struct mountlist_itself));
614 sort_mountlist_by_mountpoint(mountlist, 0);
615
616 /** menset **/
617 these_failed[0] = '\0';
618
619 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices ");
620 open_progress_form("Mounting devices",
621 "I am now mounting all the drives.",
622 "This should not take long.",
623 "", mountlist->entries);
624
625 for (lino = 0; lino < mountlist->entries; lino++) {
626 if (!strcmp(mountlist->el[lino].device, "/proc")) {
627 log_msg(1,
628 "Again with the /proc - why is this in your mountlist?");
629 } else if (is_this_device_mounted(mountlist->el[lino].device)) {
630 sprintf(tmp, "%s is already mounted",
631 mountlist->el[lino].device);
632 log_to_screen(tmp);
633 } else if (strcmp(mountlist->el[lino].mountpoint, "none")
634 && strcmp(mountlist->el[lino].mountpoint, "lvm")
635 && strcmp(mountlist->el[lino].mountpoint, "raid")
636 && strcmp(mountlist->el[lino].mountpoint, "image")) {
637 sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
638 update_progress_form(tmp);
639 strcpy(format, mountlist->el[lino].format);
640 if (!strcmp(format, "ext3")) {
641 strcpy(format, "ext2");
642 }
643 res = mount_device(mountlist->el[lino].device,
644 mountlist->el[lino].mountpoint,
645 format, writeable);
646 retval += res;
647 if (res) {
648 strcat(these_failed, mountlist->el[lino].device);
649 strcat(these_failed, " ");
650 }
651 }
652 g_current_progress++;
653 }
654 close_progress_form();
655 run_program_and_log_output("df -m", TRUE);
656 if (retval) {
657 if (g_partition_table_locked_up > 0) {
658 log_to_screen
659 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
660 log_to_screen
661 ("lock up the partition table. You might have to reboot and use Interactive Mode to");
662 log_to_screen
663 ("format and restore *without* partitioning first. Sorry for the inconvenience.");
664 }
665 sprintf(tmp, "Could not mount devices %s- shall I abort?",
666 these_failed);
667 if (!ask_me_yes_or_no(tmp)) {
668 retval = 0;
669 log_to_screen
670 ("Continuing, although some devices failed to be mounted");
671 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
672 } else {
673 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
674 log_to_screen
675 ("Unable to mount some or all of your partitions.");
676 }
677 } else {
678 log_to_screen("All partitions were mounted OK.");
679 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
680 }
681 run_program_and_log_output("df -m", 3);
682 paranoid_free(mountlist);
683 paranoid_free(tmp);
684 paranoid_free(format);
685 paranoid_free(these_failed);
686 return (retval);
687}
688
689 /**************************************************************************
690 *END_MOUNT_ALL_DEVICES *
691 **************************************************************************/
692
693
694/**
695 * Mount the CD-ROM device at /mnt/cdrom.
696 * @param bkpinfo The backup information structure. Fields used:
697 * - @c bkpinfo->backup_media_type
698 * - @c bkpinfo->disaster_recovery
699 * - @c bkpinfo->isodir
700 * - @c bkpinfo->media_device
701 * @return 0 for success, nonzero for failure.
702 */
703int mount_cdrom(struct s_bkpinfo *bkpinfo)
704{
705 char *mount_cmd;
706 int i, res;
707#ifdef __FreeBSD__
708 char mdd[32];
709 char *mddev = mdd;
710#endif
711
712 malloc_string(mount_cmd);
713 assert(bkpinfo != NULL);
714
715 if (bkpinfo->backup_media_type == tape
716 || bkpinfo->backup_media_type == udev) {
717 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
718 paranoid_free(mount_cmd);
719 return 0;
720 }
721
722 if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE)) {
723 log_msg(2, "mount_cdrom() - CD already mounted. Fair enough.");
724 paranoid_free(mount_cmd);
725 return (0);
726 }
727
728 if (bkpinfo->backup_media_type == nfs) {
729 log_msg(2, "Mounting for NFS thingy");
730 log_msg(2, "isodir = %s", bkpinfo->isodir);
731 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
732 && am_I_in_disaster_recovery_mode()) {
733 strcpy(bkpinfo->isodir, "/tmp/isodir");
734 log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
735 }
736#ifdef __FreeBSD__
737 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir,
738 bkpinfo->nfs_remote_dir, g_current_media_number);
739 mddev = make_vn(mount_cmd);
740 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
741#else
742 sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s",
743 bkpinfo->isodir, bkpinfo->nfs_remote_dir,
744 g_current_media_number, MNT_CDROM);
745#endif
746
747 } else if (bkpinfo->backup_media_type == iso) {
748#ifdef __FreeBSD__
749 sprintf(mount_cmd, "%s/%d.iso", bkpinfo->isodir,
750 g_current_media_number);
751 mddev = make_vn(mount_cmd);
752 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
753#else
754 sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s",
755 bkpinfo->isodir, g_current_media_number, MNT_CDROM);
756#endif
757 } else if (strstr(bkpinfo->media_device, "/dev/"))
758#ifdef __FreeBSD__
759 {
760 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
761 MNT_CDROM);
762 }
763#else
764 {
765 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
766 bkpinfo->media_device, MNT_CDROM);
767 }
768#endif
769
770 else {
771 if (bkpinfo->disaster_recovery
772 && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
773 strcpy(bkpinfo->media_device,
774 last_line_of_file("/tmp/CDROM-LIVES-HERE"));
775 } else {
776 find_cdrom_device(bkpinfo->media_device, TRUE);
777 }
778
779#ifdef __FreeBSD__
780 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
781 MNT_CDROM);
782#else
783 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
784 bkpinfo->media_device, MNT_CDROM);
785#endif
786
787 }
788 log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd);
789 for (i = 0; i < 2; i++) {
790 res = run_program_and_log_output(mount_cmd, FALSE);
791 if (!res) {
792 break;
793 } else {
794 log_msg(2, "Failed to mount CD-ROM drive.");
795 sleep(5);
796 run_program_and_log_output("sync", FALSE);
797 }
798 }
799 if (res) {
800 log_msg(2, "Failed, despite %d attempts", i);
801 } else {
802 log_msg(2, "Mounted CD-ROM drive OK");
803 }
804 paranoid_free(mount_cmd);
805 return (res);
806}
807
808
809
810
811
812/**************************************************************************
813 *END_MOUNT_CDROM *
814 **************************************************************************/
815
816
817/**
818 * Mount @p device at @p mpt as @p format.
819 * @param device The device (/dev entry) to mount.
820 * @param mpt The directory to mount it on.
821 * @param format The filesystem type of @p device.
822 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
823 * @return 0 for success, nonzero for failure.
824 */
825int mount_device(char *device, char *mpt, char *format, bool writeable)
826{
827 int res = 0;
828
829 /** malloc **/
830 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
831
832 assert_string_is_neither_NULL_nor_zerolength(device);
833 assert_string_is_neither_NULL_nor_zerolength(mpt);
834 assert(format != NULL);
835 malloc_string(tmp);
836 malloc_string(command);
837 malloc_string(mountdir);
838 malloc_string(mountpoint);
839 malloc_string(additional_parameters);
840
841 if (!strcmp(mpt, "/1")) {
842 strcpy(mountpoint, "/");
843 log_msg(3, "Mommm! SME is being a dildo!");
844 } else {
845 strcpy(mountpoint, mpt);
846 }
847
848 if (!strcmp(mountpoint, "lvm")) {
849 return (0);
850 }
851 if (!strcmp(mountpoint, "image")) {
852 return (0);
853 }
854 sprintf(tmp, "Mounting device %s ", device);
855 log_msg(1, tmp);
856 if (writeable) {
857 strcpy(additional_parameters, "-o rw");
858 } else {
859 strcpy(additional_parameters, "-o ro");
860 }
861 if (find_home_of_exe("setfattr")) {
862 strcat(additional_parameters, ",user_xattr");
863 }
864 if (find_home_of_exe("setfacl")) {
865 strcat(additional_parameters, ",acl");
866 }
867
868 if (!strcmp(mountpoint, "swap")) {
869 sprintf(command, "swapon %s", device);
870 } else {
871 if (!strcmp(mountpoint, "/")) {
872 strcpy(mountdir, MNT_RESTORING);
873 } else {
874 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
875 }
876 sprintf(command, "mkdir -p %s", mountdir);
877 run_program_and_log_output(command, FALSE);
878 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
879 additional_parameters, mountdir, MONDO_LOGFILE);
880 log_msg(2, "command='%s'", command);
881 }
882 res = run_program_and_log_output(command, TRUE);
883 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
884 log_msg(1, "Re-trying without the fancy extra parameters");
885 sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
886 mountdir, MONDO_LOGFILE);
887 res = run_program_and_log_output(command, TRUE);
888 }
889 if (res) {
890 log_msg(1, "Unable to mount device %s (type %s) at %s", device,
891 format, mountdir);
892 log_msg(1, "command was '%s'", command);
893 if (!strcmp(mountpoint, "swap")) {
894 log_to_screen(tmp);
895 } else {
896 log_msg(2, "Retrying w/o the '-t' switch");
897 sprintf(command, "mount %s %s 2>> %s", device, mountdir,
898 MONDO_LOGFILE);
899 log_msg(2, "2nd command = '%s'", command);
900 res = run_program_and_log_output(command, TRUE);
901 if (res == 0) {
902 log_msg(1,
903 "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
904 } else {
905 log_to_screen(tmp);
906 }
907 }
908 }
909 if (res && !strcmp(mountpoint, "swap")) {
910 log_msg(2, "That's ok. It's just a swap partition.");
911 log_msg(2, "Non-fatal error. Returning 0.");
912 res = 0;
913 }
914
915 paranoid_free(tmp);
916 paranoid_free(command);
917 paranoid_free(mountdir);
918 paranoid_free(mountpoint);
919 paranoid_free(additional_parameters);
920
921 return (res);
922}
923
924/**************************************************************************
925 *END_MOUNT_DEVICE *
926 **************************************************************************/
927
928
929
930/**
931 * Fix some miscellaneous things in the filesystem so the system will come
932 * up correctly on the first boot.
933 */
934void protect_against_braindead_sysadmins()
935{
936 run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
937 FALSE);
938 run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
939 FALSE);
940 if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
941 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
942 FALSE);
943 }
944 run_program_and_log_output("mkdir -p " MNT_RESTORING
945 "/var/run/console", FALSE);
946 run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
947 FALSE);
948 run_program_and_log_output("cd " MNT_RESTORING
949 "; 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",
950 TRUE);
951 run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
952 TRUE);
953 run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
954 TRUE);
955}
956
957/**************************************************************************
958 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS *
959 **************************************************************************/
960
961
962
963
964/**
965 * Fill out @p bkpinfo based on @p cfg_file.
966 * @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo.
967 * @param bkpinfo The backup information structure to fill out with information
968 * from @p cfg_file.
969 * @return 0 for success, nonzero for failure.
970 */
971int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo)
972{
973 /** add mallocs **/
974 char *value;
975 char *tmp;
976 char *command;
977 char *iso_mnt;
978 char *iso_path;
979 char *old_isodir;
980 char cfg_file[100];
981 t_bkptype media_specified_by_user;
982
983 malloc_string(command);
984 malloc_string(iso_mnt);
985 malloc_string(iso_path);
986 malloc_string(old_isodir);
987 malloc_string(value);
988 malloc_string(tmp);
989// assert_string_is_neither_NULL_nor_zerolength(cfg_file);
990 assert(bkpinfo != NULL);
991
992 if (!cfgf) {
993 strcpy(cfg_file, g_mondo_cfg_file);
994 } else {
995 strcpy(cfg_file, cfgf);
996 }
997
998 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
999
1000 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
1001 if (!strcmp(value, "cdstream")) {
1002 bkpinfo->backup_media_type = cdstream;
1003 } else if (!strcmp(value, "cdr")) {
1004 bkpinfo->backup_media_type = cdr;
1005 } else if (!strcmp(value, "cdrw")) {
1006 bkpinfo->backup_media_type = cdrw;
1007 } else if (!strcmp(value, "dvd")) {
1008 bkpinfo->backup_media_type = dvd;
1009 } else if (!strcmp(value, "iso")) {
1010/*
1011 if (am_I_in_disaster_recovery_mode()
1012 && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1)
1013 && does_file_exist(MNT_CDROM"/archives/filelist.0"))
1014*/
1015
1016// Patch by Conor Daly - 2004/07/12
1017 bkpinfo->backup_media_type = iso;
1018 if (am_I_in_disaster_recovery_mode()) {
1019 /* Check to see if CD is already mounted before mounting it... */
1020 if (!is_this_device_mounted("/dev/cdrom")) {
1021 log_msg(2,
1022 "NB: CDROM device not mounted, mounting...");
1023 run_program_and_log_output("mount /dev/cdrom "
1024 MNT_CDROM, 1);
1025 }
1026 if (does_file_exist(MNT_CDROM "/archives/filelist.0"))
1027// End patch
1028 {
1029 bkpinfo->backup_media_type = cdr;
1030 run_program_and_log_output("umount " MNT_CDROM, 1);
1031 log_it
1032 ("Re-jigging configuration AGAIN. CD-R, not ISO.");
1033 } else {
1034 bkpinfo->backup_media_type = iso;
1035 }
1036 }
1037 } else if (!strcmp(value, "nfs")) {
1038 bkpinfo->backup_media_type = nfs;
1039 } else if (!strcmp(value, "tape")) {
1040 bkpinfo->backup_media_type = tape;
1041 } else if (!strcmp(value, "udev")) {
1042 bkpinfo->backup_media_type = udev;
1043 } else {
1044 fatal_error("UNKNOWN bkp-media-type");
1045 }
1046 } else {
1047 fatal_error("backup-media-type not specified!");
1048 }
1049 if (bkpinfo->disaster_recovery) {
1050 if (bkpinfo->backup_media_type == cdstream) {
1051 sprintf(bkpinfo->media_device, "/dev/cdrom");
1052// bkpinfo->media_size[0] = -1;
1053 bkpinfo->media_size[0] = 1999 * 1024;
1054 bkpinfo->media_size[1] = 650; /* good guess */
1055 } else if (bkpinfo->backup_media_type == tape
1056 || bkpinfo->backup_media_type == udev) {
1057 if (read_cfg_var(cfg_file, "media-dev", value)) {
1058 fatal_error("Cannot get tape device name from cfg file");
1059 }
1060 strcpy(bkpinfo->media_device, value);
1061 read_cfg_var(cfg_file, "media-size", value);
1062 bkpinfo->media_size[1] = atol(value);
1063 sprintf(tmp, "Backup medium is TAPE --- dev=%s",
1064 bkpinfo->media_device);
1065 log_msg(2, tmp);
1066 } else {
1067 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */
1068 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
1069 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
1070 log_msg(2, "Backup medium is CD-R[W]");
1071 }
1072 } else {
1073 log_msg(2,
1074 "Not in Disaster Recovery Mode. No need to derive device name from config file.");
1075 }
1076
1077 read_cfg_var(cfg_file, "use-star", value);
1078 if (strstr(value, "yes")) {
1079 bkpinfo->use_star = TRUE;
1080 log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
1081 }
1082
1083 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
1084 bkpinfo->internal_tape_block_size = atol(value);
1085 log_msg(1, "Internal tape block size has been custom-set to %ld",
1086 bkpinfo->internal_tape_block_size);
1087 } else {
1088 bkpinfo->internal_tape_block_size =
1089 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
1090 log_msg(1, "Internal tape block size = default (%ld)",
1091 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
1092 }
1093
1094 read_cfg_var(cfg_file, "use-lzo", value);
1095 if (strstr(value, "yes")) {
1096 bkpinfo->use_lzo = TRUE;
1097 strcpy(bkpinfo->zip_exe, "lzop");
1098 strcpy(bkpinfo->zip_suffix, "lzo");
1099 } else {
1100 read_cfg_var(cfg_file, "use-comp", value);
1101 if (strstr(value, "yes")) {
1102 bkpinfo->use_lzo = FALSE;
1103 strcpy(bkpinfo->zip_exe, "bzip2");
1104 strcpy(bkpinfo->zip_suffix, "bz2");
1105 } else {
1106 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
1107 }
1108 }
1109
1110 value[0] = '\0';
1111 read_cfg_var(cfg_file, "differential", value);
1112 if (!strcmp(value, "yes") || !strcmp(value, "1")) {
1113 bkpinfo->differential = TRUE;
1114 }
1115 log_msg(2, "differential var = '%s'", value);
1116 if (bkpinfo->differential) {
1117 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
1118 } else {
1119 log_msg(2, "This is a regular (full) backup");
1120 }
1121
1122 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
1123 if (tmp[0]
1124 ||
1125 strstr(call_program_and_get_last_line_of_output
1126 ("cat /proc/cmdline"), "donteject")) {
1127 bkpinfo->please_dont_eject = TRUE;
1128 log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
1129 }
1130
1131 if (bkpinfo->backup_media_type == nfs) {
1132 if (!cfgf) {
1133 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
1134 log_msg(2, "nfs_remote_dir remains %s",
1135 bkpinfo->nfs_remote_dir);
1136 log_msg(2,
1137 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
1138 } else {
1139 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
1140 bkpinfo->nfs_mount);
1141 read_cfg_var(g_mondo_cfg_file, "nfs-server-path",
1142 bkpinfo->nfs_remote_dir);
1143 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
1144 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
1145 }
1146 } else if (bkpinfo->backup_media_type == iso) {
1147 /* Patch by Conor Daly 23-june-2004
1148 * to correctly mount iso-dev and set a sensible
1149 * isodir in disaster recovery mode
1150 */
1151 strcpy(old_isodir, bkpinfo->isodir);
1152 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
1153 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
1154 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1155 if (!bkpinfo->isodir[0]) {
1156 strcpy(bkpinfo->isodir, old_isodir);
1157 }
1158 if (!bkpinfo->disaster_recovery) {
1159 if (strcmp(old_isodir, bkpinfo->isodir)) {
1160 log_it
1161 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
1162 old_isodir, bkpinfo->isodir);
1163 strcpy(bkpinfo->isodir, old_isodir);
1164 }
1165 }
1166 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
1167 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
1168 g_isodir_device);
1169 if (bkpinfo->disaster_recovery) {
1170 if (is_this_device_mounted(g_isodir_device)) {
1171 log_msg(2, "NB: isodir is already mounted");
1172 /* Find out where it's mounted */
1173 sprintf(command,
1174 "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
1175 g_isodir_device);
1176 log_it("command = %s", command);
1177 log_it("res of it = %s",
1178 call_program_and_get_last_line_of_output(command));
1179 sprintf(iso_mnt, "%s",
1180 call_program_and_get_last_line_of_output(command));
1181 } else {
1182 sprintf(iso_mnt, "/tmp/isodir");
1183 sprintf(tmp, "mkdir -p %s", iso_mnt);
1184 run_program_and_log_output(tmp, 5);
1185 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
1186 if (run_program_and_log_output(tmp, 3)) {
1187 log_msg(1,
1188 "Unable to mount isodir. Perhaps this is really a CD backup?");
1189 bkpinfo->backup_media_type = cdr;
1190 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */
1191 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
1192 if (mount_cdrom(bkpinfo)) {
1193 fatal_error
1194 ("Unable to mount isodir. Failed to mount CD-ROM as well.");
1195 } else {
1196 log_msg(1,
1197 "You backed up to disk, then burned some CDs. Naughty monkey!");
1198 }
1199 }
1200 }
1201 /* bkpinfo->isodir should now be the true path to 1.iso etc... */
1202 if (bkpinfo->backup_media_type == iso) {
1203 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1204 }
1205 }
1206 }
1207
1208 if (media_specified_by_user != none) {
1209 if (g_restoring_live_from_cd) {
1210 if (bkpinfo->backup_media_type != media_specified_by_user) {
1211 log_msg(2,
1212 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
1213 interactively_obtain_media_parameters_from_user(bkpinfo,
1214 FALSE);
1215 media_specified_by_user = bkpinfo->backup_media_type;
1216 get_cfg_file_from_archive(bkpinfo);
1217/*
1218 if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
1219 { g_restoring_live_from_cd = FALSE; }
1220*/
1221 }
1222 }
1223 bkpinfo->backup_media_type = media_specified_by_user;
1224 }
1225 g_backup_media_type = bkpinfo->backup_media_type;
1226 paranoid_free(value);
1227 paranoid_free(tmp);
1228 paranoid_free(command);
1229 paranoid_free(iso_mnt);
1230 paranoid_free(iso_path);
1231 paranoid_free(old_isodir);
1232 return (0);
1233
1234}
1235
1236/**************************************************************************
1237 *END_READ_CFG_FILE_INTO_BKPINFO *
1238 **************************************************************************/
1239
1240
1241
1242
1243/**
1244 * Allow the user to edit the filelist and biggielist.
1245 * The filelist is unlinked after it is read.
1246 * @param bkpinfo The backup information structure. Fields used:
1247 * - @c bkpinfo->backup_media_type
1248 * - @c bkpinfo->isodir
1249 * - @c bkpinfo->media_device
1250 * - @c bkpinfo->tmpdir
1251 * @return The filelist structure containing the information read from disk.
1252 */
1253struct
1254s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo)
1255{
1256 struct s_node *filelist;
1257
1258 /** add mallocs**/
1259 char *command;
1260 char *tmp;
1261 int res = 0;
1262 pid_t pid;
1263
1264 assert(bkpinfo != NULL);
1265 malloc_string(command);
1266 malloc_string(tmp);
1267
1268 if (does_file_exist(g_filelist_full)
1269 && does_file_exist(g_biggielist_txt)) {
1270 log_msg(1, "%s exists", g_filelist_full);
1271 log_msg(1, "%s exists", g_biggielist_txt);
1272 log_msg(2,
1273 "Filelist and biggielist already recovered from media. Yay!");
1274 } else {
1275 getcwd(tmp, MAX_STR_LEN);
1276 chdir(bkpinfo->tmpdir);
1277 log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
1278 log_to_screen("Extracting filelist and biggielist from media...");
1279 unlink("/tmp/filelist.full");
1280 unlink("/" FILELIST_FULL_STUB);
1281 unlink("/tmp/i-want-my-lvm");
1282 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1283 sprintf(command,
1284 "tar -zxf %s %s %s %s %s %s",
1285 bkpinfo->media_device,
1286 MOUNTLIST_FNAME_STUB,
1287 BIGGIELIST_TXT_STUB,
1288 FILELIST_FULL_STUB,
1289 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
1290 log_msg(1, "tarcommand = %s", command);
1291 run_program_and_log_output(command, 1);
1292 } else {
1293 log_msg(2,
1294 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
1295 bkpinfo->isodir);
1296 insist_on_this_cd_number(bkpinfo, 1);
1297 log_msg(2, "Back from iotcn");
1298 run_program_and_log_output("mount", 1);
1299 sprintf(command,
1300 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
1301 MNT_CDROM,
1302 MOUNTLIST_FNAME_STUB,
1303 BIGGIELIST_TXT_STUB,
1304 FILELIST_FULL_STUB,
1305 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
1306
1307 log_msg(1, "tarcommand = %s", command);
1308 run_program_and_log_output(command, 1);
1309// popup_and_OK("Press ENTER to continue");
1310 if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
1311 fatal_error
1312 ("all.tar.gz did not include tmp/biggielist.txt");
1313 }
1314 if (!does_file_exist(FILELIST_FULL_STUB)) {
1315 fatal_error
1316 ("all.tar.gz did not include tmp/filelist.full.gz");
1317 }
1318 }
1319 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
1320 g_mondo_cfg_file);
1321 run_program_and_log_output(command, FALSE);
1322
1323 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
1324 BIGGIELIST_TXT_STUB, g_biggielist_txt);
1325 log_msg(1, "command = %s", command);
1326 paranoid_system(command);
1327 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
1328 FILELIST_FULL_STUB, g_filelist_full);
1329 log_msg(1, "command = %s", command);
1330 paranoid_system(command);
1331 }
1332
1333 if (am_I_in_disaster_recovery_mode()
1334 &&
1335 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
1336 {
1337// sprintf(command, "cp -f tmp/mountlist.txt /tmp");
1338 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
1339 bkpinfo->tmpdir);
1340 paranoid_system(command);
1341 }
1342
1343 chdir(tmp);
1344
1345 if (!does_file_exist(g_biggielist_txt)) {
1346 log_msg(1, "Warning - %s not found", g_biggielist_txt);
1347 }
1348 if (!does_file_exist(g_filelist_full)) {
1349 log_msg(1, "Warning - %s does not exist", g_filelist_full);
1350 }
1351// popup_and_OK("Wonderful.");
1352
1353 log_msg(2, "Forking");
1354 pid = fork();
1355 switch (pid) {
1356 case -1:
1357 fatal_error("Forking error");
1358 break;
1359
1360 case 0:
1361 log_to_screen("Pre-processing filelist");
1362 if (!does_file_exist(g_biggielist_txt)) {
1363 sprintf(command, "> %s", g_biggielist_txt);
1364 paranoid_system(command);
1365 }
1366 sprintf(command, "cat %s | grep -x \"/dev/.*\" > %s",
1367 g_biggielist_txt, g_filelist_imagedevs);
1368 paranoid_system(command);
1369 exit(0);
1370 break;
1371
1372 default:
1373 open_evalcall_form("Pre-processing filelist");
1374 while (!waitpid(pid, (int *) 0, WNOHANG)) {
1375 usleep(100000);
1376 update_evalcall_form(0);
1377 }
1378 }
1379 close_evalcall_form();
1380
1381 log_msg(3, "loading filelist");
1382 filelist = load_filelist(g_filelist_full);
1383 log_msg(3, "deleting original filelist");
1384 unlink(g_filelist_full);
1385 if (g_text_mode) {
1386 printf("Restore which directory? --> ");
1387 fgets(tmp, sizeof(tmp), stdin);
1388 toggle_path_selection(filelist, tmp, TRUE);
1389 if (strlen(tmp) == 0) {
1390 res = 1;
1391 } else {
1392 res = 0;
1393 }
1394 } else {
1395 res = edit_filelist(filelist);
1396 }
1397 if (res) {
1398 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
1399 free_filelist(filelist);
1400 return (NULL);
1401 }
1402 ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
1403 close_evalcall_form();
1404
1405 // NB: It's not necessary to add g_biggielist_txt to the filelist.full
1406 // file. The filelist.full file already contains the filename of EVERY
1407 // file backed up - regular and biggie files.
1408
1409 // However, we do want to make sure the imagedevs selected by the user
1410 // are flagged for restoring.
1411 if (length_of_file(g_imagedevs_restthese) > 2) {
1412 add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
1413 TRUE);
1414 }
1415
1416 paranoid_free(command);
1417 paranoid_free(tmp);
1418 return (filelist);
1419}
1420
1421/**************************************************************************
1422 *END_ PROCESS_FILELIST_AND_BIGGIELIST *
1423 **************************************************************************/
1424
1425
1426
1427
1428/**
1429 * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
1430 * The backup filename is the filename of the original with ".pristine" added.
1431 * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
1432 * @param filename The filename (absolute path) within @p path_root.
1433 * @return 0 for success, nonzero for failure.
1434 */
1435int backup_crucial_file(char *path_root, char *filename)
1436{
1437 char *tmp;
1438 char *command;
1439 int res;
1440
1441 malloc_string(tmp);
1442 malloc_string(command);
1443 assert(path_root != NULL);
1444 assert_string_is_neither_NULL_nor_zerolength(filename);
1445
1446 sprintf(tmp, "%s/%s", path_root, filename);
1447 sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
1448
1449 res = run_program_and_log_output(command, 5);
1450 paranoid_free(tmp);
1451 paranoid_free(command);
1452 return (res);
1453}
1454
1455
1456/**
1457 * Install the user's boot loader in the MBR.
1458 * Currently LILO, ELILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
1459 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1460 * @return 0 for success, nonzero for failure.
1461 */
1462int run_boot_loader(bool offer_to_hack_scripts)
1463{
1464 int res;
1465 int retval = 0;
1466
1467 /** malloc *******/
1468 char *device;
1469 char *tmp;
1470 char *name;
1471
1472 malloc_string(device);
1473 malloc_string(tmp);
1474 malloc_string(name);
1475 backup_crucial_file(MNT_RESTORING, "/etc/fstab");
1476 backup_crucial_file(MNT_RESTORING, "/etc/grub.conf");
1477 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
1478 backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
1479 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
1480 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
1481 sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
1482 log_msg(2, tmp);
1483 system("sync");
1484 if (!strcmp(name, "LILO")) {
1485 res = run_lilo(offer_to_hack_scripts);
1486 } else if (!strcmp(name, "ELILO")) {
1487 res = run_elilo(offer_to_hack_scripts);
1488 } else if (!strcmp(name, "GRUB")) {
1489// if ( does_file_exist(DO_MBR_PLEASE) || (offer_to_hack_scripts && ask_me_yes_or_no("Because of bugs in GRUB, you're much better off running mondorestore --mbr after this program terminates. Are you sure you want to install GRUB right now?")))
1490// {
1491 res = run_grub(offer_to_hack_scripts, device);
1492// unlink(DO_MBR_PLEASE);
1493// }
1494// else
1495// {
1496// log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
1497// res = 1;
1498// }
1499 } else if (!strcmp(name, "RAW")) {
1500 res = run_raw_mbr(offer_to_hack_scripts, device);
1501 }
1502#ifdef __FreeBSD__
1503 else if (!strcmp(name, "BOOT0")) {
1504 sprintf(tmp, "boot0cfg -B %s", device);
1505 res = run_program_and_log_output(tmp, FALSE);
1506 } else {
1507 sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device);
1508 if (!system(tmp)) {
1509 sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
1510 res = run_program_and_log_output(tmp, 3);
1511 } else {
1512 log_msg(1,
1513 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
1514 }
1515 }
1516#else
1517 else {
1518 log_to_screen
1519 ("Unable to determine type of boot loader. Defaulting to LILO.");
1520 res = run_lilo(offer_to_hack_scripts);
1521 }
1522#endif
1523 retval += res;
1524 if (res) {
1525 log_to_screen("Your boot loader returned an error");
1526 } else {
1527 log_to_screen("Your boot loader ran OK");
1528 }
1529 paranoid_free(device);
1530 paranoid_free(tmp);
1531 paranoid_free(name);
1532 return (retval);
1533}
1534
1535/**************************************************************************
1536 *END_ RUN_BOOT_LOADER *
1537 **************************************************************************/
1538
1539
1540
1541/**
1542 * Attempt to find the user's editor.
1543 * @return The editor found ("vi" if none could be found).
1544 * @note The returned string points to static storage that will be overwritten with each call.
1545 */
1546char *find_my_editor(void)
1547{
1548 static char output[MAX_STR_LEN];
1549 if (find_home_of_exe("pico")) {
1550 strcpy(output, "pico");
1551 } else if (find_home_of_exe("nano")) {
1552 strcpy(output, "nano");
1553 } else if (find_home_of_exe("e3em")) {
1554 strcpy(output, "e3em");
1555 } else if (find_home_of_exe("e3vi")) {
1556 strcpy(output, "e3vi");
1557 } else {
1558 strcpy(output, "vi");
1559 }
1560 if (!find_home_of_exe(output)) {
1561 log_msg(2, " (find_my_editor) --- warning - %s not found", output);
1562 }
1563 return (output);
1564}
1565
1566
1567/**
1568 * Install GRUB on @p bd.
1569 * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
1570 * @param bd The boot device where GRUB is installed.
1571 * @return 0 for success, nonzero for failure.
1572 */
1573int run_grub(bool offer_to_run_stabgrub, char *bd)
1574{
1575 /** malloc **/
1576 char *command;
1577 char *boot_device;
1578 char *rootdev;
1579 char *rootdrive;
1580 char *conffile;
1581 char *tmp;
1582 char *editor;
1583
1584 int res;
1585 int done;
1586
1587 malloc_string(command);
1588 malloc_string(boot_device);
1589 malloc_string(tmp);
1590 malloc_string(editor);
1591 malloc_string(rootdev);
1592 malloc_string(rootdrive);
1593 malloc_string(conffile);
1594 assert_string_is_neither_NULL_nor_zerolength(bd);
1595 strcpy(editor, "vi"); // find_my_editor() );
1596 strcpy(boot_device, bd);
1597
1598 if (!run_program_and_log_output("which grub-MR", FALSE)) {
1599 log_msg(1, "Yay! grub-MR found...");
1600 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
1601 log_msg(1, "command = %s", command);
1602 } else {
1603 sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
1604 boot_device);
1605 log_msg(1, "WARNING - grub-MR not found; using grub-install");
1606 }
1607 if (offer_to_run_stabgrub
1608 && ask_me_yes_or_no("Did you change the mountlist?"))
1609 /* interactive mode */
1610 {
1611 mvaddstr_and_log_it(g_currentY,
1612 0,
1613 "Modifying fstab and grub.conf, and running GRUB... ");
1614 for (done = FALSE; !done;) {
1615 popup_and_get_string("Boot device",
1616 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1617 boot_device, MAX_STR_LEN / 4);
1618 sprintf(command, "stabgrub-me %s", boot_device);
1619 res = run_program_and_log_output(command, 1);
1620 if (res) {
1621 popup_and_OK
1622 ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
1623 newtSuspend();
1624 system("chroot " MNT_RESTORING);
1625 newtResume();
1626 popup_and_OK("Thank you.");
1627 } else {
1628 done = TRUE;
1629 }
1630 popup_and_OK("You will now edit fstab and grub.conf");
1631 if (!g_text_mode) {
1632 newtSuspend();
1633 }
1634 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1635 paranoid_system(tmp);
1636 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
1637 paranoid_system(tmp);
1638 if (!g_text_mode) {
1639 newtResume();
1640 }
1641 }
1642 } else
1643 /* nuke mode */
1644 {
1645 mvaddstr_and_log_it(g_currentY,
1646 0,
1647 "Running GRUB... ");
1648 iamhere(command);
1649 res = run_program_and_log_output(command, 1);
1650 if (res) {
1651 popup_and_OK
1652 ("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.");
1653 newtSuspend();
1654 system("chroot " MNT_RESTORING);
1655 newtResume();
1656 popup_and_OK("Thank you.");
1657 }
1658 }
1659 if (res) {
1660 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1661 log_to_screen
1662 ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.");
1663 log_msg(1, "Type:-");
1664 log_msg(1, " mount-me");
1665 log_msg(1, " chroot " MNT_RESTORING);
1666 log_msg(1, " mount /boot");
1667 log_msg(1, " grub-install '(hd0)'");
1668 log_msg(1, " exit");
1669 log_msg(1, " unmount-me");
1670 log_msg(1,
1671 "If you're really stuck, please e-mail the mailing list.");
1672 } else {
1673 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1674 }
1675 paranoid_free(rootdev);
1676 paranoid_free(rootdrive);
1677 paranoid_free(conffile);
1678 paranoid_free(command);
1679 paranoid_free(boot_device);
1680 paranoid_free(tmp);
1681 paranoid_free(editor);
1682
1683 return (res);
1684}
1685
1686/**************************************************************************
1687 *END_RUN_GRUB *
1688 **************************************************************************/
1689
1690
1691/**
1692 * Install ELILO on the user's boot drive (determined by elilo.conf).
1693 * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
1694 * @return 0 for success, nonzero for failure.
1695 */
1696int run_elilo(bool offer_to_run_stabelilo)
1697{
1698 /** malloc **/
1699 char *command;
1700 char *tmp;
1701 char *editor;
1702
1703 int res;
1704 int done;
1705
1706 malloc_string(command);
1707 malloc_string(tmp);
1708 malloc_string(editor);
1709 strcpy(editor, find_my_editor());
1710 if (offer_to_run_stabelilo
1711 && ask_me_yes_or_no("Did you change the mountlist?"))
1712
1713 /* interactive mode */
1714 {
1715 mvaddstr_and_log_it(g_currentY,
1716 0,
1717 "Modifying fstab and elilo.conf... ");
1718 sprintf(command, "stabelilo-me");
1719 res = run_program_and_log_output(command, 3);
1720 if (res) {
1721 popup_and_OK
1722 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
1723 for (done = FALSE; !done;) {
1724 if (!g_text_mode) {
1725 newtSuspend();
1726 }
1727 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1728 paranoid_system(tmp);
1729 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf",
1730 editor);
1731 paranoid_system(tmp);
1732 if (!g_text_mode) {
1733 newtResume();
1734 }
1735// newtCls();
1736 if (ask_me_yes_or_no("Edit them again?")) {
1737 continue;
1738 }
1739 done = TRUE;
1740 }
1741 } else {
1742 log_to_screen("elilo.conf and fstab were modified OK");
1743 }
1744 } else
1745 /* nuke mode */
1746 {
1747 res = TRUE;
1748 }
1749 paranoid_free(command);
1750 paranoid_free(tmp);
1751 paranoid_free(editor);
1752 return (res);
1753}
1754
1755/**************************************************************************
1756 *END_RUN_ELILO *
1757 **************************************************************************/
1758
1759
1760/**
1761 * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
1762 * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
1763 * @return 0 for success, nonzero for failure.
1764 */
1765int run_lilo(bool offer_to_run_stablilo)
1766{
1767 /** malloc **/
1768 char *command;
1769 char *tmp;
1770 char *editor;
1771
1772 int res;
1773 int done;
1774 bool run_lilo_M = FALSE;
1775 malloc_string(command);
1776 malloc_string(tmp);
1777 malloc_string(editor);
1778
1779 if (!run_program_and_log_output
1780 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
1781 run_lilo_M = TRUE;
1782 }
1783
1784 strcpy(editor, find_my_editor());
1785 if (offer_to_run_stablilo
1786 && ask_me_yes_or_no("Did you change the mountlist?"))
1787
1788 /* interactive mode */
1789 {
1790 mvaddstr_and_log_it(g_currentY,
1791 0,
1792 "Modifying fstab and lilo.conf, and running LILO... ");
1793 sprintf(command, "stablilo-me");
1794 res = run_program_and_log_output(command, 3);
1795 if (res) {
1796 popup_and_OK
1797 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
1798 for (done = FALSE; !done;) {
1799 if (!g_text_mode) {
1800 newtSuspend();
1801 }
1802 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1803 paranoid_system(tmp);
1804 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
1805 paranoid_system(tmp);
1806 if (!g_text_mode) {
1807 newtResume();
1808 }
1809// newtCls();
1810 if (ask_me_yes_or_no("Edit them again?")) {
1811 continue;
1812 }
1813 res =
1814 run_program_and_log_output("chroot " MNT_RESTORING
1815 " lilo -L", 3);
1816 if (res) {
1817 res =
1818 run_program_and_log_output("chroot " MNT_RESTORING
1819 " lilo", 3);
1820 }
1821 if (res) {
1822 done =
1823 ask_me_yes_or_no
1824 ("LILO failed. Re-edit system files?");
1825 } else {
1826 done = TRUE;
1827 }
1828 }
1829 } else {
1830 log_to_screen("lilo.conf and fstab were modified OK");
1831 }
1832 } else
1833 /* nuke mode */
1834 {
1835 mvaddstr_and_log_it(g_currentY,
1836 0,
1837 "Running LILO... ");
1838 res =
1839 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
1840 3);
1841 if (res) {
1842 res =
1843 run_program_and_log_output("chroot " MNT_RESTORING " lilo",
1844 3);
1845 }
1846 if (res) {
1847 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1848 log_to_screen
1849 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
1850 } else {
1851 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1852 }
1853 }
1854 if (run_lilo_M) {
1855 run_program_and_log_output("chroot " MNT_RESTORING
1856 " lilo -M /dev/hda", 3);
1857 run_program_and_log_output("chroot " MNT_RESTORING
1858 " lilo -M /dev/sda", 3);
1859 }
1860 paranoid_free(command);
1861 paranoid_free(tmp);
1862 paranoid_free(editor);
1863 return (res);
1864}
1865
1866/**************************************************************************
1867 *END_RUN_LILO *
1868 **************************************************************************/
1869
1870
1871/**
1872 * Install a raw MBR onto @p bd.
1873 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1874 * @param bd The device to copy the stored MBR to.
1875 * @return 0 for success, nonzero for failure.
1876 */
1877int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
1878{
1879 /** malloc **/
1880 char *command;
1881 char *boot_device;
1882 char *tmp;
1883 char *editor;
1884 int res;
1885 int done;
1886
1887 malloc_string(command);
1888 malloc_string(boot_device);
1889 malloc_string(tmp);
1890 malloc_string(editor);
1891 assert_string_is_neither_NULL_nor_zerolength(bd);
1892
1893 strcpy(editor, find_my_editor());
1894 strcpy(boot_device, bd);
1895 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
1896 log_msg(2, "run_raw_mbr() --- command='%s'", command);
1897
1898 if (offer_to_hack_scripts
1899 && ask_me_yes_or_no("Did you change the mountlist?"))
1900 /* interactive mode */
1901 {
1902 mvaddstr_and_log_it(g_currentY, 0,
1903 "Modifying fstab and restoring MBR... ");
1904 for (done = FALSE; !done;) {
1905 if (!run_program_and_log_output("which vi", FALSE)) {
1906 popup_and_OK("You will now edit fstab");
1907 if (!g_text_mode) {
1908 newtSuspend();
1909 }
1910 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1911 paranoid_system(tmp);
1912 if (!g_text_mode) {
1913 newtResume();
1914 }
1915// newtCls();
1916 }
1917 popup_and_get_string("Boot device",
1918 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1919 boot_device, MAX_STR_LEN / 4);
1920 sprintf(command, "stabraw-me %s", boot_device);
1921 res = run_program_and_log_output(command, 3);
1922 if (res) {
1923 done = ask_me_yes_or_no("Modifications failed. Re-try?");
1924 } else {
1925 done = TRUE;
1926 }
1927 }
1928 } else
1929 /* nuke mode */
1930 {
1931 mvaddstr_and_log_it(g_currentY, 0,
1932 "Restoring MBR... ");
1933 res = run_program_and_log_output(command, 3);
1934 }
1935 if (res) {
1936 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1937 log_to_screen
1938 ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.");
1939 } else {
1940 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1941 }
1942 paranoid_free(command);
1943 paranoid_free(boot_device);
1944 paranoid_free(tmp);
1945 paranoid_free(editor);
1946 return (res);
1947}
1948
1949/**************************************************************************
1950 *END_RUN_RAW_MBR *
1951 **************************************************************************/
1952
1953
1954
1955
1956
1957/**
1958 * Turn signal trapping on or off.
1959 * @param on If TRUE, then do full cleanup when we receive a signal; if FALSE, then
1960 * print a message and exit immediately.
1961 */
1962void set_signals(int on)
1963{
1964 int signals[] =
1965 { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT,
1966 SIGSTOP, 0
1967 };
1968 int i;
1969 for (i = 0; signals[i]; i++) {
1970 if (on) {
1971 signal(signals[i], terminate_daemon);
1972 } else {
1973 signal(signals[i], termination_in_progress);
1974 }
1975 }
1976}
1977
1978/**************************************************************************
1979 *END_SET_SIGNALS *
1980 **************************************************************************/
1981
1982
1983/**
1984 * malloc() and set sensible defaults for the mondorestore filename variables.
1985 * @param bkpinfo The backup information structure. Fields used:
1986 * - @c bkpinfo->tmpdir
1987 * - @c bkpinfo->disaster_recovery
1988 */
1989void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo)
1990{
1991 char *temppath;
1992
1993 assert(bkpinfo != NULL);
1994
1995 malloc_string(g_biggielist_txt);
1996 malloc_string(g_filelist_full);
1997 malloc_string(g_filelist_imagedevs);
1998 malloc_string(g_imagedevs_restthese);
1999 malloc_string(g_mondo_cfg_file);
2000 malloc_string(g_mountlist_fname);
2001 malloc_string(g_tmpfs_mountpt);
2002 malloc_string(g_isodir_device);
2003 malloc_string(g_isodir_format);
2004
2005 temppath = bkpinfo->tmpdir;
2006
2007 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
2008 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
2009 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
2010// sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
2011 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
2012 temppath);
2013 if (bkpinfo->disaster_recovery) {
2014 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
2015 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
2016 } else {
2017 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
2018 sprintf(g_mountlist_fname, "%s/%s", temppath,
2019 MOUNTLIST_FNAME_STUB);
2020 }
2021}
2022
2023/**************************************************************************
2024 *END_SET_GLOBAL_FILENAME *
2025 **************************************************************************/
2026
2027
2028/**
2029 * Copy @p input_file (containing the result of a compare) to @p output_file,
2030 * deleting spurious "changes" along the way.
2031 * @param output_file The output file to write with spurious changes removed.
2032 * @param input_file The input file, a list of changed files created by a compare.
2033 */
2034void streamline_changes_file(char *output_file, char *input_file)
2035{
2036 FILE *fin;
2037 FILE *fout;
2038 /** malloc **/
2039 char *incoming;
2040
2041 assert_string_is_neither_NULL_nor_zerolength(output_file);
2042 assert_string_is_neither_NULL_nor_zerolength(input_file);
2043 malloc_string(incoming);
2044
2045 if (!(fin = fopen(input_file, "r"))) {
2046 log_OS_error(input_file);
2047 return;
2048 }
2049 if (!(fout = fopen(output_file, "w"))) {
2050 fatal_error("cannot open output_file");
2051 }
2052 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
2053 fgets(incoming, MAX_STR_LEN - 1, fin)) {
2054 if (strncmp(incoming, "etc/adjtime", 11)
2055 && strncmp(incoming, "etc/mtab", 8)
2056 && strncmp(incoming, "tmp/", 4)
2057 && strncmp(incoming, "boot/map", 8)
2058 && !strstr(incoming, "incheckentry")
2059 && strncmp(incoming, "etc/mail/statistics", 19)
2060 && strncmp(incoming, "var/", 4))
2061 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
2062 }
2063 paranoid_fclose(fout);
2064 paranoid_fclose(fin);
2065 paranoid_free(incoming);
2066}
2067
2068/**************************************************************************
2069 *END_STREAMLINE_CHANGES_FILE *
2070 **************************************************************************/
2071
2072
2073
2074
2075
2076
2077/**
2078 * Prompt the user to support the Mondo project.
2079 */
2080void success_message(void)
2081{
2082 int i;
2083 /* malloc and ptr */
2084 char *tmp;
2085
2086 malloc_string(tmp);
2087 if (strstr
2088 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2089 "restore") == NULL) {
2090 if (ask_me_yes_or_no
2091 ("Have you contributed to the Mondo project financially or in some other way, yet?"))
2092 {
2093 log_to_screen
2094 ("Thank you for supporting Mondo. It goes from strength to strength,");
2095 log_to_screen("thanks to the support of users like you.");
2096 } else {
2097 if (ask_me_yes_or_no
2098 ("Are you or your company willing to consider contributing to Mondo in some way?"))
2099 {
2100 popup_and_OK
2101 ("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'.");
2102 } else {
2103 log_to_screen
2104 ("Free Software, like freedom itself, must be supported or it will be lost.");
2105 log_msg(1,
2106 "To your credit, you were honest: you said no, you wouldn't be contributing");
2107 log_msg(1,
2108 "to this project, ever. However, that makes you a freeloader. I bet you're");
2109 log_msg(1,
2110 "the sort of person who likes to sneak into movie theatres...");
2111 popup_and_OK
2112 ("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'.");
2113 }
2114 }
2115 }
2116#ifdef FREELOADER
2117 i = (int) (random()) % 32;
2118#else
2119 i = 1;
2120#endif
2121
2122 if (i != 25) {
2123 strcpy(tmp,
2124 "Mondo has restored your system. Please remove the backup media and reboot.");
2125 } else {
2126 strcpy(tmp,
2127 "M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007.");
2128 }
2129 if (strstr
2130 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2131 "restore") == NULL) {
2132 popup_and_OK(tmp);
2133 }
2134 log_to_screen(tmp);
2135 paranoid_free(tmp);
2136}
2137
2138/**************************************************************************
2139 *END_SUCCESS_MESSAGE *
2140 **************************************************************************/
2141
2142
2143
2144/**
2145 * Exit due to a signal (normal cleanup).
2146 * @param sig The signal we're exiting due to.
2147 */
2148void terminate_daemon(int sig)
2149{
2150 log_to_screen
2151 ("Mondorestore is terminating in response to a signal from the OS");
2152 paranoid_MR_finish(254);
2153}
2154
2155/**************************************************************************
2156 *END_TERMINATE_DAEMON *
2157 **************************************************************************/
2158
2159
2160/**
2161 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
2162 */
2163void twenty_seconds_til_yikes()
2164{
2165 int i;
2166 /* MALLOC * */
2167 char *tmp;
2168
2169 malloc_string(tmp);
2170 if (does_file_exist("/tmp/NOPAUSE")) {
2171 return;
2172 }
2173 open_progress_form("CAUTION",
2174 "Be advised: I am about to ERASE your hard disk(s)!",
2175 "You may press Ctrl+Alt+Del to abort safely.",
2176 "", 20);
2177 for (i = 0; i < 20; i++) {
2178 g_current_progress = i;
2179 sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
2180 update_progress_form(tmp);
2181 sleep(1);
2182 }
2183 close_progress_form();
2184 paranoid_free(tmp);
2185}
2186
2187/**************************************************************************
2188 *END_TWENTY_SECONDS_TIL_YIKES *
2189 **************************************************************************/
2190
2191
2192
2193
2194
2195/**
2196 * Exit due to a signal (no cleanup).
2197 * @param sig The signal we're exiting due to.
2198 */
2199void termination_in_progress(int sig)
2200{
2201 log_msg(1, "Termination in progress");
2202 usleep(1000);
2203 pthread_exit(0);
2204}
2205
2206/**************************************************************************
2207 *END_TERMINATION_IN_PROGRESS *
2208 **************************************************************************/
2209
2210
2211
2212/**
2213 * Unmount all devices in @p p_external_copy_of_mountlist.
2214 * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
2215 * @return 0 for success, nonzero for failure.
2216 */
2217int unmount_all_devices(struct mountlist_itself
2218 *p_external_copy_of_mountlist)
2219{
2220 struct mountlist_itself *mountlist;
2221 int retval = 0, lino, res = 0, i;
2222 char *command;
2223 char *tmp;
2224
2225 malloc_string(command);
2226 malloc_string(tmp);
2227 assert(p_external_copy_of_mountlist != NULL);
2228
2229 mountlist = malloc(sizeof(struct mountlist_itself));
2230 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
2231 sizeof(struct mountlist_itself));
2232 sort_mountlist_by_mountpoint(mountlist, 0);
2233
2234 run_program_and_log_output("df -m", 3);
2235 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
2236 open_progress_form("Unmounting devices",
2237 "Unmounting all devices that were mounted,",
2238 "in preparation for the post-restoration reboot.",
2239 "", mountlist->entries);
2240 chdir("/");
2241 for (i = 0;
2242 i < 10
2243 &&
2244 run_program_and_log_output
2245 ("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0;
2246 i++) {
2247 sleep(1);
2248 log_msg(2, "Waiting for buffer() to finish");
2249 }
2250
2251 paranoid_system("sync");
2252
2253 if (run_program_and_log_output
2254 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE)) {
2255 log_msg(1,
2256 "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)");
2257 }
2258 if (run_program_and_log_output
2259 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE)) {
2260 log_msg(1,
2261 "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)");
2262 }
2263 if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
2264 run_program_and_log_output("mkdir -p " MNT_RESTORING
2265 "/mnt/.boot.d", 5);
2266 }
2267 for (lino = mountlist->entries - 1; lino >= 0; lino--) {
2268 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
2269 continue;
2270 }
2271 sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
2272
2273 update_progress_form(tmp);
2274 if (is_this_device_mounted(mountlist->el[lino].device)) {
2275 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
2276 sprintf(command, "swapoff %s", mountlist->el[lino].device);
2277 } else {
2278 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
2279 sprintf(command, "umount %s/", MNT_RESTORING);
2280 log_msg(3,
2281 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
2282 } else {
2283 sprintf(command, "umount " MNT_RESTORING "%s",
2284 mountlist->el[lino].mountpoint);
2285 }
2286 }
2287 log_msg(10, "The 'umount' command is '%s'", command);
2288 res = run_program_and_log_output(command, 3);
2289 } else {
2290 strcat(tmp, "...not mounted anyway :-) OK");
2291 res = 0;
2292 }
2293 g_current_progress++;
2294 if (res) {
2295 strcat(tmp, "...Failed");
2296 retval++;
2297 log_to_screen(tmp);
2298 } else {
2299 log_msg(2, tmp);
2300 }
2301 }
2302 close_progress_form();
2303 if (retval) {
2304 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2305 } else {
2306 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2307 }
2308 if (retval) {
2309 log_to_screen("Unable to unmount some of your partitions.");
2310 } else {
2311 log_to_screen("All partitions were unmounted OK.");
2312 }
2313 free(mountlist);
2314 paranoid_free(command);
2315 paranoid_free(tmp);
2316 return (retval);
2317}
2318
2319/**************************************************************************
2320 *END_UNMOUNT_ALL_DEVICES *
2321 **************************************************************************/
2322
2323
2324
2325/**
2326 * Extract mondo-restore.cfg and the mountlist from the tape inserted
2327 * to the ./tmp/ directory.
2328 * @param dev The tape device to read from.
2329 * @return 0 for success, nonzero for failure.
2330 */
2331int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
2332{
2333 char *command;
2334 int res = 0;
2335 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
2336 long tape_block_size = 32768;
2337
2338 malloc_string(command);
2339
2340 // tar -zxvf-
2341 sprintf(command,
2342 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
2343 dev,
2344 tape_block_size,
2345 1024L * 1024 * 32 / tape_block_size,
2346 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
2347 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");
2348 log_msg(2, "command = '%s'", command);
2349 res = run_program_and_log_output(command, -1);
2350 if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) {
2351 res = 0;
2352 }
2353 paranoid_free(command);
2354 return (res);
2355}
2356
2357
2358
2359/**
2360 * Get the configuration file from the floppy, tape, or CD.
2361 * @param bkpinfo The backup information structure. Fields used:
2362 * - @c bkpinfo->backup_media_type
2363 * - @c bkpinfo->media_device
2364 * - @c bkpinfo->tmpdir
2365 * @return 0 for success, nonzero for failure.
2366 */
2367int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo)
2368{
2369 int retval = 0;
2370
2371 /** malloc *****/
2372 char *device;
2373 char *command;
2374 char *cfg_file;
2375 char *mounted_cfgf_path;
2376 char *tmp;
2377 char *mountpt;
2378 char *ramdisk_fname;
2379 char *mountlist_file;
2380 int res;
2381
2382 bool try_plan_B;
2383
2384 assert(bkpinfo != NULL);
2385 malloc_string(cfg_file);
2386 malloc_string(mounted_cfgf_path);
2387 malloc_string(mountpt);
2388 malloc_string(ramdisk_fname);
2389 malloc_string(mountlist_file);
2390 malloc_string(device);
2391 malloc_string(command);
2392 malloc_string(tmp);
2393 log_msg(2, "gcffa --- starting");
2394 log_to_screen("I'm thinking...");
2395 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
2396 device[0] = '\0';
2397 chdir(bkpinfo->tmpdir);
2398 strcpy(cfg_file, MONDO_CFG_FILE_STUB);
2399 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
2400 unlink(FILELIST_FULL_STUB);
2401 unlink(BIGGIELIST_TXT_STUB);
2402 unlink("tmp/i-want-my-lvm");
2403 sprintf(command, "mkdir -p %s", mountpt);
2404 run_program_and_log_output(command, FALSE);
2405
2406// unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
2407
2408 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
2409 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
2410 MOUNTLIST_FNAME_STUB);
2411 // make_hole_for_file( cfg_file );
2412 // make_hole_for_file( mountlist_file);
2413 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
2414
2415 /* Floppy? */
2416 sprintf(tmp, "mkdir -p %s", mountpt);
2417 run_program_and_log_output(tmp, FALSE);
2418 sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
2419 run_program_and_log_output(tmp, FALSE);
2420
2421 sprintf(command, "mount /dev/fd0u1722 %s", mountpt);
2422 sprintf(tmp,
2423 "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &",
2424 command);
2425 log_msg(1, "tmp = '%s'", tmp);
2426 system(tmp);
2427 res = run_program_and_log_output(command, FALSE);
2428 if (res) {
2429 sprintf(command, "mount /dev/fd0H1440 %s", mountpt);
2430 res = run_program_and_log_output(command, FALSE);
2431 }
2432 if (res) {
2433 try_plan_B = TRUE;
2434 } else {
2435 try_plan_B = TRUE;
2436 log_msg(2,
2437 "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
2438// NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK.
2439 log_msg(2, "Processing floppy (plan A?)");
2440 sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);
2441 if (!does_file_exist(ramdisk_fname)) {
2442 sprintf(ramdisk_fname, "%s/initrd.img", mountpt);
2443 }
2444 if (!does_file_exist(ramdisk_fname)) {
2445 log_msg(2,
2446 "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?");
2447 }
2448 if (extract_config_file_from_ramdisk
2449 (bkpinfo, ramdisk_fname, cfg_file, mountlist_file)) {
2450 log_msg(2,
2451 "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled.");
2452 }
2453 sprintf(command, "umount %s", mountpt);
2454 run_program_and_log_output(command, 5);
2455 unlink(ramdisk_fname);
2456 }
2457 if (!does_file_exist(cfg_file)) {
2458 log_msg(2, "gcffa --- we don't have cfg file yet.");
2459 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2460 try_plan_B = TRUE;
2461 } else {
2462 log_msg(2, "gcffa --- calling mount_cdrom now :)");
2463 if (!mount_cdrom(bkpinfo)) {
2464 log_msg(2,
2465 "gcffa --- managed to mount CD; so, no need for Plan B");
2466 try_plan_B = FALSE;
2467 } else {
2468 try_plan_B = TRUE;
2469 }
2470 if (what_number_cd_is_this(bkpinfo) > 1) {
2471 insist_on_this_cd_number(bkpinfo,
2472 (g_current_media_number = 1));
2473 }
2474 }
2475 if (try_plan_B) {
2476 log_msg(2, "gcffa --- OK, switching to Plan B");
2477 chdir(bkpinfo->tmpdir);
2478 run_program_and_log_output("mkdir -p tmp", FALSE);
2479
2480 if (strlen(bkpinfo->media_device) == 0) {
2481 strcpy(bkpinfo->media_device, "/dev/st0");
2482 log_msg(2, "media_device is blank; assuming %s");
2483 }
2484 strcpy(tmp, bkpinfo->media_device);
2485 if (extract_cfg_file_and_mountlist_from_tape_dev
2486 (bkpinfo->media_device)) {
2487 strcpy(bkpinfo->media_device, "/dev/st0");
2488 if (extract_cfg_file_and_mountlist_from_tape_dev
2489 (bkpinfo->media_device)) {
2490 strcpy(bkpinfo->media_device, "/dev/osst0");
2491 if (extract_cfg_file_and_mountlist_from_tape_dev
2492 (bkpinfo->media_device)) {
2493 strcpy(bkpinfo->media_device, "/dev/ht0");
2494 if (extract_cfg_file_and_mountlist_from_tape_dev
2495 (bkpinfo->media_device)) {
2496 log_msg(3,
2497 "I tried lots of devices but none worked.");
2498 strcpy(bkpinfo->media_device, tmp);
2499 }
2500 }
2501 }
2502 }
2503
2504 if (!does_file_exist("tmp/mondo-restore.cfg")) {
2505 log_to_screen("Cannot find config info on tape/CD/floppy");
2506 return (1);
2507 }
2508 } else {
2509 log_msg(2,
2510 "gcffa --- looking at mounted CD for mindi-boot.2880.img");
2511 sprintf(command,
2512 "mount " MNT_CDROM
2513 "/images/mindi-boot.2880.img -o loop %s", mountpt);
2514 sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
2515 if (!does_file_exist(mounted_cfgf_path)) {
2516 log_msg(2,
2517 "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz");
2518 sprintf(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, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
2519 run_program_and_log_output(command, TRUE);
2520 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2521 fatal_error
2522 ("Please reinsert the disk/CD and try again.");
2523 }
2524 }
2525 }
2526 }
2527 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2528 log_msg(1, "gcffa --- great! We've got the config file");
2529 sprintf(tmp, "%s/%s",
2530 call_program_and_get_last_line_of_output("pwd"),
2531 MONDO_CFG_FILE_STUB);
2532 sprintf(command, "cp -f %s %s", tmp, cfg_file);
2533 iamhere(command);
2534 if (strcmp(tmp, cfg_file)
2535 && run_program_and_log_output(command, 1)) {
2536 log_msg(1,
2537 "... but an error occurred when I tried to move it to %s",
2538 cfg_file);
2539 } else {
2540 log_msg(1, "... and I moved it successfully to %s", cfg_file);
2541 }
2542 sprintf(command, "cp -f %s/%s %s",
2543 call_program_and_get_last_line_of_output("pwd"),
2544 MOUNTLIST_FNAME_STUB, mountlist_file);
2545 iamhere(command);
2546 if (strcmp(tmp, cfg_file)
2547 && run_program_and_log_output(command, 1)) {
2548 log_msg(1, "Failed to get mountlist");
2549 } else {
2550 log_msg(1, "Got mountlist too");
2551 sprintf(command, "cp -f %s %s", mountlist_file,
2552 g_mountlist_fname);
2553 if (run_program_and_log_output(command, 1)) {
2554 log_msg(1, "Failed to copy mountlist to /tmp");
2555 } else {
2556 log_msg(1, "Copied mountlist to /tmp as well OK");
2557 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
2558 run_program_and_log_output(command, 1);
2559/* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
2560 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
2561 {
2562 log_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME.");
2563 }
2564 else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
2565 {
2566 log_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool.");
2567 do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :)
2568 stop_raid_device("/dev/md0");
2569 stop_raid_device("/dev/md1");
2570 stop_raid_device("/dev/md2");
2571 unlink("/tmp/i-want-my-lvm");
2572 }
2573 else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
2574 {
2575 log_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME.");
2576 }
2577*/
2578 }
2579 }
2580 }
2581 run_program_and_log_output("umount " MNT_CDROM, FALSE);
2582 if (!does_file_exist(cfg_file)) {
2583 iamhere(cfg_file);
2584 log_msg(1, "%s not found", cfg_file);
2585 log_to_screen
2586 ("Oh dear. Unable to recover configuration file from boot disk");
2587 return (1);
2588 }
2589
2590 log_to_screen("Recovered mondo-restore.cfg");
2591 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
2592 log_to_screen("...but not mountlist.txt - a pity, really...");
2593 }
2594/* start SAH */
2595 else {
2596 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
2597 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2598 run_program_and_log_output(command, FALSE);
2599 }
2600/*--commented out by SAH
2601 sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
2602 run_program_and_log_output( command, FALSE );
2603 sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
2604 run_program_and_log_output( command, FALSE );
2605*/
2606/* end SAH */
2607
2608 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
2609 run_program_and_log_output(command, FALSE);
2610 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
2611 run_program_and_log_output(command, FALSE);
2612 sprintf(command, "cp -f etc/raidtab /etc/");
2613 run_program_and_log_output(command, FALSE);
2614 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
2615 run_program_and_log_output(command, FALSE);
2616 g_backup_media_type = bkpinfo->backup_media_type;
2617 paranoid_free(device);
2618 paranoid_free(command);
2619 paranoid_free(tmp);
2620 paranoid_free(cfg_file);
2621 paranoid_free(mounted_cfgf_path);
2622 paranoid_free(mountpt);
2623 paranoid_free(ramdisk_fname);
2624 paranoid_free(mountlist_file);
2625 return (retval);
2626}
2627
2628/**************************************************************************
2629 *END_GET_CFG_FILE_FROM_ARCHIVE *
2630 **************************************************************************/
2631
2632/* @} - end restoreUtilityGroup */
2633
2634
2635/***************************************************************************
2636 * F@ *
2637 * () -- Hugo Rabson *
2638 * *
2639 * Purpose: *
2640 * *
2641 * Called by: *
2642 * Params: - - *
2643 * Returns: 0=success; nonzero=failure *
2644 ***************************************************************************/
2645
2646
2647
2648void wait_until_software_raids_are_prepped(char *mdstat_file,
2649 int wait_for_percentage)
2650{
2651 struct s_mdstat *mdstat;
2652 int unfinished_mdstat_devices = 9999, i;
2653 char *screen_message;
2654
2655 malloc_string(screen_message);
2656 mdstat = malloc(sizeof(struct s_mdstat));
2657
2658 assert(wait_for_percentage <= 100);
2659 iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");
2660 while (unfinished_mdstat_devices > 0) {
2661 if (read_mdstat(mdstat, mdstat_file)) {
2662 log_to_screen("Sorry, cannot read %s", mdstat_file);
2663 return;
2664 }
2665 for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) {
2666 if (mdstat->el[i].progress < wait_for_percentage) {
2667 unfinished_mdstat_devices++;
2668 sprintf(screen_message, "Sync'ing /dev/md%d",
2669 mdstat->el[i].md);
2670 open_evalcall_form(screen_message);
2671 if (mdstat->el[i].progress == -1) // delayed while another partition inits
2672 {
2673 continue;
2674 }
2675 while (mdstat->el[i].progress < wait_for_percentage) {
2676 update_evalcall_form(mdstat->el[i].progress);
2677 sleep(2);
2678 if (read_mdstat(mdstat, mdstat_file)) {
2679 break;
2680 }
2681 }
2682 close_evalcall_form();
2683 }
2684 }
2685 }
2686 paranoid_free(screen_message);
2687 paranoid_free(mdstat);
2688}
Note: See TracBrowser for help on using the repository browser.