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

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

merge -r249:251 $SVN_M/branches/2.05

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