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

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

merge -r139:141 $SVN_M/branches/2.05
splint improvements (begin)

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