source: MondoRescue/branches/2.05/mondo/mondo/mondorestore/mondo-rstr-tools.c@ 251

Last change on this file since 251 was 251, checked in by bcornec, 18 years ago
  • iso-prefix should be read in iso mode even when -H not given (Stan Benoit)
  • prefix is also asked interactively for nfs mode (Bruno Cornec)
  • PACKAGE_VERSION used instead of VERSION for mondo{archive,restore} (Bruno Cornec)
  • Property svn:keywords set to Id
File size: 80.9 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 <pthread.h>
127#include "../common/my-stuff.h"
128#include "../common/mondostructures.h"
129#include "../common/libmondo.h"
130#include "mr-externs.h"
131//#include "mondo-restore.h"
132//#include "mondo-rstr-compare-EXT.h"
133#include "mondo-rstr-tools.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] = "\0";
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/%s-%d.iso", bkpinfo->isodir,
738 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 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/%s-%d.iso -t iso9660 -o loop,ro %s",
743 bkpinfo->isodir, bkpinfo->nfs_remote_dir,
744 bkpinfo->prefix, g_current_media_number, MNT_CDROM);
745#endif
746
747 } else
748 if (bkpinfo->backup_media_type == iso) {
749#ifdef __FreeBSD__
750 sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
751 bkpinfo->prefix, g_current_media_number);
752 mddev = make_vn(mount_cmd);
753 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
754#else
755 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
756 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
757#endif
758 } else if (strstr(bkpinfo->media_device, "/dev/"))
759#ifdef __FreeBSD__
760 {
761 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
762 MNT_CDROM);
763 }
764#else
765 {
766 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
767 bkpinfo->media_device, MNT_CDROM);
768 }
769#endif
770
771 else {
772 if (bkpinfo->disaster_recovery
773 && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
774 strcpy(bkpinfo->media_device,
775 last_line_of_file("/tmp/CDROM-LIVES-HERE"));
776 } else {
777 find_cdrom_device(bkpinfo->media_device, TRUE);
778 }
779
780#ifdef __FreeBSD__
781 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
782 MNT_CDROM);
783#else
784 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
785 bkpinfo->media_device, MNT_CDROM);
786#endif
787
788 }
789 log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd);
790 for (i = 0; i < 2; i++) {
791 res = run_program_and_log_output(mount_cmd, FALSE);
792 if (!res) {
793 break;
794 } else {
795 log_msg(2, "Failed to mount CD-ROM drive.");
796 sleep(5);
797 run_program_and_log_output("sync", FALSE);
798 }
799 }
800 if (res) {
801 log_msg(2, "Failed, despite %d attempts", i);
802 } else {
803 log_msg(2, "Mounted CD-ROM drive OK");
804 }
805 paranoid_free(mount_cmd);
806 return (res);
807}
808
809
810
811
812
813/**************************************************************************
814 *END_MOUNT_CDROM *
815 **************************************************************************/
816
817
818/**
819 * Mount @p device at @p mpt as @p format.
820 * @param device The device (/dev entry) to mount.
821 * @param mpt The directory to mount it on.
822 * @param format The filesystem type of @p device.
823 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
824 * @return 0 for success, nonzero for failure.
825 */
826int mount_device(char *device, char *mpt, char *format, bool writeable)
827{
828 int res = 0;
829
830 /** malloc **/
831 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
832
833 assert_string_is_neither_NULL_nor_zerolength(device);
834 assert_string_is_neither_NULL_nor_zerolength(mpt);
835 assert(format != NULL);
836 malloc_string(tmp);
837 malloc_string(command);
838 malloc_string(mountdir);
839 malloc_string(mountpoint);
840 malloc_string(additional_parameters);
841
842 if (!strcmp(mpt, "/1")) {
843 strcpy(mountpoint, "/");
844 log_msg(3, "Mommm! SME is being a dildo!");
845 } else {
846 strcpy(mountpoint, mpt);
847 }
848
849 if (!strcmp(mountpoint, "lvm")) {
850 return (0);
851 }
852 if (!strcmp(mountpoint, "image")) {
853 return (0);
854 }
855 sprintf(tmp, "Mounting device %s ", device);
856 log_msg(1, tmp);
857 if (writeable) {
858 strcpy(additional_parameters, "-o rw");
859 } else {
860 strcpy(additional_parameters, "-o ro");
861 }
862 if (find_home_of_exe("setfattr")) {
863 strcat(additional_parameters, ",user_xattr");
864 }
865 if (find_home_of_exe("setfacl")) {
866 strcat(additional_parameters, ",acl");
867 }
868
869 if (!strcmp(mountpoint, "swap")) {
870 sprintf(command, "swapon %s", device);
871 } else {
872 if (!strcmp(mountpoint, "/")) {
873 strcpy(mountdir, MNT_RESTORING);
874 } else {
875 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
876 }
877 sprintf(command, "mkdir -p %s", mountdir);
878 run_program_and_log_output(command, FALSE);
879 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
880 additional_parameters, mountdir, MONDO_LOGFILE);
881 log_msg(2, "command='%s'", command);
882 }
883 res = run_program_and_log_output(command, TRUE);
884 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
885 log_msg(1, "Re-trying without the fancy extra parameters");
886 sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
887 mountdir, MONDO_LOGFILE);
888 res = run_program_and_log_output(command, TRUE);
889 }
890 if (res) {
891 log_msg(1, "Unable to mount device %s (type %s) at %s", device,
892 format, mountdir);
893 log_msg(1, "command was '%s'", command);
894 if (!strcmp(mountpoint, "swap")) {
895 log_to_screen(tmp);
896 } else {
897 log_msg(2, "Retrying w/o the '-t' switch");
898 sprintf(command, "mount %s %s 2>> %s", device, mountdir,
899 MONDO_LOGFILE);
900 log_msg(2, "2nd command = '%s'", command);
901 res = run_program_and_log_output(command, TRUE);
902 if (res == 0) {
903 log_msg(1,
904 "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
905 } else {
906 log_to_screen(tmp);
907 }
908 }
909 }
910 if (res && !strcmp(mountpoint, "swap")) {
911 log_msg(2, "That's ok. It's just a swap partition.");
912 log_msg(2, "Non-fatal error. Returning 0.");
913 res = 0;
914 }
915
916 paranoid_free(tmp);
917 paranoid_free(command);
918 paranoid_free(mountdir);
919 paranoid_free(mountpoint);
920 paranoid_free(additional_parameters);
921
922 return (res);
923}
924
925/**************************************************************************
926 *END_MOUNT_DEVICE *
927 **************************************************************************/
928
929
930
931/**
932 * Fix some miscellaneous things in the filesystem so the system will come
933 * up correctly on the first boot.
934 */
935void protect_against_braindead_sysadmins()
936{
937 run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
938 FALSE);
939 run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
940 FALSE);
941 if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
942 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
943 FALSE);
944 }
945 run_program_and_log_output("mkdir -p " MNT_RESTORING
946 "/var/run/console", FALSE);
947 run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
948 FALSE);
949 run_program_and_log_output("cd " MNT_RESTORING
950 "; 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",
951 TRUE);
952 run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
953 TRUE);
954 run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
955 TRUE);
956}
957
958/**************************************************************************
959 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS *
960 **************************************************************************/
961
962
963
964
965/**
966 * Fill out @p bkpinfo based on @p cfg_file.
967 * @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo.
968 * @param bkpinfo The backup information structure to fill out with information
969 * from @p cfg_file.
970 * @return 0 for success, nonzero for failure.
971 */
972int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo)
973{
974 /** add mallocs **/
975 char *value;
976 char *tmp;
977 char *command;
978 char *iso_mnt;
979 char *iso_path;
980 char *old_isodir;
981 char cfg_file[100];
982 t_bkptype media_specified_by_user;
983
984 malloc_string(command);
985 malloc_string(iso_mnt);
986 malloc_string(iso_path);
987 malloc_string(old_isodir);
988 malloc_string(value);
989 malloc_string(tmp);
990// assert_string_is_neither_NULL_nor_zerolength(cfg_file);
991 assert(bkpinfo != NULL);
992
993 if (!cfgf) {
994 strcpy(cfg_file, g_mondo_cfg_file);
995 } else {
996 strcpy(cfg_file, cfgf);
997 }
998
999 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
1000
1001 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
1002 if (!strcmp(value, "cdstream")) {
1003 bkpinfo->backup_media_type = cdstream;
1004 } else if (!strcmp(value, "cdr")) {
1005 bkpinfo->backup_media_type = cdr;
1006 } else if (!strcmp(value, "cdrw")) {
1007 bkpinfo->backup_media_type = cdrw;
1008 } else if (!strcmp(value, "dvd")) {
1009 bkpinfo->backup_media_type = dvd;
1010 } else if (!strcmp(value, "iso")) {
1011/*
1012 if (am_I_in_disaster_recovery_mode()
1013 && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1)
1014 && does_file_exist(MNT_CDROM"/archives/filelist.0"))
1015*/
1016
1017// Patch by Conor Daly - 2004/07/12
1018 bkpinfo->backup_media_type = iso;
1019 if (am_I_in_disaster_recovery_mode()) {
1020 /* Check to see if CD is already mounted before mounting it... */
1021 if (!is_this_device_mounted("/dev/cdrom")) {
1022 log_msg(2,
1023 "NB: CDROM device not mounted, mounting...");
1024 run_program_and_log_output("mount /dev/cdrom "
1025 MNT_CDROM, 1);
1026 }
1027 if (does_file_exist(MNT_CDROM "/archives/filelist.0"))
1028// End patch
1029 {
1030 bkpinfo->backup_media_type = cdr;
1031 run_program_and_log_output("umount " MNT_CDROM, 1);
1032 log_it
1033 ("Re-jigging configuration AGAIN. CD-R, not ISO.");
1034 }
1035 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
1036 strcpy(bkpinfo->prefix,value);
1037 } else {
1038 strcpy(bkpinfo->prefix,STD_PREFIX);
1039 }
1040 } else if (!strcmp(value, "nfs")) {
1041 bkpinfo->backup_media_type = nfs;
1042 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
1043 strcpy(bkpinfo->prefix,value);
1044 } else {
1045 strcpy(bkpinfo->prefix,STD_PREFIX);
1046 }
1047 } else if (!strcmp(value, "tape")) {
1048 bkpinfo->backup_media_type = tape;
1049 } else if (!strcmp(value, "udev")) {
1050 bkpinfo->backup_media_type = udev;
1051 } else {
1052 fatal_error("UNKNOWN bkp-media-type");
1053 }
1054 } else {
1055 fatal_error("backup-media-type not specified!");
1056 }
1057 if (bkpinfo->disaster_recovery) {
1058 if (bkpinfo->backup_media_type == cdstream) {
1059 sprintf(bkpinfo->media_device, "/dev/cdrom");
1060// bkpinfo->media_size[0] = -1;
1061 bkpinfo->media_size[0] = 1999 * 1024;
1062 bkpinfo->media_size[1] = 650; /* good guess */
1063 } else if (bkpinfo->backup_media_type == tape
1064 || bkpinfo->backup_media_type == udev) {
1065 if (read_cfg_var(cfg_file, "media-dev", value)) {
1066 fatal_error("Cannot get tape device name from cfg file");
1067 }
1068 strcpy(bkpinfo->media_device, value);
1069 read_cfg_var(cfg_file, "media-size", value);
1070 bkpinfo->media_size[1] = atol(value);
1071 sprintf(tmp, "Backup medium is TAPE --- dev=%s",
1072 bkpinfo->media_device);
1073 log_msg(2, tmp);
1074 } else {
1075 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */
1076 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
1077 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
1078 log_msg(2, "Backup medium is CD-R[W]");
1079 }
1080 } else {
1081 log_msg(2,
1082 "Not in Disaster Recovery Mode. No need to derive device name from config file.");
1083 }
1084
1085 read_cfg_var(cfg_file, "use-star", value);
1086 if (strstr(value, "yes")) {
1087 bkpinfo->use_star = TRUE;
1088 log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
1089 }
1090
1091 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
1092 bkpinfo->internal_tape_block_size = atol(value);
1093 log_msg(1, "Internal tape block size has been custom-set to %ld",
1094 bkpinfo->internal_tape_block_size);
1095 } else {
1096 bkpinfo->internal_tape_block_size =
1097 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
1098 log_msg(1, "Internal tape block size = default (%ld)",
1099 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
1100 }
1101
1102 read_cfg_var(cfg_file, "use-lzo", value);
1103 if (strstr(value, "yes")) {
1104 bkpinfo->use_lzo = TRUE;
1105 strcpy(bkpinfo->zip_exe, "lzop");
1106 strcpy(bkpinfo->zip_suffix, "lzo");
1107 } else {
1108 read_cfg_var(cfg_file, "use-comp", value);
1109 if (strstr(value, "yes")) {
1110 bkpinfo->use_lzo = FALSE;
1111 strcpy(bkpinfo->zip_exe, "bzip2");
1112 strcpy(bkpinfo->zip_suffix, "bz2");
1113 } else {
1114 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
1115 }
1116 }
1117
1118 value[0] = '\0';
1119 read_cfg_var(cfg_file, "differential", value);
1120 if (!strcmp(value, "yes") || !strcmp(value, "1")) {
1121 bkpinfo->differential = TRUE;
1122 }
1123 log_msg(2, "differential var = '%s'", value);
1124 if (bkpinfo->differential) {
1125 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
1126 } else {
1127 log_msg(2, "This is a regular (full) backup");
1128 }
1129
1130 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
1131 if (tmp[0]
1132 ||
1133 strstr(call_program_and_get_last_line_of_output
1134 ("cat /proc/cmdline"), "donteject")) {
1135 bkpinfo->please_dont_eject = TRUE;
1136 log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
1137 }
1138
1139 if (bkpinfo->backup_media_type == nfs) {
1140 if (!cfgf) {
1141 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
1142 log_msg(2, "nfs_remote_dir remains %s",
1143 bkpinfo->nfs_remote_dir);
1144 log_msg(2,
1145 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
1146 } else {
1147 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
1148 bkpinfo->nfs_mount);
1149 read_cfg_var(g_mondo_cfg_file, "nfs-server-path",
1150 bkpinfo->nfs_remote_dir);
1151 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
1152 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
1153 }
1154 } else if (bkpinfo->backup_media_type == iso) {
1155 /* Patch by Conor Daly 23-june-2004
1156 * to correctly mount iso-dev and set a sensible
1157 * isodir in disaster recovery mode
1158 */
1159 strcpy(old_isodir, bkpinfo->isodir);
1160 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
1161 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
1162 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1163 if (!bkpinfo->isodir[0]) {
1164 strcpy(bkpinfo->isodir, old_isodir);
1165 }
1166 if (!bkpinfo->disaster_recovery) {
1167 if (strcmp(old_isodir, bkpinfo->isodir)) {
1168 log_it
1169 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
1170 old_isodir, bkpinfo->isodir);
1171 strcpy(bkpinfo->isodir, old_isodir);
1172 }
1173 }
1174 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
1175 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
1176 g_isodir_device);
1177 if (bkpinfo->disaster_recovery) {
1178 if (is_this_device_mounted(g_isodir_device)) {
1179 log_msg(2, "NB: isodir is already mounted");
1180 /* Find out where it's mounted */
1181 sprintf(command,
1182 "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
1183 g_isodir_device);
1184 log_it("command = %s", command);
1185 log_it("res of it = %s",
1186 call_program_and_get_last_line_of_output(command));
1187 sprintf(iso_mnt, "%s",
1188 call_program_and_get_last_line_of_output(command));
1189 } else {
1190 sprintf(iso_mnt, "/tmp/isodir");
1191 sprintf(tmp, "mkdir -p %s", iso_mnt);
1192 run_program_and_log_output(tmp, 5);
1193 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
1194 if (run_program_and_log_output(tmp, 3)) {
1195 log_msg(1,
1196 "Unable to mount isodir. Perhaps this is really a CD backup?");
1197 bkpinfo->backup_media_type = cdr;
1198 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */
1199 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
1200 if (mount_cdrom(bkpinfo)) {
1201 fatal_error
1202 ("Unable to mount isodir. Failed to mount CD-ROM as well.");
1203 } else {
1204 log_msg(1,
1205 "You backed up to disk, then burned some CDs. Naughty monkey!");
1206 }
1207 }
1208 }
1209 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
1210 if (bkpinfo->backup_media_type == iso) {
1211 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1212 }
1213 }
1214 }
1215
1216 if (media_specified_by_user != none) {
1217 if (g_restoring_live_from_cd) {
1218 if (bkpinfo->backup_media_type != media_specified_by_user) {
1219 log_msg(2,
1220 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
1221 interactively_obtain_media_parameters_from_user(bkpinfo,
1222 FALSE);
1223 media_specified_by_user = bkpinfo->backup_media_type;
1224 get_cfg_file_from_archive(bkpinfo);
1225/*
1226 if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
1227 { g_restoring_live_from_cd = FALSE; }
1228*/
1229 }
1230 }
1231 bkpinfo->backup_media_type = media_specified_by_user;
1232 }
1233 g_backup_media_type = bkpinfo->backup_media_type;
1234 paranoid_free(value);
1235 paranoid_free(tmp);
1236 paranoid_free(command);
1237 paranoid_free(iso_mnt);
1238 paranoid_free(iso_path);
1239 paranoid_free(old_isodir);
1240 return (0);
1241
1242}
1243
1244/**************************************************************************
1245 *END_READ_CFG_FILE_INTO_BKPINFO *
1246 **************************************************************************/
1247
1248
1249
1250
1251/**
1252 * Allow the user to edit the filelist and biggielist.
1253 * The filelist is unlinked after it is read.
1254 * @param bkpinfo The backup information structure. Fields used:
1255 * - @c bkpinfo->backup_media_type
1256 * - @c bkpinfo->isodir
1257 * - @c bkpinfo->media_device
1258 * - @c bkpinfo->tmpdir
1259 * @return The filelist structure containing the information read from disk.
1260 */
1261struct
1262s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo)
1263{
1264 struct s_node *filelist;
1265
1266 /** add mallocs**/
1267 char *command;
1268 char *tmp;
1269 int res = 0;
1270 pid_t pid;
1271
1272 assert(bkpinfo != NULL);
1273 malloc_string(command);
1274 malloc_string(tmp);
1275
1276 if (does_file_exist(g_filelist_full)
1277 && does_file_exist(g_biggielist_txt)) {
1278 log_msg(1, "%s exists", g_filelist_full);
1279 log_msg(1, "%s exists", g_biggielist_txt);
1280 log_msg(2,
1281 "Filelist and biggielist already recovered from media. Yay!");
1282 } else {
1283 getcwd(tmp, MAX_STR_LEN);
1284 chdir(bkpinfo->tmpdir);
1285 log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
1286 log_to_screen("Extracting filelist and biggielist from media...");
1287 unlink("/tmp/filelist.full");
1288 unlink("/" FILELIST_FULL_STUB);
1289 unlink("/tmp/i-want-my-lvm");
1290 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1291 sprintf(command,
1292 "tar -zxf %s %s %s %s %s %s",
1293 bkpinfo->media_device,
1294 MOUNTLIST_FNAME_STUB,
1295 BIGGIELIST_TXT_STUB,
1296 FILELIST_FULL_STUB,
1297 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
1298 log_msg(1, "tarcommand = %s", command);
1299 run_program_and_log_output(command, 1);
1300 } else {
1301 log_msg(2,
1302 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
1303 bkpinfo->isodir);
1304 insist_on_this_cd_number(bkpinfo, 1);
1305 log_msg(2, "Back from iotcn");
1306 run_program_and_log_output("mount", 1);
1307 sprintf(command,
1308 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
1309 MNT_CDROM,
1310 MOUNTLIST_FNAME_STUB,
1311 BIGGIELIST_TXT_STUB,
1312 FILELIST_FULL_STUB,
1313 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
1314
1315 log_msg(1, "tarcommand = %s", command);
1316 run_program_and_log_output(command, 1);
1317// popup_and_OK("Press ENTER to continue");
1318 if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
1319 fatal_error
1320 ("all.tar.gz did not include tmp/biggielist.txt");
1321 }
1322 if (!does_file_exist(FILELIST_FULL_STUB)) {
1323 fatal_error
1324 ("all.tar.gz did not include tmp/filelist.full.gz");
1325 }
1326 }
1327 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
1328 g_mondo_cfg_file);
1329 run_program_and_log_output(command, FALSE);
1330
1331 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
1332 BIGGIELIST_TXT_STUB, g_biggielist_txt);
1333 log_msg(1, "command = %s", command);
1334 paranoid_system(command);
1335 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
1336 FILELIST_FULL_STUB, g_filelist_full);
1337 log_msg(1, "command = %s", command);
1338 paranoid_system(command);
1339 }
1340
1341 if (am_I_in_disaster_recovery_mode()
1342 &&
1343 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
1344 {
1345// sprintf(command, "cp -f tmp/mountlist.txt /tmp");
1346 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
1347 bkpinfo->tmpdir);
1348 paranoid_system(command);
1349 }
1350
1351 chdir(tmp);
1352
1353 if (!does_file_exist(g_biggielist_txt)) {
1354 log_msg(1, "Warning - %s not found", g_biggielist_txt);
1355 }
1356 if (!does_file_exist(g_filelist_full)) {
1357 log_msg(1, "Warning - %s does not exist", g_filelist_full);
1358 }
1359// popup_and_OK("Wonderful.");
1360
1361 log_msg(2, "Forking");
1362 pid = fork();
1363 switch (pid) {
1364 case -1:
1365 fatal_error("Forking error");
1366 break;
1367
1368 case 0:
1369 log_to_screen("Pre-processing filelist");
1370 if (!does_file_exist(g_biggielist_txt)) {
1371 sprintf(command, "> %s", g_biggielist_txt);
1372 paranoid_system(command);
1373 }
1374 sprintf(command, "cat %s | grep -x \"/dev/.*\" > %s",
1375 g_biggielist_txt, g_filelist_imagedevs);
1376 paranoid_system(command);
1377 exit(0);
1378 break;
1379
1380 default:
1381 open_evalcall_form("Pre-processing filelist");
1382 while (!waitpid(pid, (int *) 0, WNOHANG)) {
1383 usleep(100000);
1384 update_evalcall_form(0);
1385 }
1386 }
1387 close_evalcall_form();
1388
1389 log_msg(3, "loading filelist");
1390 filelist = load_filelist(g_filelist_full);
1391 log_msg(3, "deleting original filelist");
1392 unlink(g_filelist_full);
1393 if (g_text_mode) {
1394 printf("Restore which directory? --> ");
1395 fgets(tmp, sizeof(tmp), stdin);
1396 toggle_path_selection(filelist, tmp, TRUE);
1397 if (strlen(tmp) == 0) {
1398 res = 1;
1399 } else {
1400 res = 0;
1401 }
1402 } else {
1403 res = edit_filelist(filelist);
1404 }
1405 if (res) {
1406 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
1407 free_filelist(filelist);
1408 return (NULL);
1409 }
1410 ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
1411 close_evalcall_form();
1412
1413 // NB: It's not necessary to add g_biggielist_txt to the filelist.full
1414 // file. The filelist.full file already contains the filename of EVERY
1415 // file backed up - regular and biggie files.
1416
1417 // However, we do want to make sure the imagedevs selected by the user
1418 // are flagged for restoring.
1419 if (length_of_file(g_imagedevs_restthese) > 2) {
1420 add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
1421 TRUE);
1422 }
1423
1424 paranoid_free(command);
1425 paranoid_free(tmp);
1426 return (filelist);
1427}
1428
1429/**************************************************************************
1430 *END_ PROCESS_FILELIST_AND_BIGGIELIST *
1431 **************************************************************************/
1432
1433
1434
1435
1436/**
1437 * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
1438 * The backup filename is the filename of the original with ".pristine" added.
1439 * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
1440 * @param filename The filename (absolute path) within @p path_root.
1441 * @return 0 for success, nonzero for failure.
1442 */
1443int backup_crucial_file(char *path_root, char *filename)
1444{
1445 char *tmp;
1446 char *command;
1447 int res;
1448
1449 malloc_string(tmp);
1450 malloc_string(command);
1451 assert(path_root != NULL);
1452 assert_string_is_neither_NULL_nor_zerolength(filename);
1453
1454 sprintf(tmp, "%s/%s", path_root, filename);
1455 sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
1456
1457 res = run_program_and_log_output(command, 5);
1458 paranoid_free(tmp);
1459 paranoid_free(command);
1460 return (res);
1461}
1462
1463
1464/**
1465 * Install the user's boot loader in the MBR.
1466 * Currently LILO, ELILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
1467 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1468 * @return 0 for success, nonzero for failure.
1469 */
1470int run_boot_loader(bool offer_to_hack_scripts)
1471{
1472 int res;
1473 int retval = 0;
1474
1475 /** malloc *******/
1476 char *device;
1477 char *tmp;
1478 char *name;
1479
1480 malloc_string(device);
1481 malloc_string(tmp);
1482 malloc_string(name);
1483 backup_crucial_file(MNT_RESTORING, "/etc/fstab");
1484 backup_crucial_file(MNT_RESTORING, "/etc/grub.conf");
1485 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
1486 backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
1487 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
1488 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
1489 sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
1490 log_msg(2, tmp);
1491 system("sync");
1492 if (!strcmp(name, "LILO")) {
1493 res = run_lilo(offer_to_hack_scripts);
1494 } else if (!strcmp(name, "ELILO")) {
1495 res = run_elilo(offer_to_hack_scripts);
1496 } else if (!strcmp(name, "GRUB")) {
1497// 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?")))
1498// {
1499 res = run_grub(offer_to_hack_scripts, device);
1500// unlink(DO_MBR_PLEASE);
1501// }
1502// else
1503// {
1504// log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
1505// res = 1;
1506// }
1507 } else if (!strcmp(name, "RAW")) {
1508 res = run_raw_mbr(offer_to_hack_scripts, device);
1509 }
1510#ifdef __FreeBSD__
1511 else if (!strcmp(name, "BOOT0")) {
1512 sprintf(tmp, "boot0cfg -B %s", device);
1513 res = run_program_and_log_output(tmp, FALSE);
1514 } else {
1515 sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device);
1516 if (!system(tmp)) {
1517 sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
1518 res = run_program_and_log_output(tmp, 3);
1519 } else {
1520 log_msg(1,
1521 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
1522 }
1523 }
1524#else
1525 else {
1526 log_to_screen
1527 ("Unable to determine type of boot loader. Defaulting to LILO.");
1528 res = run_lilo(offer_to_hack_scripts);
1529 }
1530#endif
1531 retval += res;
1532 if (res) {
1533 log_to_screen("Your boot loader returned an error");
1534 } else {
1535 log_to_screen("Your boot loader ran OK");
1536 }
1537 paranoid_free(device);
1538 paranoid_free(tmp);
1539 paranoid_free(name);
1540 return (retval);
1541}
1542
1543/**************************************************************************
1544 *END_ RUN_BOOT_LOADER *
1545 **************************************************************************/
1546
1547
1548
1549/**
1550 * Attempt to find the user's editor.
1551 * @return The editor found ("vi" if none could be found).
1552 * @note The returned string points to static storage that will be overwritten with each call.
1553 */
1554char *find_my_editor(void)
1555{
1556 static char output[MAX_STR_LEN];
1557 if (find_home_of_exe("pico")) {
1558 strcpy(output, "pico");
1559 } else if (find_home_of_exe("nano")) {
1560 strcpy(output, "nano");
1561 } else if (find_home_of_exe("e3em")) {
1562 strcpy(output, "e3em");
1563 } else if (find_home_of_exe("e3vi")) {
1564 strcpy(output, "e3vi");
1565 } else {
1566 strcpy(output, "vi");
1567 }
1568 if (!find_home_of_exe(output)) {
1569 log_msg(2, " (find_my_editor) --- warning - %s not found", output);
1570 }
1571 return (output);
1572}
1573
1574
1575/**
1576 * Install GRUB on @p bd.
1577 * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
1578 * @param bd The boot device where GRUB is installed.
1579 * @return 0 for success, nonzero for failure.
1580 */
1581int run_grub(bool offer_to_run_stabgrub, char *bd)
1582{
1583 /** malloc **/
1584 char *command;
1585 char *boot_device;
1586 char *rootdev;
1587 char *rootdrive;
1588 char *conffile;
1589 char *tmp;
1590 char *editor;
1591
1592 int res;
1593 int done;
1594
1595 malloc_string(command);
1596 malloc_string(boot_device);
1597 malloc_string(tmp);
1598 malloc_string(editor);
1599 malloc_string(rootdev);
1600 malloc_string(rootdrive);
1601 malloc_string(conffile);
1602 assert_string_is_neither_NULL_nor_zerolength(bd);
1603 strcpy(editor, "vi"); // find_my_editor() );
1604 strcpy(boot_device, bd);
1605
1606 if (!run_program_and_log_output("which grub-MR", FALSE)) {
1607 log_msg(1, "Yay! grub-MR found...");
1608 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
1609 log_msg(1, "command = %s", command);
1610 } else {
1611 sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
1612 boot_device);
1613 log_msg(1, "WARNING - grub-MR not found; using grub-install");
1614 }
1615 if (offer_to_run_stabgrub
1616 && ask_me_yes_or_no("Did you change the mountlist?"))
1617 /* interactive mode */
1618 {
1619 mvaddstr_and_log_it(g_currentY,
1620 0,
1621 "Modifying fstab and grub.conf, and running GRUB... ");
1622 for (done = FALSE; !done;) {
1623 popup_and_get_string("Boot device",
1624 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1625 boot_device, MAX_STR_LEN / 4);
1626 sprintf(command, "stabgrub-me %s", boot_device);
1627 res = run_program_and_log_output(command, 1);
1628 if (res) {
1629 popup_and_OK
1630 ("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.");
1631 newtSuspend();
1632 system("chroot " MNT_RESTORING);
1633 newtResume();
1634 popup_and_OK("Thank you.");
1635 } else {
1636 done = TRUE;
1637 }
1638 popup_and_OK("You will now edit fstab and grub.conf");
1639 if (!g_text_mode) {
1640 newtSuspend();
1641 }
1642 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1643 paranoid_system(tmp);
1644 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
1645 paranoid_system(tmp);
1646 if (!g_text_mode) {
1647 newtResume();
1648 }
1649 }
1650 } else
1651 /* nuke mode */
1652 {
1653 mvaddstr_and_log_it(g_currentY,
1654 0,
1655 "Running GRUB... ");
1656 iamhere(command);
1657 res = run_program_and_log_output(command, 1);
1658 if (res) {
1659 popup_and_OK
1660 ("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.");
1661 newtSuspend();
1662 system("chroot " MNT_RESTORING);
1663 newtResume();
1664 popup_and_OK("Thank you.");
1665 }
1666 }
1667 if (res) {
1668 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1669 log_to_screen
1670 ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.");
1671 log_msg(1, "Type:-");
1672 log_msg(1, " mount-me");
1673 log_msg(1, " chroot " MNT_RESTORING);
1674 log_msg(1, " mount /boot");
1675 log_msg(1, " grub-install '(hd0)'");
1676 log_msg(1, " exit");
1677 log_msg(1, " unmount-me");
1678 log_msg(1,
1679 "If you're really stuck, please e-mail the mailing list.");
1680 } else {
1681 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1682 }
1683 paranoid_free(rootdev);
1684 paranoid_free(rootdrive);
1685 paranoid_free(conffile);
1686 paranoid_free(command);
1687 paranoid_free(boot_device);
1688 paranoid_free(tmp);
1689 paranoid_free(editor);
1690
1691 return (res);
1692}
1693
1694/**************************************************************************
1695 *END_RUN_GRUB *
1696 **************************************************************************/
1697
1698
1699/**
1700 * Install ELILO on the user's boot drive (determined by elilo.conf).
1701 * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
1702 * @return 0 for success, nonzero for failure.
1703 */
1704int run_elilo(bool offer_to_run_stabelilo)
1705{
1706 /** malloc **/
1707 char *command;
1708 char *tmp;
1709 char *editor;
1710
1711 int res;
1712 int done;
1713
1714 malloc_string(command);
1715 malloc_string(tmp);
1716 malloc_string(editor);
1717 strcpy(editor, find_my_editor());
1718 if (offer_to_run_stabelilo
1719 && ask_me_yes_or_no("Did you change the mountlist?"))
1720
1721 /* interactive mode */
1722 {
1723 mvaddstr_and_log_it(g_currentY,
1724 0,
1725 "Modifying fstab and elilo.conf... ");
1726 sprintf(command, "stabelilo-me");
1727 res = run_program_and_log_output(command, 3);
1728 if (res) {
1729 popup_and_OK
1730 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
1731 for (done = FALSE; !done;) {
1732 if (!g_text_mode) {
1733 newtSuspend();
1734 }
1735 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1736 paranoid_system(tmp);
1737 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf",
1738 editor);
1739 paranoid_system(tmp);
1740 if (!g_text_mode) {
1741 newtResume();
1742 }
1743// newtCls();
1744 if (ask_me_yes_or_no("Edit them again?")) {
1745 continue;
1746 }
1747 done = TRUE;
1748 }
1749 } else {
1750 log_to_screen("elilo.conf and fstab were modified OK");
1751 }
1752 } else
1753 /* nuke mode */
1754 {
1755 res = TRUE;
1756 }
1757 paranoid_free(command);
1758 paranoid_free(tmp);
1759 paranoid_free(editor);
1760 return (res);
1761}
1762
1763/**************************************************************************
1764 *END_RUN_ELILO *
1765 **************************************************************************/
1766
1767
1768/**
1769 * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
1770 * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
1771 * @return 0 for success, nonzero for failure.
1772 */
1773int run_lilo(bool offer_to_run_stablilo)
1774{
1775 /** malloc **/
1776 char *command;
1777 char *tmp;
1778 char *editor;
1779
1780 int res;
1781 int done;
1782 bool run_lilo_M = FALSE;
1783 malloc_string(command);
1784 malloc_string(tmp);
1785 malloc_string(editor);
1786
1787 if (!run_program_and_log_output
1788 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
1789 run_lilo_M = TRUE;
1790 }
1791
1792 strcpy(editor, find_my_editor());
1793 if (offer_to_run_stablilo
1794 && ask_me_yes_or_no("Did you change the mountlist?"))
1795
1796 /* interactive mode */
1797 {
1798 mvaddstr_and_log_it(g_currentY,
1799 0,
1800 "Modifying fstab and lilo.conf, and running LILO... ");
1801 sprintf(command, "stablilo-me");
1802 res = run_program_and_log_output(command, 3);
1803 if (res) {
1804 popup_and_OK
1805 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
1806 for (done = FALSE; !done;) {
1807 if (!g_text_mode) {
1808 newtSuspend();
1809 }
1810 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1811 paranoid_system(tmp);
1812 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
1813 paranoid_system(tmp);
1814 if (!g_text_mode) {
1815 newtResume();
1816 }
1817// newtCls();
1818 if (ask_me_yes_or_no("Edit them again?")) {
1819 continue;
1820 }
1821 res =
1822 run_program_and_log_output("chroot " MNT_RESTORING
1823 " lilo -L", 3);
1824 if (res) {
1825 res =
1826 run_program_and_log_output("chroot " MNT_RESTORING
1827 " lilo", 3);
1828 }
1829 if (res) {
1830 done =
1831 ask_me_yes_or_no
1832 ("LILO failed. Re-edit system files?");
1833 } else {
1834 done = TRUE;
1835 }
1836 }
1837 } else {
1838 log_to_screen("lilo.conf and fstab were modified OK");
1839 }
1840 } else
1841 /* nuke mode */
1842 {
1843 mvaddstr_and_log_it(g_currentY,
1844 0,
1845 "Running LILO... ");
1846 res =
1847 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
1848 3);
1849 if (res) {
1850 res =
1851 run_program_and_log_output("chroot " MNT_RESTORING " lilo",
1852 3);
1853 }
1854 if (res) {
1855 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1856 log_to_screen
1857 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
1858 } else {
1859 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1860 }
1861 }
1862 if (run_lilo_M) {
1863 run_program_and_log_output("chroot " MNT_RESTORING
1864 " lilo -M /dev/hda", 3);
1865 run_program_and_log_output("chroot " MNT_RESTORING
1866 " lilo -M /dev/sda", 3);
1867 }
1868 paranoid_free(command);
1869 paranoid_free(tmp);
1870 paranoid_free(editor);
1871 return (res);
1872}
1873
1874/**************************************************************************
1875 *END_RUN_LILO *
1876 **************************************************************************/
1877
1878
1879/**
1880 * Install a raw MBR onto @p bd.
1881 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1882 * @param bd The device to copy the stored MBR to.
1883 * @return 0 for success, nonzero for failure.
1884 */
1885int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
1886{
1887 /** malloc **/
1888 char *command;
1889 char *boot_device;
1890 char *tmp;
1891 char *editor;
1892 int res;
1893 int done;
1894
1895 malloc_string(command);
1896 malloc_string(boot_device);
1897 malloc_string(tmp);
1898 malloc_string(editor);
1899 assert_string_is_neither_NULL_nor_zerolength(bd);
1900
1901 strcpy(editor, find_my_editor());
1902 strcpy(boot_device, bd);
1903 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
1904 log_msg(2, "run_raw_mbr() --- command='%s'", command);
1905
1906 if (offer_to_hack_scripts
1907 && ask_me_yes_or_no("Did you change the mountlist?"))
1908 /* interactive mode */
1909 {
1910 mvaddstr_and_log_it(g_currentY, 0,
1911 "Modifying fstab and restoring MBR... ");
1912 for (done = FALSE; !done;) {
1913 if (!run_program_and_log_output("which vi", FALSE)) {
1914 popup_and_OK("You will now edit fstab");
1915 if (!g_text_mode) {
1916 newtSuspend();
1917 }
1918 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1919 paranoid_system(tmp);
1920 if (!g_text_mode) {
1921 newtResume();
1922 }
1923// newtCls();
1924 }
1925 popup_and_get_string("Boot device",
1926 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1927 boot_device, MAX_STR_LEN / 4);
1928 sprintf(command, "stabraw-me %s", boot_device);
1929 res = run_program_and_log_output(command, 3);
1930 if (res) {
1931 done = ask_me_yes_or_no("Modifications failed. Re-try?");
1932 } else {
1933 done = TRUE;
1934 }
1935 }
1936 } else
1937 /* nuke mode */
1938 {
1939 mvaddstr_and_log_it(g_currentY, 0,
1940 "Restoring MBR... ");
1941 res = run_program_and_log_output(command, 3);
1942 }
1943 if (res) {
1944 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1945 log_to_screen
1946 ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.");
1947 } else {
1948 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1949 }
1950 paranoid_free(command);
1951 paranoid_free(boot_device);
1952 paranoid_free(tmp);
1953 paranoid_free(editor);
1954 return (res);
1955}
1956
1957/**************************************************************************
1958 *END_RUN_RAW_MBR *
1959 **************************************************************************/
1960
1961
1962
1963
1964
1965/**
1966 * Turn signal trapping on or off.
1967 * @param on If TRUE, then do full cleanup when we receive a signal; if FALSE, then
1968 * print a message and exit immediately.
1969 */
1970void set_signals(int on)
1971{
1972 int signals[] =
1973 { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT,
1974SIGSTOP, 0 };
1975 int i;
1976 for (i = 0; signals[i]; i++) {
1977 if (on) {
1978 signal(signals[i], terminate_daemon);
1979 } else {
1980 signal(signals[i], termination_in_progress);
1981 }
1982 }
1983}
1984
1985/**************************************************************************
1986 *END_SET_SIGNALS *
1987 **************************************************************************/
1988
1989
1990/**
1991 * malloc() and set sensible defaults for the mondorestore filename variables.
1992 * @param bkpinfo The backup information structure. Fields used:
1993 * - @c bkpinfo->tmpdir
1994 * - @c bkpinfo->disaster_recovery
1995 */
1996void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo)
1997{
1998 char *temppath;
1999
2000 assert(bkpinfo != NULL);
2001
2002 malloc_string(g_biggielist_txt);
2003 malloc_string(g_filelist_full);
2004 malloc_string(g_filelist_imagedevs);
2005 malloc_string(g_imagedevs_restthese);
2006 malloc_string(g_mondo_cfg_file);
2007 malloc_string(g_mountlist_fname);
2008 malloc_string(g_mondo_home);
2009 malloc_string(g_tmpfs_mountpt);
2010 malloc_string(g_isodir_device);
2011 malloc_string(g_isodir_format);
2012
2013 temppath = bkpinfo->tmpdir;
2014
2015 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
2016 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
2017 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
2018// sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
2019 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
2020 temppath);
2021 if (bkpinfo->disaster_recovery) {
2022 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
2023 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
2024 } else {
2025 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
2026 sprintf(g_mountlist_fname, "%s/%s", temppath,
2027 MOUNTLIST_FNAME_STUB);
2028 }
2029}
2030
2031/**************************************************************************
2032 *END_SET_GLOBAL_FILENAME *
2033 **************************************************************************/
2034
2035
2036/**
2037 * Copy @p input_file (containing the result of a compare) to @p output_file,
2038 * deleting spurious "changes" along the way.
2039 * @param output_file The output file to write with spurious changes removed.
2040 * @param input_file The input file, a list of changed files created by a compare.
2041 */
2042void streamline_changes_file(char *output_file, char *input_file)
2043{
2044 FILE *fin;
2045 FILE *fout;
2046 /** malloc **/
2047 char *incoming;
2048
2049 assert_string_is_neither_NULL_nor_zerolength(output_file);
2050 assert_string_is_neither_NULL_nor_zerolength(input_file);
2051 malloc_string(incoming);
2052
2053 if (!(fin = fopen(input_file, "r"))) {
2054 log_OS_error(input_file);
2055 return;
2056 }
2057 if (!(fout = fopen(output_file, "w"))) {
2058 fatal_error("cannot open output_file");
2059 }
2060 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
2061 fgets(incoming, MAX_STR_LEN - 1, fin)) {
2062 if (strncmp(incoming, "etc/adjtime", 11)
2063 && strncmp(incoming, "etc/mtab", 8)
2064 && strncmp(incoming, "tmp/", 4)
2065 && strncmp(incoming, "boot/map", 8)
2066 && !strstr(incoming, "incheckentry")
2067 && strncmp(incoming, "etc/mail/statistics", 19)
2068 && strncmp(incoming, "var/", 4))
2069 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
2070 }
2071 paranoid_fclose(fout);
2072 paranoid_fclose(fin);
2073 paranoid_free(incoming);
2074}
2075
2076/**************************************************************************
2077 *END_STREAMLINE_CHANGES_FILE *
2078 **************************************************************************/
2079
2080
2081
2082
2083
2084
2085/**
2086 * Prompt the user to support the Mondo project.
2087 */
2088void success_message(void)
2089{
2090 int i;
2091 /* malloc and ptr */
2092 char *tmp;
2093
2094 malloc_string(tmp);
2095 if (strstr
2096 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2097 "restore") == NULL) {
2098 if (ask_me_yes_or_no
2099 ("Have you contributed to the Mondo project financially or in some other way, yet?"))
2100 {
2101 log_to_screen
2102 ("Thank you for supporting Mondo. It goes from strength to strength,");
2103 log_to_screen("thanks to the support of users like you.");
2104 } else {
2105 if (ask_me_yes_or_no
2106 ("Are you or your company willing to consider contributing to Mondo in some way?"))
2107 {
2108 popup_and_OK
2109 ("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'.");
2110 } else {
2111 log_to_screen
2112 ("Free Software, like freedom itself, must be supported or it will be lost.");
2113 log_msg(1,
2114 "To your credit, you were honest: you said no, you wouldn't be contributing");
2115 log_msg(1,
2116 "to this project, ever. However, that makes you a freeloader. I bet you're");
2117 log_msg(1,
2118 "the sort of person who likes to sneak into movie theatres...");
2119 popup_and_OK
2120 ("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'.");
2121 }
2122 }
2123 }
2124#ifdef FREELOADER
2125 i = (int) (random()) % 32;
2126#else
2127 i = 1;
2128#endif
2129
2130 if (i != 25) {
2131 strcpy(tmp,
2132 "Mondo has restored your system. Please remove the backup media and reboot.");
2133 } else {
2134 strcpy(tmp,
2135 "M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007.");
2136 }
2137 if (strstr
2138 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2139 "restore") == NULL) {
2140 popup_and_OK(tmp);
2141 }
2142 log_to_screen(tmp);
2143 paranoid_free(tmp);
2144}
2145
2146/**************************************************************************
2147 *END_SUCCESS_MESSAGE *
2148 **************************************************************************/
2149
2150
2151
2152/**
2153 * Exit due to a signal (normal cleanup).
2154 * @param sig The signal we're exiting due to.
2155 */
2156void terminate_daemon(int sig)
2157{
2158 log_to_screen
2159 ("Mondorestore is terminating in response to a signal from the OS");
2160 paranoid_MR_finish(254);
2161}
2162
2163/**************************************************************************
2164 *END_TERMINATE_DAEMON *
2165 **************************************************************************/
2166
2167
2168/**
2169 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
2170 */
2171void twenty_seconds_til_yikes()
2172{
2173 int i;
2174 /* MALLOC * */
2175 char *tmp;
2176
2177 malloc_string(tmp);
2178 if (does_file_exist("/tmp/NOPAUSE")) {
2179 return;
2180 }
2181 open_progress_form("CAUTION",
2182 "Be advised: I am about to ERASE your hard disk(s)!",
2183 "You may press Ctrl+Alt+Del to abort safely.",
2184 "", 20);
2185 for (i = 0; i < 20; i++) {
2186 g_current_progress = i;
2187 sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
2188 update_progress_form(tmp);
2189 sleep(1);
2190 }
2191 close_progress_form();
2192 paranoid_free(tmp);
2193}
2194
2195/**************************************************************************
2196 *END_TWENTY_SECONDS_TIL_YIKES *
2197 **************************************************************************/
2198
2199
2200
2201
2202
2203/**
2204 * Exit due to a signal (no cleanup).
2205 * @param sig The signal we're exiting due to.
2206 */
2207void termination_in_progress(int sig)
2208{
2209 log_msg(1, "Termination in progress");
2210 usleep(1000);
2211 pthread_exit(0);
2212}
2213
2214/**************************************************************************
2215 *END_TERMINATION_IN_PROGRESS *
2216 **************************************************************************/
2217
2218
2219
2220/**
2221 * Unmount all devices in @p p_external_copy_of_mountlist.
2222 * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
2223 * @return 0 for success, nonzero for failure.
2224 */
2225int unmount_all_devices(struct mountlist_itself
2226 *p_external_copy_of_mountlist)
2227{
2228 struct mountlist_itself *mountlist;
2229 int retval = 0, lino, res = 0, i;
2230 char *command;
2231 char *tmp;
2232
2233 malloc_string(command);
2234 malloc_string(tmp);
2235 assert(p_external_copy_of_mountlist != NULL);
2236
2237 mountlist = malloc(sizeof(struct mountlist_itself));
2238 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
2239 sizeof(struct mountlist_itself));
2240 sort_mountlist_by_mountpoint(mountlist, 0);
2241
2242 run_program_and_log_output("df -m", 3);
2243 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
2244 open_progress_form("Unmounting devices",
2245 "Unmounting all devices that were mounted,",
2246 "in preparation for the post-restoration reboot.",
2247 "", mountlist->entries);
2248 chdir("/");
2249 for (i = 0;
2250 i < 10
2251 &&
2252 run_program_and_log_output
2253 ("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0;
2254 i++) {
2255 sleep(1);
2256 log_msg(2, "Waiting for buffer() to finish");
2257 }
2258
2259 paranoid_system("sync");
2260
2261 if (run_program_and_log_output
2262 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE)) {
2263 log_msg(1,
2264 "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)");
2265 }
2266 if (run_program_and_log_output
2267 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE)) {
2268 log_msg(1,
2269 "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)");
2270 }
2271 if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
2272 run_program_and_log_output("mkdir -p " MNT_RESTORING
2273 "/mnt/.boot.d", 5);
2274 }
2275 for (lino = mountlist->entries - 1; lino >= 0; lino--) {
2276 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
2277 continue;
2278 }
2279 sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
2280
2281 update_progress_form(tmp);
2282 if (is_this_device_mounted(mountlist->el[lino].device)) {
2283 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
2284 sprintf(command, "swapoff %s", mountlist->el[lino].device);
2285 } else {
2286 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
2287 sprintf(command, "umount %s/", MNT_RESTORING);
2288 log_msg(3,
2289 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
2290 } else {
2291 sprintf(command, "umount " MNT_RESTORING "%s",
2292 mountlist->el[lino].mountpoint);
2293 }
2294 }
2295 log_msg(10, "The 'umount' command is '%s'", command);
2296 res = run_program_and_log_output(command, 3);
2297 } else {
2298 strcat(tmp, "...not mounted anyway :-) OK");
2299 res = 0;
2300 }
2301 g_current_progress++;
2302 if (res) {
2303 strcat(tmp, "...Failed");
2304 retval++;
2305 log_to_screen(tmp);
2306 } else {
2307 log_msg(2, tmp);
2308 }
2309 }
2310 close_progress_form();
2311 if (retval) {
2312 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2313 } else {
2314 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2315 }
2316 if (retval) {
2317 log_to_screen("Unable to unmount some of your partitions.");
2318 } else {
2319 log_to_screen("All partitions were unmounted OK.");
2320 }
2321 free(mountlist);
2322 paranoid_free(command);
2323 paranoid_free(tmp);
2324 return (retval);
2325}
2326
2327/**************************************************************************
2328 *END_UNMOUNT_ALL_DEVICES *
2329 **************************************************************************/
2330
2331
2332
2333/**
2334 * Extract mondo-restore.cfg and the mountlist from the tape inserted
2335 * to the ./tmp/ directory.
2336 * @param dev The tape device to read from.
2337 * @return 0 for success, nonzero for failure.
2338 */
2339int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
2340{
2341 char *command;
2342 int res = 0;
2343 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
2344 long tape_block_size = 32768;
2345
2346 malloc_string(command);
2347
2348 // tar -zxvf-
2349 sprintf(command,
2350 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
2351 dev,
2352 tape_block_size,
2353 1024L * 1024 * 32 / tape_block_size,
2354 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
2355 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");
2356 log_msg(2, "command = '%s'", command);
2357 res = run_program_and_log_output(command, -1);
2358 if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) {
2359 res = 0;
2360 }
2361 paranoid_free(command);
2362 return (res);
2363}
2364
2365
2366
2367/**
2368 * Get the configuration file from the floppy, tape, or CD.
2369 * @param bkpinfo The backup information structure. Fields used:
2370 * - @c bkpinfo->backup_media_type
2371 * - @c bkpinfo->media_device
2372 * - @c bkpinfo->tmpdir
2373 * @return 0 for success, nonzero for failure.
2374 */
2375int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo)
2376{
2377 int retval = 0;
2378
2379 /** malloc *****/
2380 char *device;
2381 char *command;
2382 char *cfg_file;
2383 char *mounted_cfgf_path;
2384 char *tmp;
2385 char *mountpt;
2386 char *ramdisk_fname;
2387 char *mountlist_file;
2388 int res;
2389
2390 bool try_plan_B;
2391
2392 assert(bkpinfo != NULL);
2393 malloc_string(cfg_file);
2394 malloc_string(mounted_cfgf_path);
2395 malloc_string(mountpt);
2396 malloc_string(ramdisk_fname);
2397 malloc_string(mountlist_file);
2398 malloc_string(device);
2399 malloc_string(command);
2400 malloc_string(tmp);
2401 log_msg(2, "gcffa --- starting");
2402 log_to_screen("I'm thinking...");
2403 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
2404 device[0] = '\0';
2405 chdir(bkpinfo->tmpdir);
2406 strcpy(cfg_file, MONDO_CFG_FILE_STUB);
2407 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
2408 unlink(FILELIST_FULL_STUB);
2409 unlink(BIGGIELIST_TXT_STUB);
2410 unlink("tmp/i-want-my-lvm");
2411 sprintf(command, "mkdir -p %s", mountpt);
2412 run_program_and_log_output(command, FALSE);
2413
2414// unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
2415
2416 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
2417 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
2418 MOUNTLIST_FNAME_STUB);
2419 // make_hole_for_file( cfg_file );
2420 // make_hole_for_file( mountlist_file);
2421 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
2422
2423 /* Floppy? */
2424 sprintf(tmp, "mkdir -p %s", mountpt);
2425 run_program_and_log_output(tmp, FALSE);
2426 sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
2427 run_program_and_log_output(tmp, FALSE);
2428
2429 sprintf(command, "mount /dev/fd0u1722 %s", mountpt);
2430 sprintf(tmp,
2431 "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &",
2432 command);
2433 log_msg(1, "tmp = '%s'", tmp);
2434 system(tmp);
2435 res = run_program_and_log_output(command, FALSE);
2436 if (res) {
2437 sprintf(command, "mount /dev/fd0H1440 %s", mountpt);
2438 res = run_program_and_log_output(command, FALSE);
2439 }
2440 if (res) {
2441 try_plan_B = TRUE;
2442 } else {
2443 try_plan_B = TRUE;
2444 log_msg(2,
2445 "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
2446// NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK.
2447 log_msg(2, "Processing floppy (plan A?)");
2448 sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);
2449 if (!does_file_exist(ramdisk_fname)) {
2450 sprintf(ramdisk_fname, "%s/initrd.img", mountpt);
2451 }
2452 if (!does_file_exist(ramdisk_fname)) {
2453 log_msg(2,
2454 "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?");
2455 }
2456 if (extract_config_file_from_ramdisk
2457 (bkpinfo, ramdisk_fname, cfg_file, mountlist_file)) {
2458 log_msg(2,
2459 "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled.");
2460 }
2461 sprintf(command, "umount %s", mountpt);
2462 run_program_and_log_output(command, 5);
2463 unlink(ramdisk_fname);
2464 }
2465 if (!does_file_exist(cfg_file)) {
2466 log_msg(2, "gcffa --- we don't have cfg file yet.");
2467 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2468 try_plan_B = TRUE;
2469 } else {
2470 log_msg(2, "gcffa --- calling mount_cdrom now :)");
2471 if (!mount_cdrom(bkpinfo)) {
2472 log_msg(2,
2473 "gcffa --- managed to mount CD; so, no need for Plan B");
2474 try_plan_B = FALSE;
2475 } else {
2476 try_plan_B = TRUE;
2477 }
2478 if (what_number_cd_is_this(bkpinfo) > 1) {
2479 insist_on_this_cd_number(bkpinfo,
2480 (g_current_media_number = 1));
2481 }
2482 }
2483 if (try_plan_B) {
2484 log_msg(2, "gcffa --- OK, switching to Plan B");
2485 chdir(bkpinfo->tmpdir);
2486 run_program_and_log_output("mkdir -p tmp", FALSE);
2487
2488 if (strlen(bkpinfo->media_device) == 0) {
2489 strcpy(bkpinfo->media_device, "/dev/st0");
2490 log_msg(2, "media_device is blank; assuming %s");
2491 }
2492 strcpy(tmp, bkpinfo->media_device);
2493 if (extract_cfg_file_and_mountlist_from_tape_dev
2494 (bkpinfo->media_device)) {
2495 strcpy(bkpinfo->media_device, "/dev/st0");
2496 if (extract_cfg_file_and_mountlist_from_tape_dev
2497 (bkpinfo->media_device)) {
2498 strcpy(bkpinfo->media_device, "/dev/osst0");
2499 if (extract_cfg_file_and_mountlist_from_tape_dev
2500 (bkpinfo->media_device)) {
2501 strcpy(bkpinfo->media_device, "/dev/ht0");
2502 if (extract_cfg_file_and_mountlist_from_tape_dev
2503 (bkpinfo->media_device)) {
2504 log_msg(3,
2505 "I tried lots of devices but none worked.");
2506 strcpy(bkpinfo->media_device, tmp);
2507 }
2508 }
2509 }
2510 }
2511
2512 if (!does_file_exist("tmp/mondo-restore.cfg")) {
2513 log_to_screen("Cannot find config info on tape/CD/floppy");
2514 return (1);
2515 }
2516 } else {
2517 log_msg(2,
2518 "gcffa --- looking at mounted CD for mindi-boot.2880.img");
2519 sprintf(command,
2520 "mount " MNT_CDROM
2521 "/images/mindi-boot.2880.img -o loop %s", mountpt);
2522 sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
2523 if (!does_file_exist(mounted_cfgf_path)) {
2524 log_msg(2,
2525 "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz");
2526 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
2527 run_program_and_log_output(command, TRUE);
2528 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2529 fatal_error
2530 ("Please reinsert the disk/CD and try again.");
2531 }
2532 }
2533 }
2534 }
2535 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2536 log_msg(1, "gcffa --- great! We've got the config file");
2537 sprintf(tmp, "%s/%s",
2538 call_program_and_get_last_line_of_output("pwd"),
2539 MONDO_CFG_FILE_STUB);
2540 sprintf(command, "cp -f %s %s", tmp, cfg_file);
2541 iamhere(command);
2542 if (strcmp(tmp, cfg_file)
2543 && run_program_and_log_output(command, 1)) {
2544 log_msg(1,
2545 "... but an error occurred when I tried to move it to %s",
2546 cfg_file);
2547 } else {
2548 log_msg(1, "... and I moved it successfully to %s", cfg_file);
2549 }
2550 sprintf(command, "cp -f %s/%s %s",
2551 call_program_and_get_last_line_of_output("pwd"),
2552 MOUNTLIST_FNAME_STUB, mountlist_file);
2553 iamhere(command);
2554 if (strcmp(tmp, cfg_file)
2555 && run_program_and_log_output(command, 1)) {
2556 log_msg(1, "Failed to get mountlist");
2557 } else {
2558 log_msg(1, "Got mountlist too");
2559 sprintf(command, "cp -f %s %s", mountlist_file,
2560 g_mountlist_fname);
2561 if (run_program_and_log_output(command, 1)) {
2562 log_msg(1, "Failed to copy mountlist to /tmp");
2563 } else {
2564 log_msg(1, "Copied mountlist to /tmp as well OK");
2565 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
2566 run_program_and_log_output(command, 1);
2567/* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
2568 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
2569 {
2570 log_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME.");
2571 }
2572 else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
2573 {
2574 log_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool.");
2575 do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :)
2576 stop_raid_device("/dev/md0");
2577 stop_raid_device("/dev/md1");
2578 stop_raid_device("/dev/md2");
2579 unlink("/tmp/i-want-my-lvm");
2580 }
2581 else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
2582 {
2583 log_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME.");
2584 }
2585*/
2586 }
2587 }
2588 }
2589 run_program_and_log_output("umount " MNT_CDROM, FALSE);
2590 if (!does_file_exist(cfg_file)) {
2591 iamhere(cfg_file);
2592 log_msg(1, "%s not found", cfg_file);
2593 log_to_screen
2594 ("Oh dear. Unable to recover configuration file from boot disk");
2595 return (1);
2596 }
2597
2598 log_to_screen("Recovered mondo-restore.cfg");
2599 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
2600 log_to_screen("...but not mountlist.txt - a pity, really...");
2601 }
2602/* start SAH */
2603 else {
2604 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
2605 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2606 run_program_and_log_output(command, FALSE);
2607 }
2608/*--commented out by SAH
2609 sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
2610 run_program_and_log_output( command, FALSE );
2611 sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
2612 run_program_and_log_output( command, FALSE );
2613*/
2614/* end SAH */
2615
2616 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
2617 run_program_and_log_output(command, FALSE);
2618 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
2619 run_program_and_log_output(command, FALSE);
2620 sprintf(command, "cp -f etc/raidtab /etc/");
2621 run_program_and_log_output(command, FALSE);
2622 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
2623 run_program_and_log_output(command, FALSE);
2624 g_backup_media_type = bkpinfo->backup_media_type;
2625 paranoid_free(device);
2626 paranoid_free(command);
2627 paranoid_free(tmp);
2628 paranoid_free(cfg_file);
2629 paranoid_free(mounted_cfgf_path);
2630 paranoid_free(mountpt);
2631 paranoid_free(ramdisk_fname);
2632 paranoid_free(mountlist_file);
2633 return (retval);
2634}
2635
2636/**************************************************************************
2637 *END_GET_CFG_FILE_FROM_ARCHIVE *
2638 **************************************************************************/
2639
2640/* @} - end restoreUtilityGroup */
2641
2642
2643/***************************************************************************
2644 * F@ *
2645 * () -- Hugo Rabson *
2646 * *
2647 * Purpose: *
2648 * *
2649 * Called by: *
2650 * Params: - - *
2651 * Returns: 0=success; nonzero=failure *
2652 ***************************************************************************/
2653
2654
2655
2656void wait_until_software_raids_are_prepped(char *mdstat_file,
2657 int wait_for_percentage)
2658{
2659 struct s_mdstat *mdstat;
2660 int unfinished_mdstat_devices = 9999, i;
2661 char *screen_message;
2662
2663 malloc_string(screen_message);
2664 mdstat = malloc(sizeof(struct s_mdstat));
2665
2666 assert(wait_for_percentage <= 100);
2667 iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");
2668 while (unfinished_mdstat_devices > 0) {
2669 if (read_mdstat(mdstat, mdstat_file)) {
2670 log_to_screen("Sorry, cannot read %s", mdstat_file);
2671 return;
2672 }
2673 for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) {
2674 if (mdstat->el[i].progress < wait_for_percentage) {
2675 unfinished_mdstat_devices++;
2676 sprintf(screen_message, "Sync'ing /dev/md%d",
2677 mdstat->el[i].md);
2678 open_evalcall_form(screen_message);
2679 if (mdstat->el[i].progress == -1) // delayed while another partition inits
2680 {
2681 continue;
2682 }
2683 while (mdstat->el[i].progress < wait_for_percentage) {
2684 update_evalcall_form(mdstat->el[i].progress);
2685 sleep(2);
2686 if (read_mdstat(mdstat, mdstat_file)) {
2687 break;
2688 }
2689 }
2690 close_evalcall_form();
2691 }
2692 }
2693 }
2694 paranoid_free(screen_message);
2695 paranoid_free(mdstat);
2696}
Note: See TracBrowser for help on using the repository browser.