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

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

memory management continues:

  • mondoarchive handled completely
  • bkpinfo, begining of dyn. alloc.
  • lot of changes around memory everywhere

=> even if it compiles, i'm pretty sure it doesn't work yet (even not tried)

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