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