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

Last change on this file since 1770 was 1770, checked in by Bruno Cornec, 16 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

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