source: trunk/mondo/mondo/mondorestore/mondo-restore.c @ 181

Last change on this file since 181 was 181, checked in by bcornec, 14 years ago

merge -r177:180 $SVN_M/branches/2.05

  • Property svn:keywords set to Id
File size: 113.3 KB
Line 
1/***************************************************************************
2       mondo-restore.c  -  restores mondoarchive data
3                             -------------------
4    begin                : Fri May 19 2000
5    copyright            : (C) 2000 by Hugo Rabson
6    email                : Hugo Rabson <hugorabson@msn.com>
7    cvsid                : $Id: mondo-restore.c 181 2005-12-13 00:35:27Z bcornec $
8***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation; either version 2 of the License, or     *
15 *   (at your option) any later version.                                   *
16 *                                                                         *
17 ***************************************************************************/
18
19/***************************************************************************
20 *                         Change Log                                      *
21 ***************************************************************************
22.
23
24
2507/26
26- workaround - if not /dev then don't call partimagehack
27
2807/21
29- if switch to Interactive Mode during nuke then don't nuke twice :) just once
30
3107/18
32- better support of users who boot from LVM CD and nuke-restore non-LVM backups
33
3407/10
35- when using 'star', exclude all 'not removed.' messages from log (misleading, they are)
36- try w/ ACLs, then w/o ACLs if star fails w/ ACLs
37- added ACL, xattr support for afio
38
3906/26
40- remove make_relevant_partition_bootable(); roll into mondo-prep.c
41- changed various newtDrawRootText() calls to use g_noof_rows instead of
42  integers
43
4406/19
45- don't try to access biggiestruct before it is populated w/ data relating
46  to biggiefile; instead, use control char to find out if biggiefile is
47  to be restored w/ partimagehack or not
48- added AUX_VER
49
5006/15
51- read_cfg_file_into_bkpinfo() --- use user-supplied 'isodir' instead of
52  archive's 'isodir' if different
53  Conor Daly <conor.daly@met.ie>
54
5506/17
56- restore with partimagehack if NTFS device; dd, if non-NTFS device
57
5806/14
59- unmount all; remount, run grub-mr; unmount again
60
6104/09
62- fixed subset restoration bug introduced when I added 'star' support
63
6404/04
65- cleaned up restore_a_tarball_from_stream()
66
6704/03
68- added star support
69- pause for 3s between partitioning and formatting (if in Nuke Mode)
70
7103/28
72- check that g_mountlist_fname was correcfly set; abort if it wasn't
73
7403/25
75- removed dev_null code
76
7703/22/04
78- added mode_of_file()
79- added code to check for unauthorised modification of /dev/null
80  by afio (for instance)
81
8212/27/03
83- check /tmp/cmdline instead of /proc/cmdline if on FreeBSD
84
8511/15
86- added g_fprep
87- "Switch to interactive mode?" msg is now more informative
88
8911/05
90- after 'Are you sure?' when user specifies / as restore path, set
91  restore_path[] to "" so that files are restored to [blank]/file/name :)
92
9310/29
94- moved "No restoring or comparing will take place today" block
95  up to before iso_fiddly_bits (if iso) is called - fix bug
96  if you're in ISO Mode and you say "exit to shell"
97
9810/22
99- swapped calls to chmod() and chown() after restoration
100  of big files (Jens)
101
10210/21
103- changed "/mnt/cdrom" to MNT_CDROM
104
10510/19
106- restore biggiefiles selectively from CD properly
107- use find_my_editor() to find pico/vi/whatever
108- better use of call_program_and_get_last_line_of_output() to
109  scan /proc/cmdline
110
11110/18
112- don't report 'missing compressor' if no compressor used at all
113
11410/14
115- log afio's error messages to /var/log/mondo-archive.log
116  when restoring :)
117- call vi if pico is not available
118
11910/09
120- better logging if fatal error (cannot openout bigfile)
121- better GUI feedback when restoring big files
122- restore_everything() now uses s_node* instead of char*
123- ditto restore_all_*_from_*()
124
12510/02
126- succinct msg instead of pop-ups, if used -H
127
12809/27
129- tweaked restore-time gui
130
13109/26
132- proper reporting of DVD/CDR/etc. type in displayed dialogs
133
13409/23
135- malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
136  and free_libmondo_global_strings() - which are in libmondo-tools.c
137
13809/21
139- trying to fix "mondorestore <no params>" segfault
140
14109/18
142- better remounting of /
143- cleaned up run_grub()
144- sensible command-line handling in Live Mode
145
14609/17
147- cleaned up GRUB installer script a bit
148
14909/15
150- remount / as r/w if in disaster recovery mode;
151  helps for b0rken distros
152
15309/13
154- major NTFS hackage
155
15609/12
157- changed some in-sub var decl'ns to malloc()'s
158
15909/05
160- don't let me run unless I'm root
161- finished NTFS/partimagehack support (CD only); working on tape now
162
16309/01
164- fixed cosmetic bug in biggiefile restore window
165
16606/01 - 08/31
167- added code to main() to make sure NFS
168  (backup) share is mounted in Nuke and Compare Modes
169- added code to run_grub() to mount /boot before running grub-install
170- fixed some stray assert()'s in restore_a_biggiefile_from_stream()
171- fixed bugs in extract_config_file_from_ramdisk()
172  and get_cfg_file_from_archive() which
173  stopped fape+floppy users from being able to
174  boot from floppy and leave floppy in drive :)
175- added hooks to partimage for doing imagedevs
176- fixed calls to popup_and_get_string()
177
17805/01 - 05/31
179- fixed biggiefile atime/utime dates restoration bug, I think
180- added misc clean-up (Steve Hindle)
181- fixed support for subdir-within-NFS-mount
182- if nuke mode fails & user reverts to interactive mode _and succeeds_,
183  don't claim nuke mode aborted :)
184- unmount_all_devices() uses mountlist->el[lino].mountpt
185  instead of mountlist->el[lino].device where possible
186- added Joshua Oreman's FreeBSD patches
187- copied missing paragraph from 1.6x's read_cfg_file_into_bkpinfo()
188  to 1.7x's; affected tape streamer users (badly!)
189- cleaned up some paranoid assert()'s
190- use which("post-nuke") instead of find_home_of_exe("post-nuke")
191- fixed "Don't eject while restoring" mode
192- get_cfg_file_from_archive() --- also recovers mountlist.txt now :)
193- don't eject if 'donteject' is in kernel's command line
194- added 'don't panic' msg to start of log
195
19604/01 - 04/30
197- added text mode (cat /proc/cmdline; if textonly then text mode is on)
198- delete /var/lock/subsys/ * when nuking
199- don't resize mountlist if "noresize" present in /proc/cmdline
200- changed from chmod -R 1777 tmp to chmod 1777 tmp
201- replace newtFinished() and newtInit() with
202  newtSuspend() and newtResume()
203- get_cfg_file_from_archive() returns 1 instead of aborting now
204- read_cfg_file_into_bkpinfo) --- if autorun CD but its config
205  file indicates a non-CD backup media then ask, just in case
206- sped up restore_a_tarball_from_CD() a bit
207- line 4469 --- if post-nuke not found then don't run it :)
208- replaced "/mnt/RESTORING" with MNT_RESTORING (#define'd)
209- moved compare_*() into mondorestore/mondo-rstr-compare.c
210- moved some RAID subroutines into common/libmondo-raid.c
211- fixed some iso live compare problems
212- replaced FILELIST_FULL with g_filelist_full and FILELIST_FULL_STUB;
213  g_filelist_full being the full path of the filelist.full text file and
214  FILELIST_FULL_STUB being "tmp/filelist.full" (relative path);
215- ditto BIGGIELIST_TXT, MONDO_CFG_FILE
216- added lots of assert()'s and log_OS_error()'s
217- in Nuke Mode, check mountlist's sanity before doing anything else;
218  if it fails sanity test, offer to revert to Interactive Mode (or abort)
219- copy log to /mnt/RESTORING/root at end
220- read_cfg_file_into_bkpinfo() --- read iso-dev and isodir if bkptype==iso
221- line 1701 --- delete ramdisk file after extracting config info
222- moved call to make_relevant_partitions_bootable() from
223  within run_boot_loader() to within interactive_mode() and
224  nuke_mode(), after unmounting disks
225- if editing fstab or *.conf, try to use pico if available
226- better calling of make-me-bootable
227- don't sort mountlist anywhere anymore except _locally_ in
228  mount_all_devices() and unmount_all_devices()
229- edit fstab, grub.conf _after_ stabgrub-me if it fails
230- run_boot_loader() --- backup all crucial files to /etc/ *.pristine first
231- added iso_fiddly_bits()
232- fixed ISO mode support
233- mount_cdrom() only searches for device if NOT in disaster recovery mode
234- changed lost of system()'s into run_program_and_log_output()'s
235- don't eject if bkpinfo->please_dont_eject_when_restoring
236- cleaned up post-nuke handling code
237- always eject CD at end, unless bkpinfo->please_dont_...
238- misc clean-up (Tom Mortell)
239- afio uses -c (1024L*1024L)/TAPE_BLOCK_SIZE now
240  instead of -c 1024
241
24201/01 - 03/31/2003
243- commented out sort_... line (BB)
244- clean-up (Stan Benoit)
245- added code for LVM and SW Raid (Brian Borgeson)
246- line 814 - added -p to 'mkdir -p tmp'
247- mount_cdrom() - calls find_cdrom_device() if
248  bkpinfo->media_device is blank (to fill it)
249
25011/01 - 12/31/2002
251- mount_cdrom() better at handling multiple CD drives
252- minor clean-up in restore_a_tarball_from_CD()
253- if --live-from-cd then assume restoring live from CD
254- tweaked it to run better w/ ArkLinux
255- create /mnt/RESTORING/mnt/.boot.d for Gentoo users
256  after restoring
257- cleaned up iso_mode(); no longer asks for NFS info 3 times
258- mount_cdrom() was trying to mount /mnt/isodir/%s/%d.iso;
259  is now just %s/%d.iso
260- mount/unmount /boot if necessary (Gentoo)
261- added RAW MBR support; added run_raw_mbr() for the purpose
262- unmount & remount supermounts at start/end of live restore
263- copy /tmp/mountlist.txt to /tmp/mountlist.txt.orig at start
264- cleaned up string-handling in get_cfg_info_from_archives()
265- fixed run_grub() to call new stabgrub-me script
266- popup list of changed files after Compare Mode
267- permit mondorestore --edit-mountlist even if live mode
268- create a repaired copy of grub-install which is RAID-friendly;
269  use it when initializing boot sector with run_grub()
270- use grub-MR instead of grub-install
271- fixed read_cfg_file_into_bkpinfo() to ignore cfg file's backup_media_type
272  if user has already specified a backup media type interactively
273
27410/01 - 10/31
275- run_grub() will let you specify the boot device as well as edit the system
276  files, if grub-install fails
277- fixed bug in fwrite() call in restore_biggiefile_from_CD()
278- fixed bug affecting restoration of bigfiles from CD's w/0 compression
279- run_grub() will run 'grub-install {boot device}' instead of
280  'grub-install (hd0)'
281
28209/01 - 09/30
283- use /tmp/tmpfs/mondo.tmp instead of /tmp/mondo.tmp
284- initialize MOUNTLIST_FNAME at start of main()
285- differential-related cleanup
286- better handling of CD-ROM drives which aren't /dev/cdrom :)
287- run_program_and_log_output() now takes boolean operator to specify
288  whether it will log its activities in the event of _success_
289- always load config file from archive before operating on it
290- moved some subroutines around; now closer to alphabetical order
291- changed mount.mindi to mount.bootisk
292- mount disks readonly if in Compare Mode
293- set /dev/null's permissions to 777, just in case it somehow gets mangled
294  ...which apparently happen with some devfs-based Linux distributions
295- remove /var/run/ *.pid after restoring
296- move spurious lockfiles from /home/ * to /home/ * /.disabled
297- if Interactive Mode then ask user which media, etc. (i.e. catchall mode
298  is now same as Interactive Mode)
299
30008/01 - 08/30
301- use data structure to store the fname, checksum, mods & perms of each bigfile
302  ... biggiestruct :)
303- if a filelist is tiny (2 bytes or less) then ignore it
304- insist_on_this_cd_number() --- now takes 2 params, not 1
305- re-enabled 'g_current_media_number = 1' in restore_everything()
306- added same to compare_mode()
307- replaced lots of global char[]'s with malloc()'s
308- if differential backup then don't permit formatting or fdisking,
309  whether Interactive or Nuke mode
310- added call to register_pid() at start of main()
311- if Nuke Mode & it succeeds then ask user if they have contributed yet
312- changed tape-size to media-size (config file)
313- changed using_* to backup_media_type
314- changed *_from_tape to *_from_stream
315
31607/01 - 07/31
317- added find_and_mount_actual_cdrom()
318- temp dir is always random
319- skip tarballs if they don't contain files we're looking for
320  (used to read the whole thing & _then_ skip)
321- use media_size[1] instead of media_size[0]
322- fixed serious bug in line 1546 - should have been !=, not ==; stopped
323  mondorestore from correctly restoring big files
324- bigfile piping enhancements (Philippe de Muyter)
325- unmount CD-ROM after restoring from live filesystem
326- TAPE_BLOCK_SIZE treated as %ld, not %d
327
32806/01 - 06/30
329- added signal-trapping
330- disabled 'nr-failed-disks' flag
331- fixed problem w/selective restore
332- don't change /tmp's permissions unless it doesn't exist & must be created
333- fixed bug in --mbr
334- is_file_in_list() enhanced to exclude /mnt/RESTORING or whatever
335- added support for uncompressed archives
336- --monitas-live now accepts path-to-restore_to_, not just path to restore
337- added some debugging/tracking code to the NFS section
338- various monitas-related enhancements
339- added --isonuke and --mbr switches
340- better logging in run_grub()
341- improved --monitas-live
342- mkdir -p /mnt/RESTORING/var/run/console just in case user excludes it
343- afio now uses 16MB buffer instead of 8MB
344- always use bkpinfo->media_size[0], now that -s has been expanded
345- popup and ask where to restore data, if restoring selectively
346
34705/01 - 05/31
348- add '--monitas' flag
349- don't run chmod -R 1777 /mnt/RESTORING/tmp before unmounting unless
350  restoring at the time...
351
35204/01 - 04/30
353- delete old /tmp/filelist.full,biggielist.txt if found when restoring to
354  live filesystem
355- replace MONDO_VERSION #define with VERSION from ../config.h
356- write fname of bigfile to screen when having trouble reading/comparing it
357- if restoring to live filesystem then wipe /tmp/tmpfs/ * afterwards
358- removed spurious finish(0) from main()
359
36003/01 - 03/31/2002
361- if /tmp/m*ndo-restore.cfg not found then assume live restore; restore
362  to / instead of /mnt/RESTORING
363- clean up is_file_in_list() to deal with the /mnt/RESTORING/ prefix
364- exclude leading '/' from filelist.restore-these
365- if /tmp/fstab.new exists then use _it_ instead of /tmp/fstab to label
366  ext2 or ext3 partitions
367- improved logging
368
369[...]
370
37107/10/2001 --- first incarnation
372*/
373
374
375/**
376 * @file
377 * The main file for mondorestore.
378 */
379
380/**************************************************************************
381 * #include statements                                                    *
382 **************************************************************************/
383#include "../common/my-stuff.h"
384#include "../common/mondostructures.h"
385#include "../common/libmondo.h"
386#include "mr-externs.h"
387#include "mondo-restore.h"
388#include "mondo-rstr-compare-EXT.h"
389#include "mondo-rstr-tools-EXT.h"
390#ifndef S_SPLINT_S
391#include <pthread.h>
392#endif
393
394extern void success_message(void);
395extern void twenty_seconds_til_yikes(void);
396
397
398/* For use in other programs (ex. XMondo) */
399#ifdef MONDORESTORE_MODULE
400#define main __mondorestore_main
401#define g_ISO_restore_mode __mondorestore_g_ISO_restore_mode
402#endif
403
404#ifndef VERSION
405#define VERSION AUX_VER
406#endif
407
408char g_version[] = VERSION;
409
410
411//static char cvsid[] = "$Id: mondo-restore.c 181 2005-12-13 00:35:27Z bcornec $";
412
413/**************************************************************************
414 * Globals                                                                *
415 **************************************************************************/
416extern char *g_tmpfs_mountpt;   // declared in libmondo-tools.c
417extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free
418                                                // up global bkpinfo struct
419extern bool g_text_mode;
420extern FILE *g_fprep;
421extern double g_kernel_version;
422extern int g_partition_table_locked_up;
423extern int g_noof_rows;
424
425extern int partition_everything(struct mountlist_itself *mountlist);
426
427
428/**
429 * @name Restore-Time Globals
430 * @ingroup globalGroup
431 * @{
432 */
433/**
434 * If TRUE, then SIGPIPE was just caught.
435 * Set by the signal handler; cleared after it's handled.
436 */
437bool g_sigpipe_caught = FALSE;
438
439/**
440 * If TRUE, then we're restoring from ISOs or an NFS server.
441 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
442 */
443bool g_ISO_restore_mode = FALSE;    /* are we in Iso Mode? */
444
445/**
446 * If TRUE, then we have had a successful "nuke" restore.
447 */
448bool g_I_have_just_nuked = FALSE;
449
450/**
451 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
452 */
453char *g_isodir_device;
454
455/**
456 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
457 */
458char *g_isodir_format;
459
460/**
461 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
462 */
463char *g_biggielist_txt;
464
465/**
466 * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
467 * the current archive set.
468 */
469char *g_filelist_full;
470
471/**
472 * The location of a file containing a list of the devices that were archived
473 * as images, not as individual files.
474 */
475char *g_filelist_imagedevs;
476
477/**
478 * The location of a file containing a list of imagedevs to actually restore.
479 * @see g_filelist_imagedevs
480 */
481char *g_imagedevs_restthese;
482
483/**
484 * The location of 'mondo-restore.cfg', containing the metadata
485 * information for this backup.
486 */
487char *g_mondo_cfg_file;
488
489/**
490 * The location of 'mountlist.txt', containing the information on the
491 * user's partitions and hard drives.
492 */
493char *g_mountlist_fname;
494
495/**
496 * Mondo's home directory during backup. Unused in mondo-restore; included
497 * to avoid link errors.
498 */
499char *g_mondo_home;
500
501/* @} - end of "Restore-Time Globals" in globalGroup */
502
503
504
505extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
506                                 char direction);
507
508
509
510/**************************************************************************
511 * COMPAQ PROLIANT Stuff:  needs some special help                        *
512**************************************************************************/
513
514/**
515 * The message to display if we detect that the user is using a Compaq Proliant.
516 */
517#define COMPAQ_PROLIANTS_SUCK "Partition and format your disk using Compaq's disaster recovery CD. After you've done that, please reboot with your Mondo CD/floppy in Interactive Mode."
518
519
520
521
522/**
523 * Allow the user to modify the mountlist before we partition & format their drives.
524 * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
525 * @param mountlist The mountlist to let the user modify.
526 * @param raidlist The raidlist that goes with @p mountlist.
527 * @return 0 for success, nonzero for failure.
528 * @ingroup restoreGuiGroup
529 */
530int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
531                                struct mountlist_itself *mountlist,
532                                struct raidlist_itself *raidlist)
533{
534    int retval = 0, res = 0;
535
536    log_msg(2, "let_user_edit_the_mountlist() --- starting");
537
538    assert(bkpinfo != NULL);
539    assert(mountlist != NULL);
540    assert(raidlist != NULL);
541    if (!bkpinfo->disaster_recovery) {
542        strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
543        log_msg(2, "I guess you're testing edit_mountlist()");
544    }
545    if (!does_file_exist(g_mountlist_fname)) {
546        log_to_screen(g_mountlist_fname);
547        log_to_screen("does not exist");
548        return (1);
549    }
550
551    retval = load_mountlist(mountlist, g_mountlist_fname);
552    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
553    if (retval) {
554        log_to_screen
555            ("Warning - load_raidtab_into_raidlist returned an error");
556    }
557    res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
558    if (res) {
559        return (1);
560    }
561
562    save_mountlist_to_disk(mountlist, g_mountlist_fname);
563    save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
564
565    log_to_screen("I have finished editing the mountlist for you.");
566
567    return (retval);
568}
569
570
571
572
573
574/**
575 * Determine whether @p mountlist contains a Compaq diagnostic partition.
576 * @param mountlist The mountlist to examine.
577 * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
578 * @ingroup restoreUtilityGroup
579 */
580bool
581partition_table_contains_Compaq_diagnostic_partition(struct
582                                                     mountlist_itself *
583                                                     mountlist)
584{
585    int i;
586
587    assert(mountlist != NULL);
588
589    for (i = 0; i < mountlist->entries; i++) {
590        if (strstr(mountlist->el[i].format, "ompaq")) {
591            log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
592                    i, mountlist->el[i].device, mountlist->el[i].format);
593
594            return (TRUE);
595        }
596    }
597    return (FALSE);
598}
599
600/**************************************************************************
601 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION                *
602 **************************************************************************/
603
604
605/**
606 * Allow the user to abort the backup if we find that there is a Compaq diagnostic partition.
607 * @note This function does not actually check for the presence of a Compaq partition.
608 * @ingroup restoreUtilityGroup
609 */
610void offer_to_abort_because_Compaq_Proliants_suck(void)
611{
612    popup_and_OK(COMPAQ_PROLIANTS_SUCK);
613    if (ask_me_yes_or_no
614        ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
615    {
616        fatal_error
617            ("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
618    }
619}
620
621/**************************************************************************
622 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK                        *
623 **************************************************************************/
624
625
626
627/**
628 * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
629 * @param bkpinfo The backup information structure. Most fields are used.
630 * @param mountlist The mountlist containing information about the user's partitions.
631 * @param raidlist The raidlist to go with @p mountlist.
632 * @return The return code from the mode function called.
633 * @ingroup restoreGroup
634 */
635int
636catchall_mode(struct s_bkpinfo *bkpinfo,
637              struct mountlist_itself *mountlist,
638              struct raidlist_itself *raidlist)
639{
640    char c, *tmp;
641    int retval = 0;
642
643    iamhere("inside catchall");
644    assert(bkpinfo != NULL);
645    assert(mountlist != NULL);
646    assert(raidlist != NULL);
647    malloc_string(tmp);
648    iamhere("pre wrm");
649    c = which_restore_mode();
650    iamhere("post wrm");
651    if (c == 'I' || c == 'N' || c == 'C') {
652        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
653    } else {
654        popup_and_OK("No restoring or comparing will take place today.");
655        if (is_this_device_mounted("/mnt/cdrom")) {
656            run_program_and_log_output("umount /mnt/cdrom", FALSE);
657        }
658        if (g_ISO_restore_mode) {
659            sprintf(tmp, "umount %s", bkpinfo->isodir);
660            run_program_and_log_output(tmp, FALSE);
661        }
662        paranoid_MR_finish(0);
663    }
664
665    iamhere("post int");
666
667    if (bkpinfo->backup_media_type == iso) {
668        if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
669            log_msg(2,
670                    "catchall_mode --- iso_fiddly_bits returned w/ error");
671            return (1);
672        } else {
673            log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
674        }
675    }
676
677    if (c == 'I') {
678        log_msg(2, "IM selected");
679        retval += interactive_mode(bkpinfo, mountlist, raidlist);
680    } else if (c == 'N') {
681        log_msg(2, "NM selected");
682        retval += nuke_mode(bkpinfo, mountlist, raidlist);
683    } else if (c == 'C') {
684        log_msg(2, "CM selected");
685        retval += compare_mode(bkpinfo, mountlist, raidlist);
686    }
687    paranoid_free(tmp);
688    return (retval);
689}
690
691/**************************************************************************
692 *END_CATCHALL_MODE                                                      *
693 **************************************************************************/
694
695/**************************************************************************
696 *END_  EXTRACT_CONFIG_FILE_FROM_RAMDISK                                  *
697 **************************************************************************/
698
699
700/**
701 * Locate an executable in the directory structure rooted at @p restg.
702 * @param out_path Where to put the executable.
703 * @param fname The basename of the executable.
704 * @param restg The directory structure to look in.
705 * @note If it could not be found in @p restg then @p fname is put in @p out_path.
706 * @ingroup restoreUtilityGroup
707 */
708void
709find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
710                                                    char *fname,
711                                                    char *restg)
712{
713    assert(out_path != NULL);
714    assert_string_is_neither_NULL_nor_zerolength(fname);
715
716    sprintf(out_path, "%s/sbin/%s", restg, fname);
717    if (does_file_exist(out_path)) {
718        sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
719        if (does_file_exist(out_path)) {
720            sprintf(out_path, "%s/bin/%s", restg, fname);
721            if (does_file_exist(out_path)) {
722                sprintf(out_path, "%s/usr/bin/%s", restg, fname);
723                if (does_file_exist(out_path)) {
724                    strcpy(out_path, fname);
725                }
726            }
727        }
728    }
729}
730
731/**************************************************************************
732 *END_FIND_PATHNAME_OF_EXECUTABLE_PREFERABLY_IN_RESTORING                 *
733 **************************************************************************/
734
735
736
737
738/**
739 * @addtogroup restoreGroup
740 * @{
741 */
742/**
743 * Restore the user's data, in a disaster recovery situation, prompting the
744 * user about whether or not to do every step.
745 * The user can edit the mountlist, choose files to restore, etc.
746 * @param bkpinfo The backup information structure. Most fields are used.
747 * @param mountlist The mountlist containing information about the user's partitions.
748 * @param raidlist The raidlist to go with @p mountlist.
749 * @return 0 for success, or the number of errors encountered.
750 */
751int
752interactive_mode(struct s_bkpinfo *bkpinfo,
753                 struct mountlist_itself *mountlist,
754                 struct raidlist_itself *raidlist)
755{
756    int retval = 0;
757    int res;
758    int ptn_errs = 0;
759    int fmt_errs = 0;
760
761    bool done;
762    bool restore_all;
763
764  /** needs malloc **********/
765    char *tmp;
766    char *fstab_fname;
767    char *old_restpath;
768
769    struct s_node *filelist;
770
771    /* try to partition and format */
772
773    log_msg(2, "interactive_mode --- starting (great, assertions OK)");
774
775    malloc_string(tmp);
776    malloc_string(fstab_fname);
777    malloc_string(old_restpath);
778    assert(bkpinfo != NULL);
779    assert(mountlist != NULL);
780    assert(raidlist != NULL);
781
782    log_msg(2, "interactive_mode --- assertions OK");
783
784    if (g_text_mode) {
785        if (!ask_me_yes_or_no
786            ("Interactive Mode + textonly = experimental! Proceed anyway?"))
787        {
788            fatal_error("Wise move.");
789        }
790    }
791
792    iamhere("About to load config file");
793    get_cfg_file_from_archive_or_bust(bkpinfo);
794    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
795    iamhere("Done loading config file; resizing ML");
796#ifdef __FreeBSD__
797    if (strstr
798        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
799         "noresize"))
800#else
801    if (strstr
802        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
803         "noresize"))
804#endif
805    {
806        log_msg(1, "Not resizing mountlist.");
807    } else {
808        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
809    }
810    for (done = FALSE; !done;) {
811        iamhere("About to edit mountlist");
812        if (g_text_mode) {
813            save_mountlist_to_disk(mountlist, g_mountlist_fname);
814            sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
815            res = system(tmp);
816            load_mountlist(mountlist, g_mountlist_fname);
817        } else {
818            res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
819        }
820        iamhere("Finished editing mountlist");
821        if (res) {
822            paranoid_MR_finish(1);
823        }
824        log_msg(2, "Proceeding...");
825        save_mountlist_to_disk(mountlist, g_mountlist_fname);
826        save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
827        mvaddstr_and_log_it(1, 30, "Restoring Interactively");
828        if (bkpinfo->differential) {
829            log_to_screen("Because this is a differential backup, disk");
830            log_to_screen
831                (" partitioning and formatting will not take place.");
832            done = TRUE;
833        } else {
834            if (ask_me_yes_or_no
835                ("Do you want to erase and partition your hard drives?")) {
836                if (partition_table_contains_Compaq_diagnostic_partition
837                    (mountlist)) {
838                    offer_to_abort_because_Compaq_Proliants_suck();
839                    done = TRUE;
840                } else {
841                    twenty_seconds_til_yikes();
842                    g_fprep = fopen("/tmp/prep.sh", "w");
843                    ptn_errs = partition_everything(mountlist);
844                    if (ptn_errs) {
845                        log_to_screen
846                            ("Warning. Errors occurred during disk partitioning.");
847                    }
848
849                    fmt_errs = format_everything(mountlist, FALSE);
850                    if (!fmt_errs) {
851                        log_to_screen
852                            ("Errors during disk partitioning were handled OK.");
853                        log_to_screen
854                            ("Partitions were formatted OK despite those errors.");
855                        ptn_errs = 0;
856                    }
857                    if (!ptn_errs && !fmt_errs) {
858                        done = TRUE;
859                    }
860                }
861                paranoid_fclose(g_fprep);
862            } else {
863                mvaddstr_and_log_it(g_currentY++, 0,
864                                    "User opted not to partition the devices");
865                if (ask_me_yes_or_no
866                    ("Do you want to format your hard drives?")) {
867                    fmt_errs = format_everything(mountlist, TRUE);
868                    if (!fmt_errs) {
869                        done = TRUE;
870                    }
871                } else {
872                    ptn_errs = fmt_errs = 0;
873                    done = TRUE;
874                }
875            }
876            if (fmt_errs) {
877                mvaddstr_and_log_it(g_currentY++,
878                                    0,
879                                    "Errors occurred. Please repartition and format drives manually.");
880                done = FALSE;
881            }
882            if (ptn_errs & !fmt_errs) {
883                mvaddstr_and_log_it(g_currentY++,
884                                    0,
885                                    "Errors occurred during partitioning. Formatting, however, went OK.");
886                done = TRUE;
887            }
888            if (!done) {
889                if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
890                    retval++;
891                    goto end_of_func;
892                }
893            }
894        }
895    }
896
897    /* mount */
898    if (mount_all_devices(mountlist, TRUE)) {
899        unmount_all_devices(mountlist);
900        retval++;
901        goto end_of_func;
902    }
903    /* restore */
904    if ((restore_all =
905         ask_me_yes_or_no("Do you want me to restore all of your data?")))
906    {
907        log_msg(1, "Restoring all data");
908        retval += restore_everything(bkpinfo, NULL);
909    } else
910        if ((restore_all =
911             ask_me_yes_or_no
912             ("Do you want me to restore _some_ of your data?"))) {
913        strcpy(old_restpath, bkpinfo->restore_path);
914        for (done = FALSE; !done;) {
915            unlink("/tmp/filelist.full");
916            filelist = process_filelist_and_biggielist(bkpinfo);
917            /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
918               the former is a list of regular files; the latter, biggiefiles and imagedevs.
919             */
920            if (filelist) {
921              gotos_suck:
922                strcpy(tmp, old_restpath);
923// (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
924                if (popup_and_get_string
925                    ("Restore path", "Restore files to where?", tmp,
926                     MAX_STR_LEN / 4)) {
927                    if (!strcmp(tmp, "/")) {
928                        if (!ask_me_yes_or_no("Are you sure?")) {
929                            goto gotos_suck;
930                        }
931                        tmp[0] = '\0';  // so we restore to [blank]/file/name :)
932                    }
933                    strcpy(bkpinfo->restore_path, tmp);
934                    log_msg(1, "Restoring subset");
935                    retval += restore_everything(bkpinfo, filelist);
936                    free_filelist(filelist);
937                } else {
938                    strcpy(bkpinfo->restore_path, old_restpath);
939                    free_filelist(filelist);
940                }
941                if (!ask_me_yes_or_no
942                    ("Restore another subset of your backup?")) {
943                    done = TRUE;
944                }
945            } else {
946                done = TRUE;
947            }
948        }
949        strcpy(old_restpath, bkpinfo->restore_path);
950    } else {
951        mvaddstr_and_log_it(g_currentY++,
952                            0,
953                            "User opted not to restore any data.                                  ");
954    }
955    if (retval) {
956        mvaddstr_and_log_it(g_currentY++,
957                            0,
958                            "Errors occurred during the restore phase.            ");
959    }
960
961    if (ask_me_yes_or_no("Initialize the boot loader?")) {
962        run_boot_loader(TRUE);
963    } else {
964        mvaddstr_and_log_it(g_currentY++,
965                            0,
966                            "User opted not to initialize the boot loader.");
967    }
968
969//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
970    protect_against_braindead_sysadmins();
971    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
972    retval += unmount_all_devices(mountlist);
973    /*  if (restore_some || restore_all || */
974    if (ask_me_yes_or_no
975        ("Label your ext2 and ext3 partitions if necessary?")) {
976        mvaddstr_and_log_it(g_currentY, 0,
977                            "Using e2label to label your ext2,3 partitions");
978        if (does_file_exist("/tmp/fstab.new")) {
979            strcpy(fstab_fname, "/tmp/fstab.new");
980        } else {
981            strcpy(fstab_fname, "/tmp/fstab");
982        }
983        sprintf(tmp,
984                "label-partitions-as-necessary %s < %s >> %s 2>> %s",
985                g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
986                MONDO_LOGFILE);
987        res = system(tmp);
988        if (res) {
989            log_to_screen
990                ("label-partitions-as-necessary returned an error");
991            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
992        } else {
993            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
994        }
995        retval += res;
996    }
997
998    iamhere("About to leave interactive_mode()");
999    if (retval) {
1000        mvaddstr_and_log_it(g_currentY++,
1001                            0,
1002                            "Warning - errors occurred during the restore phase.");
1003    }
1004  end_of_func:
1005    paranoid_free(tmp);
1006    paranoid_free(fstab_fname);
1007    paranoid_free(old_restpath);
1008    iamhere("Leaving interactive_mode()");
1009    return (retval);
1010}
1011
1012/**************************************************************************
1013 *END_INTERACTIVE_MODE                                                    *
1014 **************************************************************************/
1015
1016
1017
1018/**
1019 * Run an arbitrary restore mode (prompt the user), but from ISO images
1020 * instead of real media.
1021 * @param bkpinfo The backup information structure. Most fields are used.
1022 * @param mountlist The mountlist containing information about the user's partitions.
1023 * @param raidlist The raidlist that goes with @p mountlist.
1024 * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
1025 * @return 0 for success, or the number of errors encountered.
1026 */
1027int
1028iso_mode(struct s_bkpinfo *bkpinfo,
1029         struct mountlist_itself *mountlist,
1030         struct raidlist_itself *raidlist, bool nuke_me_please)
1031{
1032    char c;
1033    int retval = 0;
1034
1035    assert(bkpinfo != NULL);
1036    assert(mountlist != NULL);
1037    assert(raidlist != NULL);
1038    if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
1039        log_msg(1, "iso_mode --- returning w/ error");
1040        return (1);
1041    } else {
1042        c = which_restore_mode();
1043        if (c == 'I' || c == 'N' || c == 'C') {
1044            interactively_obtain_media_parameters_from_user(bkpinfo,
1045                                                            FALSE);
1046        }
1047        if (c == 'I') {
1048            retval += interactive_mode(bkpinfo, mountlist, raidlist);
1049        } else if (c == 'N') {
1050            retval += nuke_mode(bkpinfo, mountlist, raidlist);
1051        } else if (c == 'C') {
1052            retval += compare_mode(bkpinfo, mountlist, raidlist);
1053        } else {
1054            log_to_screen("OK, I shan't restore/compare any files.");
1055        }
1056    }
1057    if (is_this_device_mounted(MNT_CDROM)) {
1058        paranoid_system("umount " MNT_CDROM);
1059    }
1060//  if (! already_mounted)
1061//    {
1062    if (system("umount /tmp/isodir 2> /dev/null")) {
1063        log_to_screen
1064            ("WARNING - unable to unmount device where the ISO files are stored.");
1065    }
1066//    }
1067    return (retval);
1068}
1069
1070/**************************************************************************
1071 *END_ISO_MODE                                                            *
1072 **************************************************************************/
1073
1074
1075/*            MONDO - saving your a$$ since Feb 18th, 2000            */
1076
1077
1078
1079
1080/**
1081 * Restore the user's data automatically (no prompts), after a twenty-second
1082 * warning period.
1083 * @param bkpinfo The backup information structure. Most fields are used.
1084 * @param mountlist The mountlist containing information about the user's partitions.
1085 * @param raidlist The raidlist that goes with @p mountlist.
1086 * @return 0 for success, or the number of errors encountered.
1087 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
1088 */
1089int
1090nuke_mode(struct s_bkpinfo *bkpinfo,
1091          struct mountlist_itself *mountlist,
1092          struct raidlist_itself *raidlist)
1093{
1094    int retval = 0;
1095    int res = 0;
1096    bool boot_loader_installed = FALSE;
1097  /** malloc **/
1098    char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
1099        tmpC[MAX_STR_LEN];
1100
1101    assert(bkpinfo != NULL);
1102    assert(mountlist != NULL);
1103    assert(raidlist != NULL);
1104
1105    log_msg(2, "nuke_mode --- starting");
1106
1107    get_cfg_file_from_archive_or_bust(bkpinfo);
1108    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
1109#ifdef __FreeBSD__
1110    if (strstr
1111        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
1112         "noresize"))
1113#else
1114    if (strstr
1115        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
1116         "noresize"))
1117#endif
1118    {
1119        log_msg(2, "Not resizing mountlist.");
1120    } else {
1121        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
1122    }
1123    if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
1124        sprintf(tmp,
1125                "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?",
1126                tmpA, tmpB, tmpC);
1127        if (ask_me_yes_or_no(tmp)) {
1128            retval = interactive_mode(bkpinfo, mountlist, raidlist);
1129            finish(retval);
1130        } else {
1131            fatal_error("Nuke Mode aborted. ");
1132        }
1133    }
1134    save_mountlist_to_disk(mountlist, g_mountlist_fname);
1135    mvaddstr_and_log_it(1, 30, "Restoring Automatically");
1136    if (bkpinfo->differential) {
1137        log_to_screen("Because this is a differential backup, disk");
1138        log_to_screen("partitioning and formatting will not take place.");
1139        res = 0;
1140    } else {
1141        if (partition_table_contains_Compaq_diagnostic_partition
1142            (mountlist)) {
1143            offer_to_abort_because_Compaq_Proliants_suck();
1144        } else {
1145            twenty_seconds_til_yikes();
1146            g_fprep = fopen("/tmp/prep.sh", "w");
1147#ifdef __FreeBSD__
1148            if (strstr
1149                (call_program_and_get_last_line_of_output
1150                 ("cat /tmp/cmdline"), "nopart"))
1151#else
1152            if (strstr
1153                (call_program_and_get_last_line_of_output
1154                 ("cat /proc/cmdline"), "nopart"))
1155#endif
1156            {
1157                log_msg(2,
1158                        "Not partitioning drives due to 'nopart' option.");
1159                res = 0;
1160            } else {
1161                res = partition_everything(mountlist);
1162                if (res) {
1163                    log_to_screen
1164                        ("Warning. Errors occurred during partitioning.");
1165                    res = 0;
1166                }
1167            }
1168            retval += res;
1169            if (!res) {
1170                log_to_screen("Preparing to format your disk(s)");
1171                sleep(1);
1172                system("sync");
1173                log_to_screen("Please wait. This may take a few minutes.");
1174                res += format_everything(mountlist, FALSE);
1175            }
1176            paranoid_fclose(g_fprep);
1177        }
1178    }
1179    retval += res;
1180    if (res) {
1181        mvaddstr_and_log_it(g_currentY++,
1182                            0,
1183                            "Failed to partition and/or format your hard drives.");
1184
1185        if (ask_me_yes_or_no("Try in interactive mode instead?")) {
1186            retval = interactive_mode(bkpinfo, mountlist, raidlist);
1187            goto after_the_nuke;
1188        } else
1189            if (!ask_me_yes_or_no
1190                ("Would you like to try to proceed anyway?")) {
1191            return (retval);
1192        }
1193    }
1194    retval = mount_all_devices(mountlist, TRUE);
1195    if (retval) {
1196        unmount_all_devices(mountlist);
1197        log_to_screen
1198            ("Unable to mount all partitions. Sorry, I cannot proceed.");
1199        return (retval);
1200    }
1201    iamhere("Restoring everything");
1202    retval += restore_everything(bkpinfo, NULL);
1203    if (!run_boot_loader(FALSE)) {
1204        log_msg(1,
1205                "Great! Boot loader was installed. No need for msg at end.");
1206        boot_loader_installed = TRUE;
1207    }
1208    protect_against_braindead_sysadmins();
1209//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
1210    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
1211    retval += unmount_all_devices(mountlist);
1212    mvaddstr_and_log_it(g_currentY,
1213                        0,
1214                        "Using e2label to label your ext2,3 partitions");
1215
1216    sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab",
1217            g_mountlist_fname);
1218    res = run_program_and_log_output(tmp, TRUE);
1219    if (res) {
1220        log_to_screen("label-partitions-as-necessary returned an error");
1221        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1222    } else {
1223        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1224    }
1225    retval += res;
1226
1227  after_the_nuke:
1228    if (retval) {
1229        log_to_screen("Errors occurred during the nuke phase.");
1230    } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE"))    // Bruno's thing
1231    {
1232        log_to_screen
1233            ("PC was restored successfully. Thank you for using Mondo Rescue.");
1234        log_to_screen
1235            ("Please visit http://www.mondorescue.org and thank the dev team.");
1236    } else {
1237#ifdef FREELOADER
1238        success_message();
1239#else
1240        log_to_screen("PC was restored successfully!");
1241#endif
1242    }
1243    g_I_have_just_nuked = TRUE;
1244/*
1245  if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE))
1246    {
1247      log_to_screen("PLEASE RUN 'mondorestore --mbr' NOW TO INITIALIZE YOUR BOOT SECTOR");
1248      write_one_liner_data_file(DO_MBR_PLEASE, "mondorestore --mbr");
1249    }
1250*/
1251    return (retval);
1252}
1253
1254/**************************************************************************
1255 *END_NUKE_MODE                                                           *
1256 **************************************************************************/
1257
1258
1259
1260/**
1261 * Restore the user's data (or a subset of it) to the live filesystem.
1262 * This should not be called if we're booted from CD!
1263 * @param bkpinfo The backup information structure. Most fields are used.
1264 * @return 0 for success, or the number of errors encountered.
1265 */
1266int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
1267{
1268    int retval = 0;
1269
1270  /** malloc **/
1271    char *old_restpath;
1272
1273    struct mountlist_itself *mountlist;
1274//  static
1275    struct raidlist_itself *raidlist;
1276    struct s_node *filelist;
1277
1278    log_msg(1, "restore_to_live_filesystem() - starting");
1279    assert(bkpinfo != NULL);
1280    malloc_string(old_restpath);
1281    mountlist = malloc(sizeof(struct mountlist_itself));
1282    raidlist = malloc(sizeof(struct raidlist_itself));
1283    if (!mountlist || !raidlist) {
1284        fatal_error("Cannot malloc() mountlist and/or raidlist");
1285    }
1286
1287    strcpy(bkpinfo->restore_path, "/");
1288    if (!g_restoring_live_from_cd) {
1289        popup_and_OK
1290            ("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
1291        sleep(1);
1292    }
1293    interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
1294    if (bkpinfo->media_device == NULL) {
1295        log_msg(2, "Warning - failed to find media dev");
1296    } else {
1297        log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
1298    }
1299
1300
1301    log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
1302
1303    open_evalcall_form("Thinking...");
1304
1305    get_cfg_file_from_archive_or_bust(bkpinfo);
1306    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
1307    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo
1308
1309    close_evalcall_form();
1310    retval = load_mountlist(mountlist, g_mountlist_fname);
1311    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
1312    filelist = process_filelist_and_biggielist(bkpinfo);
1313    if (filelist) {
1314        save_filelist(filelist, "/tmp/selected-files.txt");
1315        strcpy(old_restpath, bkpinfo->restore_path);
1316        if (popup_and_get_string("Restore path",
1317                                 "Restore files to where? )",
1318                                 bkpinfo->restore_path, MAX_STR_LEN / 4)) {
1319            iamhere("Restoring everything");
1320            retval += restore_everything(bkpinfo, filelist);
1321            free_filelist(filelist);
1322            strcpy(bkpinfo->restore_path, old_restpath);
1323        } else {
1324            free_filelist(filelist);
1325        }
1326        strcpy(bkpinfo->restore_path, old_restpath);
1327    }
1328    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1329        log_msg(2,
1330                "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
1331    }
1332    run_program_and_log_output("umount " MNT_CDROM, FALSE);
1333    if ((!bkpinfo->please_dont_eject) && (bkpinfo->media_device != NULL)) {
1334        eject_device(bkpinfo->media_device);
1335    }
1336    paranoid_free(old_restpath);
1337    free(mountlist);
1338    free(raidlist);
1339    return (retval);
1340}
1341
1342/**************************************************************************
1343 *END_RESTORE_TO_LIVE_FILESYSTEM                                          *
1344 **************************************************************************/
1345
1346/* @} - end of restoreGroup */
1347
1348
1349#include <utime.h>
1350/**
1351 * @addtogroup LLrestoreGroup
1352 * @{
1353 */
1354/**
1355 * Restore biggiefile @p bigfileno from the currently mounted CD.
1356 * @param bkpinfo The backup information structure. Fields used:
1357 * - @c bkpinfo->backup_media_type
1358 * - @c bkpinfo->restore_path
1359 * @param bigfileno The biggiefile number (starting from 0) to restore.
1360 * @param filelist The node structure containing the list of files to restore.
1361 * If the biggiefile is not in this list, it will be skipped (return value will
1362 * still indicate success).
1363 * @return 0 for success (or skip), nonzero for failure.
1364 */
1365int
1366restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
1367                             long bigfileno,
1368                             struct s_node *filelist,
1369                             char *pathname_of_last_file_restored)
1370{
1371    FILE *fin;
1372    FILE *fout;
1373    FILE *fbzip2;
1374
1375  /** malloc ***/
1376    char *checksum, *outfile_fname, *tmp, *bzip2_command,
1377        *partimagehack_command, *suffix, *sz_devfile;
1378    char *bigblk;
1379    char *p;
1380    int retval = 0;
1381    int finished = FALSE;
1382    long sliceno;
1383    long siz;
1384    char partimagehack_fifo[MAX_STR_LEN];
1385    char *file_to_openout = NULL;
1386    struct s_filename_and_lstat_info biggiestruct;
1387    struct utimbuf the_utime_buf, *ubuf;
1388    bool use_partimage_hack = FALSE;
1389    pid_t pid;
1390    int res = 0;
1391    int old_loglevel;
1392    char sz_msg[MAX_STR_LEN];
1393    struct s_node *node;
1394
1395    old_loglevel = g_loglevel;
1396    ubuf = &the_utime_buf;
1397    assert(bkpinfo != NULL);
1398
1399    malloc_string(checksum);
1400    malloc_string(outfile_fname);
1401    malloc_string(tmp);
1402    malloc_string(bzip2_command);
1403    malloc_string(partimagehack_command);
1404    malloc_string(suffix);
1405    malloc_string(sz_devfile);
1406
1407    pathname_of_last_file_restored[0] = '\0';
1408    if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
1409        fatal_error("Cannot malloc bigblk");
1410    }
1411
1412    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
1413        log_to_screen("Cannot even open bigfile's info file");
1414        return (1);
1415    }
1416
1417    memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
1418    if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
1419        sizeof(biggiestruct)) {
1420        log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
1421                bigfileno + 1);
1422    }
1423    paranoid_fclose(fin);
1424
1425    strcpy(checksum, biggiestruct.checksum);
1426
1427    if (!checksum[0]) {
1428        sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
1429                bigfileno + 1);
1430        log_msg(3, tmp);
1431        p = checksum;
1432    }
1433
1434    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
1435    {
1436        strcpy(outfile_fname, biggiestruct.filename);
1437    } else {
1438        sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
1439                biggiestruct.filename);
1440    }
1441
1442    /* skip file if we have a selective restore subset & it doesn't match */
1443    if (filelist != NULL) {
1444        node = find_string_at_node(filelist, biggiestruct.filename);
1445        if (!node) {
1446            log_msg(0, "Skipping %s (name isn't in filelist)",
1447                    biggiestruct.filename);
1448            pathname_of_last_file_restored[0] = '\0';
1449            return (0);
1450        } else if (!(node->selected)) {
1451            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1452                    biggiestruct.filename);
1453            pathname_of_last_file_restored[0] = '\0';
1454            return (0);
1455        }
1456    }
1457    /* otherwise, continue */
1458
1459    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
1460    if (biggiestruct.use_partimagehack) {
1461        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
1462            log_msg(1,
1463                    "I was in error when I set biggiestruct.use_partimagehack to TRUE.");
1464            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
1465            biggiestruct.use_partimagehack = FALSE;
1466        }
1467    }
1468
1469    if (biggiestruct.use_partimagehack) // if it's an NTFS device
1470//  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
1471    {
1472        g_loglevel = 4;
1473        use_partimage_hack = TRUE;
1474        log_msg(2,
1475                "Calling partimagehack in background because %s is an NTFS /dev entry",
1476                outfile_fname);
1477        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
1478                (int) (random() % 32768));
1479        mkfifo(sz_devfile, 0x770);
1480        strcpy(partimagehack_fifo, sz_devfile);
1481        file_to_openout = partimagehack_fifo;
1482        switch (pid = fork()) {
1483        case -1:
1484            fatal_error("Fork failure");
1485        case 0:
1486            log_msg(3,
1487                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
1488                    biggiestruct.filename, partimagehack_fifo);
1489            res =
1490                feed_outfrom_partimage(biggiestruct.filename,
1491                                       partimagehack_fifo);
1492//          log_msg(3, "CHILD - fip - exiting");
1493            exit(res);
1494            break;
1495        default:
1496            log_msg(3,
1497                    "feed_into_partimage() called in background --- pid=%ld",
1498                    (long int) (pid));
1499        }
1500    } else {
1501        use_partimage_hack = FALSE;
1502        partimagehack_fifo[0] = '\0';
1503        file_to_openout = outfile_fname;
1504        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
1505        {
1506            make_hole_for_file(outfile_fname);
1507        }
1508    }
1509
1510    sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
1511            outfile_fname);
1512    log_msg(2, tmp);
1513
1514    /*
1515       last slice is zero-length and uncompressed; when we find it, we stop.
1516       We DON'T wait until there are no more slices; if we did that,
1517       We might stop at end of CD, not at last slice (which is 0-len and uncompd)
1518     */
1519
1520    strncpy(pathname_of_last_file_restored, biggiestruct.filename,
1521            MAX_STR_LEN - 1);
1522    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1523
1524    log_msg(3, "file_to_openout = %s", file_to_openout);
1525    if (!(fout = fopen(file_to_openout, "w"))) {
1526        log_to_screen("Cannot openout outfile_fname - hard disk full?");
1527        return (1);
1528    }
1529    log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> partimagehack --> hard disk itself
1530
1531    for (sliceno = 1, finished = FALSE; !finished;) {
1532        if (!does_file_exist
1533            (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
1534            &&
1535            !does_file_exist(slice_fname
1536                             (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
1537            &&
1538            !does_file_exist(slice_fname
1539                             (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1540            log_msg(3,
1541                    "Cannot find a data slice or terminator slice on CD %d",
1542                    g_current_media_number);
1543            g_current_media_number++;
1544            sprintf(tmp,
1545                    "Asking for %s #%d so that I may read slice #%ld\n",
1546                    media_descriptor_string(bkpinfo->backup_media_type),
1547                    g_current_media_number, sliceno);
1548            log_msg(2, tmp);
1549            sprintf(tmp, "Restoring from %s #%d",
1550                    media_descriptor_string(bkpinfo->backup_media_type),
1551                    g_current_media_number);
1552            log_to_screen(tmp);
1553            insist_on_this_cd_number(bkpinfo, g_current_media_number);
1554            log_to_screen("Continuing to restore.");
1555        } else {
1556            strcpy(tmp,
1557                   slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
1558            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
1559                log_msg(2,
1560                        "End of bigfile # %ld (slice %ld is the terminator)",
1561                        bigfileno + 1, sliceno);
1562                finished = TRUE;
1563                continue;
1564            } else {
1565                if (does_file_exist
1566                    (slice_fname
1567                     (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
1568                    strcpy(bzip2_command, "lzop");
1569                    strcpy(suffix, "lzo");
1570                } else
1571                    if (does_file_exist
1572                        (slice_fname
1573                         (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1574                    strcpy(bzip2_command, "bzip2");
1575                    strcpy(suffix, "bz2");
1576                } else
1577                    if (does_file_exist
1578                        (slice_fname
1579                         (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
1580                    strcpy(bzip2_command, "");
1581                    strcpy(suffix, "");
1582                } else {
1583                    log_to_screen("OK, that's pretty fsck0red...");
1584                    return (1);
1585                }
1586            }
1587            if (bzip2_command[0] != '\0') {
1588                sprintf(bzip2_command + strlen(bzip2_command),
1589                        " -dc %s 2>> %s",
1590                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1591                                    suffix), MONDO_LOGFILE);
1592            } else {
1593                sprintf(bzip2_command, "cat %s 2>> %s",
1594                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1595                                    suffix), MONDO_LOGFILE);
1596            }
1597            sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ",
1598                    media_descriptor_string(bkpinfo->backup_media_type),
1599                    g_current_media_number, bigfileno + 1, sliceno);
1600            log_msg(2, tmp);
1601
1602            if (!g_text_mode) {
1603                newtDrawRootText(0, g_noof_rows - 2, tmp);
1604                newtRefresh();
1605                strip_spaces(tmp);
1606                update_progress_form(tmp);
1607            }
1608            if (!(fbzip2 = popen(bzip2_command, "r"))) {
1609                fatal_error("Can't run popen command");
1610            }
1611            while (!feof(fbzip2)) {
1612                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
1613                if (siz > 0) {
1614                    sprintf(sz_msg, "Read %ld from fbzip2", siz);
1615                    siz = fwrite(bigblk, 1, siz, fout);
1616                    sprintf(sz_msg + strlen(sz_msg),
1617                            "; written %ld to fout", siz);
1618//        log_msg(2. sz_msg);
1619                }
1620            }
1621            paranoid_pclose(fbzip2);
1622
1623
1624            sliceno++;
1625            g_current_progress++;
1626        }
1627    }
1628/*
1629  memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
1630  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1631  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1632  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1633  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1634*/
1635    paranoid_fclose(fout);
1636    g_loglevel = old_loglevel;
1637
1638    if (use_partimage_hack) {
1639        log_msg(3, "Waiting for partimage to finish");
1640        sprintf(tmp,
1641                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
1642        while (system(tmp) == 0) {
1643            sleep(1);
1644        }
1645        log_it("OK, partimage has really finished");
1646    }
1647
1648    if (strcmp(outfile_fname, "/dev/null")) {
1649        chown(outfile_fname, biggiestruct.properties.st_uid,
1650              biggiestruct.properties.st_gid);
1651        chmod(outfile_fname, biggiestruct.properties.st_mode);
1652        ubuf->actime = biggiestruct.properties.st_atime;
1653        ubuf->modtime = biggiestruct.properties.st_mtime;
1654        utime(outfile_fname, ubuf);
1655    }
1656    paranoid_free(bigblk);
1657    paranoid_free(checksum);
1658    paranoid_free(outfile_fname);
1659    paranoid_free(tmp);
1660    paranoid_free(bzip2_command);
1661    paranoid_free(partimagehack_command);
1662    paranoid_free(suffix);
1663    paranoid_free(sz_devfile);
1664
1665    return (retval);
1666}
1667
1668/**************************************************************************
1669 *END_ RESTORE_A_BIGGIEFILE_FROM_CD                                       *
1670 **************************************************************************/
1671
1672
1673
1674/**
1675 * Restore a biggiefile from the currently opened stream.
1676 * @param bkpinfo The backup information structure. Fields used:
1677 * - @c bkpinfo->restore_path
1678 * - @c bkpinfo->zip_exe
1679 * @param orig_bf_fname The original filename of the biggiefile.
1680 * @param biggiefile_number The number of the biggiefile (starting from 0).
1681 * @param orig_checksum Unused.
1682 * @param biggiefile_size Unused.
1683 * @param filelist The node structure containing the list of files to be restored.
1684 * If @p orig_bf_fname is not in the list, it will be ignored.
1685 * @return 0 for success (or skip), nonzero for failure.
1686 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
1687 */
1688int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum,   //UNUSED
1689                                     long long biggiefile_size, //UNUSED
1690                                     struct s_node *filelist,
1691                                     int use_partimagehack,
1692                                     char *pathname_of_last_file_restored)
1693{
1694    FILE *pout;
1695    FILE *fin;
1696
1697  /** mallocs ********/
1698    char *tmp;
1699    char *command;
1700    char *outfile_fname;
1701    char *partimagehack_command;
1702    char *sz_devfile;
1703    char *partimagehack_fifo;
1704    char *file_to_openout = NULL;
1705
1706    struct s_node *node;
1707
1708    int old_loglevel;
1709    long current_slice_number = 0;
1710    int retval = 0;
1711    int res = 0;
1712    int ctrl_chr = '\0';
1713    long long slice_siz;
1714    bool dummy_restore = FALSE;
1715    bool use_partimage_hack = FALSE;
1716    pid_t pid;
1717    struct s_filename_and_lstat_info biggiestruct;
1718    struct utimbuf the_utime_buf, *ubuf;
1719    ubuf = &the_utime_buf;
1720
1721    malloc_string(tmp);
1722    malloc_string(partimagehack_fifo);
1723    malloc_string(outfile_fname);
1724    malloc_string(command);
1725    malloc_string(sz_devfile);
1726    malloc_string(partimagehack_command);
1727    old_loglevel = g_loglevel;
1728    assert(bkpinfo != NULL);
1729    assert(orig_bf_fname != NULL);
1730    assert(orig_checksum != NULL);
1731
1732    pathname_of_last_file_restored[0] = '\0';
1733    if (use_partimagehack == BLK_START_A_PIHBIGGIE) {
1734        use_partimagehack = 1;
1735        log_msg(1, "%s --- pih=YES", orig_bf_fname);
1736    } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) {
1737        use_partimagehack = 0;
1738        log_msg(1, "%s --- pih=NO", orig_bf_fname);
1739    } else {
1740        use_partimagehack = 0;
1741        log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1742    }
1743
1744    strncpy(pathname_of_last_file_restored, orig_bf_fname,
1745            MAX_STR_LEN - 1);
1746    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1747
1748    /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1749
1750    if (filelist != NULL) {
1751        node = find_string_at_node(filelist, orig_bf_fname);
1752        if (!node) {
1753            dummy_restore = TRUE;
1754            log_msg(1,
1755                    "Skipping big file %ld (%s) - not in biggielist subset",
1756                    biggiefile_number + 1, orig_bf_fname);
1757            pathname_of_last_file_restored[0] = '\0';
1758        } else if (!(node->selected)) {
1759            dummy_restore = TRUE;
1760            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1761                    orig_bf_fname);
1762            pathname_of_last_file_restored[0] = '\0';
1763        }
1764    }
1765
1766    if (use_partimagehack) {
1767        if (strncmp(orig_bf_fname, "/dev/", 5)) {
1768            log_msg(1,
1769                    "I was in error when I set use_partimagehack to TRUE.");
1770            log_msg(1, "%s isn't even in /dev", orig_bf_fname);
1771            use_partimagehack = FALSE;
1772        }
1773    }
1774
1775    if (use_partimagehack) {
1776        g_loglevel = 4;
1777        strcpy(outfile_fname, orig_bf_fname);
1778        use_partimage_hack = TRUE;
1779        log_msg(2,
1780                "Calling partimagehack in background because %s is a /dev entry",
1781                outfile_fname);
1782        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
1783                (int) (random() % 32768));
1784        mkfifo(sz_devfile, 0x770);
1785        strcpy(partimagehack_fifo, sz_devfile);
1786        file_to_openout = partimagehack_fifo;
1787        switch (pid = fork()) {
1788        case -1:
1789            fatal_error("Fork failure");
1790        case 0:
1791            log_msg(3,
1792                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
1793                    outfile_fname, partimagehack_fifo);
1794            res =
1795                feed_outfrom_partimage(outfile_fname, partimagehack_fifo);
1796//          log_msg(3, "CHILD - fip - exiting");
1797            exit(res);
1798            break;
1799        default:
1800            log_msg(3,
1801                    "feed_into_partimage() called in background --- pid=%ld",
1802                    (long int) (pid));
1803        }
1804    } else {
1805        if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
1806        {
1807            strcpy(outfile_fname, orig_bf_fname);
1808        } else                  // biggiefile
1809        {
1810            sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
1811                    orig_bf_fname);
1812        }
1813        use_partimage_hack = FALSE;
1814        partimagehack_fifo[0] = '\0';
1815        file_to_openout = outfile_fname;
1816        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
1817        {
1818            make_hole_for_file(outfile_fname);
1819        }
1820        sprintf(tmp, "Reassembling big file %ld (%s)",
1821                biggiefile_number + 1, orig_bf_fname);
1822        log_msg(2, tmp);
1823    }
1824
1825    if (dummy_restore) {
1826        sprintf(outfile_fname, "/dev/null");
1827    }
1828
1829    if (!bkpinfo->zip_exe[0]) {
1830        sprintf(command, "cat > \"%s\"", file_to_openout);
1831    } else {
1832        sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
1833                file_to_openout, MONDO_LOGFILE);
1834    }
1835    sprintf(tmp, "Pipe command = '%s'", command);
1836    log_msg(3, tmp);
1837
1838    /* restore biggiefile, one slice at a time */
1839    if (!(pout = popen(command, "w"))) {
1840        fatal_error("Cannot pipe out");
1841    }
1842    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1843         ctrl_chr != BLK_STOP_A_BIGGIE;
1844         res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
1845        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1846            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1847        }
1848        sprintf(tmp, "Working on file #%ld, slice #%ld    ",
1849                biggiefile_number + 1, current_slice_number);
1850        log_msg(2, tmp);
1851        if (!g_text_mode) {
1852            newtDrawRootText(0, g_noof_rows - 2, tmp);
1853            newtRefresh();
1854        }
1855        strip_spaces(tmp);
1856        update_progress_form(tmp);
1857        if (current_slice_number == 0) {
1858            res =
1859                read_file_from_stream_to_file(bkpinfo,
1860                                              "/tmp/biggie-blah.txt",
1861                                              slice_siz);
1862            if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1863                log_OS_error("blah blah");
1864            } else {
1865                if (fread
1866                    ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1867                     fin) < sizeof(biggiestruct)) {
1868                    log_msg(2,
1869                            "Warning - unable to get biggiestruct of bigfile #%d",
1870                            biggiefile_number + 1);
1871                }
1872                paranoid_fclose(fin);
1873            }
1874        } else {
1875            res =
1876                read_file_from_stream_to_stream(bkpinfo, pout, slice_siz);
1877        }
1878        retval += res;
1879        res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1880        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1881            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1882        }
1883        current_slice_number++;
1884        g_current_progress++;
1885    }
1886    paranoid_pclose(pout);
1887
1888    log_msg(1, "pathname_of_last_file_restored is now %s",
1889            pathname_of_last_file_restored);
1890
1891    if (use_partimage_hack) {
1892        log_msg(3, "Waiting for partimage to finish");
1893        sprintf(tmp,
1894                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
1895        while (system(tmp) == 0) {
1896            sleep(1);
1897        }
1898        log_msg(3, "OK, partimage has really finished");
1899    }
1900
1901    log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1902    log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
1903    if (strcmp(outfile_fname, "/dev/null")) {
1904        chmod(outfile_fname, biggiestruct.properties.st_mode);
1905        chown(outfile_fname, biggiestruct.properties.st_uid,
1906              biggiestruct.properties.st_gid);
1907        ubuf->actime = biggiestruct.properties.st_atime;
1908        ubuf->modtime = biggiestruct.properties.st_mtime;
1909        utime(outfile_fname, ubuf);
1910    }
1911
1912    paranoid_free(tmp);
1913    paranoid_free(outfile_fname);
1914    paranoid_free(command);
1915    paranoid_free(partimagehack_command);
1916    paranoid_free(sz_devfile);
1917    paranoid_free(partimagehack_fifo);
1918    g_loglevel = old_loglevel;
1919    return (retval);
1920}
1921
1922/**************************************************************************
1923 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM                                    *
1924 **************************************************************************/
1925
1926
1927
1928/**
1929 * Restore @p tarball_fname from CD.
1930 * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
1931 * This will be used unmodified.
1932 * @param current_tarball_number The number (starting from 0) of the fileset
1933 * we're restoring now.
1934 * @param filelist The node structure containing the list of files to be
1935 * restored. If no file in the afioball is in this list, afio will still be
1936 * called, but nothing will be written.
1937 * @return 0 for success, nonzero for failure.
1938 */
1939int
1940restore_a_tarball_from_CD(char *tarball_fname,
1941                          long current_tarball_number,
1942                          struct s_node *filelist)
1943{
1944    int retval = 0;
1945    int res;
1946    char *p;
1947
1948  /** malloc **/
1949    char *command;
1950    char *tmp;
1951    char *filelist_name;
1952    char *filelist_subset_fname;
1953    char *executable;
1954    char *temp_log;
1955    char screen_message[100];
1956    long matches = 0;
1957    bool use_star;
1958    char *xattr_fname;
1959    char *acl_fname;
1960//  char files_to_restore_this_time_fname[MAX_STR_LEN];
1961
1962    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1963    malloc_string(command);
1964    malloc_string(tmp);
1965    malloc_string(filelist_name);
1966    malloc_string(filelist_subset_fname);
1967    malloc_string(executable);
1968    malloc_string(temp_log);
1969    malloc_string(xattr_fname);
1970    malloc_string(acl_fname);
1971
1972    log_msg(5, "Entering");
1973    filelist_subset_fname[0] = '\0';
1974    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1975//  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
1976    sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
1977    run_program_and_log_output(command, 9);
1978    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
1979            (int) (random() % 32768));
1980
1981    sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
1982            current_tarball_number);
1983    if (length_of_file(filelist_name) <= 2) {
1984        log_msg(2, "There are _zero_ files in filelist '%s'",
1985                filelist_name);
1986        log_msg(2,
1987                "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)");
1988        log_msg(2,
1989                "but it's non-critical. It's cosmetic. Don't worry about it.");
1990        retval = 0;
1991        goto leave_sub;
1992    }
1993    if (count_lines_in_file(filelist_name) <= 0
1994        || length_of_file(tarball_fname) <= 0) {
1995        log_msg(3, "length_of_file(%s) = %ld", tarball_fname,
1996                length_of_file(tarball_fname));
1997        sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
1998                current_tarball_number);
1999        log_to_screen(tmp);
2000        retval = 1;
2001        goto leave_sub;
2002    }
2003
2004    if (filelist) {
2005        sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
2006                current_tarball_number);
2007        if ((matches =
2008             save_filelist_entries_in_common(filelist_name, filelist,
2009                                             filelist_subset_fname,
2010                                             use_star))
2011            <= 0) {
2012            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2013            log_msg(1, tmp);
2014        } else {
2015            log_msg(3, "Saved fileset %ld's subset to %s",
2016                    current_tarball_number, filelist_subset_fname);
2017        }
2018        sprintf(screen_message, "Tarball #%ld --- %ld matches",
2019                current_tarball_number, matches);
2020        log_to_screen(screen_message);
2021    } else {
2022        filelist_subset_fname[0] = '\0';
2023    }
2024
2025    if (filelist == NULL || matches > 0) {
2026        sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
2027                MNT_CDROM "/archives", current_tarball_number);
2028        sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
2029                current_tarball_number);
2030        if (strstr(tarball_fname, ".bz2")) {
2031            strcpy(executable, "bzip2");
2032        } else if (strstr(tarball_fname, ".lzo")) {
2033            strcpy(executable, "lzop");
2034        } else {
2035            executable[0] = '\0';
2036        }
2037        if (executable[0]) {
2038            sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
2039            if (run_program_and_log_output(tmp, FALSE)) {
2040                log_to_screen
2041                    ("(compare_a_tarball) Compression program not found - oh no!");
2042                paranoid_MR_finish(1);
2043            }
2044            strcpy(tmp, executable);
2045            sprintf(executable, "-P %s -Z", tmp);
2046        }
2047#ifdef __FreeBSD__
2048#define BUFSIZE 512
2049#else
2050#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
2051#endif
2052
2053//      if (strstr(tarball_fname, ".star."))
2054        if (use_star) {
2055            sprintf(command,
2056                    "star -x -force-remove -U " STAR_ACL_SZ
2057                    " errctl= file=%s", tarball_fname);
2058            if (strstr(tarball_fname, ".bz2")) {
2059                strcat(command, " -bz");
2060            }
2061        } else {
2062            if (filelist_subset_fname[0] != '\0') {
2063                sprintf(command,
2064                        "afio -i -M 8m -b %ld -c %ld %s -w %s %s",
2065                        TAPE_BLOCK_SIZE,
2066                        BUFSIZE, executable, filelist_subset_fname,
2067//             files_to_restore_this_time_fname,
2068                        tarball_fname);
2069            } else {
2070                sprintf(command,
2071                        "afio -i -b %ld -c %ld -M 8m %s %s",
2072                        TAPE_BLOCK_SIZE,
2073                        BUFSIZE, executable, tarball_fname);
2074            }
2075        }
2076#undef BUFSIZE
2077        sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
2078                temp_log);
2079        log_msg(1, "command = '%s'", command);
2080        unlink(temp_log);
2081        res = system(command);
2082        if (res) {
2083            p = strstr(command, "-acl ");
2084            if (p) {
2085                p[0] = p[1] = p[2] = p[3] = ' ';
2086                log_msg(1, "new command = '%s'", command);
2087                res = system(command);
2088            }
2089        }
2090        if (res && length_of_file(temp_log) < 5) {
2091            res = 0;
2092        }
2093
2094        log_msg(1, "Setting fattr list %s", xattr_fname);
2095        if (length_of_file(xattr_fname) > 0) {
2096            res = set_fattr_list(filelist_subset_fname, xattr_fname);
2097            if (res) {
2098                log_to_screen
2099                    ("Errors occurred while setting extended attributes");
2100            } else {
2101                log_msg(1, "I set xattr OK");
2102            }
2103            retval += res;
2104        }
2105        if (length_of_file(acl_fname) > 0) {
2106            log_msg(1, "Setting acl list %s", acl_fname);
2107            res = set_acl_list(filelist_subset_fname, acl_fname);
2108            if (res) {
2109                log_to_screen
2110                    ("Errors occurred while setting access control lists");
2111            } else {
2112                log_msg(1, "I set ACL OK");
2113            }
2114            retval += res;
2115        }
2116        if (retval) {
2117            sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
2118            system(command);
2119            log_msg(2, "Errors occurred while processing fileset #%d",
2120                    current_tarball_number);
2121        } else {
2122            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
2123        }
2124    }
2125    if (does_file_exist("/PAUSE")) {
2126        popup_and_OK
2127            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2128    }
2129    unlink(filelist_subset_fname);
2130    unlink(xattr_fname);
2131    unlink(acl_fname);
2132    unlink(temp_log);
2133
2134  leave_sub:
2135    paranoid_free(command);
2136    paranoid_free(tmp);
2137    paranoid_free(filelist_name);
2138    paranoid_free(filelist_subset_fname);
2139    paranoid_free(executable);
2140    paranoid_free(temp_log);
2141    paranoid_free(xattr_fname);
2142    paranoid_free(acl_fname);
2143    log_msg(5, "Leaving");
2144    return (retval);
2145}
2146
2147/**************************************************************************
2148 *END_RESTORE_A_TARBALL_FROM_CD                                           *
2149 **************************************************************************/
2150
2151
2152/**
2153 * Restore a tarball from the currently opened stream.
2154 * @param bkpinfo The backup information structure. Fields used:
2155 * - @c bkpinfo->backup_media_type
2156 * - @c bkpinfo->media_device
2157 * - @c bkpinfo->zip_exe
2158 * @param tarball_fname The filename of the afioball to restore.
2159 * @param current_tarball_number The number (starting from 0) of the fileset
2160 * we're restoring now.
2161 * @param filelist The node structure containing the list of files to be
2162 * restored. If no file in the afioball is in this list, afio will still be
2163 * called, but nothing will be written.
2164 * @param size The size (in @b bytes) of the afioball.
2165 * @return 0 for success, nonzero for failure.
2166 */
2167int
2168restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
2169                              char *tarball_fname,
2170                              long current_tarball_number,
2171                              struct s_node *filelist,
2172                              long long size, char *xattr_fname,
2173                              char *acl_fname)
2174{
2175    int retval = 0;
2176    int res = 0;
2177
2178  /** malloc add ***/
2179    char *tmp;
2180    char *command;
2181    char *afio_fname;
2182    char *filelist_fname;
2183    char *filelist_subset_fname;
2184    char *executable;
2185    long matches = 0;
2186    bool restore_this_fileset = FALSE;
2187    bool use_star;
2188
2189    assert(bkpinfo != NULL);
2190    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
2191    malloc_string(filelist_subset_fname);
2192    malloc_string(filelist_fname);
2193    malloc_string(afio_fname);
2194    malloc_string(executable);
2195    malloc_string(command);
2196    malloc_string(tmp);
2197    filelist_subset_fname[0] = '\0';
2198    /* to do it with a file... */
2199    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
2200    sprintf(tmp,
2201            "Restoring from fileset #%ld (%ld KB) on %s #%d",
2202            current_tarball_number, (long) size >> 10,
2203            media_descriptor_string(bkpinfo->backup_media_type),
2204            g_current_media_number);
2205    log_msg(2, tmp);
2206    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
2207
2208  /****************************************************************************
2209   * Use RAMDISK's /tmp; saves time; oh wait, it's too small                  *
2210   * Well, pipe from tape to afio, then; oh wait, can't do that either: bug   *
2211   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
2212   ****************************************************************************/
2213    filelist_fname[0] = filelist_subset_fname[0] = '\0';
2214    sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
2215            current_tarball_number);
2216    sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
2217            current_tarball_number);
2218    sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
2219            bkpinfo->tmpdir, current_tarball_number);
2220//  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
2221    res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
2222    if (strstr(tarball_fname, ".star")) {
2223        bkpinfo->use_star = TRUE;
2224    }
2225    if (res) {
2226        log_msg(1, "Warning - error reading afioball from tape");
2227    }
2228    if (bkpinfo->compression_level == 0) {
2229        executable[0] = '\0';
2230    } else {
2231        if (bkpinfo->use_star) {
2232            strcpy(executable, " -bz");
2233        } else {
2234            sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
2235        }
2236    }
2237
2238    if (!filelist)              // if unconditional restore then restore entire fileset
2239    {
2240        restore_this_fileset = TRUE;
2241    } else                      // If restoring selectively then get TOC from tarball
2242    {
2243        if (strstr(tarball_fname, ".star.")) {
2244            use_star = TRUE;
2245            sprintf(command, "star -t file=%s %s", afio_fname, executable);
2246        } else {
2247            use_star = FALSE;
2248            sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
2249                    executable, afio_fname);
2250        }
2251        sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
2252                MONDO_LOGFILE);
2253        log_msg(1, "command = %s", command);
2254        if (system(command)) {
2255            log_msg(4, "Warning - error occurred while retrieving TOC");
2256        }
2257        if ((matches =
2258             save_filelist_entries_in_common(filelist_fname, filelist,
2259                                             filelist_subset_fname,
2260                                             use_star))
2261            <= 0 || length_of_file(filelist_subset_fname) < 2) {
2262            if (length_of_file(filelist_subset_fname) < 2) {
2263                log_msg(1, "No matches found in fileset %ld",
2264                        current_tarball_number);
2265            }
2266            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2267            log_msg(2, tmp);
2268            restore_this_fileset = FALSE;
2269        } else {
2270            log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
2271                    matches, current_tarball_number,
2272                    filelist_subset_fname);
2273            restore_this_fileset = TRUE;
2274        }
2275    }
2276
2277// Concoct the call to star/afio to restore files
2278    if (strstr(tarball_fname, ".star."))    // star
2279    {
2280        sprintf(command, "star -x file=%s %s", afio_fname, executable);
2281        if (filelist) {
2282            sprintf(command + strlen(command), " list=%s",
2283                    filelist_subset_fname);
2284        }
2285    } else                      // afio
2286    {
2287        sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
2288                executable);
2289        if (filelist) {
2290            sprintf(command + strlen(command), " -w %s",
2291                    filelist_subset_fname);
2292        }
2293        sprintf(command + strlen(command), " %s", afio_fname);
2294    }
2295    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
2296
2297// Call if IF there are files to restore (selectively/unconditionally)
2298    if (restore_this_fileset) {
2299        log_msg(1, "Calling command='%s'", command);
2300        paranoid_system(command);
2301
2302        iamhere("Restoring xattr, acl stuff");
2303        res = set_fattr_list(filelist_subset_fname, xattr_fname);
2304        if (res) {
2305            log_msg(1, "Errors occurred while setting xattr");
2306        } else {
2307            log_msg(1, "I set xattr OK");
2308        }
2309        retval += res;
2310
2311        res = set_acl_list(filelist_subset_fname, acl_fname);
2312        if (res) {
2313            log_msg(1, "Errors occurred while setting ACL");
2314        } else {
2315            log_msg(1, "I set ACL OK");
2316        }
2317        retval += res;
2318
2319    } else {
2320        log_msg(1, "NOT CALLING '%s'", command);
2321    }
2322
2323    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
2324        log_to_screen("Paused after set %ld", current_tarball_number);
2325        popup_and_OK("Pausing. Press ENTER to continue.");
2326    }
2327
2328    unlink(filelist_subset_fname);
2329    unlink(filelist_fname);
2330    unlink(afio_fname);
2331
2332    paranoid_free(filelist_subset_fname);
2333    paranoid_free(filelist_fname);
2334    paranoid_free(afio_fname);
2335    paranoid_free(command);
2336    paranoid_free(tmp);
2337    return (retval);
2338}
2339
2340/**************************************************************************
2341 *END_RESTORE_A_TARBALL_FROM_STREAM                                       *
2342 **************************************************************************/
2343
2344
2345
2346
2347/**
2348 * Restore all biggiefiles from all media in this CD backup.
2349 * The CD with the last afioball should be currently mounted.
2350 * @param bkpinfo The backup information structure. @c backup_media_type is the
2351 * only field used in this function.
2352 * @param filelist The node structure containing the list of files to be
2353 * restored. If a prospective biggiefile is not in this list, it will be ignored.
2354 * @return 0 for success, nonzero for failure.
2355 */
2356int
2357restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
2358                                struct s_node *filelist)
2359{
2360    int retval = 0;
2361    int res;
2362    long noof_biggiefiles, bigfileno = 0, total_slices;
2363  /** malloc **/
2364    char *tmp;
2365    bool just_changed_cds = FALSE, finished;
2366    char *xattr_fname;
2367    char *acl_fname;
2368    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2369    char *pathname_of_last_biggie_restored;
2370    FILE *fbw = NULL;
2371
2372    malloc_string(xattr_fname);
2373    malloc_string(acl_fname);
2374    malloc_string(tmp);
2375    malloc_string(biggies_whose_EXATs_we_should_set);
2376    malloc_string(pathname_of_last_biggie_restored);
2377    assert(bkpinfo != NULL);
2378
2379    sprintf(biggies_whose_EXATs_we_should_set,
2380            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2381    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2382        log_msg(1, "Warning - cannot openout %s",
2383                biggies_whose_EXATs_we_should_set);
2384    }
2385
2386    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2387    total_slices = atol(tmp);
2388    sprintf(tmp, "Reassembling large files      ");
2389    mvaddstr_and_log_it(g_currentY, 0, tmp);
2390    if (length_of_file(BIGGIELIST) < 6) {
2391        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
2392        return (0);
2393    }
2394    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
2395    if (noof_biggiefiles <= 0) {
2396        log_msg(2,
2397                "OK, no biggiefiles in biggielist; not restoring biggiefiles");
2398        return (0);
2399    }
2400    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2401            noof_biggiefiles);
2402    log_msg(2, tmp);
2403
2404    open_progress_form("Reassembling large files",
2405                       "I am now reassembling all the large files.",
2406                       "Please wait. This may take some time.",
2407                       "", total_slices);
2408    for (bigfileno = 0, finished = FALSE; !finished;) {
2409        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
2410        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
2411            log_msg(3,
2412                    "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
2413            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
2414                    bigfileno + 1,
2415                    media_descriptor_string(bkpinfo->backup_media_type),
2416                    g_current_media_number);
2417            log_msg(3, "Slicename would have been %s",
2418                    slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
2419            // I'm not positive 'just_changed_cds' is even necessary...
2420            if (just_changed_cds) {
2421                just_changed_cds = FALSE;
2422                log_msg(3,
2423                        "I'll continue to scan this CD for bigfiles to be restored.");
2424            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
2425                insist_on_this_cd_number(bkpinfo,
2426                                         ++g_current_media_number);
2427                sprintf(tmp, "Restoring from %s #%d",
2428                        media_descriptor_string(bkpinfo->
2429                                                backup_media_type),
2430                        g_current_media_number);
2431                log_to_screen(tmp);
2432                just_changed_cds = TRUE;
2433            } else {
2434                log_msg(2, "There was no bigfile #%ld. That's OK.",
2435                        bigfileno + 1);
2436                log_msg(2, "I'm going to stop restoring bigfiles now.");
2437                finished = TRUE;
2438            }
2439        } else {
2440            just_changed_cds = FALSE;
2441            sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
2442            update_progress_form(tmp);
2443            res =
2444                restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
2445                                             pathname_of_last_biggie_restored);
2446            iamhere(pathname_of_last_biggie_restored);
2447            if (fbw && pathname_of_last_biggie_restored[0]) {
2448                fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2449            }
2450            retval += res;
2451            bigfileno++;
2452
2453        }
2454    }
2455
2456    if (fbw) {
2457        fclose(fbw);
2458        sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2459        sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2460        if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) {
2461            set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2462        }
2463        if (length_of_file(xattr_fname) > 0
2464            && find_home_of_exe("setfattr")) {
2465            set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2466        }
2467    }
2468    if (does_file_exist("/PAUSE")) {
2469        popup_and_OK
2470            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2471    }
2472    close_progress_form();
2473    if (retval) {
2474        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2475    } else {
2476        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2477    }
2478    paranoid_free(xattr_fname);
2479    paranoid_free(acl_fname);
2480    paranoid_free(tmp);
2481    paranoid_free(biggies_whose_EXATs_we_should_set);
2482    paranoid_free(pathname_of_last_biggie_restored);
2483    return (retval);
2484}
2485
2486/**************************************************************************
2487 *END_RESTORE_ALL_BIGGIFILES_FROM_CD                                      *
2488 **************************************************************************/
2489
2490
2491
2492/**
2493 * Restore all afioballs from all CDs in the backup.
2494 * The first CD should be inserted (if not, it will be asked for).
2495 * @param bkpinfo The backup information structure. @c backup_media_type is the
2496 * only field used in @e this function.
2497 * @param filelist The node structure containing the list of files to be
2498 * restored. If no file in some particular afioball is in this list, afio will
2499 * still be called for that fileset, but nothing will be written.
2500 * @return 0 for success, or the number of filesets that failed.
2501 */
2502int
2503restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
2504                             struct s_node *filelist)
2505{
2506    int retval = 0;
2507    int res;
2508    int attempts;
2509    long current_tarball_number = 0;
2510    long max_val;
2511  /**malloc ***/
2512    char *tmp;
2513    char *tarball_fname;
2514    char *progress_str;
2515    char *comment;
2516
2517    malloc_string(tmp);
2518    malloc_string(tarball_fname);
2519    malloc_string(progress_str);
2520    malloc_string(comment);
2521
2522    assert(bkpinfo != NULL);
2523
2524    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2525    log_msg(2,
2526            "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
2527    if (g_current_media_number != 1) {
2528        log_msg(3, "OK, that's jacked up.");
2529        g_current_media_number = 1;
2530    }
2531    insist_on_this_cd_number(bkpinfo, g_current_media_number);
2532    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2533    max_val = atol(tmp) + 1;
2534    sprintf(progress_str, "Restoring from %s #%d",
2535            media_descriptor_string(bkpinfo->backup_media_type),
2536            g_current_media_number);
2537    log_to_screen(progress_str);
2538    open_progress_form("Restoring from archives",
2539                       "Restoring data from the archives.",
2540                       "Please wait. This may take some time.",
2541                       progress_str, max_val);
2542    for (;;) {
2543        insist_on_this_cd_number(bkpinfo, g_current_media_number);
2544        update_progress_form(progress_str);
2545        sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
2546                current_tarball_number);
2547        if (!does_file_exist(tarball_fname)) {
2548            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2549                    current_tarball_number);
2550        }
2551        if (!does_file_exist(tarball_fname)) {
2552            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
2553                    current_tarball_number);
2554        }
2555        if (!does_file_exist(tarball_fname)) {
2556            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
2557                    current_tarball_number);
2558        }
2559        if (!does_file_exist(tarball_fname)) {
2560            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
2561                    current_tarball_number);
2562        }
2563        if (!does_file_exist(tarball_fname)) {
2564            if (current_tarball_number == 0) {
2565                log_to_screen
2566                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2567                return (0);
2568            }
2569            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2570                || system("find " MNT_CDROM
2571                          "/archives/slice* > /dev/null 2> /dev/null") ==
2572                0) {
2573                break;
2574            }
2575            g_current_media_number++;
2576            sprintf(progress_str, "Restoring from %s #%d",
2577                    media_descriptor_string(bkpinfo->backup_media_type),
2578                    g_current_media_number);
2579            log_to_screen(progress_str);
2580        } else {
2581            sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2582                    current_tarball_number,
2583                    media_descriptor_string(bkpinfo->backup_media_type),
2584                    g_current_media_number);
2585//    log_msg(3, "progress_str = %s", progress_str);
2586            for (res = 999, attempts = 0; attempts < 3 && res != 0;
2587                 attempts++) {
2588                res =
2589                    restore_a_tarball_from_CD(tarball_fname,
2590                                              current_tarball_number,
2591                                              filelist);
2592            }
2593            sprintf(tmp, "%s #%d, fileset #%ld - restore ",
2594                    media_descriptor_string(bkpinfo->backup_media_type),
2595                    g_current_media_number, current_tarball_number);
2596            if (res) {
2597                strcat(tmp, "reported errors");
2598            } else if (attempts > 1) {
2599                strcat(tmp, "succeeded");
2600            } else {
2601                strcat(tmp, "succeeded");
2602            }
2603            if (attempts > 1) {
2604                sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
2605                        attempts);
2606            }
2607            strcpy(comment, tmp);
2608            if (attempts > 1) {
2609                log_to_screen(comment);
2610            }
2611
2612            retval += res;
2613            current_tarball_number++;
2614            g_current_progress++;
2615        }
2616    }
2617    close_progress_form();
2618    if (retval) {
2619        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2620    } else {
2621        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2622    }
2623    paranoid_free(tmp);
2624    paranoid_free(tarball_fname);
2625    paranoid_free(progress_str);
2626    paranoid_free(comment);
2627
2628    return (retval);
2629}
2630
2631/**************************************************************************
2632 *END_RESTORE_ALL_TARBALLS_FROM_CD                                        *
2633 **************************************************************************/
2634
2635
2636
2637/**
2638 * Restore all biggiefiles from the currently opened stream.
2639 * @param bkpinfo The backup information structure. Passed to other functions.
2640 * @param filelist The node structure containing the list of files to be
2641 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2642 * @return 0 for success, or the number of biggiefiles that failed.
2643 */
2644int
2645restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
2646                                    struct s_node *filelist)
2647{
2648    long noof_biggiefiles;
2649    long current_bigfile_number = 0;
2650    long total_slices;
2651
2652    int retval = 0;
2653    int res = 0;
2654    int ctrl_chr;
2655
2656  /** malloc add ****/
2657    char *tmp;
2658    char *biggie_fname;
2659    char *biggie_cksum;
2660    char *xattr_fname;
2661    char *acl_fname;
2662    char *p;
2663    char *pathname_of_last_biggie_restored;
2664    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2665    long long biggie_size;
2666    FILE *fbw = NULL;
2667
2668    malloc_string(tmp);
2669    malloc_string(biggie_fname);
2670    malloc_string(biggie_cksum);
2671    malloc_string(xattr_fname);
2672    malloc_string(acl_fname);
2673    malloc_string(biggies_whose_EXATs_we_should_set);
2674    malloc_string(pathname_of_last_biggie_restored);
2675    assert(bkpinfo != NULL);
2676
2677    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2678
2679    total_slices = atol(tmp);
2680    sprintf(tmp, "Reassembling large files      ");
2681    sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2682    sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2683    mvaddstr_and_log_it(g_currentY, 0, tmp);
2684    sprintf(biggies_whose_EXATs_we_should_set,
2685            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2686    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2687        log_msg(1, "Warning - cannot openout %s",
2688                biggies_whose_EXATs_we_should_set);
2689    }
2690// get xattr and acl files if they're there
2691    res =
2692        read_header_block_from_stream(&biggie_size, biggie_fname,
2693                                      &ctrl_chr);
2694    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2695        res =
2696            read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
2697                                      &ctrl_chr, xattr_fname, acl_fname);
2698    }
2699
2700    noof_biggiefiles = atol(biggie_fname);
2701    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2702            noof_biggiefiles);
2703    log_msg(2, tmp);
2704    open_progress_form("Reassembling large files",
2705                       "I am now reassembling all the large files.",
2706                       "Please wait. This may take some time.",
2707                       "", total_slices);
2708
2709    for (res =
2710         read_header_block_from_stream(&biggie_size, biggie_fname,
2711                                       &ctrl_chr);
2712         ctrl_chr != BLK_STOP_BIGGIEFILES;
2713         res =
2714         read_header_block_from_stream(&biggie_size, biggie_fname,
2715                                       &ctrl_chr)) {
2716        if (ctrl_chr != BLK_START_A_NORMBIGGIE
2717            && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2718            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2719        }
2720        p = strrchr(biggie_fname, '/');
2721        if (!p) {
2722            p = biggie_fname;
2723        } else {
2724            p++;
2725        }
2726        sprintf(tmp, "Restoring big file %ld (%lld K)",
2727                current_bigfile_number + 1, biggie_size / 1024);
2728        update_progress_form(tmp);
2729        res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
2730                                               current_bigfile_number,
2731                                               biggie_cksum,
2732                                               biggie_size,
2733                                               filelist, ctrl_chr,
2734                                               pathname_of_last_biggie_restored);
2735        log_msg(1, "I believe I have restored %s",
2736                pathname_of_last_biggie_restored);
2737        if (fbw && pathname_of_last_biggie_restored[0]) {
2738            fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2739        }
2740        retval += res;
2741        current_bigfile_number++;
2742
2743    }
2744    if (current_bigfile_number != noof_biggiefiles
2745        && noof_biggiefiles != 0) {
2746        sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
2747                current_bigfile_number, noof_biggiefiles);
2748    } else {
2749        sprintf(tmp,
2750                "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
2751                noof_biggiefiles, current_bigfile_number);
2752    }
2753    log_msg(1, tmp);
2754
2755    if (fbw) {
2756        fclose(fbw);
2757        if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2758            iamhere("Setting biggie-EXATs");
2759            if (length_of_file(acl_fname) > 0) {
2760                log_msg(1, "set_acl_list(%s,%s)",
2761                        biggies_whose_EXATs_we_should_set, acl_fname);
2762                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2763            }
2764            if (length_of_file(xattr_fname) > 0) {
2765                log_msg(1, "set_fattr_List(%s,%s)",
2766                        biggies_whose_EXATs_we_should_set, xattr_fname);
2767                set_fattr_list(biggies_whose_EXATs_we_should_set,
2768                               xattr_fname);
2769            }
2770        } else {
2771            iamhere
2772                ("No biggiefiles selected. So, no biggie-EXATs to set.");
2773        }
2774    }
2775    if (does_file_exist("/PAUSE")) {
2776        popup_and_OK
2777            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2778    }
2779
2780    close_progress_form();
2781    if (retval) {
2782        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2783    } else {
2784        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2785    }
2786    paranoid_free(biggies_whose_EXATs_we_should_set);
2787    paranoid_free(pathname_of_last_biggie_restored);
2788    paranoid_free(biggie_fname);
2789    paranoid_free(biggie_cksum);
2790    paranoid_free(xattr_fname);
2791    paranoid_free(acl_fname);
2792    paranoid_free(tmp);
2793    return (retval);
2794}
2795
2796/**************************************************************************
2797 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM                                 *
2798 **************************************************************************/
2799
2800
2801
2802
2803
2804
2805/**
2806 * Restore all afioballs from the currently opened tape stream.
2807 * @param bkpinfo The backup information structure. Fields used:
2808 * - @c bkpinfo->backup_media_type
2809 * - @c bkpinfo->restore_path
2810 * @param filelist The node structure containing the list of files to be
2811 * restored. If no file in an afioball is in this list, afio will still be
2812 * called for that fileset, but nothing will be written.
2813 * @return 0 for success, or the number of filesets that failed.
2814 */
2815int
2816restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
2817                                 struct s_node *filelist)
2818{
2819    int retval = 0;
2820    int res;
2821    long current_afioball_number = 0;
2822    int ctrl_chr;
2823    long max_val /*, total_noof_files */ ;
2824
2825  /** malloc **/
2826    char *tmp;
2827    char *progress_str;
2828    char *tmp_fname;
2829    char *xattr_fname;
2830    char *acl_fname;
2831
2832    long long tmp_size;
2833
2834    malloc_string(tmp);
2835    malloc_string(progress_str);
2836    malloc_string(tmp_fname);
2837    assert(bkpinfo != NULL);
2838    malloc_string(xattr_fname);
2839    malloc_string(acl_fname);
2840    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2841    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2842    max_val = atol(tmp) + 1;
2843
2844    chdir(bkpinfo->restore_path);   /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2845
2846    run_program_and_log_output("pwd", 5);
2847
2848    sprintf(progress_str, "Restoring from media #%d",
2849            g_current_media_number);
2850    log_to_screen(progress_str);
2851    open_progress_form("Restoring from archives",
2852                       "Restoring data from the archives.",
2853                       "Please wait. This may take some time.",
2854                       progress_str, max_val);
2855
2856    log_msg(3, "hey");
2857
2858    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2859    if (res) {
2860        log_msg(2, "Warning - error reading afioball from tape");
2861    }
2862    retval += res;
2863    if (ctrl_chr != BLK_START_AFIOBALLS) {
2864        wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2865    }
2866    log_msg(2, "ho");
2867    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2868    while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2869        update_progress_form(progress_str);
2870        sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
2871                current_afioball_number);
2872        sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
2873                current_afioball_number);
2874        unlink(xattr_fname);
2875        unlink(acl_fname);
2876        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2877            iamhere("Reading EXAT files from tape");
2878            res =
2879                read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
2880                                          &ctrl_chr, xattr_fname,
2881                                          acl_fname);
2882        }
2883        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2884            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2885        }
2886        sprintf(tmp,
2887                "Restoring from fileset #%ld (name=%s, size=%ld K)",
2888                current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2889        res =
2890            restore_a_tarball_from_stream(bkpinfo, tmp_fname,
2891                                          current_afioball_number,
2892                                          filelist, tmp_size, xattr_fname,
2893                                          acl_fname);
2894        retval += res;
2895        if (res) {
2896            sprintf(tmp, "Fileset %ld - errors occurred",
2897                    current_afioball_number);
2898            log_to_screen(tmp);
2899        }
2900        res =
2901            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2902        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2903            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2904        }
2905
2906        current_afioball_number++;
2907        g_current_progress++;
2908        sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2909                current_afioball_number,
2910                media_descriptor_string(bkpinfo->backup_media_type),
2911                g_current_media_number);
2912        res =
2913            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2914        unlink(xattr_fname);
2915        unlink(acl_fname);
2916    }                           // next
2917    log_msg(1, "All done with afioballs");
2918    close_progress_form();
2919    if (retval) {
2920        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2921    } else {
2922        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2923    }
2924    paranoid_free(tmp);
2925    paranoid_free(progress_str);
2926    paranoid_free(tmp_fname);
2927    paranoid_free(xattr_fname);
2928    paranoid_free(acl_fname);
2929    return (retval);
2930}
2931
2932/**************************************************************************
2933 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM                                   *
2934 **************************************************************************/
2935
2936/* @} - end of LLrestoreGroup */
2937
2938
2939/**
2940 * Restore all files in @p filelist.
2941 * @param bkpinfo The backup information structure. Most fields are used.
2942 * @param filelist The node structure containing the list of files to be
2943 * restored.
2944 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2945 * @ingroup restoreGroup
2946 */
2947int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
2948{
2949    int resA;
2950    int resB;
2951
2952  /** mallco ***/
2953    char *cwd;
2954    char *newpath;
2955    char *tmp;
2956    assert(bkpinfo != NULL);
2957
2958    malloc_string(cwd);
2959    malloc_string(newpath);
2960    malloc_string(tmp);
2961    log_msg(2, "restore_everything() --- starting");
2962    g_current_media_number = 1;
2963    getcwd(cwd, MAX_STR_LEN - 1);
2964    sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2965    run_program_and_log_output(tmp, FALSE);
2966    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2967    chdir(bkpinfo->restore_path);
2968    getcwd(newpath, MAX_STR_LEN - 1);
2969    log_msg(1, "path is now %s", newpath);
2970    log_msg(1, "restoring everything");
2971    if (!find_home_of_exe("petris") && !g_text_mode) {
2972        newtDrawRootText(0, g_noof_rows - 2,
2973                         "Press ALT-<left cursor> twice to play Petris :-) ");
2974        newtRefresh();
2975    }
2976    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
2977    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2978        mount_cdrom(bkpinfo);
2979        mvaddstr_and_log_it(g_currentY++, 0,
2980                            "Restoring OS and data from streaming media");
2981        if (bkpinfo->backup_media_type == cdstream) {
2982            openin_cdstream(bkpinfo);
2983        } else {
2984            assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
2985                                                         media_device);
2986            openin_tape(bkpinfo);
2987        }
2988        resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
2989        resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
2990        if (bkpinfo->backup_media_type == cdstream) {
2991            closein_cdstream(bkpinfo);
2992        } else {
2993            closein_tape(bkpinfo);
2994        }
2995    } else {
2996        mvaddstr_and_log_it(g_currentY++, 0,
2997                            "Restoring OS and data from CD       ");
2998        mount_cdrom(bkpinfo);
2999        resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
3000        resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
3001    }
3002    chdir(cwd);
3003    if (resA + resB) {
3004        log_to_screen("Errors occurred while data was being restored.");
3005    }
3006    if (length_of_file("/etc/raidtab") > 0) {
3007        log_msg(2, "Copying local raidtab to restored filesystem");
3008        run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
3009                                   "/etc/raidtab", FALSE);
3010    }
3011    kill_petris();
3012    log_msg(2, "restore_everything() --- leaving");
3013    paranoid_free(cwd);
3014    paranoid_free(newpath);
3015    paranoid_free(tmp);
3016    return (resA + resB);
3017}
3018
3019/**************************************************************************
3020 *END_RESTORE_EVERYTHING                                                  *
3021 **************************************************************************/
3022
3023
3024
3025/**
3026 * @brief Haha. You wish! (This function is not implemented :-)
3027 */
3028int
3029restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
3030                                 char *monitas_device,
3031                                 char *restore_this_directory,
3032                                 char *restore_here)
3033     /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
3034{
3035    FILE *fout;
3036    int retval = 0;
3037    int i;
3038    int j;
3039    struct mountlist_itself the_mountlist;
3040    static struct raidlist_itself the_raidlist;
3041  /** malloc **/
3042    char tmp[MAX_STR_LEN + 1];
3043    char command[MAX_STR_LEN + 1];
3044    char datablock[256 * 1024];
3045    char datadisks_fname[MAX_STR_LEN + 1];
3046    long k;
3047    long length;
3048    long long llt;
3049    struct s_node *filelist = NULL;
3050    assert(bkpinfo != NULL);
3051    assert_string_is_neither_NULL_nor_zerolength(monitas_device);
3052    assert(restore_this_directory != NULL);
3053    assert(restore_here != NULL);
3054
3055    sprintf(tmp, "restore_here = '%s'", restore_here);
3056
3057    log_msg(2, tmp);
3058
3059    log_msg(2, "restore_live_from_monitas_server() - starting");
3060    unlink("/tmp/mountlist.txt");
3061    unlink("/tmp/filelist.full");
3062    unlink("/tmp/biggielist.txt");
3063    if (restore_here[0] == '\0') {
3064        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3065    } else {
3066        strcpy(bkpinfo->restore_path, restore_here);
3067    }
3068    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3069    sprintf(tmp, "FYI - data will be restored to %s",
3070            bkpinfo->restore_path);
3071    log_msg(3, tmp);
3072    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3073    sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
3074            (int) (random() % 32768));
3075    chdir(bkpinfo->tmpdir);
3076
3077    sprintf(command, "cat %s", monitas_device);
3078    g_tape_stream = popen(command, "r");    // for compatibility with openin_tape()
3079    if (!(fout = fopen(datadisks_fname, "w"))) {
3080        log_OS_error(datadisks_fname);
3081        return (1);
3082    }
3083    for (i = 0; i < 32; i++) {
3084        for (j = 0; j < 4; j++) {
3085            for (length = k = 0; length < 256 * 1024; length += k) {
3086                k = fread(datablock + length, 1, 256 * 1024 - length,
3087                          g_tape_stream);
3088            }
3089            fwrite(datablock, 1, length, fout);
3090            g_tape_posK += length;
3091        }
3092    }
3093    paranoid_fclose(fout);
3094    sprintf(command,
3095            "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
3096            datadisks_fname);
3097    run_program_and_log_output(command, 4);
3098    read_header_block_from_stream(&llt, tmp, &i);
3099    read_header_block_from_stream(&llt, tmp, &i);
3100
3101    unlink(datadisks_fname);
3102    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3103    retval = load_mountlist(&the_mountlist, g_mountlist_fname);
3104
3105
3106    load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
3107    iamhere("FIXME");
3108    fatal_error("This will fail");
3109    sprintf(command,
3110            "cat %s | grep -x \"%s.*\" > %s",
3111            g_filelist_full, restore_this_directory, g_filelist_full);
3112    if (system(command)) {
3113        retval++;
3114        log_to_screen
3115            ("Error(s) occurred while processing filelist and wildcard");
3116    }
3117    iamhere("FIXME");
3118    fatal_error("This will fail");
3119    sprintf(command,
3120            "cat %s | grep -x \"%s.*\" > %s",
3121            g_biggielist_txt, restore_this_directory, g_biggielist_txt);
3122    if (system(command)) {
3123        log_msg(1,
3124                "Error(s) occurred while processing biggielist and wildcard");
3125    }
3126    sprintf(command, "touch %s", g_biggielist_txt);
3127    run_program_and_log_output(command, FALSE);
3128//  filelist = load_filelist(g_filelist_restthese);  // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
3129    retval += restore_everything(bkpinfo, filelist);
3130    free_filelist(filelist);
3131    log_msg(2, "--------End of restore_live_from_monitas_server--------");
3132    return (retval);
3133}
3134
3135/**************************************************************************
3136 *END_RESTORE_LIVE_FROM_MONITAS_SERVER                                    *
3137 **************************************************************************/
3138
3139
3140
3141
3142extern void wait_until_software_raids_are_prepped(char *, int);
3143
3144
3145char which_restore_mode(void);
3146
3147
3148/**
3149 * Log a "don't panic" message to the logfile.
3150 */
3151void welcome_to_mondorestore()
3152{
3153    log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION);
3154    log_msg(0,
3155            "DON'T PANIC! Mondorestore logs almost everything, so please ");
3156    log_msg(0,
3157            "don't break out in a cold sweat just because you see a few  ");
3158    log_msg(0,
3159            "error messages in the log. Read them; analyze them; see if  ");
3160    log_msg(0,
3161            "they are significant; above all, verify your backups! Please");
3162    log_msg(0,
3163            "attach a compressed copy of this log to any e-mail you send ");
3164    log_msg(0,
3165            "to the Mondo mailing list when you are seeking technical    ");
3166    log_msg(0,
3167            "support. Without it, we can't help you.               - Hugo");
3168    log_msg(0,
3169            "------------------------------------------------------------");
3170    log_msg(0,
3171            "BTW, despite (or perhaps because of) the wealth of messages,");
3172    log_msg(0,
3173            "some users are inclined to stop reading this log.  If Mondo ");
3174    log_msg(0,
3175            "stopped for some reason, chances are it's detailed here.    ");
3176    log_msg(0,
3177            "More than likely there's a message at the very end of this  ");
3178    log_msg(0,
3179            "log that will tell you what is wrong.  Please read it!      ");
3180    log_msg(0,
3181            "------------------------------------------------------------");
3182}
3183
3184
3185
3186/**
3187 * Restore the user's data.
3188 * What did you think it did, anyway? :-)
3189 */
3190int main(int argc, char *argv[])
3191{
3192    FILE *fin;
3193    FILE *fout;
3194    int retval = 0;
3195    int res;
3196//  int c;
3197    char *tmp;
3198
3199#ifndef VERSION
3200#define VERSION "1.7x_cvs"
3201#endif
3202
3203    struct mountlist_itself *mountlist;
3204    struct raidlist_itself *raidlist;
3205    struct s_bkpinfo *bkpinfo;
3206    struct s_node *filelist;
3207    char *a, *b;
3208
3209  /**************************************************************************
3210   * hugo-                                                                  *
3211   * busy stuff here - it needs some comments -stan                           *
3212   *                                                                        *
3213   **************************************************************************/
3214    if (getuid() != 0) {
3215        fprintf(stderr, "Please run as root.\r\n");
3216        exit(127);
3217    }
3218
3219    g_loglevel = DEFAULT_MR_LOGLEVEL;
3220    malloc_string(tmp);
3221
3222/* Configure global variables */
3223#ifdef __FreeBSD__
3224    if (strstr
3225        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
3226         "textonly"))
3227#else
3228    if (strstr
3229        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
3230         "textonly"))
3231#endif
3232    {
3233        g_text_mode = TRUE;
3234        log_msg(1, "TEXTONLY MODE");
3235    } else {
3236        g_text_mode = FALSE;
3237    }                           // newt :-)
3238    if (!
3239        (bkpinfo = g_bkpinfo_DONTUSETHIS =
3240         malloc(sizeof(struct s_bkpinfo)))) {
3241        fatal_error("Cannot malloc bkpinfo");
3242    }
3243    if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
3244        fatal_error("Cannot malloc mountlist");
3245    }
3246    if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
3247        fatal_error("Cannot malloc raidlist");
3248    }
3249
3250    malloc_libmondo_global_strings();
3251
3252    asprintf(&g_mondo_home,
3253             call_program_and_get_last_line_of_output
3254             ("which mondorestore"));
3255    sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
3256    make_hole_for_dir(g_tmpfs_mountpt);
3257    g_current_media_number = 1; // precaution
3258
3259    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
3260    run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
3261
3262    malloc_string(tmp);
3263    malloc_string(a);
3264    malloc_string(b);
3265    setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
3266    reset_bkpinfo(bkpinfo);
3267    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
3268    bkpinfo->restore_data = TRUE;   // Well, yeah :-)
3269    if (am_I_in_disaster_recovery_mode()) {
3270        run_program_and_log_output("mount / -o remount,rw", 2);
3271    }                           // for b0rken distros
3272    g_main_pid = getpid();
3273    srandom((int) (time(NULL)));
3274    register_pid(getpid(), "mondo");
3275    set_signals(TRUE);
3276    g_kernel_version = get_kernel_version();
3277
3278    log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
3279    if (strlen(g_mountlist_fname) < 3) {
3280        fatal_error
3281            ("Serious error in malloc()'ing. Could be a bug in your glibc.");
3282    }
3283    mkdir(MNT_CDROM, 0x770);
3284
3285/* Backup original mountlist.txt */
3286    sprintf(tmp, "%s.orig", g_mountlist_fname);
3287    if (!does_file_exist(g_mountlist_fname)) {
3288        log_msg(2,
3289                "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
3290                __LINE__, g_mountlist_fname);
3291    } else if (!does_file_exist(tmp)) {
3292        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
3293                g_mountlist_fname);
3294        run_program_and_log_output(tmp, FALSE);
3295    }
3296
3297/* Init directories */
3298    make_hole_for_dir(bkpinfo->tmpdir);
3299    sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
3300    run_program_and_log_output(tmp, FALSE);
3301    make_hole_for_dir("/var/log");
3302    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
3303    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3304    run_program_and_log_output
3305        ("ln -sf "MONDO_LOGFILE" /tmp/mondo-restore.log",
3306         FALSE);
3307
3308    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
3309
3310/* Init GUI */
3311    malloc_libmondo_global_strings();
3312    setup_newt_stuff();         /* call newtInit and setup screen log */
3313    welcome_to_mondorestore();
3314    if (bkpinfo->disaster_recovery) {
3315        log_msg(1, "I am in disaster recovery mode");
3316    } else {
3317        log_msg(1, "I am in normal, live mode");
3318    }
3319
3320    iamhere("what time is it");
3321
3322/* Process command-line parameters */
3323    if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
3324#ifdef __FreeBSD__
3325        system("mv -f /tmp/raidconf.txt /etc/raidtab");
3326        if (!does_file_exist("/etc/raidtab"))
3327            system("vinum printconfig > /etc/raidtab");
3328#endif
3329        load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3330        if (!does_file_exist(g_mountlist_fname)) {
3331            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3332        }
3333        res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
3334#ifdef __FreeBSD__
3335        system("mv -f /etc/raidtab /tmp/raidconf.txt");
3336#endif
3337        paranoid_MR_finish(res);
3338    }
3339
3340    g_loglevel = DEFAULT_MR_LOGLEVEL;
3341    if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
3342        fout = fopen("/tmp/out.txt", "w");
3343        fput_string_one_char_at_a_time(stderr, argv[2]);
3344        finish(0);
3345    }
3346
3347    if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
3348        make_grub_install_scriptlet(argv[2]);
3349        finish(0);
3350    }
3351
3352    if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
3353        if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
3354            system("mount " MNT_CDROM);
3355        }
3356        bkpinfo->compression_level = 1;
3357        g_current_media_number = 2;
3358        strcpy(bkpinfo->restore_path, "/tmp/TESTING");
3359        bkpinfo->backup_media_type = dvd;
3360        open_progress_form("Reassembling /dev/hda1",
3361                           "Shark is a bit of a silly person.",
3362                           "Please wait. This may take some time.",
3363                           "", 1999);
3364        system("rm -Rf /tmp/*pih*");
3365
3366        restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
3367    }
3368
3369    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
3370        g_loglevel = 6;
3371        filelist = load_filelist(argv[2]);
3372        if (!filelist) {
3373            fatal_error("Failed to load filelist");
3374        }
3375        toggle_node_selection(filelist, FALSE);
3376        toggle_all_root_dirs_on(filelist);
3377        // BERLIOS: /usr/lib ???
3378        toggle_path_selection(filelist, "/usr/share", TRUE);
3379//      show_filelist(filelist);
3380        save_filelist(filelist, "/tmp/out.txt");
3381//      finish(0);
3382//      toggle_path_selection (filelist, "/root/stuff", TRUE);
3383        strcpy(a, argv[3]);
3384        strcpy(b, argv[4]);
3385
3386        res = save_filelist_entries_in_common(a, filelist, b, FALSE);
3387        free_filelist(filelist);
3388        printf("res = %d", res);
3389        finish(0);
3390    }
3391
3392    if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3393        popup_changelist_from_file(argv[2]);
3394        paranoid_MR_finish(0);
3395    }
3396
3397    if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
3398        log_msg(1, "SCORE");
3399        g_loglevel = 10;
3400        if (strstr(argv[2], "save")) {
3401            log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
3402            fin = fopen(argv[3], "r");
3403            fout = fopen(argv[4], "w");
3404            copy_from_src_to_dest(fin, fout, 'w');
3405            fclose(fin);
3406            fin = fopen(argv[3], "r");
3407            copy_from_src_to_dest(fin, fout, 'w');
3408            fclose(fout);
3409            fclose(fin);
3410        } else if (strstr(argv[2], "restore")) {
3411            fout = fopen(argv[3], "w");
3412            fin = fopen(argv[4], "r");
3413            copy_from_src_to_dest(fout, fin, 'r');
3414            fclose(fin);
3415            fin = fopen(argv[4], "r");
3416            copy_from_src_to_dest(fout, fin, 'r');
3417            fclose(fout);
3418            fclose(fin);
3419        } else {
3420            fatal_error("Unknown additional param");
3421        }
3422        finish(0);
3423    }
3424
3425    if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
3426        wait_until_software_raids_are_prepped(argv[2], 100);
3427        finish(0);
3428    }
3429
3430    if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) {
3431        finish(create_raidtab_from_mdstat(argv[2], argv[3]));
3432    }
3433
3434
3435    if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3436        retval = run_grub(FALSE, "/dev/hda");
3437        if (retval) {
3438            log_to_screen("Failed to write Master Boot Record");
3439        }
3440        paranoid_MR_finish(0);
3441    }
3442    if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3443        g_current_media_number = atoi(argv[2]);
3444        pause_and_ask_for_cdr(5, NULL);
3445        paranoid_MR_finish(0);
3446    } else if (!bkpinfo->disaster_recovery) {   // live!
3447        if (argc != 1) {
3448            popup_and_OK
3449                ("Live mode doesn't support command-line parameters yet.");
3450            paranoid_MR_finish(1);
3451//    return(1);
3452        }
3453        log_msg(1, "I am in normal, live mode.");
3454        log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
3455        mount_boot_if_necessary();  /* for Gentoo users */
3456        log_msg(2, "Still here.");
3457        if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
3458            g_restoring_live_from_cd = TRUE;
3459        }
3460        if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
3461            retval =
3462                restore_live_from_monitas_server(bkpinfo,
3463                                                 argv[2],
3464                                                 argv[3], argv[4]);
3465        } else {
3466            log_msg(2, "Calling restore_to_live_filesystem()");
3467            retval = restore_to_live_filesystem(bkpinfo);
3468        }
3469        log_msg(2, "Still here. Yay.");
3470        if (strlen(bkpinfo->tmpdir) > 0) {
3471            sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
3472            run_program_and_log_output(tmp, FALSE);
3473        }
3474        unmount_boot_if_necessary();    /* for Gentoo users */
3475        paranoid_MR_finish(retval);
3476    } else {
3477/* Disaster recovery mode (must be) */
3478        log_msg(1, "I must be in disaster recovery mode.");
3479        log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
3480        if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
3481            log_to_screen("Uh, that hasn't been implemented yet.");
3482            paranoid_MR_finish(1);
3483        }
3484
3485        iamhere("About to call load_mountlist and load_raidtab");
3486        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3487        read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3488        retval = load_mountlist(mountlist, g_mountlist_fname);
3489        retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3490        iamhere
3491            ("Returned from calling load_mountlist and load_raidtab successfully");
3492
3493        if (argc > 1
3494            && (strcmp(argv[1], "--compare") == 0
3495                || strcmp(argv[1], "--nuke") == 0)) {
3496            if (bkpinfo->backup_media_type == nfs
3497                && !is_this_device_mounted(bkpinfo->nfs_mount)) {
3498                log_msg(1, "Mounting nfs dir");
3499                sprintf(bkpinfo->isodir, "/tmp/isodir");
3500                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
3501                sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
3502                        bkpinfo->nfs_mount);
3503                run_program_and_log_output(tmp, 1);
3504            }
3505        }
3506
3507
3508        if (retval) {
3509            log_to_screen
3510                ("Warning - load_raidtab_into_raidlist returned an error");
3511        }
3512
3513
3514        log_msg(1, "Send in the clowns.");
3515
3516        if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
3517            log_msg(0, "Partitioning only.");
3518            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3519            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3520            load_mountlist(mountlist, g_mountlist_fname);
3521            res = partition_everything(mountlist);
3522            finish(res);
3523        }
3524
3525        if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
3526            log_msg(0, "Formatting only.");
3527            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3528            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3529            load_mountlist(mountlist, g_mountlist_fname);
3530            res = format_everything(mountlist, FALSE);
3531            finish(res);
3532        }
3533
3534        if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
3535            log_msg(0, "Stopping LVM and RAID");
3536            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3537            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3538            load_mountlist(mountlist, g_mountlist_fname);
3539            res = do_my_funky_lvm_stuff(TRUE, FALSE);
3540            res += stop_all_raid_devices(mountlist);
3541            finish(res);
3542        }
3543
3544        if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
3545            iamhere("nuking");
3546            retval += nuke_mode(bkpinfo, mountlist, raidlist);
3547        } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
3548            iamhere("catchall");
3549            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3550        } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
3551            iamhere("compare");
3552            retval += compare_mode(bkpinfo, mountlist, raidlist);
3553        } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
3554            iamhere("iso");
3555            retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
3556        } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
3557            iamhere("mbr");
3558            retval = mount_all_devices(mountlist, TRUE);
3559            if (!retval) {
3560                retval += run_boot_loader(FALSE);
3561                retval += unmount_all_devices(mountlist);
3562            }
3563            if (retval) {
3564                log_to_screen("Failed to write Master Boot Record");
3565            }
3566        } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
3567            iamhere("isonuke");
3568            retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
3569        } else if (argc != 1) {
3570            log_to_screen("Invalid paremeters");
3571            paranoid_MR_finish(1);
3572        } else {
3573            iamhere("catchall (no mode specified in command-line call");
3574            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3575        }
3576    }
3577
3578    /* clean up at the end */
3579    if (retval) {
3580        if (does_file_exist("/tmp/changed.files")) {
3581            log_to_screen
3582                ("See /tmp/changed.files for list of files that have changed.");
3583        }
3584        mvaddstr_and_log_it(g_currentY++,
3585                            0,
3586                            "Run complete. Errors were reported. Please review the logfile.");
3587    } else {
3588        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3589            mvaddstr_and_log_it(g_currentY++,
3590                                0,
3591                                "Run complete. Please remove floppy/CD/media and reboot.");
3592        } else {
3593            run_program_and_log_output("sync", FALSE);
3594            if (is_this_device_mounted(MNT_CDROM)) {
3595                res =
3596                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3597            } else {
3598                res = 0;
3599            }
3600
3601            if (!bkpinfo->please_dont_eject) {
3602                res = eject_device("/dev/cdrom");
3603/*
3604              if (res)
3605        {
3606          log_to_screen( "WARNING - failed to eject CD-ROM disk" );
3607        }
3608*/
3609            }
3610            mvaddstr_and_log_it(g_currentY++,
3611                                0,
3612                                "Run complete. Please remove media and reboot.");
3613        }
3614    }
3615
3616// g_I_have_just_nuked is set true by nuke_mode() just before it returns
3617    if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3618        if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3619            log_msg(1, "post-nuke found; running...");
3620            if (mount_all_devices(mountlist, TRUE)) {
3621                log_to_screen
3622                    ("Unable to re-mount partitions for post-nuke stuff");
3623            } else {
3624                log_msg(1, "Re-mounted partitions for post-nuke stuff");
3625                sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
3626                        retval);
3627                if (!g_text_mode) {
3628                    newtSuspend();
3629                }
3630                log_msg(2, "Calling '%s'", tmp);
3631                if ((res = system(tmp))) {
3632                    log_OS_error(tmp);
3633                }
3634                if (!g_text_mode) {
3635                    newtResume();
3636                }
3637//              newtCls();
3638                log_msg(1, "post-nuke returned w/ res=%d", res);
3639            }
3640            unmount_all_devices(mountlist);
3641            log_msg(1, "I've finished post-nuking.");
3642        }
3643    }
3644/* 
3645  log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3646  log_to_screen("Otherwise, please wait until the RAID disks are done.");
3647  wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3648  log_to_screen("Thank you.");
3649*/
3650    unlink("/tmp/mondo-run-prog.tmp");
3651    set_signals(FALSE);
3652    sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3653    run_program_and_log_output(tmp, FALSE);
3654    log_to_screen
3655        ("Restore log copied to /tmp/mondo-restore.log on your hard disk");
3656    sprintf(tmp,
3657            "Mondo-restore is exiting (retval=%d)                                      ",
3658            retval);
3659    log_to_screen(tmp);
3660    sprintf(tmp, "umount %s", bkpinfo->isodir);
3661    run_program_and_log_output(tmp, 5);
3662    paranoid_free(mountlist);
3663    paranoid_free(raidlist);
3664    if (am_I_in_disaster_recovery_mode()) {
3665        run_program_and_log_output("mount / -o remount,rw", 2);
3666    }                           // for b0rken distros
3667    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3668    free_libmondo_global_strings(); // it's fine to have this here :) really :)
3669    paranoid_free(a);
3670    paranoid_free(b);
3671    paranoid_free(tmp);
3672
3673    unlink("/tmp/filelist.full");
3674    unlink("/tmp/filelist.full.gz");
3675
3676    exit(retval);
3677}
3678
3679/**************************************************************************
3680 *END_MAIN                                                                *
3681 **************************************************************************/
3682
3683
3684
3685
3686
3687/**************************************************************************
3688 *END_MONDO-RESTORE.C                                                     *
3689 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.