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