[1] | 1 | /***************************************************************************
|
---|
| 2 | main.c - description
|
---|
| 3 | -------------------
|
---|
| 4 | begin : Fri Apr 19 16:40:35 EDT 2002
|
---|
| 5 | copyright : (C) 2002 by Stan Benoit
|
---|
| 6 | email : troff@nakedsoul.org
|
---|
[128] | 7 | cvsid : $Id: main.c 1697 2007-10-21 11:39:59Z bruno $
|
---|
[1] | 8 | ***************************************************************************/
|
---|
| 9 |
|
---|
| 10 | /***************************************************************************
|
---|
| 11 | * *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify *
|
---|
| 13 | * it under the terms of the GNU General Public License as published by *
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
| 15 | * (at your option) any later version. *
|
---|
| 16 | * *
|
---|
| 17 | ***************************************************************************/
|
---|
| 18 |
|
---|
| 19 | /** change log ****** MONDO-DEVEL
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | 12/10
|
---|
| 23 | - disable stopping/starting of autofs
|
---|
| 24 |
|
---|
| 25 | 10/01
|
---|
| 26 | - update g_erase_tmpdir_and_scratchdir to delete user-specified tmpdir, scratchdir
|
---|
| 27 |
|
---|
| 28 | 06/19
|
---|
| 29 | - added AUX_VER
|
---|
| 30 |
|
---|
| 31 | 06/14/2004
|
---|
| 32 | - use mondorescue.iso, not mindi.iso
|
---|
| 33 |
|
---|
| 34 | 02/10/2004
|
---|
| 35 | - tell users where BusyBox's sources are
|
---|
| 36 |
|
---|
| 37 | 11/14/2003
|
---|
| 38 | - cleaned up logging at end#
|
---|
| 39 |
|
---|
| 40 | 10/23
|
---|
| 41 | - don't try to test-read tape ... That's already
|
---|
| 42 | handled by post_param_configuration()
|
---|
| 43 |
|
---|
| 44 | 10/19
|
---|
| 45 | - if your PATH var is too long, abort
|
---|
| 46 |
|
---|
| 47 | 09/23
|
---|
| 48 | - added some comments
|
---|
| 49 | - malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
|
---|
| 50 | and free_libmondo_global_strings() - which are in libmondo-tools.c
|
---|
| 51 | - better magicdev support
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | 09/16
|
---|
| 55 | - delete /var/log/partimagehack-debug.log at start of main()
|
---|
| 56 |
|
---|
| 57 | 09/15
|
---|
| 58 | - added askbootloader
|
---|
| 59 |
|
---|
| 60 | 09/09
|
---|
| 61 | - if your tape is weird, I'll pause between backup and verify
|
---|
| 62 | - fixed silly bug in main() - re: say_at_end
|
---|
| 63 |
|
---|
| 64 | 01/01 - 08/31
|
---|
| 65 | - call 'dmesg -n1' at start, to shut the kernel logger up
|
---|
| 66 | - moved g_erase_tmpdir_and_scratchdir to common/newt-specific.c
|
---|
| 67 | - added 'don't panic' msg to start of logfile
|
---|
| 68 | - added 'nice(20)' to main()
|
---|
| 69 | - added lots of assert()'s and log_OS_error()'s
|
---|
| 70 | - clean-up (Hugo)
|
---|
| 71 | - make post_param_configuration() setup g_erase_tmpdir_and_scratchdir
|
---|
| 72 | - if --version then print & exit quickly
|
---|
| 73 | - re-run g_erase_tmpdir_and_scratchdir via system() at very end
|
---|
| 74 |
|
---|
| 75 | Year: 2002
|
---|
| 76 | - if user goes root with 'su' instead of 'su -' then
|
---|
| 77 | workaround it by setting PATH correctly
|
---|
| 78 | - wipe mondoarchive.log at very beginning
|
---|
| 79 | - cleaned up code
|
---|
| 80 | - if changed.files.N exists then copy to changes.files for display
|
---|
| 81 | - run_program_and_log_output() now takes boolean operator to specify
|
---|
| 82 | whether it will log its activities in the event of _success_
|
---|
| 83 | - added popup list of changed files
|
---|
| 84 | - removed 'beta-quality' warnings
|
---|
| 85 | - if kernel not found and mondo in graphics mode then popup and ask
|
---|
| 86 | for kernel path+filename
|
---|
| 87 | - fixed tmp[] 'too small' bug
|
---|
| 88 | - unmount and eject CD at end of verify cycle
|
---|
| 89 | - moved interactively_obtain...() to libmondo-stream.c
|
---|
| 90 | - wrote stuff to autodetect tape+cdrw+etc.
|
---|
| 91 | - renamed from main.c to mondo-archive.c
|
---|
| 92 | - fore+after warnings that this code is beta-quality
|
---|
| 93 | - abort if running from ramdisk
|
---|
| 94 | - remount floppy at end & unmount at start if Mandrake
|
---|
| 95 | - took out #debug stuff
|
---|
| 96 | - add 2> /dev/null to 'find' command
|
---|
| 97 | - add support for bkpinfo->nonbootable_backup
|
---|
| 98 | - add main function begin comment and debug conditional
|
---|
| 99 | compilation - Stan Benoit
|
---|
| 100 | - add debug statements to build a run tree. Stan Benoit
|
---|
| 101 | **** end change log **********/
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * @file
|
---|
| 106 | * The main file for mondoarchive.
|
---|
| 107 | */
|
---|
| 108 |
|
---|
| 109 | /************************* #include statements *************************/
|
---|
| 110 | #include <pthread.h>
|
---|
| 111 | //#include <config.h>
|
---|
| 112 | //#include "../../config.h"
|
---|
| 113 | #include <stdio.h>
|
---|
| 114 | #include <stdlib.h>
|
---|
| 115 | #include "../common/my-stuff.h"
|
---|
| 116 | #include "../common/mondostructures.h"
|
---|
| 117 | #include "../common/libmondo.h"
|
---|
| 118 | #include "mondo-cli-EXT.h"
|
---|
[1383] | 119 | #include "../common/libmondo-tools-EXT.h"
|
---|
[1315] | 120 | #include "mondoarchive.h"
|
---|
[1] | 121 |
|
---|
| 122 | // for CVS
|
---|
[128] | 123 | //static char cvsid[] = "$Id: main.c 1697 2007-10-21 11:39:59Z bruno $";
|
---|
[1] | 124 |
|
---|
| 125 | /************************* external variables *************************/
|
---|
| 126 | extern void set_signals(int);
|
---|
| 127 | extern int g_current_media_number;
|
---|
[128] | 128 | extern void register_pid(pid_t, char *);
|
---|
[1] | 129 | extern int g_currentY;
|
---|
| 130 | extern bool g_text_mode;
|
---|
| 131 | extern char *g_boot_mountpt;
|
---|
| 132 | extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
|
---|
| 133 | extern char *g_mondo_home;
|
---|
| 134 | extern char *g_tmpfs_mountpt;
|
---|
| 135 | extern char *g_erase_tmpdir_and_scratchdir;
|
---|
| 136 | extern char *g_cdrw_drive_is_here;
|
---|
[128] | 137 | static char *g_cdrom_drive_is_here = NULL;
|
---|
| 138 | static char *g_dvd_drive_is_here = NULL;
|
---|
[1] | 139 | extern double g_kernel_version;
|
---|
| 140 |
|
---|
| 141 | /***************** global vars, used only by main.c ******************/
|
---|
| 142 | bool g_skip_floppies;
|
---|
| 143 | long diffs;
|
---|
| 144 |
|
---|
| 145 | extern t_bkptype g_backup_media_type;
|
---|
| 146 | extern int g_loglevel;
|
---|
| 147 |
|
---|
[1645] | 148 | /* Reference to global bkpinfo */
|
---|
| 149 | struct s_bkpinfo *bkpinfo;
|
---|
| 150 |
|
---|
[1] | 151 | /****************** subroutines used only by main.c ******************/
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | /**
|
---|
| 155 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
---|
| 156 | */
|
---|
[1236] | 157 | void welcome_to_mondoarchive(void)
|
---|
[1] | 158 | {
|
---|
[1375] | 159 | char *tmp = NULL;
|
---|
| 160 |
|
---|
[128] | 161 | log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
|
---|
[251] | 162 | PACKAGE_VERSION);
|
---|
[1375] | 163 | log_msg(0, "running %s binaries", get_architecture());
|
---|
| 164 | tmp = get_uname_m();
|
---|
| 165 | log_msg(0, "running on %s architecture", tmp);
|
---|
[1381] | 166 | free(tmp);
|
---|
[128] | 167 | log_msg(0,
|
---|
| 168 | "-----------------------------------------------------------");
|
---|
| 169 | log_msg(0,
|
---|
| 170 | "NB: Mondo logs almost everything, so don't panic if you see");
|
---|
| 171 | log_msg(0,
|
---|
| 172 | "some error messages. Please read them carefully before you");
|
---|
| 173 | log_msg(0,
|
---|
| 174 | "decide to break out in a cold sweat. Despite (or perhaps");
|
---|
| 175 | log_msg(0,
|
---|
| 176 | "because of) the wealth of messages. some users are inclined");
|
---|
| 177 | log_msg(0,
|
---|
| 178 | "to stop reading this log. If Mondo stopped for some reason,");
|
---|
| 179 | log_msg(0,
|
---|
| 180 | "chances are it's detailed here. More than likely there's a");
|
---|
| 181 | log_msg(0,
|
---|
| 182 | "message at the very end of this log that will tell you what");
|
---|
| 183 | log_msg(0,
|
---|
| 184 | "is wrong. Please read it! -Devteam");
|
---|
| 185 | log_msg(0,
|
---|
| 186 | "-----------------------------------------------------------");
|
---|
[1] | 187 |
|
---|
[128] | 188 | log_msg(0, "Zero...");
|
---|
| 189 | log_msg(1, "One...");
|
---|
| 190 | log_msg(2, "Two...");
|
---|
| 191 | log_msg(3, "Three...");
|
---|
| 192 | log_msg(4, "Four...");
|
---|
| 193 | log_msg(5, "Five...");
|
---|
| 194 | log_msg(6, "Six...");
|
---|
| 195 | log_msg(7, "Seven...");
|
---|
| 196 | log_msg(8, "Eight...");
|
---|
| 197 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
[1] | 198 | }
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | extern char *g_magicdev_command;
|
---|
| 202 |
|
---|
| 203 | /**
|
---|
| 204 | * Do whatever is necessary to insure a successful backup on the Linux distribution
|
---|
| 205 | * of the day.
|
---|
| 206 | */
|
---|
[1236] | 207 | void distro_specific_kludges_at_start_of_mondoarchive(void)
|
---|
[1] | 208 | {
|
---|
[128] | 209 | log_msg(2, "Unmounting old ramdisks if necessary");
|
---|
| 210 | stop_magicdev_if_necessary(); // for RH+Gnome users
|
---|
| 211 | run_program_and_log_output
|
---|
| 212 | ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
|
---|
| 213 | unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
|
---|
| 214 | // stop_autofs_if_necessary(); // for Xandros users
|
---|
| 215 | mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
|
---|
| 216 | clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
|
---|
[1] | 217 | }
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 |
|
---|
| 221 | /**
|
---|
| 222 | * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
|
---|
| 223 | */
|
---|
[1236] | 224 | void distro_specific_kludges_at_end_of_mondoarchive(void)
|
---|
[1] | 225 | {
|
---|
| 226 | // char tmp[500];
|
---|
[128] | 227 | log_msg(2, "Restarting magicdev if necessary");
|
---|
| 228 | sync();
|
---|
| 229 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
---|
[1] | 230 |
|
---|
[128] | 231 | log_msg(2, "Restarting autofs if necessary");
|
---|
| 232 | sync();
|
---|
| 233 | // restart_autofs_if_necessary(); // for Xandros users
|
---|
[1] | 234 |
|
---|
[128] | 235 | log_msg(2, "Restarting supermounts if necessary");
|
---|
| 236 | sync();
|
---|
| 237 | remount_supermounts_if_necessary(); // for Mandrake users
|
---|
[1] | 238 |
|
---|
[128] | 239 | log_msg(2, "Unmounting /boot if necessary");
|
---|
| 240 | sync();
|
---|
| 241 | unmount_boot_if_necessary(); // for Gentoo users
|
---|
[1] | 242 |
|
---|
| 243 | // log_msg( 2, "Cleaning up KDE desktop");
|
---|
| 244 | // clean_up_KDE_desktop_if_necessary();
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[813] | 247 | /* Return a string containing the date */
|
---|
| 248 | char *mr_date(void) {
|
---|
| 249 |
|
---|
| 250 | time_t tcurr;
|
---|
[1] | 251 |
|
---|
[813] | 252 | tcurr = time(NULL);
|
---|
| 253 | return(ctime(&tcurr));
|
---|
| 254 | }
|
---|
| 255 |
|
---|
[1] | 256 | /*-----------------------------------------------------------*/
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | /**
|
---|
| 261 | * Backup/verify the user's data.
|
---|
| 262 | * What did you think it did, anyway? :-)
|
---|
| 263 | */
|
---|
[128] | 264 | int main(int argc, char *argv[])
|
---|
[1] | 265 | {
|
---|
[128] | 266 | char *tmp;
|
---|
| 267 | int res, retval;
|
---|
| 268 | char *say_at_end;
|
---|
[1] | 269 |
|
---|
| 270 | /* Make sure I'm root; abort if not */
|
---|
[128] | 271 | if (getuid() != 0) {
|
---|
[541] | 272 | fprintf(stderr, "Please run as root.\r\n");
|
---|
[128] | 273 | exit(127);
|
---|
| 274 | }
|
---|
[1] | 275 |
|
---|
| 276 | /* If -V, -v or --version then echo version no. and quit */
|
---|
[128] | 277 | if (argc == 2
|
---|
| 278 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
---|
| 279 | || !strcmp(argv[argc - 1], "--version"))) {
|
---|
[541] | 280 | printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
|
---|
[128] | 281 | exit(0);
|
---|
| 282 | }
|
---|
[1] | 283 |
|
---|
| 284 | /* Initialize variables */
|
---|
| 285 |
|
---|
[1652] | 286 | printf("Initializing...\n");
|
---|
| 287 | if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
|
---|
| 288 | fatal_error("Cannot malloc bkpinfo");
|
---|
| 289 | }
|
---|
| 290 | reset_bkpinfo();
|
---|
[1] | 291 |
|
---|
[128] | 292 | res = 0;
|
---|
| 293 | retval = 0;
|
---|
| 294 | diffs = 0;
|
---|
[1652] | 295 | malloc_string(tmp);
|
---|
| 296 | malloc_string(say_at_end);
|
---|
[128] | 297 | say_at_end[0] = '\0';
|
---|
[1652] | 298 | malloc_libmondo_global_strings();
|
---|
[1] | 299 |
|
---|
[810] | 300 | /* initialize log file with time stamp */
|
---|
| 301 | unlink(MONDO_LOGFILE);
|
---|
[813] | 302 | log_msg(0, "Time started: %s", mr_date());
|
---|
[1] | 303 |
|
---|
[807] | 304 | /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
|
---|
[128] | 305 | strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
|
---|
| 306 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
| 307 | if (strlen(tmp) >= MAX_STR_LEN - 33) {
|
---|
| 308 | fatal_error
|
---|
| 309 | ("Your PATH environmental variable is too long. Please shorten it.");
|
---|
| 310 | }
|
---|
| 311 | strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
|
---|
| 312 | setenv("PATH", tmp, 1);
|
---|
[1] | 313 |
|
---|
[807] | 314 | /* Add the ARCH environment variable for ia64 purposes */
|
---|
[128] | 315 | strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
|
---|
| 316 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
| 317 | setenv("ARCH", tmp, 1);
|
---|
[1] | 318 |
|
---|
[424] | 319 | /* Add MONDO_SHARE environment variable for mindi */
|
---|
| 320 | setenv_mondo_share();
|
---|
[258] | 321 |
|
---|
[807] | 322 | /* Configure the bkpinfo structure, global file paths, etc. */
|
---|
[128] | 323 | g_main_pid = getpid();
|
---|
| 324 | log_msg(9, "This");
|
---|
[1] | 325 |
|
---|
[128] | 326 | register_pid(g_main_pid, "mondo");
|
---|
| 327 | set_signals(TRUE); // catch SIGTERM, etc.
|
---|
| 328 | run_program_and_log_output("dmesg -n1", TRUE);
|
---|
[1] | 329 |
|
---|
[128] | 330 | log_msg(9, "Next");
|
---|
| 331 | welcome_to_mondoarchive();
|
---|
| 332 | distro_specific_kludges_at_start_of_mondoarchive();
|
---|
| 333 | g_kernel_version = get_kernel_version();
|
---|
[1] | 334 |
|
---|
[128] | 335 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
---|
| 336 | g_loglevel = 10;
|
---|
| 337 | g_text_mode = TRUE;
|
---|
| 338 | setup_newt_stuff();
|
---|
| 339 | if (!strstr(argv[2], "filelist")) {
|
---|
[541] | 340 | printf("Sorry - filelist goes first\n");
|
---|
[128] | 341 | finish(1);
|
---|
| 342 | } else {
|
---|
| 343 | finish(get_fattr_list(argv[2], argv[3]));
|
---|
| 344 | }
|
---|
| 345 | finish(0);
|
---|
[1] | 346 | }
|
---|
[128] | 347 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
---|
| 348 | g_loglevel = 10;
|
---|
[1] | 349 | // chdir("/tmp");
|
---|
[128] | 350 | g_text_mode = TRUE;
|
---|
| 351 | setup_newt_stuff();
|
---|
| 352 | finish(set_fattr_list(argv[2], argv[3]));
|
---|
[1] | 353 | }
|
---|
[128] | 354 |
|
---|
| 355 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
---|
| 356 | g_loglevel = 10;
|
---|
| 357 | g_text_mode = TRUE;
|
---|
| 358 | setup_newt_stuff();
|
---|
| 359 | turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
|
---|
| 360 | printf("in=%s; out=%s\n", argv[2], tmp);
|
---|
| 361 | finish(1);
|
---|
[1] | 362 | }
|
---|
[128] | 363 |
|
---|
| 364 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
---|
| 365 | g_loglevel = 10;
|
---|
| 366 | g_text_mode = TRUE;
|
---|
| 367 | setup_newt_stuff();
|
---|
| 368 | if (!strstr(argv[2], "filelist")) {
|
---|
[541] | 369 | printf("Sorry - filelist goes first\n");
|
---|
[128] | 370 | finish(1);
|
---|
| 371 | } else {
|
---|
| 372 | finish(get_acl_list(argv[2], argv[3]));
|
---|
| 373 | }
|
---|
| 374 | finish(0);
|
---|
| 375 | }
|
---|
| 376 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
---|
| 377 | g_loglevel = 10;
|
---|
[1] | 378 | // chdir("/tmp");
|
---|
[128] | 379 | g_text_mode = TRUE;
|
---|
| 380 | setup_newt_stuff();
|
---|
| 381 | finish(set_acl_list(argv[2], argv[3]));
|
---|
| 382 | }
|
---|
[1] | 383 |
|
---|
[128] | 384 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
---|
| 385 | g_loglevel = 10;
|
---|
| 386 | g_text_mode = TRUE;
|
---|
| 387 | setup_newt_stuff();
|
---|
| 388 | if (find_cdrw_device(tmp)) {
|
---|
[541] | 389 | printf("Failed to find CDR-RW drive\n");
|
---|
[128] | 390 | } else {
|
---|
[541] | 391 | printf("CD-RW is at %s\n", tmp);
|
---|
[128] | 392 | }
|
---|
| 393 | tmp[0] = '\0';
|
---|
| 394 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
---|
[541] | 395 | printf("Failed to find CD-ROM drive\n");
|
---|
[128] | 396 | } else {
|
---|
[541] | 397 | printf("CD-ROM is at %s\n", tmp);
|
---|
[128] | 398 | }
|
---|
| 399 | finish(0);
|
---|
| 400 | }
|
---|
[1] | 401 |
|
---|
[128] | 402 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
---|
| 403 | g_loglevel = 10;
|
---|
| 404 | g_text_mode = TRUE;
|
---|
| 405 | setup_newt_stuff();
|
---|
| 406 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
---|
[541] | 407 | printf("Failed to find DVD drive\n");
|
---|
[128] | 408 | } else {
|
---|
[541] | 409 | printf("DVD is at %s\n", tmp);
|
---|
[128] | 410 | }
|
---|
| 411 | finish(0);
|
---|
| 412 | }
|
---|
[1] | 413 |
|
---|
[128] | 414 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
---|
| 415 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
---|
| 416 | finish(0);
|
---|
| 417 | }
|
---|
| 418 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
---|
| 419 | if (is_dev_an_NTFS_dev(argv[2])) {
|
---|
[541] | 420 | printf("%s is indeed an NTFS dev\n", argv[2]);
|
---|
[128] | 421 | } else {
|
---|
[541] | 422 | printf("%s is _not_ an NTFS dev\n", argv[2]);
|
---|
[128] | 423 | }
|
---|
| 424 | finish(0);
|
---|
| 425 | }
|
---|
| 426 |
|
---|
[1645] | 427 | if (pre_param_configuration()) {
|
---|
[128] | 428 | fatal_error
|
---|
| 429 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
---|
| 430 | }
|
---|
| 431 |
|
---|
[1] | 432 | /* Process command line, if there is one. If not, ask user for info. */
|
---|
[128] | 433 | if (argc == 1) {
|
---|
| 434 | g_text_mode = FALSE;
|
---|
| 435 | setup_newt_stuff();
|
---|
[1645] | 436 | res = interactively_obtain_media_parameters_from_user(TRUE); /* yes, archiving */
|
---|
[128] | 437 | if (res) {
|
---|
| 438 | fatal_error
|
---|
| 439 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
---|
| 440 | }
|
---|
| 441 | } else {
|
---|
[1645] | 442 | res = handle_incoming_parameters(argc, argv);
|
---|
[128] | 443 | if (res) {
|
---|
| 444 | printf
|
---|
[541] | 445 | ("Errors were detected in the command line you supplied.\n");
|
---|
[1319] | 446 | printf("Please review the log file - %s\n", MONDO_LOGFILE );
|
---|
[128] | 447 | log_msg(1, "Mondoarchive will now exit.");
|
---|
| 448 | finish(1);
|
---|
| 449 | }
|
---|
| 450 | setup_newt_stuff();
|
---|
[1] | 451 | }
|
---|
| 452 |
|
---|
| 453 | /* Finish configuring global structures */
|
---|
[1645] | 454 | if (post_param_configuration()) {
|
---|
[128] | 455 | fatal_error
|
---|
| 456 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
---|
| 457 | }
|
---|
[1] | 458 |
|
---|
[128] | 459 | log_to_screen
|
---|
[541] | 460 | ("BusyBox's sources are available from http://www.busybox.net");
|
---|
[128] | 461 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
---|
| 462 | bkpinfo->scratchdir);
|
---|
[1] | 463 |
|
---|
[128] | 464 | /* If we're meant to backup then backup */
|
---|
| 465 | if (bkpinfo->backup_data) {
|
---|
[1645] | 466 | res = backup_data();
|
---|
[128] | 467 | retval += res;
|
---|
| 468 | if (res) {
|
---|
| 469 | strcat(say_at_end,
|
---|
[541] | 470 | "Data archived. Please check the logs, just as a precaution. ");
|
---|
[128] | 471 | } else {
|
---|
[541] | 472 | strcat(say_at_end, "Data archived OK. ");
|
---|
[128] | 473 | }
|
---|
| 474 | }
|
---|
[1] | 475 |
|
---|
| 476 | /* If we're meant to verify then verify */
|
---|
[128] | 477 | if (bkpinfo->verify_data) {
|
---|
[1645] | 478 | res = verify_data();
|
---|
[128] | 479 | if (res < 0) {
|
---|
[541] | 480 | sprintf(tmp, "%d difference%c found.", -res,
|
---|
[128] | 481 | (-res != 1) ? 's' : ' ');
|
---|
| 482 | strcat(say_at_end, tmp);
|
---|
| 483 | log_to_screen(tmp);
|
---|
| 484 | res = 0;
|
---|
| 485 | }
|
---|
| 486 | retval += res;
|
---|
| 487 | }
|
---|
[1] | 488 |
|
---|
| 489 | /* Offer to write floppy disk images to physical disks */
|
---|
[128] | 490 | if (bkpinfo->backup_data && !g_skip_floppies) {
|
---|
[1645] | 491 | res = offer_to_write_boot_floppies_to_physical_disks();
|
---|
[128] | 492 | retval += res;
|
---|
[1645] | 493 | // res = offer_to_write_boot_ISO_to_physical_CD();
|
---|
[1] | 494 | // retval += res;
|
---|
[128] | 495 | }
|
---|
[1] | 496 |
|
---|
| 497 | /* Report result of entire operation (success? errors?) */
|
---|
[128] | 498 | if (!retval) {
|
---|
| 499 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[541] | 500 | "Backup and/or verify ran to completion. Everything appears to be fine.");
|
---|
[128] | 501 | } else {
|
---|
| 502 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[541] | 503 | "Backup and/or verify ran to completion. However, errors did occur.");
|
---|
[128] | 504 | }
|
---|
[1] | 505 |
|
---|
[1437] | 506 | if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
|
---|
[128] | 507 | log_to_screen
|
---|
[1437] | 508 | (MINDI_CACHE"/mondorescue.iso, a boot/utility CD, is available if you want it.");
|
---|
[128] | 509 | }
|
---|
[1] | 510 |
|
---|
[1644] | 511 | if (length_of_file(MINDI_CACHE"/changed.files") > 2) {
|
---|
[128] | 512 | if (g_text_mode) {
|
---|
[1644] | 513 | log_to_screen("Type 'less "MINDI_CACHE"/changed.files' to see which files don't match the archives");
|
---|
[128] | 514 | } else {
|
---|
[1644] | 515 | log_msg(1, "Type 'less "MINDI_CACHE"/changed.files' to see which files don't match the archives");
|
---|
[128] | 516 | log_msg(2, "Calling popup_changelist_from_file()");
|
---|
[1644] | 517 | popup_changelist_from_file(MINDI_CACHE"/changed.files");
|
---|
[128] | 518 | log_msg(2, "Returned from popup_changelist_from_file()");
|
---|
| 519 | }
|
---|
| 520 | } else {
|
---|
[1644] | 521 | unlink(MINDI_CACHE"/changed.files");
|
---|
[128] | 522 | }
|
---|
| 523 | log_to_screen(say_at_end);
|
---|
| 524 | sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 525 | run_program_and_log_output(tmp, TRUE);
|
---|
[1697] | 526 | if (bkpinfo->backup_media_type == usb) {
|
---|
| 527 | log_msg(1, "Unmounting USB device.");
|
---|
| 528 | sprintf(tmp, "umount %s1", bkpinfo->media_device);
|
---|
| 529 | run_program_and_log_output(tmp, TRUE);
|
---|
| 530 | }
|
---|
[128] | 531 | run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
|
---|
[1] | 532 |
|
---|
[128] | 533 | run_program_and_log_output("mount", 2);
|
---|
[1] | 534 |
|
---|
[128] | 535 | system("rm -f /var/cache/mondo-archive/last-backup.aborted");
|
---|
| 536 | if (!retval) {
|
---|
[541] | 537 | printf("Mondoarchive ran OK.\n");
|
---|
[128] | 538 | } else {
|
---|
[541] | 539 | printf("Errors occurred during backup. Please check logfile.\n");
|
---|
[128] | 540 | }
|
---|
| 541 | distro_specific_kludges_at_end_of_mondoarchive();
|
---|
| 542 | register_pid(0, "mondo");
|
---|
| 543 | set_signals(FALSE);
|
---|
| 544 | chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir
|
---|
| 545 | system(g_erase_tmpdir_and_scratchdir);
|
---|
[1644] | 546 |
|
---|
[1659] | 547 | /* assemble command string for deletion of Mondo's tmp directory */
|
---|
[1644] | 548 | sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
|
---|
| 549 |
|
---|
[128] | 550 | free_libmondo_global_strings();
|
---|
| 551 | paranoid_free(say_at_end);
|
---|
| 552 | paranoid_free(bkpinfo);
|
---|
[1] | 553 |
|
---|
[128] | 554 | if (!g_cdrom_drive_is_here) {
|
---|
| 555 | log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
---|
| 556 | }
|
---|
| 557 | if (!g_dvd_drive_is_here) {
|
---|
| 558 | log_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
---|
| 559 | }
|
---|
[1] | 560 |
|
---|
[810] | 561 | /* finalize log file with time stamp */
|
---|
[813] | 562 | log_msg(0, "Time finished: %s", mr_date());
|
---|
[810] | 563 |
|
---|
[1644] | 564 | /* remove Mondo's tmp directory */
|
---|
| 565 | system(tmp);
|
---|
| 566 | paranoid_free(tmp);
|
---|
| 567 |
|
---|
[128] | 568 | if (!g_text_mode) {
|
---|
| 569 | popup_and_OK
|
---|
[541] | 570 | ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
|
---|
| 571 | log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
|
---|
[128] | 572 | finish(retval);
|
---|
| 573 | } else {
|
---|
[541] | 574 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
[128] | 575 | exit(retval);
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 | return EXIT_SUCCESS;
|
---|
[1] | 579 | }
|
---|