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