1 | /***************************************************************************
|
---|
2 | * $Id: mondoarchive.c 1977 2008-06-02 08:49:01Z 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 1977 2008-06-02 08:49:01Z 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_cdrw_drive_is_here;
|
---|
46 | extern double g_kernel_version;
|
---|
47 | extern char *g_magicdev_command;
|
---|
48 | extern t_bkptype g_backup_media_type;
|
---|
49 |
|
---|
50 | extern char *get_uname_m(void);
|
---|
51 |
|
---|
52 | static char *g_cdrom_drive_is_here = NULL;
|
---|
53 | static char *g_dvd_drive_is_here = NULL;
|
---|
54 |
|
---|
55 | struct mr_ar_conf *mr_conf = NULL;
|
---|
56 |
|
---|
57 | /***************** global vars ******************/
|
---|
58 | long diffs;
|
---|
59 |
|
---|
60 | /****************** subroutines used only here ******************/
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Whether we're restoring from ISOs. Obviously not, since this is the
|
---|
64 | * backup program.
|
---|
65 | * @note You @b MUST declare this variable somewhere in your program if
|
---|
66 | * you use libmondo. Otherwise the link will fail.
|
---|
67 | * @ingroup globalGroup
|
---|
68 | */
|
---|
69 | bool g_ISO_restore_mode = FALSE;
|
---|
70 |
|
---|
71 | /* Do we use extended attributes and acl ?
|
---|
72 | * * By default no, use --acl & --attr options to force their usage */
|
---|
73 | char *g_getfacl = NULL;
|
---|
74 | char *g_getfattr = NULL;
|
---|
75 |
|
---|
76 | /* Reference to global bkpinfo */
|
---|
77 | struct s_bkpinfo *bkpinfo;
|
---|
78 |
|
---|
79 | /****************** subroutines used only by main.c ******************/
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
---|
83 | */
|
---|
84 | static void welcome_to_mondoarchive(void)
|
---|
85 | {
|
---|
86 | char *tmp = NULL;
|
---|
87 |
|
---|
88 | mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
|
---|
89 | mr_msg(0, "running %s binaries", get_architecture());
|
---|
90 | tmp = get_uname_m();
|
---|
91 | mr_msg(0, "running on %s architecture", tmp);
|
---|
92 | mr_free(tmp);
|
---|
93 | mr_msg(0, "-----------------------------------------------------------");
|
---|
94 | mr_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
|
---|
95 | mr_msg(0, "some error messages. Please read them carefully before you");
|
---|
96 | mr_msg(0, "decide to break out in a cold sweat. Despite (or perhaps");
|
---|
97 | mr_msg(0, "because of) the wealth of messages. some users are inclined");
|
---|
98 | mr_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
|
---|
99 | mr_msg(0, "chances are it's detailed here. More than likely there's a");
|
---|
100 | mr_msg(0, "message at the very end of this log that will tell you what");
|
---|
101 | mr_msg(0, "is wrong. Please read it! -Devteam");
|
---|
102 | mr_msg(0, "-----------------------------------------------------------");
|
---|
103 |
|
---|
104 | mr_msg(0, "Zero...");
|
---|
105 | mr_msg(1, "One...");
|
---|
106 | mr_msg(2, "Two...");
|
---|
107 | mr_msg(3, "Three...");
|
---|
108 | mr_msg(4, "Four...");
|
---|
109 | mr_msg(5, "Five...");
|
---|
110 | mr_msg(6, "Six...");
|
---|
111 | mr_msg(7, "Seven...");
|
---|
112 | mr_msg(8, "Eight...");
|
---|
113 | printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Do whatever is necessary to insure a successful backup on the Linux distribution
|
---|
118 | * of the day.
|
---|
119 | */
|
---|
120 | static void distro_specific_kludges_at_start_of_mondoarchive(void)
|
---|
121 | {
|
---|
122 | mr_msg(2, "Unmounting old ramdisks if necessary");
|
---|
123 | stop_magicdev_if_necessary(); // for RH+Gnome users
|
---|
124 | run_program_and_log_output
|
---|
125 | ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
|
---|
126 | unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
|
---|
127 | mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
|
---|
128 | clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
|
---|
134 | */
|
---|
135 | static void distro_specific_kludges_at_end_of_mondoarchive(void)
|
---|
136 | {
|
---|
137 | mr_msg(2, "Restarting magicdev if necessary");
|
---|
138 | sync();
|
---|
139 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
---|
140 |
|
---|
141 | mr_msg(2, "Restarting supermounts if necessary");
|
---|
142 | sync();
|
---|
143 | remount_supermounts_if_necessary(); // for Mandrake users
|
---|
144 |
|
---|
145 | mr_msg(2, "Unmounting /boot if necessary");
|
---|
146 | sync();
|
---|
147 | unmount_boot_if_necessary(); // for Gentoo users
|
---|
148 | }
|
---|
149 |
|
---|
150 | /* reset/empty the mr_ar_conf structure from mondo's conf file */
|
---|
151 | static void mr_ar_reset_conf(struct mr_ar_conf *mr_cnf) {
|
---|
152 |
|
---|
153 | /* This should correspond to the default conf file */
|
---|
154 | /* Especially for boolean values */
|
---|
155 | mr_cnf->iso_creation_cmd = NULL;
|
---|
156 | mr_cnf->iso_creation_opt = NULL;
|
---|
157 | mr_cnf->iso_burning_cmd = NULL;
|
---|
158 | mr_cnf->iso_burning_opt = NULL;
|
---|
159 | mr_cnf->iso_burning_dev = NULL;
|
---|
160 | mr_cnf->iso_burning_speed = 0;
|
---|
161 | mr_cnf->media_size = 0;
|
---|
162 | mr_cnf->media_device = NULL;
|
---|
163 | mr_cnf->iso_burning_dev = NULL;
|
---|
164 | mr_cnf->manual_tray = FALSE;
|
---|
165 | mr_cnf->log_level = 0;
|
---|
166 | mr_cnf->prefix = NULL;
|
---|
167 | mr_cnf->external_tape_blocksize = 0;
|
---|
168 | mr_cnf->internal_tape_blocksize = 0;
|
---|
169 | mr_cnf->kernel = NULL;
|
---|
170 | mr_cnf->additional_modules = NULL;
|
---|
171 | mr_cnf->boot_loader = NULL;
|
---|
172 | mr_cnf->differential = FALSE;
|
---|
173 | mr_cnf->compression_tool = NULL;
|
---|
174 | mr_cnf->compression_level = 0;
|
---|
175 | mr_cnf->exclude_paths = NULL;
|
---|
176 | mr_cnf->include_paths = NULL;
|
---|
177 | mr_cnf->ui_mode = NULL;
|
---|
178 | mr_cnf->automatic_restore = FALSE;
|
---|
179 | mr_cnf->scratch_dir = NULL;
|
---|
180 | mr_cnf->tmp_dir = NULL;
|
---|
181 | mr_cnf->images_dir = NULL;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /* fill the mr_ar_conf structure from mindi's conf file */
|
---|
185 | static void mr_ar_store_conf_mindi(struct mr_ar_conf *mr_cnf) {
|
---|
186 |
|
---|
187 | char *p = NULL;
|
---|
188 |
|
---|
189 | p = mr_conf_sread("mr_iso_creation_cmd");
|
---|
190 | if (p != NULL) {
|
---|
191 | mr_cnf->iso_creation_cmd = p;
|
---|
192 | }
|
---|
193 | p = mr_conf_sread("mr_iso_creation_opt");
|
---|
194 | if (p != NULL) {
|
---|
195 | mr_cnf->iso_creation_opt = p;
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | /* create the mr_ar_conf structure from mondo's conf file */
|
---|
200 | static void mr_ar_store_conf(struct mr_ar_conf *mr_cnf) {
|
---|
201 |
|
---|
202 | char *p = NULL;
|
---|
203 |
|
---|
204 | p = mr_conf_sread("mondo_iso_burning_cmd");
|
---|
205 | if (p != NULL) {
|
---|
206 | mr_cnf->iso_burning_cmd = p;
|
---|
207 | }
|
---|
208 |
|
---|
209 | p = mr_conf_sread("mondo_iso_burning_opt");
|
---|
210 | if (p != NULL) {
|
---|
211 | mr_cnf->iso_burning_opt = p;
|
---|
212 | }
|
---|
213 |
|
---|
214 | p = mr_conf_sread("mondo_iso_burning_dev");
|
---|
215 | if (p != NULL) {
|
---|
216 | mr_cnf->iso_burning_dev = p;
|
---|
217 | }
|
---|
218 |
|
---|
219 | p = mr_conf_iread("mondo_iso_burning_speed");
|
---|
220 | if (p != NULL ) {
|
---|
221 | mr_cnf->iso_burning_speed = atoi(p);
|
---|
222 | mr_free(p);
|
---|
223 | }
|
---|
224 |
|
---|
225 | p = mr_conf_iread("mondo_media_size");
|
---|
226 | if (p != NULL ) {
|
---|
227 | mr_cnf->media_size = atoi(p);
|
---|
228 | mr_free(p);
|
---|
229 | }
|
---|
230 |
|
---|
231 | p = mr_conf_sread("mondo_media_device");
|
---|
232 | if (p != NULL) {
|
---|
233 | mr_cnf->media_device = p;
|
---|
234 | }
|
---|
235 | /* If no specific device name for the burning command (a la ATAPI:0,0,0),
|
---|
236 | * then use the normal device name (a la /dev/hda) */
|
---|
237 | if ((mr_cnf->iso_burning_dev == NULL) && (mr_cnf->media_device != NULL)) {
|
---|
238 | mr_asprintf(&p, mr_cnf->media_device);
|
---|
239 | mr_cnf->iso_burning_dev = p;
|
---|
240 | }
|
---|
241 |
|
---|
242 | p = mr_conf_bread("mondo_manual_tray");
|
---|
243 | if (p != NULL) {
|
---|
244 | mr_cnf->manual_tray = mr_atob(p);
|
---|
245 | mr_free(p);
|
---|
246 | }
|
---|
247 |
|
---|
248 | p = mr_conf_iread("mondo_log_level");
|
---|
249 | if (p != NULL) {
|
---|
250 | mr_cnf->log_level = atoi(p);
|
---|
251 | mr_free(p);
|
---|
252 | }
|
---|
253 |
|
---|
254 | p = mr_conf_sread("mondo_prefix");
|
---|
255 | if (p != NULL) {
|
---|
256 | mr_cnf->prefix = p;
|
---|
257 | }
|
---|
258 |
|
---|
259 | p = mr_conf_iread("mondo_external_tape_blocksize");
|
---|
260 | if (p != NULL) {
|
---|
261 | mr_cnf->external_tape_blocksize = atoi(p);
|
---|
262 | mr_free(p);
|
---|
263 | }
|
---|
264 |
|
---|
265 | p = mr_conf_iread("mondo_internal_tape_blocksize");
|
---|
266 | if (p != NULL) {
|
---|
267 | mr_cnf->internal_tape_blocksize = atoi(p);
|
---|
268 | mr_free(p);
|
---|
269 | }
|
---|
270 |
|
---|
271 | p = mr_conf_sread("mondo_kernel");
|
---|
272 | if (p != NULL) {
|
---|
273 | mr_cnf->kernel = p;
|
---|
274 | }
|
---|
275 |
|
---|
276 | p = mr_conf_sread("mondo_additional_modules");
|
---|
277 | if (p != NULL) {
|
---|
278 | mr_cnf->additional_modules = p;
|
---|
279 | }
|
---|
280 |
|
---|
281 | p = mr_conf_sread("mondo_boot_loader");
|
---|
282 | if (p != NULL) {
|
---|
283 | mr_cnf->boot_loader = p;
|
---|
284 | }
|
---|
285 |
|
---|
286 | p = mr_conf_bread("mondo_differential");
|
---|
287 | if (p != NULL) {
|
---|
288 | mr_cnf->differential = mr_atob(p);
|
---|
289 | mr_free(p);
|
---|
290 | }
|
---|
291 |
|
---|
292 | p = mr_conf_sread("mondo_compression_tool");
|
---|
293 | if (p != NULL) {
|
---|
294 | mr_cnf->compression_tool = p;
|
---|
295 | }
|
---|
296 |
|
---|
297 | p = mr_conf_sread("mondo_compression_suffix");
|
---|
298 | if (p != NULL) {
|
---|
299 | mr_cnf->compression_suffix = p;
|
---|
300 | }
|
---|
301 |
|
---|
302 | p = mr_conf_iread("mondo_compression_level");
|
---|
303 | if (p != NULL) {
|
---|
304 | mr_cnf->compression_level = atoi(p);
|
---|
305 | mr_free(p);
|
---|
306 | }
|
---|
307 |
|
---|
308 | p = mr_conf_sread("mondo_exclude_paths");
|
---|
309 | if (p != NULL) {
|
---|
310 | mr_cnf->exclude_paths = p;
|
---|
311 | }
|
---|
312 |
|
---|
313 | p = mr_conf_sread("mondo_include_paths");
|
---|
314 | if (p != NULL) {
|
---|
315 | mr_cnf->include_paths = p;
|
---|
316 | }
|
---|
317 |
|
---|
318 | p = mr_conf_sread("mondo_ui_mode");
|
---|
319 | if (p != NULL) {
|
---|
320 | mr_cnf->ui_mode = p;
|
---|
321 | }
|
---|
322 |
|
---|
323 | p = mr_conf_bread("mondo_automatic_restore");
|
---|
324 | if (p != NULL) {
|
---|
325 | mr_cnf->automatic_restore = mr_atob(p);
|
---|
326 | mr_free(p);
|
---|
327 | }
|
---|
328 |
|
---|
329 | p = mr_conf_sread("mondo_scratch_dir");
|
---|
330 | if (p != NULL) {
|
---|
331 | mr_cnf->scratch_dir = p;
|
---|
332 | }
|
---|
333 |
|
---|
334 | p = mr_conf_sread("mondo_tmp_dir");
|
---|
335 | if (p != NULL) {
|
---|
336 | mr_cnf->tmp_dir = p;
|
---|
337 | }
|
---|
338 |
|
---|
339 | p = mr_conf_sread("mondo_images_dir");
|
---|
340 | if (p != NULL) {
|
---|
341 | mr_cnf->images_dir = p;
|
---|
342 | }
|
---|
343 | mr_msg(5, "Directory for images is %s", mr_cnf->images_dir);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /* destroy the mr_ar_conf structure's content */
|
---|
347 | static void mr_ar_clean_conf(struct mr_ar_conf *mr_cnf) {
|
---|
348 |
|
---|
349 | if (mr_cnf == NULL) {
|
---|
350 | return;
|
---|
351 | }
|
---|
352 | mr_free(mr_cnf->iso_creation_cmd);
|
---|
353 | mr_free(mr_cnf->iso_creation_opt);
|
---|
354 | mr_free(mr_cnf->iso_burning_cmd);
|
---|
355 | mr_free(mr_cnf->iso_burning_dev);
|
---|
356 | mr_free(mr_cnf->iso_burning_opt);
|
---|
357 | mr_free(mr_cnf->media_device);
|
---|
358 | mr_free(mr_cnf->prefix);
|
---|
359 | mr_free(mr_cnf->kernel);
|
---|
360 | mr_free(mr_cnf->additional_modules);
|
---|
361 | mr_free(mr_cnf->boot_loader);
|
---|
362 | mr_free(mr_cnf->compression_tool);
|
---|
363 | mr_free(mr_cnf->exclude_paths);
|
---|
364 | mr_free(mr_cnf->include_paths);
|
---|
365 | mr_free(mr_cnf->ui_mode);
|
---|
366 | mr_free(mr_cnf->scratch_dir);
|
---|
367 | mr_free(mr_cnf->tmp_dir);
|
---|
368 | mr_free(mr_cnf->images_dir);
|
---|
369 | mr_free(mr_cnf);
|
---|
370 | }
|
---|
371 |
|
---|
372 | /* Create the pointer to the function called in mr_exit */
|
---|
373 | void (*mr_cleanup)(void) = NULL;
|
---|
374 |
|
---|
375 | /* Just for init */
|
---|
376 | void mr_ar_cleanup_empty(void) {
|
---|
377 | }
|
---|
378 |
|
---|
379 | /* Cleanup all memory allocated in various structures */
|
---|
380 | void mr_ar_cleanup(void) {
|
---|
381 | /* Highly incomplete function for the moment */
|
---|
382 | /* We have to free all allocated memory */
|
---|
383 | mr_ar_clean_conf(mr_conf);
|
---|
384 | /* We have to remove all temporary files */
|
---|
385 | /* We have to unmount what has been mounted */
|
---|
386 | /* We have to properly end newt */
|
---|
387 | /* We have to remind people of log files */
|
---|
388 |
|
---|
389 | mr_msg_close();
|
---|
390 | }
|
---|
391 |
|
---|
392 | /*-----------------------------------------------------------*/
|
---|
393 |
|
---|
394 |
|
---|
395 |
|
---|
396 | /**
|
---|
397 | * Backup/verify the user's data.
|
---|
398 | * What did you think it did, anyway? :-)
|
---|
399 | */
|
---|
400 | int main(int argc, char *argv[])
|
---|
401 | {
|
---|
402 | struct stat stbuf;
|
---|
403 | char *tmp = NULL;
|
---|
404 | int res = 0;
|
---|
405 | int retval = 0;
|
---|
406 | char *say_at_end = NULL;
|
---|
407 | char *say_at_end2 = NULL;
|
---|
408 |
|
---|
409 | #ifdef ENABLE_NLS
|
---|
410 | setlocale(LC_ALL, "");
|
---|
411 | (void) textdomain("mondo");
|
---|
412 | #endif
|
---|
413 | printf(_("Initializing...\n"));
|
---|
414 |
|
---|
415 | bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
|
---|
416 | reset_bkpinfo();
|
---|
417 |
|
---|
418 | /* Reference a dummy cleanup function for mr_exit temporarily */
|
---|
419 | mr_cleanup = &mr_ar_cleanup_empty;
|
---|
420 |
|
---|
421 | /* initialize log file with time stamp */
|
---|
422 | /* We start with a loglevel of 4 - Adapted later on */
|
---|
423 | /* It's mandatory to set this up first as all mr_ functions rely on it */
|
---|
424 | unlink(MONDO_LOGFILE);
|
---|
425 | mr_msg_init(MONDO_LOGFILE,4);
|
---|
426 | mr_msg(0, _("Time started: %s"), mr_date());
|
---|
427 |
|
---|
428 | /* Make sure I'm root; abort if not */
|
---|
429 | if (getuid() != 0) {
|
---|
430 | mr_log_exit(127, _("Please run as root."));
|
---|
431 | }
|
---|
432 |
|
---|
433 | /* If -V, -v or --version then echo version no. and quit */
|
---|
434 | if (argc == 2
|
---|
435 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
---|
436 | || !strcmp(argv[argc - 1], "--version"))) {
|
---|
437 | printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
|
---|
438 | mr_exit(0, NULL);
|
---|
439 | }
|
---|
440 |
|
---|
441 | /* Conf file management */
|
---|
442 | mr_conf = mr_malloc(sizeof(struct mr_ar_conf));
|
---|
443 | mr_ar_reset_conf(mr_conf);
|
---|
444 | /* Check md5 sum before */
|
---|
445 | /* Get content */
|
---|
446 | if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
|
---|
447 | mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
|
---|
448 | }
|
---|
449 | mr_ar_store_conf(mr_conf);
|
---|
450 | /* Reference the right cleanup function for mr_exit now it's allocated */
|
---|
451 | mr_cleanup = &mr_ar_cleanup;
|
---|
452 | mr_conf_close();
|
---|
453 |
|
---|
454 | if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf") == 0) {
|
---|
455 | mr_ar_store_conf(mr_conf);
|
---|
456 | mr_conf_close();
|
---|
457 | }
|
---|
458 |
|
---|
459 | /* Check md5 sum before */
|
---|
460 | /* Get content of mindi conf file now to finish structure initialization */
|
---|
461 | /* Tempo Hack */
|
---|
462 | #define MINDI_CONF_DIR MONDO_CONF_DIR"/../mindi"
|
---|
463 | if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf.dist") != 0) {
|
---|
464 | mr_log_exit(-1, "Unable to open "MINDI_CONF_DIR"/mindi.conf.dist");
|
---|
465 | }
|
---|
466 | mr_ar_store_conf_mindi(mr_conf);
|
---|
467 | mr_conf_close();
|
---|
468 |
|
---|
469 | if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf") == 0) {
|
---|
470 | mr_ar_store_conf_mindi(mr_conf);
|
---|
471 | mr_conf_close();
|
---|
472 | }
|
---|
473 | mr_msg(5, "Command for ISO images is %s", mr_conf->iso_creation_cmd);
|
---|
474 |
|
---|
475 | /* Add MONDO_SHARE + other environment variables for mindi */
|
---|
476 | setenv_mondo_var();
|
---|
477 |
|
---|
478 | /* Initialize variables */
|
---|
479 | malloc_libmondo_global_strings();
|
---|
480 | diffs = 0;
|
---|
481 | if (stat(MONDO_CACHE, &stbuf) != 0) {
|
---|
482 | mr_mkdir(MONDO_CACHE,0x755);
|
---|
483 | }
|
---|
484 |
|
---|
485 | /* BERLIOS: Hardcoded to be improved */
|
---|
486 | unlink(MONDO_CACHE"/mindi.conf");
|
---|
487 | unlink(MONDORESTORECFG);
|
---|
488 |
|
---|
489 | /* Configure the bkpinfo structure, global file paths, etc. */
|
---|
490 | g_main_pid = getpid();
|
---|
491 | mr_msg(9, "This");
|
---|
492 |
|
---|
493 | register_pid(g_main_pid, "mondo");
|
---|
494 | set_signals(TRUE); // catch SIGTERM, etc.
|
---|
495 | run_program_and_log_output("dmesg -n1", TRUE);
|
---|
496 |
|
---|
497 | mr_msg(9, "Next");
|
---|
498 | make_hole_for_dir(MONDO_CACHE);
|
---|
499 |
|
---|
500 | welcome_to_mondoarchive();
|
---|
501 | distro_specific_kludges_at_start_of_mondoarchive();
|
---|
502 | g_kernel_version = get_kernel_version();
|
---|
503 |
|
---|
504 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
---|
505 | mr_conf->log_level = 10;
|
---|
506 | g_text_mode = TRUE;
|
---|
507 | setup_newt_stuff();
|
---|
508 | if (!strstr(argv[2], "filelist")) {
|
---|
509 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
---|
510 | finish(1);
|
---|
511 | } else {
|
---|
512 | finish(get_fattr_list(argv[2], argv[3]));
|
---|
513 | }
|
---|
514 | finish(0);
|
---|
515 | }
|
---|
516 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
---|
517 | mr_conf->log_level = 10;
|
---|
518 | g_text_mode = TRUE;
|
---|
519 | setup_newt_stuff();
|
---|
520 | finish(set_fattr_list(argv[2], argv[3]));
|
---|
521 | }
|
---|
522 |
|
---|
523 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
---|
524 | mr_conf->log_level = 10;
|
---|
525 | g_text_mode = TRUE;
|
---|
526 | setup_newt_stuff();
|
---|
527 | tmp = mr_stresc(argv[2], WILDCHARS, BACKSLASH);
|
---|
528 | printf("in=%s; out=%s\n", argv[2], tmp);
|
---|
529 | mr_free(tmp);
|
---|
530 | finish(1);
|
---|
531 | }
|
---|
532 |
|
---|
533 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
---|
534 | mr_conf->log_level = 10;
|
---|
535 | g_text_mode = TRUE;
|
---|
536 | setup_newt_stuff();
|
---|
537 | if (!strstr(argv[2], "filelist")) {
|
---|
538 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
---|
539 | finish(1);
|
---|
540 | } else {
|
---|
541 | finish(get_acl_list(argv[2], argv[3]));
|
---|
542 | }
|
---|
543 | finish(0);
|
---|
544 | }
|
---|
545 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
---|
546 | mr_conf->log_level = 10;
|
---|
547 | g_text_mode = TRUE;
|
---|
548 | setup_newt_stuff();
|
---|
549 | finish(set_acl_list(argv[2], argv[3]));
|
---|
550 | }
|
---|
551 |
|
---|
552 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
---|
553 | mr_conf->log_level = 10;
|
---|
554 | g_text_mode = TRUE;
|
---|
555 | setup_newt_stuff();
|
---|
556 | malloc_string(tmp);
|
---|
557 | if (find_cdrw_device(tmp)) {
|
---|
558 | mr_msg(1,_("Failed to find CDR-RW drive\n"));
|
---|
559 | } else {
|
---|
560 | mr_msg(1,_("CD-RW is at %s\n"), tmp);
|
---|
561 | }
|
---|
562 | tmp[0] = '\0';
|
---|
563 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
---|
564 | mr_msg(1,_("Failed to find CD-ROM drive\n"));
|
---|
565 | } else {
|
---|
566 | mr_msg(1,_("CD-ROM is at %s\n"), tmp);
|
---|
567 | }
|
---|
568 | mr_free(tmp);
|
---|
569 | finish(0);
|
---|
570 | }
|
---|
571 |
|
---|
572 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
---|
573 | mr_conf->log_level = 10;
|
---|
574 | g_text_mode = TRUE;
|
---|
575 | setup_newt_stuff();
|
---|
576 | malloc_string(tmp);
|
---|
577 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
---|
578 | mr_msg(1,_("Failed to find DVD drive\n"));
|
---|
579 | } else {
|
---|
580 | mr_msg(1,_("DVD is at %s\n"), tmp);
|
---|
581 | }
|
---|
582 | mr_free(tmp);
|
---|
583 | finish(0);
|
---|
584 | }
|
---|
585 |
|
---|
586 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
---|
587 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
---|
588 | finish(0);
|
---|
589 | }
|
---|
590 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
---|
591 | if (is_dev_an_NTFS_dev(argv[2])) {
|
---|
592 | mr_msg(1,_("%s is indeed an NTFS dev\n"), argv[2]);
|
---|
593 | } else {
|
---|
594 | mr_msg(1,_("%s is _not_ an NTFS dev\n"), argv[2]);
|
---|
595 | }
|
---|
596 | finish(0);
|
---|
597 | }
|
---|
598 |
|
---|
599 | if (pre_param_configuration()) {
|
---|
600 | fatal_error
|
---|
601 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
---|
602 | }
|
---|
603 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
---|
604 | bkpinfo->scratchdir);
|
---|
605 |
|
---|
606 | /* Process command line, if there is one. If not, ask user for info. */
|
---|
607 | if (argc == 1) {
|
---|
608 | g_text_mode = FALSE;
|
---|
609 | setup_newt_stuff();
|
---|
610 | res = interactively_obtain_media_parameters_from_user(TRUE); /* yes, archiving */
|
---|
611 | if (res) {
|
---|
612 | fatal_error
|
---|
613 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
---|
614 | }
|
---|
615 | } else {
|
---|
616 | res = handle_incoming_parameters(argc, argv);
|
---|
617 | if (res) {
|
---|
618 | mr_msg(1,
|
---|
619 | _("Errors were detected in the command line you supplied.\n"));
|
---|
620 | mr_msg(1,_("Please review the log file - %s \n"),MONDO_LOGFILE);
|
---|
621 | mr_msg(1, "Mondoarchive will now exit.");
|
---|
622 | finish(1);
|
---|
623 | }
|
---|
624 | setup_newt_stuff();
|
---|
625 | }
|
---|
626 |
|
---|
627 | /* Finish configuring global structures */
|
---|
628 | if (post_param_configuration()) {
|
---|
629 | fatal_error
|
---|
630 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
---|
631 | }
|
---|
632 |
|
---|
633 | log_to_screen
|
---|
634 | (_("BusyBox's sources are available from http://www.busybox.net"));
|
---|
635 |
|
---|
636 |
|
---|
637 | /* If we're meant to backup then backup */
|
---|
638 | if (bkpinfo->backup_data) {
|
---|
639 | res = backup_data();
|
---|
640 | retval += res;
|
---|
641 | if (res) {
|
---|
642 | mr_strcat(say_at_end,
|
---|
643 | _("Data archived. Please check the logs, just as a precaution. "));
|
---|
644 | } else {
|
---|
645 | mr_strcat(say_at_end, _("Data archived OK. "));
|
---|
646 | }
|
---|
647 | }
|
---|
648 |
|
---|
649 | /* If we're meant to verify then verify */
|
---|
650 | if (bkpinfo->verify_data) {
|
---|
651 | res = verify_data();
|
---|
652 | if (res < 0) {
|
---|
653 | mr_asprintf(&say_at_end2, _("%d difference%c found."), -res,
|
---|
654 | (-res != 1) ? 's' : ' ');
|
---|
655 | res = 0;
|
---|
656 | }
|
---|
657 | retval += res;
|
---|
658 | }
|
---|
659 |
|
---|
660 | /* Report result of entire operation (success? errors?) */
|
---|
661 | if (!retval) {
|
---|
662 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
663 | _("Backup and/or verify ran to completion. Everything appears to be fine."));
|
---|
664 | } else {
|
---|
665 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
666 | _("Backup and/or verify ran to completion. However, errors did occur."));
|
---|
667 | }
|
---|
668 |
|
---|
669 | if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
|
---|
670 | log_to_screen
|
---|
671 | (_(MINDI_CACHE"/mondorescue.iso, a boot/utility CD, is available if you want it."));
|
---|
672 | }
|
---|
673 |
|
---|
674 | if (length_of_file(MONDO_CACHE"/changed.files") > 2) {
|
---|
675 | if (g_text_mode) {
|
---|
676 | log_to_screen
|
---|
677 | (_("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
|
---|
678 | } else {
|
---|
679 | mr_msg(1,
|
---|
680 | _("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
|
---|
681 | mr_msg(2, "Calling popup_changelist_from_file()");
|
---|
682 | popup_changelist_from_file(MONDO_CACHE"/changed.files");
|
---|
683 | mr_msg(2, "Returned from popup_changelist_from_file()");
|
---|
684 | }
|
---|
685 | } else {
|
---|
686 | unlink(MONDO_CACHE"/changed.files");
|
---|
687 | }
|
---|
688 | log_to_screen(say_at_end);
|
---|
689 | mr_free(say_at_end);
|
---|
690 | if (say_at_end2 != NULL) {
|
---|
691 | log_to_screen(say_at_end2);
|
---|
692 | mr_free(say_at_end2);
|
---|
693 | }
|
---|
694 |
|
---|
695 | mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
---|
696 | run_program_and_log_output(tmp, TRUE);
|
---|
697 | mr_free(tmp);
|
---|
698 | if (bkpinfo->backup_media_type == usb) {
|
---|
699 | log_msg(1, "Unmounting USB device.");
|
---|
700 | mr_asprintf(&tmp, "umount %s1", bkpinfo->media_device);
|
---|
701 | run_program_and_log_output(tmp, TRUE);
|
---|
702 | mr_free(tmp);
|
---|
703 | }
|
---|
704 |
|
---|
705 | run_program_and_log_output("mount", 2);
|
---|
706 |
|
---|
707 | system("rm -f "MONDO_CACHE"/last-backup.aborted");
|
---|
708 | if (!retval) {
|
---|
709 | printf(_("Mondoarchive ran OK.\n"));
|
---|
710 | } else {
|
---|
711 | printf(_("Errors occurred during backup. Please check logfile.\n"));
|
---|
712 | }
|
---|
713 | distro_specific_kludges_at_end_of_mondoarchive();
|
---|
714 | register_pid(0, "mondo");
|
---|
715 | set_signals(FALSE);
|
---|
716 |
|
---|
717 | free_libmondo_global_strings();
|
---|
718 | mr_free(bkpinfo);
|
---|
719 |
|
---|
720 | if (!g_cdrom_drive_is_here) {
|
---|
721 | mr_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
---|
722 | }
|
---|
723 | if (!g_dvd_drive_is_here) {
|
---|
724 | mr_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
---|
725 | }
|
---|
726 |
|
---|
727 | /* finalize log file with time stamp */
|
---|
728 | mr_msg(1, "Time finished: %s", mr_date());
|
---|
729 | mr_msg_close();
|
---|
730 |
|
---|
731 | chdir("/tmp");
|
---|
732 |
|
---|
733 | if (!g_text_mode) {
|
---|
734 | popup_and_OK
|
---|
735 | (_("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."));
|
---|
736 | log_to_screen(_("See %s for details of backup run."), MONDO_LOGFILE);
|
---|
737 | } else {
|
---|
738 | printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
|
---|
739 | mr_exit(retval, NULL);
|
---|
740 | }
|
---|
741 | finish(retval);
|
---|
742 |
|
---|
743 | return EXIT_SUCCESS;
|
---|
744 | }
|
---|
745 | =======
|
---|
746 | /***************************************************************************
|
---|
747 | main.c - description
|
---|
748 | -------------------
|
---|
749 | begin : Fri Apr 19 16:40:35 EDT 2002
|
---|
750 | copyright : (C) 2002 by Stan Benoit
|
---|
751 | email : troff@nakedsoul.org
|
---|
752 | cvsid : $Id: mondoarchive.c 1977 2008-06-02 08:49:01Z bruno $
|
---|
753 | ***************************************************************************/
|
---|
754 |
|
---|
755 | /***************************************************************************
|
---|
756 | * *
|
---|
757 | * This program is free software; you can redistribute it and/or modify *
|
---|
758 | * it under the terms of the GNU General Public License as published by *
|
---|
759 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
760 | * (at your option) any later version. *
|
---|
761 | * *
|
---|
762 | ***************************************************************************/
|
---|
763 |
|
---|
764 | /**
|
---|
765 | * @file
|
---|
766 | * The main file for mondoarchive.
|
---|
767 | */
|
---|
768 |
|
---|
769 | /************************* #include statements *************************/
|
---|
770 | #include <pthread.h>
|
---|
771 | #include <stdio.h>
|
---|
772 | #include <stdlib.h>
|
---|
773 | #include "my-stuff.h"
|
---|
774 | #include "../common/mondostructures.h"
|
---|
775 | #include "../common/libmondo.h"
|
---|
776 | #include "../common/libmondo-cli-EXT.h"
|
---|
777 | #include "../common/libmondo-tools-EXT.h"
|
---|
778 | #include "mondoarchive.h"
|
---|
779 |
|
---|
780 | // for CVS
|
---|
781 | //static char cvsid[] = "$Id: mondoarchive.c 1977 2008-06-02 08:49:01Z bruno $";
|
---|
782 |
|
---|
783 | /************************* external variables *************************/
|
---|
784 | extern void set_signals(int);
|
---|
785 | extern int g_current_media_number;
|
---|
786 | extern void register_pid(pid_t, char *);
|
---|
787 | extern int g_currentY;
|
---|
788 | extern bool g_text_mode;
|
---|
789 | extern char *g_boot_mountpt;
|
---|
790 | extern bool g_remount_floppy_at_end;
|
---|
791 | extern char *g_cdrw_drive_is_here;
|
---|
792 | static char *g_cdrom_drive_is_here = NULL;
|
---|
793 | static char *g_dvd_drive_is_here = NULL;
|
---|
794 | extern double g_kernel_version;
|
---|
795 |
|
---|
796 | /***************** global vars, used only by main.c ******************/
|
---|
797 | long diffs;
|
---|
798 |
|
---|
799 | extern t_bkptype g_backup_media_type;
|
---|
800 | extern int g_loglevel;
|
---|
801 |
|
---|
802 | /**
|
---|
803 | * Whether we're restoring from ISOs. Obviously not, since this is the
|
---|
804 | * backup program.
|
---|
805 | * @note You @b MUST declare this variable somewhere in your program if
|
---|
806 | * you use libmondo. Otherwise the link will fail.
|
---|
807 | * @ingroup globalGroup
|
---|
808 | */
|
---|
809 | bool g_ISO_restore_mode = FALSE;
|
---|
810 |
|
---|
811 | /* Do we use extended attributes and acl ?
|
---|
812 | * * By default no, use --acl & --attr options to force their usage */
|
---|
813 | char *g_getfacl = NULL;
|
---|
814 | char *g_getfattr = NULL;
|
---|
815 |
|
---|
816 | /* Reference to global bkpinfo */
|
---|
817 | struct s_bkpinfo *bkpinfo;
|
---|
818 |
|
---|
819 | /* To be coded */
|
---|
820 | void free_MR_global_filenames(void) {
|
---|
821 | }
|
---|
822 |
|
---|
823 | /****************** subroutines used only by main.c ******************/
|
---|
824 |
|
---|
825 |
|
---|
826 | /**
|
---|
827 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
---|
828 | */
|
---|
829 | void welcome_to_mondoarchive(void)
|
---|
830 | {
|
---|
831 | char *tmp = NULL;
|
---|
832 |
|
---|
833 | log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
|
---|
834 | PACKAGE_VERSION);
|
---|
835 | log_msg(0, "running %s binaries", get_architecture());
|
---|
836 | tmp = get_uname_m();
|
---|
837 | log_msg(0, "running on %s architecture", tmp);
|
---|
838 | free(tmp);
|
---|
839 | log_msg(0,
|
---|
840 | "-----------------------------------------------------------");
|
---|
841 | log_msg(0,
|
---|
842 | "NB: Mondo logs almost everything, so don't panic if you see");
|
---|
843 | log_msg(0,
|
---|
844 | "some error messages. Please read them carefully before you");
|
---|
845 | log_msg(0,
|
---|
846 | "decide to break out in a cold sweat. Despite (or perhaps");
|
---|
847 | log_msg(0,
|
---|
848 | "because of) the wealth of messages. some users are inclined");
|
---|
849 | log_msg(0,
|
---|
850 | "to stop reading this log. If Mondo stopped for some reason,");
|
---|
851 | log_msg(0,
|
---|
852 | "chances are it's detailed here. More than likely there's a");
|
---|
853 | log_msg(0,
|
---|
854 | "message at the very end of this log that will tell you what");
|
---|
855 | log_msg(0,
|
---|
856 | "is wrong. Please read it! -Devteam");
|
---|
857 | log_msg(0,
|
---|
858 | "-----------------------------------------------------------");
|
---|
859 |
|
---|
860 | log_msg(0, "Zero...");
|
---|
861 | log_msg(1, "One...");
|
---|
862 | log_msg(2, "Two...");
|
---|
863 | log_msg(3, "Three...");
|
---|
864 | log_msg(4, "Four...");
|
---|
865 | log_msg(5, "Five...");
|
---|
866 | log_msg(6, "Six...");
|
---|
867 | log_msg(7, "Seven...");
|
---|
868 | log_msg(8, "Eight...");
|
---|
869 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
870 | }
|
---|
871 |
|
---|
872 |
|
---|
873 | extern char *g_magicdev_command;
|
---|
874 |
|
---|
875 | /**
|
---|
876 | * Do whatever is necessary to insure a successful backup on the Linux distribution
|
---|
877 | * of the day.
|
---|
878 | */
|
---|
879 | void distro_specific_kludges_at_start_of_mondoarchive(void)
|
---|
880 | {
|
---|
881 | log_msg(2, "Unmounting old ramdisks if necessary");
|
---|
882 | stop_magicdev_if_necessary(); // for RH+Gnome users
|
---|
883 | run_program_and_log_output
|
---|
884 | ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
|
---|
885 | unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
|
---|
886 | // stop_autofs_if_necessary(); // for Xandros users
|
---|
887 | mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
|
---|
888 | clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
|
---|
889 | }
|
---|
890 |
|
---|
891 |
|
---|
892 |
|
---|
893 | /**
|
---|
894 | * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
|
---|
895 | */
|
---|
896 | void distro_specific_kludges_at_end_of_mondoarchive(void)
|
---|
897 | {
|
---|
898 | // char tmp[500];
|
---|
899 | log_msg(2, "Restarting magicdev if necessary");
|
---|
900 | sync();
|
---|
901 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
---|
902 |
|
---|
903 | log_msg(2, "Restarting autofs if necessary");
|
---|
904 | sync();
|
---|
905 | // restart_autofs_if_necessary(); // for Xandros users
|
---|
906 |
|
---|
907 | log_msg(2, "Restarting supermounts if necessary");
|
---|
908 | sync();
|
---|
909 | remount_supermounts_if_necessary(); // for Mandrake users
|
---|
910 |
|
---|
911 | log_msg(2, "Unmounting /boot if necessary");
|
---|
912 | sync();
|
---|
913 | unmount_boot_if_necessary(); // for Gentoo users
|
---|
914 |
|
---|
915 | // log_msg( 2, "Cleaning up KDE desktop");
|
---|
916 | // clean_up_KDE_desktop_if_necessary();
|
---|
917 | }
|
---|
918 |
|
---|
919 |
|
---|
920 | /**
|
---|
921 | * Backup/verify the user's data.
|
---|
922 | * What did you think it did, anyway? :-)
|
---|
923 | */
|
---|
924 | int main(int argc, char *argv[])
|
---|
925 | {
|
---|
926 | char *tmp;
|
---|
927 | int res, retval;
|
---|
928 | char *say_at_end;
|
---|
929 |
|
---|
930 | /* Make sure I'm root; abort if not */
|
---|
931 | if (getuid() != 0) {
|
---|
932 | fprintf(stderr, "Please run as root.\r\n");
|
---|
933 | exit(127);
|
---|
934 | }
|
---|
935 |
|
---|
936 | /* If -V, -v or --version then echo version no. and quit */
|
---|
937 | if (argc == 2
|
---|
938 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
---|
939 | || !strcmp(argv[argc - 1], "--version"))) {
|
---|
940 | printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
|
---|
941 | exit(0);
|
---|
942 | }
|
---|
943 |
|
---|
944 | /* Initialize variables */
|
---|
945 |
|
---|
946 | printf("Initializing...\n");
|
---|
947 | if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
|
---|
948 | fatal_error("Cannot malloc bkpinfo");
|
---|
949 | }
|
---|
950 | reset_bkpinfo();
|
---|
951 |
|
---|
952 | res = 0;
|
---|
953 | retval = 0;
|
---|
954 | diffs = 0;
|
---|
955 | malloc_string(tmp);
|
---|
956 | malloc_string(say_at_end);
|
---|
957 | say_at_end[0] = '\0';
|
---|
958 | malloc_libmondo_global_strings();
|
---|
959 |
|
---|
960 | /* initialize log file with time stamp */
|
---|
961 | unlink(MONDO_LOGFILE);
|
---|
962 | log_msg(0, "Time started: %s", mr_date());
|
---|
963 |
|
---|
964 | /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
|
---|
965 | strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
|
---|
966 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
967 | if (strlen(tmp) >= MAX_STR_LEN - 33) {
|
---|
968 | fatal_error
|
---|
969 | ("Your PATH environmental variable is too long. Please shorten it.");
|
---|
970 | }
|
---|
971 | strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
|
---|
972 | setenv("PATH", tmp, 1);
|
---|
973 |
|
---|
974 | /* Add the ARCH environment variable for ia64 purposes */
|
---|
975 | strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
|
---|
976 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
977 | setenv("ARCH", tmp, 1);
|
---|
978 |
|
---|
979 | /* Add MONDO_SHARE environment variable for mindi */
|
---|
980 | setenv_mondo_share();
|
---|
981 |
|
---|
982 | /* Configure the bkpinfo structure, global file paths, etc. */
|
---|
983 | g_main_pid = getpid();
|
---|
984 | log_msg(9, "This");
|
---|
985 |
|
---|
986 | register_pid(g_main_pid, "mondo");
|
---|
987 | set_signals(TRUE); // catch SIGTERM, etc.
|
---|
988 | run_program_and_log_output("dmesg -n1", TRUE);
|
---|
989 |
|
---|
990 | log_msg(9, "Next");
|
---|
991 | make_hole_for_dir(MONDO_CACHE);
|
---|
992 |
|
---|
993 | welcome_to_mondoarchive();
|
---|
994 | distro_specific_kludges_at_start_of_mondoarchive();
|
---|
995 | g_kernel_version = get_kernel_version();
|
---|
996 |
|
---|
997 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
---|
998 | g_loglevel = 10;
|
---|
999 | g_text_mode = TRUE;
|
---|
1000 | setup_newt_stuff();
|
---|
1001 | if (!strstr(argv[2], "filelist")) {
|
---|
1002 | printf("Sorry - filelist goes first\n");
|
---|
1003 | finish(1);
|
---|
1004 | } else {
|
---|
1005 | finish(get_fattr_list(argv[2], argv[3]));
|
---|
1006 | }
|
---|
1007 | finish(0);
|
---|
1008 | }
|
---|
1009 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
---|
1010 | g_loglevel = 10;
|
---|
1011 | // chdir("/tmp");
|
---|
1012 | g_text_mode = TRUE;
|
---|
1013 | setup_newt_stuff();
|
---|
1014 | finish(set_fattr_list(argv[2], argv[3]));
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
---|
1018 | g_loglevel = 10;
|
---|
1019 | g_text_mode = TRUE;
|
---|
1020 | setup_newt_stuff();
|
---|
1021 | turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
|
---|
1022 | printf("in=%s; out=%s\n", argv[2], tmp);
|
---|
1023 | finish(1);
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
---|
1027 | g_loglevel = 10;
|
---|
1028 | g_text_mode = TRUE;
|
---|
1029 | setup_newt_stuff();
|
---|
1030 | if (!strstr(argv[2], "filelist")) {
|
---|
1031 | printf("Sorry - filelist goes first\n");
|
---|
1032 | finish(1);
|
---|
1033 | } else {
|
---|
1034 | finish(get_acl_list(argv[2], argv[3]));
|
---|
1035 | }
|
---|
1036 | finish(0);
|
---|
1037 | }
|
---|
1038 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
---|
1039 | g_loglevel = 10;
|
---|
1040 | // chdir("/tmp");
|
---|
1041 | g_text_mode = TRUE;
|
---|
1042 | setup_newt_stuff();
|
---|
1043 | finish(set_acl_list(argv[2], argv[3]));
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
---|
1047 | g_loglevel = 10;
|
---|
1048 | g_text_mode = TRUE;
|
---|
1049 | setup_newt_stuff();
|
---|
1050 | if (find_cdrw_device(tmp)) {
|
---|
1051 | printf("Failed to find CDR-RW drive\n");
|
---|
1052 | } else {
|
---|
1053 | printf("CD-RW is at %s\n", tmp);
|
---|
1054 | }
|
---|
1055 | tmp[0] = '\0';
|
---|
1056 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
---|
1057 | printf("Failed to find CD-ROM drive\n");
|
---|
1058 | } else {
|
---|
1059 | printf("CD-ROM is at %s\n", tmp);
|
---|
1060 | }
|
---|
1061 | finish(0);
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
---|
1065 | g_loglevel = 10;
|
---|
1066 | g_text_mode = TRUE;
|
---|
1067 | setup_newt_stuff();
|
---|
1068 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
---|
1069 | printf("Failed to find DVD drive\n");
|
---|
1070 | } else {
|
---|
1071 | printf("DVD is at %s\n", tmp);
|
---|
1072 | }
|
---|
1073 | finish(0);
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
---|
1077 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
---|
1078 | finish(0);
|
---|
1079 | }
|
---|
1080 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
---|
1081 | if (is_dev_an_NTFS_dev(argv[2])) {
|
---|
1082 | printf("%s is indeed an NTFS dev\n", argv[2]);
|
---|
1083 | } else {
|
---|
1084 | printf("%s is _not_ an NTFS dev\n", argv[2]);
|
---|
1085 | }
|
---|
1086 | finish(0);
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | if (pre_param_configuration()) {
|
---|
1090 | fatal_error
|
---|
1091 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | /* Process command line, if there is one. If not, ask user for info. */
|
---|
1095 | if (argc == 1) {
|
---|
1096 | g_text_mode = FALSE;
|
---|
1097 | setup_newt_stuff();
|
---|
1098 | res = interactively_obtain_media_parameters_from_user(TRUE); /* yes, archiving */
|
---|
1099 | if (res) {
|
---|
1100 | fatal_error
|
---|
1101 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
---|
1102 | }
|
---|
1103 | } else {
|
---|
1104 | res = handle_incoming_parameters(argc, argv);
|
---|
1105 | if (res) {
|
---|
1106 | printf
|
---|
1107 | ("Errors were detected in the command line you supplied.\n");
|
---|
1108 | printf("Please review the log file - %s\n", MONDO_LOGFILE );
|
---|
1109 | log_msg(1, "Mondoarchive will now exit.");
|
---|
1110 | finish(1);
|
---|
1111 | }
|
---|
1112 | setup_newt_stuff();
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | /* Finish configuring global structures */
|
---|
1116 | if (post_param_configuration()) {
|
---|
1117 | fatal_error
|
---|
1118 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | log_to_screen
|
---|
1122 | ("BusyBox's sources are available from http://www.busybox.net");
|
---|
1123 |
|
---|
1124 | /* If we're meant to backup then backup */
|
---|
1125 | if (bkpinfo->backup_data) {
|
---|
1126 | res = backup_data();
|
---|
1127 | retval += res;
|
---|
1128 | if (res) {
|
---|
1129 | strcat(say_at_end,
|
---|
1130 | "Data archived. Please check the logs, just as a precaution. ");
|
---|
1131 | } else {
|
---|
1132 | strcat(say_at_end, "Data archived OK. ");
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | /* If we're meant to verify then verify */
|
---|
1137 | if (bkpinfo->verify_data) {
|
---|
1138 | res = verify_data();
|
---|
1139 | if (res < 0) {
|
---|
1140 | sprintf(tmp, "%d difference%c found.", -res,
|
---|
1141 | (-res != 1) ? 's' : ' ');
|
---|
1142 | strcat(say_at_end, tmp);
|
---|
1143 | log_to_screen(tmp);
|
---|
1144 | res = 0;
|
---|
1145 | }
|
---|
1146 | retval += res;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | /* Report result of entire operation (success? errors?) */
|
---|
1150 | if (!retval) {
|
---|
1151 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
1152 | "Backup and/or verify ran to completion. Everything appears to be fine.");
|
---|
1153 | } else {
|
---|
1154 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
1155 | "Backup and/or verify ran to completion. However, errors did occur.");
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
|
---|
1159 | log_to_screen
|
---|
1160 | (MINDI_CACHE"/mondorescue.iso, a boot/utility CD, is available if you want it.");
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | if (length_of_file(MONDO_CACHE"/changed.files") > 2) {
|
---|
1164 | if (g_text_mode) {
|
---|
1165 | log_to_screen("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives");
|
---|
1166 | } else {
|
---|
1167 | log_msg(1, "Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives");
|
---|
1168 | log_msg(2, "Calling popup_changelist_from_file()");
|
---|
1169 | popup_changelist_from_file(MONDO_CACHE"/changed.files");
|
---|
1170 | log_msg(2, "Returned from popup_changelist_from_file()");
|
---|
1171 | }
|
---|
1172 | } else {
|
---|
1173 | unlink(MONDO_CACHE"/changed.files");
|
---|
1174 | }
|
---|
1175 | log_to_screen(say_at_end);
|
---|
1176 | sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
---|
1177 | run_program_and_log_output(tmp, TRUE);
|
---|
1178 | if (bkpinfo->backup_media_type == usb) {
|
---|
1179 | log_msg(1, "Unmounting USB device.");
|
---|
1180 | sprintf(tmp, "umount %s1", bkpinfo->media_device);
|
---|
1181 | run_program_and_log_output(tmp, TRUE);
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | run_program_and_log_output("mount", 2);
|
---|
1185 |
|
---|
1186 | system("rm -f "MONDO_CACHE"/last-backup.aborted");
|
---|
1187 | if (!retval) {
|
---|
1188 | printf("Mondoarchive ran OK.\n");
|
---|
1189 | } else {
|
---|
1190 | printf("Errors occurred during backup. Please check logfile.\n");
|
---|
1191 | }
|
---|
1192 | distro_specific_kludges_at_end_of_mondoarchive();
|
---|
1193 | register_pid(0, "mondo");
|
---|
1194 | set_signals(FALSE);
|
---|
1195 |
|
---|
1196 | free_libmondo_global_strings();
|
---|
1197 | paranoid_free(say_at_end);
|
---|
1198 |
|
---|
1199 |
|
---|
1200 | if (!g_cdrom_drive_is_here) {
|
---|
1201 | log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
---|
1202 | }
|
---|
1203 | if (!g_dvd_drive_is_here) {
|
---|
1204 | log_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | /* finalize log file with time stamp */
|
---|
1208 | log_msg(0, "Time finished: %s", mr_date());
|
---|
1209 |
|
---|
1210 | chdir("/tmp");
|
---|
1211 |
|
---|
1212 | if (!g_text_mode) {
|
---|
1213 | popup_and_OK
|
---|
1214 | ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
|
---|
1215 | log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
|
---|
1216 | } else {
|
---|
1217 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
1218 | }
|
---|
1219 | finish(retval);
|
---|
1220 |
|
---|
1221 | return EXIT_SUCCESS;
|
---|
1222 | }
|
---|