[1] | 1 | /***************************************************************************
|
---|
[1080] | 2 | * $Id: mondoarchive.c 1422 2007-05-09 09:02:24Z bruno $
|
---|
| 3 | */
|
---|
[1] | 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>
|
---|
[1100] | 15 | #include <sys/types.h>
|
---|
| 16 | #include <sys/stat.h>
|
---|
| 17 | #include <unistd.h>
|
---|
| 18 |
|
---|
[1067] | 19 | #include "my-stuff.h"
|
---|
[1190] | 20 | #include "mondostructures.h"
|
---|
| 21 | #include "libmondo.h"
|
---|
[1] | 22 | #include "mondo-cli-EXT.h"
|
---|
| 23 |
|
---|
[1256] | 24 | #include "mondoarchive.h"
|
---|
[1187] | 25 | #include "mr_mem.h"
|
---|
[1087] | 26 | #include "mr_str.h"
|
---|
[1112] | 27 | #include "mr_msg.h"
|
---|
[1102] | 28 | #include "mr_file.h"
|
---|
[1264] | 29 | #include "mr_err.h"
|
---|
[1256] | 30 | #include "mr_conf.h"
|
---|
[1087] | 31 |
|
---|
[1] | 32 | // for CVS
|
---|
[128] | 33 | //static char cvsid[] = "$Id: mondoarchive.c 1422 2007-05-09 09:02:24Z bruno $";
|
---|
[1] | 34 |
|
---|
| 35 | /************************* external variables *************************/
|
---|
| 36 | extern void set_signals(int);
|
---|
| 37 | extern int g_current_media_number;
|
---|
[128] | 38 | extern void register_pid(pid_t, char *);
|
---|
[1] | 39 | extern int g_currentY;
|
---|
| 40 | extern bool g_text_mode;
|
---|
| 41 | extern char *g_boot_mountpt;
|
---|
| 42 | extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
|
---|
| 43 | extern char *g_tmpfs_mountpt;
|
---|
| 44 | extern char *g_erase_tmpdir_and_scratchdir;
|
---|
| 45 | extern char *g_cdrw_drive_is_here;
|
---|
[1256] | 46 | extern double g_kernel_version;
|
---|
| 47 | extern char *g_magicdev_command;
|
---|
| 48 | extern t_bkptype g_backup_media_type;
|
---|
| 49 | extern int g_loglevel;
|
---|
| 50 |
|
---|
[1384] | 51 | extern char *get_uname_m();
|
---|
| 52 |
|
---|
[128] | 53 | static char *g_cdrom_drive_is_here = NULL;
|
---|
| 54 | static char *g_dvd_drive_is_here = NULL;
|
---|
[1] | 55 |
|
---|
[1256] | 56 | struct mr_ar_conf mr_conf;
|
---|
| 57 |
|
---|
| 58 | /***************** global vars ******************/
|
---|
[1] | 59 | bool g_skip_floppies;
|
---|
| 60 | long diffs;
|
---|
| 61 |
|
---|
[1256] | 62 | /****************** subroutines used only here ******************/
|
---|
[1] | 63 |
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
---|
| 67 | */
|
---|
[1256] | 68 | static void welcome_to_mondoarchive(void)
|
---|
[1] | 69 | {
|
---|
[1377] | 70 | char *tmp = NULL;
|
---|
| 71 |
|
---|
[1256] | 72 | mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
|
---|
[1378] | 73 | mr_msg(0, "running %s binaries", get_architecture());
|
---|
[1377] | 74 | tmp = get_uname_m();
|
---|
[1378] | 75 | mr_msg(0, "running on %s architecture", tmp);
|
---|
[1377] | 76 | mr_free(tmp);
|
---|
[1256] | 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, "-----------------------------------------------------------");
|
---|
[1] | 87 |
|
---|
[1108] | 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...");
|
---|
[128] | 97 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
[1] | 98 | }
|
---|
| 99 |
|
---|
| 100 | /**
|
---|
| 101 | * Do whatever is necessary to insure a successful backup on the Linux distribution
|
---|
| 102 | * of the day.
|
---|
| 103 | */
|
---|
[1256] | 104 | static void distro_specific_kludges_at_start_of_mondoarchive(void)
|
---|
[1] | 105 | {
|
---|
[1108] | 106 | mr_msg(2, "Unmounting old ramdisks if necessary");
|
---|
[128] | 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
|
---|
[1] | 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | /**
|
---|
| 117 | * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
|
---|
| 118 | */
|
---|
[1256] | 119 | static void distro_specific_kludges_at_end_of_mondoarchive(void)
|
---|
[1] | 120 | {
|
---|
[1108] | 121 | mr_msg(2, "Restarting magicdev if necessary");
|
---|
[128] | 122 | sync();
|
---|
| 123 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
---|
[1] | 124 |
|
---|
[1108] | 125 | mr_msg(2, "Restarting supermounts if necessary");
|
---|
[128] | 126 | sync();
|
---|
| 127 | remount_supermounts_if_necessary(); // for Mandrake users
|
---|
[1] | 128 |
|
---|
[1108] | 129 | mr_msg(2, "Unmounting /boot if necessary");
|
---|
[128] | 130 | sync();
|
---|
| 131 | unmount_boot_if_necessary(); // for Gentoo users
|
---|
[1] | 132 | }
|
---|
| 133 |
|
---|
[1256] | 134 | /* create the mr_ar_conf structure from mondo's conf file */
|
---|
[1264] | 135 | static void mr_ar_store_conf(struct mr_ar_conf *mr_cnf) {
|
---|
[1256] | 136 |
|
---|
[1415] | 137 | char *p = NULL;
|
---|
[1422] | 138 | char *s = NULL;
|
---|
[1415] | 139 |
|
---|
[1422] | 140 | s = mr_conf_sread("mondo_iso_creation_cmd");
|
---|
| 141 | fprintf(stderr,"s: %s\n",s);
|
---|
| 142 | mr_asprintf(&p, s);
|
---|
[1415] | 143 | mr_cnf->iso_creation_cmd = p;
|
---|
[1422] | 144 | p = NULL;
|
---|
| 145 |
|
---|
| 146 | mr_asprintf(&p, mr_conf_sread("mondo_iso_creation_options"));
|
---|
| 147 | mr_cnf->iso_creation_options = p;
|
---|
| 148 | p = NULL;
|
---|
| 149 |
|
---|
| 150 | mr_asprintf(&p, mr_conf_sread("mondo_iso_burning_cmd"));
|
---|
| 151 | mr_cnf->iso_burning_cmd = p;
|
---|
| 152 | p = NULL;
|
---|
| 153 |
|
---|
| 154 | mr_asprintf(&p, mr_conf_sread("mondo_iso_burning_options"));
|
---|
| 155 | mr_cnf->iso_burning_options = p;
|
---|
| 156 | p = NULL;
|
---|
| 157 |
|
---|
[1264] | 158 | mr_cnf->iso_burning_speed = mr_conf_iread("mondo_iso_burning_speed");
|
---|
| 159 | mr_cnf->media_size = mr_conf_iread("mondo_media_size");
|
---|
[1422] | 160 |
|
---|
| 161 | mr_asprintf(&p, mr_conf_sread("mondo_media_device"));
|
---|
| 162 | mr_cnf->media_device = p;
|
---|
| 163 | p = NULL;
|
---|
| 164 |
|
---|
[1264] | 165 | mr_cnf->manual_tray = mr_conf_bread("mondo_manual_tray");
|
---|
| 166 | mr_cnf->log_level = mr_conf_iread("mondo_log_level");
|
---|
[1422] | 167 |
|
---|
| 168 | mr_asprintf(&p, mr_conf_sread("mondo_prefix"));
|
---|
| 169 | mr_cnf->prefix = p;
|
---|
| 170 | p = NULL;
|
---|
| 171 |
|
---|
[1264] | 172 | mr_cnf->external_tape_blocksize = mr_conf_iread("mondo_external_tape_blocksize");
|
---|
| 173 | mr_cnf->internal_tape_blocksize = mr_conf_iread("mondo_internal_tape_blocksize");
|
---|
| 174 | mr_cnf->slice_size = mr_conf_iread("mondo_slice_size");
|
---|
[1422] | 175 |
|
---|
| 176 | mr_asprintf(&p, mr_conf_sread("mondo_deplist_file"));
|
---|
| 177 | mr_cnf->deplist_file = p;
|
---|
| 178 | p = NULL;
|
---|
| 179 |
|
---|
[1264] | 180 | mr_cnf->write_boot_floppy = mr_conf_bread("mondo_write_boot_floppy");
|
---|
| 181 | mr_cnf->create_mindi_cd = mr_conf_bread("mondo_create_mindi_cd");
|
---|
[1422] | 182 |
|
---|
| 183 | mr_asprintf(&p, mr_conf_sread("mondo_kernel"));
|
---|
| 184 | mr_cnf->kernel = p;
|
---|
| 185 | p = NULL;
|
---|
| 186 |
|
---|
| 187 | mr_asprintf(&p, mr_conf_sread("mondo_additional_modules"));
|
---|
| 188 | mr_cnf->additional_modules = p;
|
---|
| 189 | p = NULL;
|
---|
| 190 |
|
---|
| 191 | mr_asprintf(&p, mr_conf_sread("mondo_boot_loader"));
|
---|
| 192 | mr_cnf->boot_loader = p;
|
---|
| 193 | p = NULL;
|
---|
| 194 |
|
---|
[1264] | 195 | mr_cnf->differential = mr_conf_bread("mondo_differential");
|
---|
[1422] | 196 |
|
---|
| 197 | mr_asprintf(&p, mr_conf_sread("mondo_compression_tool"));
|
---|
| 198 | mr_cnf->compression_tool = p;
|
---|
| 199 | p = NULL;
|
---|
| 200 |
|
---|
[1264] | 201 | mr_cnf->compression_level = mr_conf_iread("mondo_compression_level");
|
---|
[1422] | 202 |
|
---|
| 203 | mr_asprintf(&p, mr_conf_sread("mondo_exclude_paths"));
|
---|
| 204 | mr_cnf->exclude_paths = p;
|
---|
| 205 | p = NULL;
|
---|
| 206 |
|
---|
| 207 | mr_asprintf(&p, mr_conf_sread("mondo_include_paths"));
|
---|
| 208 | mr_cnf->include_paths = p;
|
---|
| 209 | p = NULL;
|
---|
| 210 |
|
---|
| 211 | mr_asprintf(&p, mr_conf_sread("mondo_ui_mode"));
|
---|
| 212 | mr_cnf->ui_mode = p;
|
---|
| 213 | p = NULL;
|
---|
| 214 |
|
---|
[1264] | 215 | mr_cnf->automatic_restore = mr_conf_bread("mondo_automatic_restore");
|
---|
[1422] | 216 |
|
---|
| 217 | mr_asprintf(&p, mr_conf_sread("mondo_scratch_dir"));
|
---|
| 218 | mr_cnf->scratch_dir = p;
|
---|
| 219 | p = NULL;
|
---|
| 220 |
|
---|
| 221 | mr_asprintf(&p, mr_conf_sread("mondo_tmp_dir"));
|
---|
| 222 | mr_cnf->tmp_dir = p;
|
---|
| 223 | p = NULL;
|
---|
| 224 |
|
---|
| 225 | mr_asprintf(&p, mr_conf_sread("mondo_images_dir"));
|
---|
| 226 | mr_cnf->images_dir = p;
|
---|
| 227 | p = NULL;
|
---|
[1264] | 228 | mr_msg(5, "Directory for images is %s", mr_cnf->images_dir);
|
---|
[1256] | 229 | }
|
---|
| 230 |
|
---|
[1264] | 231 | /* destroy the mr_ar_conf structure's content */
|
---|
| 232 | static void mr_ar_clean_conf(struct mr_ar_conf *mr_cnf) {
|
---|
| 233 |
|
---|
| 234 | if (mr_cnf == NULL) {
|
---|
| 235 | return;
|
---|
| 236 | }
|
---|
| 237 | mr_free(mr_cnf->iso_creation_cmd);
|
---|
| 238 | mr_free(mr_cnf->iso_creation_options);
|
---|
| 239 | mr_free(mr_cnf->iso_burning_cmd);
|
---|
| 240 | mr_free(mr_cnf->iso_burning_options);
|
---|
| 241 | mr_free(mr_cnf->media_device);
|
---|
| 242 | mr_free(mr_cnf->prefix);
|
---|
| 243 | mr_free(mr_cnf->deplist_file);
|
---|
| 244 | mr_free(mr_cnf->kernel);
|
---|
| 245 | mr_free(mr_cnf->additional_modules);
|
---|
| 246 | mr_free(mr_cnf->boot_loader);
|
---|
| 247 | mr_free(mr_cnf->compression_tool);
|
---|
| 248 | mr_free(mr_cnf->exclude_paths);
|
---|
| 249 | mr_free(mr_cnf->include_paths);
|
---|
| 250 | mr_free(mr_cnf->ui_mode);
|
---|
| 251 | mr_free(mr_cnf->scratch_dir);
|
---|
| 252 | mr_free(mr_cnf->tmp_dir);
|
---|
| 253 | mr_free(mr_cnf->images_dir);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | /* Create the pointer to the function called in mr_exit */
|
---|
| 257 | void (*mr_cleanup)(void) = NULL;
|
---|
| 258 |
|
---|
[1390] | 259 | /* Just for init */
|
---|
| 260 | void mr_ar_cleanup_empty(void) {
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[1264] | 263 | /* Cleanup all memory allocated in various structures */
|
---|
| 264 | void mr_ar_cleanup(void) {
|
---|
| 265 | /* Highly incomplete function for the moment */
|
---|
| 266 | /* We have to free all allocated memory */
|
---|
| 267 | mr_ar_clean_conf(&mr_conf);
|
---|
| 268 | /* We have to remove all temporary files */
|
---|
| 269 | /* We have to unmount what has been mounted */
|
---|
| 270 | /* We have to properly end newt */
|
---|
| 271 | /* We have to remind people of log files */
|
---|
| 272 |
|
---|
| 273 | mr_msg_close();
|
---|
| 274 | }
|
---|
| 275 |
|
---|
[1] | 276 | /*-----------------------------------------------------------*/
|
---|
| 277 |
|
---|
| 278 |
|
---|
| 279 |
|
---|
| 280 | /**
|
---|
| 281 | * Backup/verify the user's data.
|
---|
| 282 | * What did you think it did, anyway? :-)
|
---|
| 283 | */
|
---|
[128] | 284 | int main(int argc, char *argv[])
|
---|
[1] | 285 | {
|
---|
[1256] | 286 | struct s_bkpinfo *bkpinfo = NULL;
|
---|
[1100] | 287 | struct stat stbuf;
|
---|
[1152] | 288 | char *tmp = NULL;
|
---|
[1187] | 289 | int res = 0;
|
---|
| 290 | int retval = 0;
|
---|
| 291 | char *say_at_end = NULL;
|
---|
[1190] | 292 | char *say_at_end2 = NULL;
|
---|
[1] | 293 |
|
---|
[1187] | 294 | #ifdef ENABLE_NLS
|
---|
| 295 | setlocale(LC_ALL, "");
|
---|
| 296 | (void) textdomain("mondo");
|
---|
| 297 | #endif
|
---|
[1256] | 298 | printf(_("Initializing..."));
|
---|
| 299 |
|
---|
[1390] | 300 | /* Reference a dummy cleanup function for mr_exit temporarily */
|
---|
| 301 | mr_cleanup = &mr_ar_cleanup_empty;
|
---|
[1264] | 302 |
|
---|
[1256] | 303 | /* initialize log file with time stamp */
|
---|
| 304 | /* We start with a loglevel of 4 - Adapted later on */
|
---|
| 305 | /* It's mandatory to set this up first as all mr_ functions rely on it */
|
---|
| 306 | unlink(MONDO_LOGFILE);
|
---|
| 307 | mr_msg_init(MONDO_LOGFILE,4);
|
---|
| 308 | mr_msg(0, _("Time started: %s"), mr_date());
|
---|
| 309 |
|
---|
| 310 | /* Make sure I'm root; abort if not */
|
---|
[128] | 311 | if (getuid() != 0) {
|
---|
[1256] | 312 | mr_log_exit(127, _("Please run as root."));
|
---|
[128] | 313 | }
|
---|
[1] | 314 |
|
---|
[1187] | 315 | /* If -V, -v or --version then echo version no. and quit */
|
---|
[128] | 316 | if (argc == 2
|
---|
| 317 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
---|
| 318 | || !strcmp(argv[argc - 1], "--version"))) {
|
---|
[1187] | 319 | printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
|
---|
[1256] | 320 | mr_exit(0, NULL);
|
---|
[128] | 321 | }
|
---|
[1] | 322 |
|
---|
[1256] | 323 | /* Conf file management */
|
---|
| 324 | /* Check md5 sum before */
|
---|
| 325 | /* Get content */
|
---|
| 326 | if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
|
---|
| 327 | mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
|
---|
| 328 | }
|
---|
| 329 | mr_ar_store_conf(&mr_conf);
|
---|
[1390] | 330 | /* Reference the right cleanup function for mr_exit now it's allocated */
|
---|
| 331 | mr_cleanup = &mr_ar_cleanup;
|
---|
| 332 |
|
---|
[1256] | 333 | mr_conf_close();
|
---|
| 334 |
|
---|
| 335 | /* Add MONDO_SHARE + other environment variables for mindi */
|
---|
| 336 | setenv_mondo_var();
|
---|
| 337 |
|
---|
[1187] | 338 | /* Initialize variables */
|
---|
[128] | 339 | malloc_libmondo_global_strings();
|
---|
| 340 | diffs = 0;
|
---|
[1132] | 341 | bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
|
---|
[1100] | 342 | if (stat(MONDO_CACHE, &stbuf) != 0) {
|
---|
| 343 | mr_mkdir(MONDO_CACHE,0x755);
|
---|
| 344 | }
|
---|
| 345 |
|
---|
[1140] | 346 | /* BERLIOS: Hardcoded to be improved */
|
---|
| 347 | unlink(MONDO_CACHE"/mindi.conf");
|
---|
[1143] | 348 | unlink(MONDORESTORECFG);
|
---|
[1140] | 349 |
|
---|
[807] | 350 | /* Configure the bkpinfo structure, global file paths, etc. */
|
---|
[128] | 351 | g_main_pid = getpid();
|
---|
[1108] | 352 | mr_msg(9, "This");
|
---|
[1] | 353 |
|
---|
[128] | 354 | register_pid(g_main_pid, "mondo");
|
---|
| 355 | set_signals(TRUE); // catch SIGTERM, etc.
|
---|
| 356 | run_program_and_log_output("dmesg -n1", TRUE);
|
---|
[1] | 357 |
|
---|
[1108] | 358 | mr_msg(9, "Next");
|
---|
[128] | 359 | welcome_to_mondoarchive();
|
---|
| 360 | distro_specific_kludges_at_start_of_mondoarchive();
|
---|
| 361 | g_kernel_version = get_kernel_version();
|
---|
[1] | 362 |
|
---|
[128] | 363 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
---|
| 364 | g_loglevel = 10;
|
---|
| 365 | g_text_mode = TRUE;
|
---|
| 366 | setup_newt_stuff();
|
---|
| 367 | if (!strstr(argv[2], "filelist")) {
|
---|
[1187] | 368 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
---|
[128] | 369 | finish(1);
|
---|
| 370 | } else {
|
---|
| 371 | finish(get_fattr_list(argv[2], argv[3]));
|
---|
| 372 | }
|
---|
| 373 | finish(0);
|
---|
[1] | 374 | }
|
---|
[128] | 375 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
---|
| 376 | g_loglevel = 10;
|
---|
| 377 | g_text_mode = TRUE;
|
---|
| 378 | setup_newt_stuff();
|
---|
| 379 | finish(set_fattr_list(argv[2], argv[3]));
|
---|
[1] | 380 | }
|
---|
[128] | 381 |
|
---|
| 382 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
---|
| 383 | g_loglevel = 10;
|
---|
| 384 | g_text_mode = TRUE;
|
---|
| 385 | setup_newt_stuff();
|
---|
[1241] | 386 | tmp = mr_stresc(argv[2], WILDCHARS, BACKSLASH);
|
---|
[128] | 387 | printf("in=%s; out=%s\n", argv[2], tmp);
|
---|
[1152] | 388 | mr_free(tmp);
|
---|
[128] | 389 | finish(1);
|
---|
[1] | 390 | }
|
---|
[128] | 391 |
|
---|
| 392 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
---|
| 393 | g_loglevel = 10;
|
---|
| 394 | g_text_mode = TRUE;
|
---|
| 395 | setup_newt_stuff();
|
---|
| 396 | if (!strstr(argv[2], "filelist")) {
|
---|
[1187] | 397 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
---|
[128] | 398 | finish(1);
|
---|
| 399 | } else {
|
---|
| 400 | finish(get_acl_list(argv[2], argv[3]));
|
---|
| 401 | }
|
---|
| 402 | finish(0);
|
---|
| 403 | }
|
---|
| 404 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
---|
| 405 | g_loglevel = 10;
|
---|
| 406 | g_text_mode = TRUE;
|
---|
| 407 | setup_newt_stuff();
|
---|
| 408 | finish(set_acl_list(argv[2], argv[3]));
|
---|
| 409 | }
|
---|
[1] | 410 |
|
---|
[128] | 411 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
---|
| 412 | g_loglevel = 10;
|
---|
| 413 | g_text_mode = TRUE;
|
---|
| 414 | setup_newt_stuff();
|
---|
[1152] | 415 | malloc_string(tmp);
|
---|
[128] | 416 | if (find_cdrw_device(tmp)) {
|
---|
[1187] | 417 | mr_msg(1,_("Failed to find CDR-RW drive\n"));
|
---|
[128] | 418 | } else {
|
---|
[1187] | 419 | mr_msg(1,_("CD-RW is at %s\n"), tmp);
|
---|
[128] | 420 | }
|
---|
| 421 | tmp[0] = '\0';
|
---|
| 422 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
---|
[1187] | 423 | mr_msg(1,_("Failed to find CD-ROM drive\n"));
|
---|
[128] | 424 | } else {
|
---|
[1187] | 425 | mr_msg(1,_("CD-ROM is at %s\n"), tmp);
|
---|
[128] | 426 | }
|
---|
[1152] | 427 | mr_free(tmp);
|
---|
[128] | 428 | finish(0);
|
---|
| 429 | }
|
---|
[1] | 430 |
|
---|
[128] | 431 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
---|
| 432 | g_loglevel = 10;
|
---|
| 433 | g_text_mode = TRUE;
|
---|
| 434 | setup_newt_stuff();
|
---|
[1152] | 435 | malloc_string(tmp);
|
---|
[128] | 436 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
---|
[1187] | 437 | mr_msg(1,_("Failed to find DVD drive\n"));
|
---|
[128] | 438 | } else {
|
---|
[1187] | 439 | mr_msg(1,_("DVD is at %s\n"), tmp);
|
---|
[128] | 440 | }
|
---|
[1152] | 441 | mr_free(tmp);
|
---|
[128] | 442 | finish(0);
|
---|
| 443 | }
|
---|
[1] | 444 |
|
---|
[128] | 445 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
---|
| 446 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
---|
| 447 | finish(0);
|
---|
| 448 | }
|
---|
| 449 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
---|
| 450 | if (is_dev_an_NTFS_dev(argv[2])) {
|
---|
[1187] | 451 | mr_msg(1,_("%s is indeed an NTFS dev\n"), argv[2]);
|
---|
[128] | 452 | } else {
|
---|
[1187] | 453 | mr_msg(1,_("%s is _not_ an NTFS dev\n"), argv[2]);
|
---|
[128] | 454 | }
|
---|
| 455 | finish(0);
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | if (pre_param_configuration(bkpinfo)) {
|
---|
| 459 | fatal_error
|
---|
| 460 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
---|
| 461 | }
|
---|
[1140] | 462 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
---|
| 463 | bkpinfo->scratchdir);
|
---|
[128] | 464 |
|
---|
[1140] | 465 | /* Process command line, if there is one. If not, ask user for info. */
|
---|
[128] | 466 | if (argc == 1) {
|
---|
| 467 | g_text_mode = FALSE;
|
---|
| 468 | setup_newt_stuff();
|
---|
| 469 | res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */
|
---|
| 470 | if (res) {
|
---|
| 471 | fatal_error
|
---|
| 472 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
---|
| 473 | }
|
---|
| 474 | } else {
|
---|
| 475 | res = handle_incoming_parameters(argc, argv, bkpinfo);
|
---|
| 476 | if (res) {
|
---|
[1187] | 477 | mr_msg(1,
|
---|
| 478 | _("Errors were detected in the command line you supplied.\n"));
|
---|
| 479 | mr_msg(1,_("Please review the log file - %s \n"),MONDO_LOGFILE);
|
---|
[1108] | 480 | mr_msg(1, "Mondoarchive will now exit.");
|
---|
[128] | 481 | finish(1);
|
---|
| 482 | }
|
---|
| 483 | setup_newt_stuff();
|
---|
[1] | 484 | }
|
---|
| 485 |
|
---|
| 486 | /* Finish configuring global structures */
|
---|
[128] | 487 | if (post_param_configuration(bkpinfo)) {
|
---|
| 488 | fatal_error
|
---|
| 489 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
---|
| 490 | }
|
---|
[1] | 491 |
|
---|
[128] | 492 | log_to_screen
|
---|
[1187] | 493 | (_("BusyBox's sources are available from http://www.busybox.net"));
|
---|
| 494 |
|
---|
[128] | 495 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
---|
| 496 | bkpinfo->scratchdir);
|
---|
[1] | 497 |
|
---|
[128] | 498 | /* If we're meant to backup then backup */
|
---|
| 499 | if (bkpinfo->backup_data) {
|
---|
[541] | 500 | res = backup_data(bkpinfo);
|
---|
[128] | 501 | retval += res;
|
---|
| 502 | if (res) {
|
---|
[1187] | 503 | mr_strcat(say_at_end,
|
---|
| 504 | _("Data archived. Please check the logs, just as a precaution. "));
|
---|
[128] | 505 | } else {
|
---|
[1187] | 506 | mr_strcat(say_at_end, _("Data archived OK. "));
|
---|
[128] | 507 | }
|
---|
| 508 | }
|
---|
[1] | 509 |
|
---|
[1187] | 510 | /* If we're meant to verify then verify */
|
---|
[128] | 511 | if (bkpinfo->verify_data) {
|
---|
| 512 | res = verify_data(bkpinfo);
|
---|
| 513 | if (res < 0) {
|
---|
[1190] | 514 | mr_asprintf(&say_at_end2, _("%d difference%c found."), -res,
|
---|
[128] | 515 | (-res != 1) ? 's' : ' ');
|
---|
| 516 | res = 0;
|
---|
| 517 | }
|
---|
| 518 | retval += res;
|
---|
| 519 | }
|
---|
[1] | 520 |
|
---|
[1187] | 521 | /* Offer to write floppy disk images to physical disks */
|
---|
[128] | 522 | if (bkpinfo->backup_data && !g_skip_floppies) {
|
---|
| 523 | res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
|
---|
| 524 | retval += res;
|
---|
| 525 | }
|
---|
[1] | 526 |
|
---|
[1187] | 527 | /* Report result of entire operation (success? errors?) */
|
---|
[128] | 528 | if (!retval) {
|
---|
| 529 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[1187] | 530 | _("Backup and/or verify ran to completion. Everything appears to be fine."));
|
---|
[128] | 531 | } else {
|
---|
| 532 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[1187] | 533 | _("Backup and/or verify ran to completion. However, errors did occur."));
|
---|
[128] | 534 | }
|
---|
[1] | 535 |
|
---|
[1044] | 536 | if (does_file_exist("/var/cache/mindi/mondorescue.iso")) {
|
---|
[128] | 537 | log_to_screen
|
---|
[1187] | 538 | (_("/var/cache/mindi/mondorescue.iso, a boot/utility CD, is available if you want it."));
|
---|
[128] | 539 | }
|
---|
[1] | 540 |
|
---|
| 541 |
|
---|
[128] | 542 | if (length_of_file("/tmp/changed.files") > 2) {
|
---|
| 543 | if (g_text_mode) {
|
---|
| 544 | log_to_screen
|
---|
[1187] | 545 | (_("Type 'less /tmp/changed.files' to see which files don't match the archives"));
|
---|
[128] | 546 | } else {
|
---|
[1108] | 547 | mr_msg(1,
|
---|
[1187] | 548 | _("Type 'less /tmp/changed.files' to see which files don't match the archives"));
|
---|
[1108] | 549 | mr_msg(2, "Calling popup_changelist_from_file()");
|
---|
[128] | 550 | popup_changelist_from_file("/tmp/changed.files");
|
---|
[1108] | 551 | mr_msg(2, "Returned from popup_changelist_from_file()");
|
---|
[128] | 552 | }
|
---|
| 553 | } else {
|
---|
| 554 | unlink("/tmp/changed.files");
|
---|
| 555 | }
|
---|
| 556 | log_to_screen(say_at_end);
|
---|
[1187] | 557 | mr_free(say_at_end);
|
---|
[1190] | 558 | if (say_at_end2 != NULL) {
|
---|
| 559 | log_to_screen(say_at_end2);
|
---|
| 560 | mr_free(say_at_end2);
|
---|
| 561 | }
|
---|
[1187] | 562 |
|
---|
[1152] | 563 | mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
---|
[128] | 564 | run_program_and_log_output(tmp, TRUE);
|
---|
[1152] | 565 | mr_free(tmp);
|
---|
[128] | 566 | run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
|
---|
[1] | 567 |
|
---|
[128] | 568 | run_program_and_log_output("mount", 2);
|
---|
[1] | 569 |
|
---|
[128] | 570 | system("rm -f /var/cache/mondo-archive/last-backup.aborted");
|
---|
| 571 | system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
|
---|
| 572 | if (!retval) {
|
---|
[1187] | 573 | printf(_("Mondoarchive ran OK.\n"));
|
---|
[128] | 574 | } else {
|
---|
[1187] | 575 | printf(_("Errors occurred during backup. Please check logfile.\n"));
|
---|
[128] | 576 | }
|
---|
| 577 | distro_specific_kludges_at_end_of_mondoarchive();
|
---|
| 578 | register_pid(0, "mondo");
|
---|
| 579 | set_signals(FALSE);
|
---|
| 580 | chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir
|
---|
| 581 | system(g_erase_tmpdir_and_scratchdir);
|
---|
| 582 | free_libmondo_global_strings();
|
---|
[1080] | 583 | mr_free(bkpinfo);
|
---|
[1] | 584 |
|
---|
[128] | 585 | unlink("/tmp/filelist.full");
|
---|
| 586 | unlink("/tmp/filelist.full.gz");
|
---|
[1] | 587 |
|
---|
[128] | 588 | if (!g_cdrom_drive_is_here) {
|
---|
[1108] | 589 | mr_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
---|
[128] | 590 | }
|
---|
| 591 | if (!g_dvd_drive_is_here) {
|
---|
[1108] | 592 | mr_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
---|
[128] | 593 | }
|
---|
[1] | 594 |
|
---|
[810] | 595 | /* finalize log file with time stamp */
|
---|
[1187] | 596 | mr_msg(1, "Time finished: %s", mr_date());
|
---|
[1132] | 597 | mr_msg_close();
|
---|
[810] | 598 |
|
---|
[128] | 599 | if (!g_text_mode) {
|
---|
| 600 | popup_and_OK
|
---|
[1187] | 601 | (_("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."));
|
---|
| 602 | log_to_screen(_("See %s for details of backup run."), MONDO_LOGFILE);
|
---|
[128] | 603 | finish(retval);
|
---|
| 604 | } else {
|
---|
[1187] | 605 | printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
|
---|
[1264] | 606 | mr_exit(retval, NULL);
|
---|
[128] | 607 | }
|
---|
| 608 |
|
---|
| 609 | return EXIT_SUCCESS;
|
---|
[1] | 610 | }
|
---|