source: MondoRescue/branches/stable/mondo/src/mondoarchive/mondoarchive.c @ 1842

Last change on this file since 1842 was 1842, checked in by Bruno Cornec, 12 years ago
  • Fix lack of /etc/raidtab at restore rime in the right place
  • Adds support for nls_utf8 and pata_serverworks Patches from Dirk Husung (husung_at_tu-harburg.de)
  • Add efibootmgr to deplist.txt in order to be able to modify EFI menu at restore time on ia64
  • Usage of the new testver param of pb 0.8.12 to deliver 2.2.5 packages in a test dir.
  • Update pbcl files for upcoming delivery of 2.2.5
  • Fix an issue on parted output (K instead of KB) in parted2fdisk at restore time
  • Adds support for alb/aft types of bonding on Intel cards (Mark Pinkerton <Mark.Pinkerton_at_emageon.com>)
  • Escape variables in a perl script like mindi-bkphw
  • Better Proliant support at restore time now.
  • Fix a label bug where the variable label should also be re-initialized at each loop
  • start-nfs should NOT do exit => kernel panix as init exits
  • some other fixes for init on denymods
  • Adds boot options denymods (for udev) and forcemods (if not udev)
  • kqemu is denied. Probably should also be done for kvm stuff
  • Fix again the bug on modules link at root of the initrd. Hopefully for good.
  • Wait more around the USB CD emulated by iLO as it takes up to 5 seconds to come up
  • Attempt to fix udev support for RHEL 5.1
  • Better support for automatic iLO Virtual Media with udev
  • Some VMWare support improvements (however, it seems that VMWare support won't be possible anytime soon)
  • during init at restore time, copy all static evices availble for udev, as some distro implementation are no

t yet supported correctly for udev. Not very elegant, but should solve our current issues

  • Fedora 8 now supported as a build target for pb
  • svn.log removed.
  • dependencies reviewd for rhel_3
  • Attempt to fix the lack of modules loaded at restore time - especially fs device drivers
  • removes bkphw dir before potential creation
  • render mount command more vebose at restore time
  • Should fix #217
  • Increase BOOT_SIZE and EXTRA_SIZE to support features such as HW recovery
  • Handles udev.files files which could be symlinks
  • Improve udev support for distro with compressed modules (mdv e.g.)
  • Fix modules.dep copy
  • /sbin/pam_console_apply is needed by mdv udev conf
  • Adds support for nohw boot option to avoid re-setuping the HW conf
  • Improved support for Proliant on cpqacuxe
  • RstHW should be called after driver initialization
  • For debian/ubuntu mindi dpends on mindi-busybox
  • Update mindi-busybox pbcl for correct debian changelog generation, and up2date infos
  • Should fix #215
  • Fix #214 (Thanks to xdelaruelle)
  • Fix again svn.log not used anymore with new pb version
  • Adaptation of build process to upcoming 0.8.12 version of pb
  • Remove MONOTONIC clock to continue to support 2.4 kernels (RHEL 3 e.g. or ESX)
  • Attempt to solve ia64 BMC access through the serial port
  • parted2fdisk binary no more generated
  • do not require perl modules (strict.pm) at restore time
  • try to avoid modprobe messages at restore time
  • on ia64 now use the perl script parted2fdisk at retore time also
  • Also modprobe modules for udev after decompressing the additional ones
  • replace gzip -v9 by gzip -c9. Fix a bug at least on ia64
  • For all modules supported, create symlinks under the mountpoint and extract dev files as some are not automat ically created at the moment
  • Support /vmfs/volumes for ESX
  • Finally do not use vdf for ESX. Only creates issues.
  • Avoids continuing hw support if no product name found
  • Improves ia64 support for bootable image build
  • Fix a potential problem with ramdisk_blocksize param
  • MAKEDEV should also be included in deplist.txt
  • More fixes for udev support for Debian
  • Do not mount /boot if it's already mounted - avoids ESX hang
  • Fix NICs renumbering on Debian at least
  • Udev startup improvement to support iLO + NFS so modprobing all modules seems required as of now
  • Update to version 1.7.3 of busybox for pb
  • Load USB earlier in order to support KBD such as with iLO
  • Do busybox ldd first in order to create a potential /lib64 link correctly and then use it later in the image
  • Use variable DF in mindi to be able to support the ESX vdf
  • Fix mindi for Debian x86_64 where /lib64 is a link
  • Fix issue at restore time for ext2fs params not reused (Fix from Klaus Ade Johnstad <klaus_at_skolelinux.no>)
  • Do not copy udev files if they do not exist In udev case do not insert modules at all (udev should do it alone) May avoid the issue with rhel4.5 kernel ? To be tested
  • Update dependencies for rpm base build as well
  • And also perl is a debian/ubuntu dep
  • Better debian/ubuntu dependecies requirements (mtools)
  • Fix modes on mindi-bkphw (Thanks Phil Walker phil.walker_at_hp.com)
  • Complete rev [1771] for upper case RESTORE cli with syslinux as well
  • Update mindi-busybox to 1.7.3
  • Use RESTORE consistently across mondo to restore without interaction (report from Takeshi Shoji t.shoji_at_tripodw.jp)

(merge -r1769:1841 $SVN_M/branches/2.2.5)

  • Property svn:keywords set to Id
File size: 19.1 KB
Line 
1/***************************************************************************
2* $Id: mondoarchive.c 1842 2007-12-15 01:24:34Z bruno $
3*/
4
5
6/**
7 * @file
8 * The main file for mondoarchive.
9 */
10
11/************************* #include statements *************************/
12#include <pthread.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <unistd.h>
18#include <locale.h>
19
20#include "mr_gettext.h"
21#include "mondoarchive.h"
22#include "mr_mem.h"
23#include "mr_str.h"
24#include "mr_msg.h"
25#include "mr_file.h"
26#include "mr_err.h"
27#include "mr_conf.h"
28
29#include "my-stuff.h"
30#include "mondostructures.h"
31#include "libmondo.h"
32#include "mondo-cli-EXT.h"
33
34// for CVS
35//static char cvsid[] = "$Id: mondoarchive.c 1842 2007-12-15 01:24:34Z bruno $";
36
37/************************* external variables *************************/
38extern void set_signals(int);
39extern int g_current_media_number;
40extern void register_pid(pid_t, char *);
41extern int g_currentY;
42extern bool g_text_mode;
43extern char *g_boot_mountpt;
44extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
45extern char *g_cdrw_drive_is_here;
46extern double g_kernel_version;
47extern char *g_magicdev_command;
48extern t_bkptype g_backup_media_type;
49
50extern char *get_uname_m(void);
51
52static char *g_cdrom_drive_is_here = NULL;
53static char *g_dvd_drive_is_here = NULL;
54
55struct mr_ar_conf *mr_conf = NULL;
56
57/***************** global vars ******************/
58long diffs;
59
60/****************** subroutines used only here ******************/
61
62/* Reference to global bkpinfo */
63struct s_bkpinfo *bkpinfo;
64
65/****************** subroutines used only by main.c ******************/
66
67/**
68 * Print a "don't panic" message to the log and a message about the logfile to the screen.
69 */
70static void welcome_to_mondoarchive(void)
71{
72    char *tmp = NULL;
73
74    mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
75    mr_msg(0, "running %s binaries", get_architecture());
76    tmp = get_uname_m();
77    mr_msg(0, "running on %s architecture", tmp);
78    mr_free(tmp);
79    mr_msg(0, "-----------------------------------------------------------");
80    mr_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
81    mr_msg(0, "some error messages.  Please read them carefully before you");
82    mr_msg(0, "decide to break out in a cold sweat.    Despite (or perhaps");
83    mr_msg(0, "because of) the wealth of messages. some users are inclined");
84    mr_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
85    mr_msg(0, "chances are it's detailed here.  More than likely there's a");
86    mr_msg(0, "message at the very end of this log that will tell you what");
87    mr_msg(0, "is wrong. Please read it!                          -Devteam");
88    mr_msg(0, "-----------------------------------------------------------");
89
90    mr_msg(0, "Zero...");
91    mr_msg(1, "One...");
92    mr_msg(2, "Two...");
93    mr_msg(3, "Three...");
94    mr_msg(4, "Four...");
95    mr_msg(5, "Five...");
96    mr_msg(6, "Six...");
97    mr_msg(7, "Seven...");
98    mr_msg(8, "Eight...");
99    printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
100}
101
102/**
103 * Do whatever is necessary to insure a successful backup on the Linux distribution
104 * of the day.
105 */
106static void distro_specific_kludges_at_start_of_mondoarchive(void)
107{
108    mr_msg(2, "Unmounting old ramdisks if necessary");
109    stop_magicdev_if_necessary();   // for RH+Gnome users
110    run_program_and_log_output
111        ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
112    unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
113    mount_boot_if_necessary();  // for Gentoo users with non-mounted /boot partitions
114    clean_up_KDE_desktop_if_necessary();    // delete various misc ~/.* files that get in the way
115}
116
117
118/**
119 * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
120 */
121static void distro_specific_kludges_at_end_of_mondoarchive(void)
122{
123    mr_msg(2, "Restarting magicdev if necessary");
124    sync();
125    restart_magicdev_if_necessary();    // for RH+Gnome users
126
127    mr_msg(2, "Restarting supermounts if necessary");
128    sync();
129    remount_supermounts_if_necessary(); // for Mandrake users
130
131    mr_msg(2, "Unmounting /boot if necessary");
132    sync();
133    unmount_boot_if_necessary();    // for Gentoo users
134}
135
136/* reset/empty the mr_ar_conf structure from mondo's conf file */
137static void mr_ar_reset_conf(struct mr_ar_conf *mr_cnf) {
138
139    /* This should correspond to the default conf file */
140    /* Especially for boolean values */
141    mr_cnf->iso_creation_cmd = NULL;
142    mr_cnf->iso_creation_opt = NULL;
143    mr_cnf->iso_burning_cmd = NULL;
144    mr_cnf->iso_burning_opt = NULL;
145    mr_cnf->iso_burning_dev = NULL;
146    mr_cnf->iso_burning_speed = 0;
147    mr_cnf->media_size = 0;
148    mr_cnf->media_device = NULL;
149    mr_cnf->iso_burning_dev = NULL;
150    mr_cnf->manual_tray = FALSE;
151    mr_cnf->log_level = 0;
152    mr_cnf->prefix = NULL;
153    mr_cnf->external_tape_blocksize = 0;
154    mr_cnf->internal_tape_blocksize = 0;
155    mr_cnf->kernel = NULL;
156    mr_cnf->additional_modules = NULL;
157    mr_cnf->boot_loader = NULL;
158    mr_cnf->differential = FALSE;
159    mr_cnf->compression_tool = NULL;
160    mr_cnf->compression_level = 0;
161    mr_cnf->exclude_paths = NULL;
162    mr_cnf->include_paths = NULL;
163    mr_cnf->ui_mode = NULL;
164    mr_cnf->automatic_restore = FALSE;
165    mr_cnf->scratch_dir = NULL;
166    mr_cnf->tmp_dir = NULL;
167    mr_cnf->images_dir = NULL;
168}
169
170/* fill the mr_ar_conf structure from mindi's conf file */
171static void mr_ar_store_conf_mindi(struct mr_ar_conf *mr_cnf) {
172   
173    char *p = NULL;
174
175    p = mr_conf_sread("mr_iso_creation_cmd");
176    if (p != NULL) {
177        mr_cnf->iso_creation_cmd = p;
178    }
179    p = mr_conf_sread("mr_iso_creation_opt");
180    if (p != NULL) {
181        mr_cnf->iso_creation_opt = p;
182    }
183}
184
185/* create the mr_ar_conf structure from mondo's conf file */
186static void mr_ar_store_conf(struct mr_ar_conf *mr_cnf) {
187   
188    char *p = NULL;
189
190    p = mr_conf_sread("mondo_iso_burning_cmd");
191    if (p != NULL) {
192        mr_cnf->iso_burning_cmd = p;
193    }
194
195    p = mr_conf_sread("mondo_iso_burning_opt");
196    if (p != NULL) {
197        mr_cnf->iso_burning_opt = p;
198    }
199
200    p = mr_conf_sread("mondo_iso_burning_dev");
201    if (p != NULL) {
202        mr_cnf->iso_burning_dev = p;
203    }
204
205    p = mr_conf_iread("mondo_iso_burning_speed");
206    if (p != NULL ) {
207        mr_cnf->iso_burning_speed = atoi(p);
208        mr_free(p);
209    }
210
211    p = mr_conf_iread("mondo_media_size");
212    if (p != NULL ) {
213        mr_cnf->media_size = atoi(p);
214        mr_free(p);
215    }
216
217    p = mr_conf_sread("mondo_media_device");
218    if (p != NULL) {
219        mr_cnf->media_device = p;
220    }
221    /* If no specific device name for the burning command (a la ATAPI:0,0,0),
222     * then use the normal device name (a la /dev/hda) */
223    if ((mr_cnf->iso_burning_dev == NULL) && (mr_cnf->media_device != NULL)) {
224        mr_asprintf(&p, mr_cnf->media_device);
225        mr_cnf->iso_burning_dev = p;
226    }
227
228    p = mr_conf_bread("mondo_manual_tray");
229    if (p != NULL) {
230        mr_cnf->manual_tray = mr_atob(p);
231        mr_free(p);
232    }
233
234    p = mr_conf_iread("mondo_log_level");
235    if (p != NULL) {
236        mr_cnf->log_level = atoi(p);
237        mr_free(p);
238    }
239
240    p = mr_conf_sread("mondo_prefix");
241    if (p != NULL) {
242        mr_cnf->prefix = p;
243    }
244
245    p = mr_conf_iread("mondo_external_tape_blocksize");
246    if (p != NULL) {
247        mr_cnf->external_tape_blocksize = atoi(p);
248        mr_free(p);
249    }
250
251    p = mr_conf_iread("mondo_internal_tape_blocksize");
252    if (p != NULL) {
253        mr_cnf->internal_tape_blocksize = atoi(p);
254        mr_free(p);
255    }
256
257    p = mr_conf_sread("mondo_kernel");
258    if (p != NULL) {
259        mr_cnf->kernel = p;
260    }
261
262    p = mr_conf_sread("mondo_additional_modules");
263    if (p != NULL) {
264        mr_cnf->additional_modules = p;
265    }
266
267    p = mr_conf_sread("mondo_boot_loader");
268    if (p != NULL) {
269        mr_cnf->boot_loader = p;
270    }
271
272    p = mr_conf_bread("mondo_differential");
273    if (p != NULL) {
274        mr_cnf->differential = mr_atob(p);
275        mr_free(p);
276    }
277
278    p = mr_conf_sread("mondo_compression_tool");
279    if (p != NULL) {
280        mr_cnf->compression_tool = p;
281    }
282
283    p = mr_conf_sread("mondo_compression_suffix");
284    if (p != NULL) {
285        mr_cnf->compression_suffix = p;
286    }
287
288    p = mr_conf_iread("mondo_compression_level");
289    if (p != NULL) {
290        mr_cnf->compression_level = atoi(p);
291        mr_free(p);
292    }
293
294    p = mr_conf_sread("mondo_exclude_paths");
295    if (p != NULL) {
296        mr_cnf->exclude_paths = p;
297    }
298
299    p = mr_conf_sread("mondo_include_paths");
300    if (p != NULL) {
301        mr_cnf->include_paths = p;
302    }
303
304    p = mr_conf_sread("mondo_ui_mode");
305    if (p != NULL) {
306        mr_cnf->ui_mode = p;
307    }
308
309    p = mr_conf_bread("mondo_automatic_restore");
310    if (p != NULL) {
311        mr_cnf->automatic_restore = mr_atob(p);
312        mr_free(p);
313    }
314
315    p = mr_conf_sread("mondo_scratch_dir");
316    if (p != NULL) {
317        mr_cnf->scratch_dir = p;
318    }
319
320    p = mr_conf_sread("mondo_tmp_dir");
321    if (p != NULL) {
322        mr_cnf->tmp_dir = p;
323    }
324
325    p = mr_conf_sread("mondo_images_dir");
326    if (p != NULL) {
327        mr_cnf->images_dir = p;
328    }
329    mr_msg(5, "Directory for images is %s", mr_cnf->images_dir);
330}
331
332/* destroy the mr_ar_conf structure's content */
333static void mr_ar_clean_conf(struct mr_ar_conf *mr_cnf) {
334   
335    if (mr_cnf == NULL) {
336        return;
337    }
338    mr_free(mr_cnf->iso_creation_cmd);
339    mr_free(mr_cnf->iso_creation_opt);
340    mr_free(mr_cnf->iso_burning_cmd);
341    mr_free(mr_cnf->iso_burning_dev);
342    mr_free(mr_cnf->iso_burning_opt);
343    mr_free(mr_cnf->media_device);
344    mr_free(mr_cnf->prefix);
345    mr_free(mr_cnf->kernel);
346    mr_free(mr_cnf->additional_modules);
347    mr_free(mr_cnf->boot_loader);
348    mr_free(mr_cnf->compression_tool);
349    mr_free(mr_cnf->exclude_paths);
350    mr_free(mr_cnf->include_paths);
351    mr_free(mr_cnf->ui_mode);
352    mr_free(mr_cnf->scratch_dir);
353    mr_free(mr_cnf->tmp_dir);
354    mr_free(mr_cnf->images_dir);
355    mr_free(mr_cnf);
356}
357
358/* Create the pointer to the function called in mr_exit */
359void (*mr_cleanup)(void) = NULL;
360
361/* Just for init */
362void mr_ar_cleanup_empty(void) {
363}
364
365/* Cleanup all memory allocated in various structures */
366void mr_ar_cleanup(void) {
367    /* Highly incomplete function for the moment */
368    /* We have to free all allocated memory */
369    mr_ar_clean_conf(mr_conf);
370    /* We have to remove all temporary files */
371    /* We have to unmount what has been mounted */
372    /* We have to properly end newt */
373    /* We have to remind people of log files */
374
375    mr_msg_close();
376}
377
378/*-----------------------------------------------------------*/
379
380
381
382/**
383 * Backup/verify the user's data.
384 * What did you think it did, anyway? :-)
385 */
386int main(int argc, char *argv[])
387{
388    struct stat stbuf;
389    char *tmp = NULL;
390    int res = 0;
391    int retval = 0;
392    char *say_at_end = NULL;
393    char *say_at_end2 = NULL;
394
395#ifdef ENABLE_NLS
396    setlocale(LC_ALL, "");
397    (void) textdomain("mondo");
398#endif
399    printf(_("Initializing...\n"));
400
401    bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
402    reset_bkpinfo();
403
404    /* Reference a dummy cleanup function for mr_exit temporarily */
405    mr_cleanup = &mr_ar_cleanup_empty;
406
407    /* initialize log file with time stamp */
408    /* We start with a loglevel of 4 - Adapted later on */
409    /* It's mandatory to set this up first as all mr_ functions rely on it */
410    unlink(MONDO_LOGFILE);
411    mr_msg_init(MONDO_LOGFILE,4);
412    mr_msg(0, _("Time started: %s"), mr_date());
413
414    /* Make sure I'm root; abort if not */
415    if (getuid() != 0) {
416        mr_log_exit(127, _("Please run as root."));
417    }
418
419    /* If -V, -v or --version then echo version no. and quit */
420    if (argc == 2
421        && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
422            || !strcmp(argv[argc - 1], "--version"))) {
423        printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
424        mr_exit(0, NULL);
425    }
426
427    /* Conf file management */
428    mr_conf = mr_malloc(sizeof(struct mr_ar_conf));
429    mr_ar_reset_conf(mr_conf);
430    /* Check md5 sum before */
431    /* Get content */
432    if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
433            mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
434    }
435    mr_ar_store_conf(mr_conf);
436    /* Reference the right cleanup function for mr_exit now it's allocated */
437    mr_cleanup = &mr_ar_cleanup;
438    mr_conf_close();
439
440    if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf") == 0) {
441        mr_ar_store_conf(mr_conf);
442        mr_conf_close();
443    }
444
445    /* Check md5 sum before */
446    /* Get content of mindi conf file now to finish structure initialization */
447/* Tempo Hack */
448#define MINDI_CONF_DIR MONDO_CONF_DIR"/../mindi"
449    if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf.dist") != 0) {
450            mr_log_exit(-1, "Unable to open "MINDI_CONF_DIR"/mindi.conf.dist");
451    }
452    mr_ar_store_conf_mindi(mr_conf);
453    mr_conf_close();
454
455    if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf") == 0) {
456        mr_ar_store_conf_mindi(mr_conf);
457        mr_conf_close();
458    }
459    mr_msg(5, "Command for ISO images is %s", mr_conf->iso_creation_cmd);
460
461    /* Add MONDO_SHARE + other environment variables for mindi */
462    setenv_mondo_var();
463
464    /* Initialize variables */
465    malloc_libmondo_global_strings();
466    diffs = 0;
467    if (stat(MONDO_CACHE, &stbuf) != 0) {
468        mr_mkdir(MONDO_CACHE,0x755);
469    }
470
471    /* BERLIOS: Hardcoded to be improved */
472    unlink(MONDO_CACHE"/mindi.conf");
473    unlink(MONDORESTORECFG);
474
475    /* Configure the bkpinfo structure, global file paths, etc. */
476    g_main_pid = getpid();
477    mr_msg(9, "This");
478
479    register_pid(g_main_pid, "mondo");
480    set_signals(TRUE);          // catch SIGTERM, etc.
481    run_program_and_log_output("dmesg -n1", TRUE);
482
483    mr_msg(9, "Next");
484    make_hole_for_dir(MONDO_CACHE);
485
486    welcome_to_mondoarchive();
487    distro_specific_kludges_at_start_of_mondoarchive();
488    g_kernel_version = get_kernel_version();
489
490    if (argc == 4 && !strcmp(argv[1], "getfattr")) {
491        mr_conf->log_level = 10;
492        g_text_mode = TRUE;
493        setup_newt_stuff();
494        if (!strstr(argv[2], "filelist")) {
495            mr_msg(1,_("Sorry - filelist goes first\n"));
496            finish(1);
497        } else {
498            finish(get_fattr_list(argv[2], argv[3]));
499        }
500        finish(0);
501    }
502    if (argc == 4 && !strcmp(argv[1], "setfattr")) {
503        mr_conf->log_level = 10;
504        g_text_mode = TRUE;
505        setup_newt_stuff();
506        finish(set_fattr_list(argv[2], argv[3]));
507    }
508
509    if (argc == 3 && !strcmp(argv[1], "wildcards")) {
510        mr_conf->log_level = 10;
511        g_text_mode = TRUE;
512        setup_newt_stuff();
513        tmp = mr_stresc(argv[2], WILDCHARS, BACKSLASH);
514        printf("in=%s; out=%s\n", argv[2], tmp);
515        mr_free(tmp);
516        finish(1);
517    }
518
519    if (argc == 4 && !strcmp(argv[1], "getfacl")) {
520        mr_conf->log_level = 10;
521        g_text_mode = TRUE;
522        setup_newt_stuff();
523        if (!strstr(argv[2], "filelist")) {
524            mr_msg(1,_("Sorry - filelist goes first\n"));
525            finish(1);
526        } else {
527            finish(get_acl_list(argv[2], argv[3]));
528        }
529        finish(0);
530    }
531    if (argc == 4 && !strcmp(argv[1], "setfacl")) {
532        mr_conf->log_level = 10;
533        g_text_mode = TRUE;
534        setup_newt_stuff();
535        finish(set_acl_list(argv[2], argv[3]));
536    }
537
538    if (argc > 2 && !strcmp(argv[1], "find-cd")) {
539        mr_conf->log_level = 10;
540        g_text_mode = TRUE;
541        setup_newt_stuff();
542        malloc_string(tmp);
543        if (find_cdrw_device(tmp)) {
544            mr_msg(1,_("Failed to find CDR-RW drive\n"));
545        } else {
546            mr_msg(1,_("CD-RW is at %s\n"), tmp);
547        }
548        tmp[0] = '\0';
549        if (find_cdrom_device(tmp, atoi(argv[2]))) {
550            mr_msg(1,_("Failed to find CD-ROM drive\n"));
551        } else {
552            mr_msg(1,_("CD-ROM is at %s\n"), tmp);
553        }
554        mr_free(tmp);
555        finish(0);
556    }
557
558    if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
559        mr_conf->log_level = 10;
560        g_text_mode = TRUE;
561        setup_newt_stuff();
562        malloc_string(tmp);
563        if (find_dvd_device(tmp, atoi(argv[2]))) {
564            mr_msg(1,_("Failed to find DVD drive\n"));
565        } else {
566            mr_msg(1,_("DVD is at %s\n"), tmp);
567        }
568        mr_free(tmp);
569        finish(0);
570    }
571
572    if (argc > 2 && !strcmp(argv[1], "disksize")) {
573        printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
574        finish(0);
575    }
576    if (argc > 2 && !strcmp(argv[1], "test-dev")) {
577        if (is_dev_an_NTFS_dev(argv[2])) {
578            mr_msg(1,_("%s is indeed an NTFS dev\n"), argv[2]);
579        } else {
580            mr_msg(1,_("%s is _not_ an NTFS dev\n"), argv[2]);
581        }
582        finish(0);
583    }
584
585    if (pre_param_configuration()) {
586        fatal_error
587            ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
588    }
589    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
590            bkpinfo->scratchdir);
591
592    /* Process command line, if there is one. If not, ask user for info. */
593    if (argc == 1) {
594        g_text_mode = FALSE;
595        setup_newt_stuff();
596        res = interactively_obtain_media_parameters_from_user(TRUE);    /* yes, archiving */
597        if (res) {
598            fatal_error
599                ("Syntax error. Please review the parameters you have supplied and try again.");
600        }
601    } else {
602        res = handle_incoming_parameters(argc, argv);
603        if (res) {
604            mr_msg(1,
605                _("Errors were detected in the command line you supplied.\n"));
606            mr_msg(1,_("Please review the log file - %s \n"),MONDO_LOGFILE);
607            mr_msg(1, "Mondoarchive will now exit.");
608            finish(1);
609        }
610        setup_newt_stuff();
611    }
612
613/* Finish configuring global structures */
614    if (post_param_configuration()) {
615        fatal_error
616            ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
617    }
618
619    log_to_screen
620        (_("BusyBox's sources are available from http://www.busybox.net"));
621
622
623    /* If we're meant to backup then backup */
624    if (bkpinfo->backup_data) {
625        res = backup_data();
626        retval += res;
627        if (res) {
628            mr_strcat(say_at_end,
629                   _("Data archived. Please check the logs, just as a precaution. "));
630        } else {
631            mr_strcat(say_at_end, _("Data archived OK. "));
632        }
633    }
634
635    /* If we're meant to verify then verify */
636    if (bkpinfo->verify_data) {
637        res = verify_data();
638        if (res < 0) {
639            mr_asprintf(&say_at_end2, _("%d difference%c found."), -res,
640                    (-res != 1) ? 's' : ' ');
641            res = 0;
642        }
643        retval += res;
644    }
645
646    /* Report result of entire operation (success? errors?) */
647    if (!retval) {
648        mvaddstr_and_log_it(g_currentY++, 0,
649                            _("Backup and/or verify ran to completion. Everything appears to be fine."));
650    } else {
651        mvaddstr_and_log_it(g_currentY++, 0,
652                            _("Backup and/or verify ran to completion. However, errors did occur."));
653    }
654
655    if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
656        log_to_screen
657            (_(MINDI_CACHE"/mondorescue.iso, a boot/utility CD, is available if you want it."));
658    }
659
660    if (length_of_file(MONDO_CACHE"/changed.files") > 2) {
661        if (g_text_mode) {
662            log_to_screen
663                (_("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
664        } else {
665            mr_msg(1,
666                    _("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
667            mr_msg(2, "Calling popup_changelist_from_file()");
668            popup_changelist_from_file(MONDO_CACHE"/changed.files");
669            mr_msg(2, "Returned from popup_changelist_from_file()");
670        }
671    } else {
672        unlink(MONDO_CACHE"/changed.files");
673    }
674    log_to_screen(say_at_end);
675    mr_free(say_at_end);
676    if (say_at_end2 != NULL) {
677        log_to_screen(say_at_end2);
678        mr_free(say_at_end2);
679    }
680
681    mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
682    run_program_and_log_output(tmp, TRUE);
683    mr_free(tmp);
684    if (bkpinfo->backup_media_type == usb) {
685        log_msg(1, "Unmounting USB device.");
686        mr_asprintf(&tmp, "umount %s1", bkpinfo->media_device);
687        run_program_and_log_output(tmp, TRUE);
688        mr_free(tmp);
689    }
690
691    run_program_and_log_output("mount", 2);
692
693    system("rm -f "MONDO_CACHE"/last-backup.aborted");
694    if (!retval) {
695        printf(_("Mondoarchive ran OK.\n"));
696    } else {
697        printf(_("Errors occurred during backup. Please check logfile.\n"));
698    }
699    distro_specific_kludges_at_end_of_mondoarchive();
700    register_pid(0, "mondo");
701    set_signals(FALSE);
702
703    free_libmondo_global_strings();
704    mr_free(bkpinfo);
705
706    if (!g_cdrom_drive_is_here) {
707        mr_msg(10, "FYI, g_cdrom_drive_is_here was never used");
708    }
709    if (!g_dvd_drive_is_here) {
710        mr_msg(10, "FYI, g_dvd_drive_is_here was never used");
711    }
712
713    /* finalize log file with time stamp */
714    mr_msg(1, "Time finished: %s", mr_date());
715    mr_msg_close();
716
717    chdir("/tmp");
718
719    if (!g_text_mode) {
720        popup_and_OK
721            (_("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."));
722        log_to_screen(_("See %s for details of backup run."), MONDO_LOGFILE);
723    } else {
724        printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
725        mr_exit(retval, NULL);
726    }
727    finish(retval);
728
729    return EXIT_SUCCESS;
730}
Note: See TracBrowser for help on using the repository browser.