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