[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 1736 2007-10-30 00:45:03Z 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 1736 2007-10-30 00:45:03Z 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;
|
---|
[1736] | 132 | extern bool g_remount_floppy_at_end;
|
---|
[1] | 133 | extern char *g_tmpfs_mountpt;
|
---|
| 134 | extern char *g_cdrw_drive_is_here;
|
---|
[128] | 135 | static char *g_cdrom_drive_is_here = NULL;
|
---|
| 136 | static char *g_dvd_drive_is_here = NULL;
|
---|
[1] | 137 | extern double g_kernel_version;
|
---|
| 138 |
|
---|
| 139 | /***************** global vars, used only by main.c ******************/
|
---|
| 140 | bool g_skip_floppies;
|
---|
| 141 | long diffs;
|
---|
| 142 |
|
---|
| 143 | extern t_bkptype g_backup_media_type;
|
---|
| 144 | extern int g_loglevel;
|
---|
| 145 |
|
---|
[1645] | 146 | /* Reference to global bkpinfo */
|
---|
| 147 | struct s_bkpinfo *bkpinfo;
|
---|
| 148 |
|
---|
[1] | 149 | /****************** subroutines used only by main.c ******************/
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | /**
|
---|
| 153 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
---|
| 154 | */
|
---|
[1236] | 155 | void welcome_to_mondoarchive(void)
|
---|
[1] | 156 | {
|
---|
[1375] | 157 | char *tmp = NULL;
|
---|
| 158 |
|
---|
[128] | 159 | log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
|
---|
[251] | 160 | PACKAGE_VERSION);
|
---|
[1375] | 161 | log_msg(0, "running %s binaries", get_architecture());
|
---|
| 162 | tmp = get_uname_m();
|
---|
| 163 | log_msg(0, "running on %s architecture", tmp);
|
---|
[1381] | 164 | free(tmp);
|
---|
[128] | 165 | log_msg(0,
|
---|
| 166 | "-----------------------------------------------------------");
|
---|
| 167 | log_msg(0,
|
---|
| 168 | "NB: Mondo logs almost everything, so don't panic if you see");
|
---|
| 169 | log_msg(0,
|
---|
| 170 | "some error messages. Please read them carefully before you");
|
---|
| 171 | log_msg(0,
|
---|
| 172 | "decide to break out in a cold sweat. Despite (or perhaps");
|
---|
| 173 | log_msg(0,
|
---|
| 174 | "because of) the wealth of messages. some users are inclined");
|
---|
| 175 | log_msg(0,
|
---|
| 176 | "to stop reading this log. If Mondo stopped for some reason,");
|
---|
| 177 | log_msg(0,
|
---|
| 178 | "chances are it's detailed here. More than likely there's a");
|
---|
| 179 | log_msg(0,
|
---|
| 180 | "message at the very end of this log that will tell you what");
|
---|
| 181 | log_msg(0,
|
---|
| 182 | "is wrong. Please read it! -Devteam");
|
---|
| 183 | log_msg(0,
|
---|
| 184 | "-----------------------------------------------------------");
|
---|
[1] | 185 |
|
---|
[128] | 186 | log_msg(0, "Zero...");
|
---|
| 187 | log_msg(1, "One...");
|
---|
| 188 | log_msg(2, "Two...");
|
---|
| 189 | log_msg(3, "Three...");
|
---|
| 190 | log_msg(4, "Four...");
|
---|
| 191 | log_msg(5, "Five...");
|
---|
| 192 | log_msg(6, "Six...");
|
---|
| 193 | log_msg(7, "Seven...");
|
---|
| 194 | log_msg(8, "Eight...");
|
---|
| 195 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
[1] | 196 | }
|
---|
| 197 |
|
---|
| 198 |
|
---|
| 199 | extern char *g_magicdev_command;
|
---|
| 200 |
|
---|
| 201 | /**
|
---|
| 202 | * Do whatever is necessary to insure a successful backup on the Linux distribution
|
---|
| 203 | * of the day.
|
---|
| 204 | */
|
---|
[1236] | 205 | void distro_specific_kludges_at_start_of_mondoarchive(void)
|
---|
[1] | 206 | {
|
---|
[128] | 207 | log_msg(2, "Unmounting old ramdisks if necessary");
|
---|
| 208 | stop_magicdev_if_necessary(); // for RH+Gnome users
|
---|
| 209 | run_program_and_log_output
|
---|
| 210 | ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
|
---|
| 211 | unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
|
---|
| 212 | // stop_autofs_if_necessary(); // for Xandros users
|
---|
| 213 | mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
|
---|
| 214 | clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
|
---|
[1] | 215 | }
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | /**
|
---|
| 220 | * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
|
---|
| 221 | */
|
---|
[1236] | 222 | void distro_specific_kludges_at_end_of_mondoarchive(void)
|
---|
[1] | 223 | {
|
---|
| 224 | // char tmp[500];
|
---|
[128] | 225 | log_msg(2, "Restarting magicdev if necessary");
|
---|
| 226 | sync();
|
---|
| 227 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
---|
[1] | 228 |
|
---|
[128] | 229 | log_msg(2, "Restarting autofs if necessary");
|
---|
| 230 | sync();
|
---|
| 231 | // restart_autofs_if_necessary(); // for Xandros users
|
---|
[1] | 232 |
|
---|
[128] | 233 | log_msg(2, "Restarting supermounts if necessary");
|
---|
| 234 | sync();
|
---|
| 235 | remount_supermounts_if_necessary(); // for Mandrake users
|
---|
[1] | 236 |
|
---|
[128] | 237 | log_msg(2, "Unmounting /boot if necessary");
|
---|
| 238 | sync();
|
---|
| 239 | unmount_boot_if_necessary(); // for Gentoo users
|
---|
[1] | 240 |
|
---|
| 241 | // log_msg( 2, "Cleaning up KDE desktop");
|
---|
| 242 | // clean_up_KDE_desktop_if_necessary();
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[813] | 245 | /* Return a string containing the date */
|
---|
| 246 | char *mr_date(void) {
|
---|
| 247 |
|
---|
| 248 | time_t tcurr;
|
---|
[1] | 249 |
|
---|
[813] | 250 | tcurr = time(NULL);
|
---|
| 251 | return(ctime(&tcurr));
|
---|
| 252 | }
|
---|
| 253 |
|
---|
[1] | 254 | /*-----------------------------------------------------------*/
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 | /**
|
---|
| 259 | * Backup/verify the user's data.
|
---|
| 260 | * What did you think it did, anyway? :-)
|
---|
| 261 | */
|
---|
[128] | 262 | int main(int argc, char *argv[])
|
---|
[1] | 263 | {
|
---|
[128] | 264 | char *tmp;
|
---|
| 265 | int res, retval;
|
---|
| 266 | char *say_at_end;
|
---|
[1] | 267 |
|
---|
| 268 | /* Make sure I'm root; abort if not */
|
---|
[128] | 269 | if (getuid() != 0) {
|
---|
[541] | 270 | fprintf(stderr, "Please run as root.\r\n");
|
---|
[128] | 271 | exit(127);
|
---|
| 272 | }
|
---|
[1] | 273 |
|
---|
| 274 | /* If -V, -v or --version then echo version no. and quit */
|
---|
[128] | 275 | if (argc == 2
|
---|
| 276 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
---|
| 277 | || !strcmp(argv[argc - 1], "--version"))) {
|
---|
[541] | 278 | printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
|
---|
[128] | 279 | exit(0);
|
---|
| 280 | }
|
---|
[1] | 281 |
|
---|
| 282 | /* Initialize variables */
|
---|
| 283 |
|
---|
[1652] | 284 | printf("Initializing...\n");
|
---|
| 285 | if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
|
---|
| 286 | fatal_error("Cannot malloc bkpinfo");
|
---|
| 287 | }
|
---|
| 288 | reset_bkpinfo();
|
---|
[1] | 289 |
|
---|
[128] | 290 | res = 0;
|
---|
| 291 | retval = 0;
|
---|
| 292 | diffs = 0;
|
---|
[1652] | 293 | malloc_string(tmp);
|
---|
| 294 | malloc_string(say_at_end);
|
---|
[128] | 295 | say_at_end[0] = '\0';
|
---|
[1652] | 296 | malloc_libmondo_global_strings();
|
---|
[1] | 297 |
|
---|
[810] | 298 | /* initialize log file with time stamp */
|
---|
| 299 | unlink(MONDO_LOGFILE);
|
---|
[813] | 300 | log_msg(0, "Time started: %s", mr_date());
|
---|
[1] | 301 |
|
---|
[807] | 302 | /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
|
---|
[128] | 303 | strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
|
---|
| 304 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
| 305 | if (strlen(tmp) >= MAX_STR_LEN - 33) {
|
---|
| 306 | fatal_error
|
---|
| 307 | ("Your PATH environmental variable is too long. Please shorten it.");
|
---|
| 308 | }
|
---|
| 309 | strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
|
---|
| 310 | setenv("PATH", tmp, 1);
|
---|
[1] | 311 |
|
---|
[807] | 312 | /* Add the ARCH environment variable for ia64 purposes */
|
---|
[128] | 313 | strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
|
---|
| 314 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
| 315 | setenv("ARCH", tmp, 1);
|
---|
[1] | 316 |
|
---|
[424] | 317 | /* Add MONDO_SHARE environment variable for mindi */
|
---|
| 318 | setenv_mondo_share();
|
---|
[258] | 319 |
|
---|
[807] | 320 | /* Configure the bkpinfo structure, global file paths, etc. */
|
---|
[128] | 321 | g_main_pid = getpid();
|
---|
| 322 | log_msg(9, "This");
|
---|
[1] | 323 |
|
---|
[128] | 324 | register_pid(g_main_pid, "mondo");
|
---|
| 325 | set_signals(TRUE); // catch SIGTERM, etc.
|
---|
| 326 | run_program_and_log_output("dmesg -n1", TRUE);
|
---|
[1] | 327 |
|
---|
[128] | 328 | log_msg(9, "Next");
|
---|
| 329 | welcome_to_mondoarchive();
|
---|
| 330 | distro_specific_kludges_at_start_of_mondoarchive();
|
---|
| 331 | g_kernel_version = get_kernel_version();
|
---|
[1] | 332 |
|
---|
[128] | 333 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
---|
| 334 | g_loglevel = 10;
|
---|
| 335 | g_text_mode = TRUE;
|
---|
| 336 | setup_newt_stuff();
|
---|
| 337 | if (!strstr(argv[2], "filelist")) {
|
---|
[541] | 338 | printf("Sorry - filelist goes first\n");
|
---|
[128] | 339 | finish(1);
|
---|
| 340 | } else {
|
---|
| 341 | finish(get_fattr_list(argv[2], argv[3]));
|
---|
| 342 | }
|
---|
| 343 | finish(0);
|
---|
[1] | 344 | }
|
---|
[128] | 345 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
---|
| 346 | g_loglevel = 10;
|
---|
[1] | 347 | // chdir("/tmp");
|
---|
[128] | 348 | g_text_mode = TRUE;
|
---|
| 349 | setup_newt_stuff();
|
---|
| 350 | finish(set_fattr_list(argv[2], argv[3]));
|
---|
[1] | 351 | }
|
---|
[128] | 352 |
|
---|
| 353 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
---|
| 354 | g_loglevel = 10;
|
---|
| 355 | g_text_mode = TRUE;
|
---|
| 356 | setup_newt_stuff();
|
---|
| 357 | turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
|
---|
| 358 | printf("in=%s; out=%s\n", argv[2], tmp);
|
---|
| 359 | finish(1);
|
---|
[1] | 360 | }
|
---|
[128] | 361 |
|
---|
| 362 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
---|
| 363 | g_loglevel = 10;
|
---|
| 364 | g_text_mode = TRUE;
|
---|
| 365 | setup_newt_stuff();
|
---|
| 366 | if (!strstr(argv[2], "filelist")) {
|
---|
[541] | 367 | printf("Sorry - filelist goes first\n");
|
---|
[128] | 368 | finish(1);
|
---|
| 369 | } else {
|
---|
| 370 | finish(get_acl_list(argv[2], argv[3]));
|
---|
| 371 | }
|
---|
| 372 | finish(0);
|
---|
| 373 | }
|
---|
| 374 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
---|
| 375 | g_loglevel = 10;
|
---|
[1] | 376 | // chdir("/tmp");
|
---|
[128] | 377 | g_text_mode = TRUE;
|
---|
| 378 | setup_newt_stuff();
|
---|
| 379 | finish(set_acl_list(argv[2], argv[3]));
|
---|
| 380 | }
|
---|
[1] | 381 |
|
---|
[128] | 382 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
---|
| 383 | g_loglevel = 10;
|
---|
| 384 | g_text_mode = TRUE;
|
---|
| 385 | setup_newt_stuff();
|
---|
| 386 | if (find_cdrw_device(tmp)) {
|
---|
[541] | 387 | printf("Failed to find CDR-RW drive\n");
|
---|
[128] | 388 | } else {
|
---|
[541] | 389 | printf("CD-RW is at %s\n", tmp);
|
---|
[128] | 390 | }
|
---|
| 391 | tmp[0] = '\0';
|
---|
| 392 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
---|
[541] | 393 | printf("Failed to find CD-ROM drive\n");
|
---|
[128] | 394 | } else {
|
---|
[541] | 395 | printf("CD-ROM is at %s\n", tmp);
|
---|
[128] | 396 | }
|
---|
| 397 | finish(0);
|
---|
| 398 | }
|
---|
[1] | 399 |
|
---|
[128] | 400 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
---|
| 401 | g_loglevel = 10;
|
---|
| 402 | g_text_mode = TRUE;
|
---|
| 403 | setup_newt_stuff();
|
---|
| 404 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
---|
[541] | 405 | printf("Failed to find DVD drive\n");
|
---|
[128] | 406 | } else {
|
---|
[541] | 407 | printf("DVD is at %s\n", tmp);
|
---|
[128] | 408 | }
|
---|
| 409 | finish(0);
|
---|
| 410 | }
|
---|
[1] | 411 |
|
---|
[128] | 412 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
---|
| 413 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
---|
| 414 | finish(0);
|
---|
| 415 | }
|
---|
| 416 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
---|
| 417 | if (is_dev_an_NTFS_dev(argv[2])) {
|
---|
[541] | 418 | printf("%s is indeed an NTFS dev\n", argv[2]);
|
---|
[128] | 419 | } else {
|
---|
[541] | 420 | printf("%s is _not_ an NTFS dev\n", argv[2]);
|
---|
[128] | 421 | }
|
---|
| 422 | finish(0);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[1645] | 425 | if (pre_param_configuration()) {
|
---|
[128] | 426 | fatal_error
|
---|
| 427 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
---|
| 428 | }
|
---|
| 429 |
|
---|
[1] | 430 | /* Process command line, if there is one. If not, ask user for info. */
|
---|
[128] | 431 | if (argc == 1) {
|
---|
| 432 | g_text_mode = FALSE;
|
---|
| 433 | setup_newt_stuff();
|
---|
[1645] | 434 | res = interactively_obtain_media_parameters_from_user(TRUE); /* yes, archiving */
|
---|
[128] | 435 | if (res) {
|
---|
| 436 | fatal_error
|
---|
| 437 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
---|
| 438 | }
|
---|
| 439 | } else {
|
---|
[1645] | 440 | res = handle_incoming_parameters(argc, argv);
|
---|
[128] | 441 | if (res) {
|
---|
| 442 | printf
|
---|
[541] | 443 | ("Errors were detected in the command line you supplied.\n");
|
---|
[1319] | 444 | printf("Please review the log file - %s\n", MONDO_LOGFILE );
|
---|
[128] | 445 | log_msg(1, "Mondoarchive will now exit.");
|
---|
| 446 | finish(1);
|
---|
| 447 | }
|
---|
| 448 | setup_newt_stuff();
|
---|
[1] | 449 | }
|
---|
| 450 |
|
---|
| 451 | /* Finish configuring global structures */
|
---|
[1645] | 452 | if (post_param_configuration()) {
|
---|
[128] | 453 | fatal_error
|
---|
| 454 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
---|
| 455 | }
|
---|
[1] | 456 |
|
---|
[128] | 457 | log_to_screen
|
---|
[541] | 458 | ("BusyBox's sources are available from http://www.busybox.net");
|
---|
[1] | 459 |
|
---|
[128] | 460 | /* If we're meant to backup then backup */
|
---|
| 461 | if (bkpinfo->backup_data) {
|
---|
[1645] | 462 | res = backup_data();
|
---|
[128] | 463 | retval += res;
|
---|
| 464 | if (res) {
|
---|
| 465 | strcat(say_at_end,
|
---|
[541] | 466 | "Data archived. Please check the logs, just as a precaution. ");
|
---|
[128] | 467 | } else {
|
---|
[541] | 468 | strcat(say_at_end, "Data archived OK. ");
|
---|
[128] | 469 | }
|
---|
| 470 | }
|
---|
[1] | 471 |
|
---|
| 472 | /* If we're meant to verify then verify */
|
---|
[128] | 473 | if (bkpinfo->verify_data) {
|
---|
[1645] | 474 | res = verify_data();
|
---|
[128] | 475 | if (res < 0) {
|
---|
[541] | 476 | sprintf(tmp, "%d difference%c found.", -res,
|
---|
[128] | 477 | (-res != 1) ? 's' : ' ');
|
---|
| 478 | strcat(say_at_end, tmp);
|
---|
| 479 | log_to_screen(tmp);
|
---|
| 480 | res = 0;
|
---|
| 481 | }
|
---|
| 482 | retval += res;
|
---|
| 483 | }
|
---|
[1] | 484 |
|
---|
| 485 | /* Offer to write floppy disk images to physical disks */
|
---|
[128] | 486 | if (bkpinfo->backup_data && !g_skip_floppies) {
|
---|
[1645] | 487 | res = offer_to_write_boot_floppies_to_physical_disks();
|
---|
[128] | 488 | retval += res;
|
---|
[1645] | 489 | // res = offer_to_write_boot_ISO_to_physical_CD();
|
---|
[1] | 490 | // retval += res;
|
---|
[128] | 491 | }
|
---|
[1] | 492 |
|
---|
| 493 | /* Report result of entire operation (success? errors?) */
|
---|
[128] | 494 | if (!retval) {
|
---|
| 495 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[541] | 496 | "Backup and/or verify ran to completion. Everything appears to be fine.");
|
---|
[128] | 497 | } else {
|
---|
| 498 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[541] | 499 | "Backup and/or verify ran to completion. However, errors did occur.");
|
---|
[128] | 500 | }
|
---|
[1] | 501 |
|
---|
[1437] | 502 | if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
|
---|
[128] | 503 | log_to_screen
|
---|
[1437] | 504 | (MINDI_CACHE"/mondorescue.iso, a boot/utility CD, is available if you want it.");
|
---|
[128] | 505 | }
|
---|
[1] | 506 |
|
---|
[1644] | 507 | if (length_of_file(MINDI_CACHE"/changed.files") > 2) {
|
---|
[128] | 508 | if (g_text_mode) {
|
---|
[1644] | 509 | log_to_screen("Type 'less "MINDI_CACHE"/changed.files' to see which files don't match the archives");
|
---|
[128] | 510 | } else {
|
---|
[1644] | 511 | log_msg(1, "Type 'less "MINDI_CACHE"/changed.files' to see which files don't match the archives");
|
---|
[128] | 512 | log_msg(2, "Calling popup_changelist_from_file()");
|
---|
[1644] | 513 | popup_changelist_from_file(MINDI_CACHE"/changed.files");
|
---|
[128] | 514 | log_msg(2, "Returned from popup_changelist_from_file()");
|
---|
| 515 | }
|
---|
| 516 | } else {
|
---|
[1644] | 517 | unlink(MINDI_CACHE"/changed.files");
|
---|
[128] | 518 | }
|
---|
| 519 | log_to_screen(say_at_end);
|
---|
| 520 | sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 521 | run_program_and_log_output(tmp, TRUE);
|
---|
[1697] | 522 | if (bkpinfo->backup_media_type == usb) {
|
---|
| 523 | log_msg(1, "Unmounting USB device.");
|
---|
| 524 | sprintf(tmp, "umount %s1", bkpinfo->media_device);
|
---|
| 525 | run_program_and_log_output(tmp, TRUE);
|
---|
| 526 | }
|
---|
[1] | 527 |
|
---|
[128] | 528 | run_program_and_log_output("mount", 2);
|
---|
[1] | 529 |
|
---|
[128] | 530 | system("rm -f /var/cache/mondo-archive/last-backup.aborted");
|
---|
| 531 | if (!retval) {
|
---|
[541] | 532 | printf("Mondoarchive ran OK.\n");
|
---|
[128] | 533 | } else {
|
---|
[541] | 534 | printf("Errors occurred during backup. Please check logfile.\n");
|
---|
[128] | 535 | }
|
---|
| 536 | distro_specific_kludges_at_end_of_mondoarchive();
|
---|
| 537 | register_pid(0, "mondo");
|
---|
| 538 | set_signals(FALSE);
|
---|
[1644] | 539 |
|
---|
[128] | 540 | free_libmondo_global_strings();
|
---|
| 541 | paranoid_free(say_at_end);
|
---|
[1703] | 542 |
|
---|
[1] | 543 |
|
---|
[128] | 544 | if (!g_cdrom_drive_is_here) {
|
---|
| 545 | log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
---|
| 546 | }
|
---|
| 547 | if (!g_dvd_drive_is_here) {
|
---|
| 548 | log_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
---|
| 549 | }
|
---|
[1] | 550 |
|
---|
[810] | 551 | /* finalize log file with time stamp */
|
---|
[813] | 552 | log_msg(0, "Time finished: %s", mr_date());
|
---|
[810] | 553 |
|
---|
[1708] | 554 | chdir("/tmp");
|
---|
[1644] | 555 |
|
---|
[128] | 556 | if (!g_text_mode) {
|
---|
| 557 | popup_and_OK
|
---|
[541] | 558 | ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
|
---|
| 559 | log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
|
---|
[128] | 560 | } else {
|
---|
[541] | 561 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
[128] | 562 | }
|
---|
[1703] | 563 | finish(retval);
|
---|
[128] | 564 |
|
---|
| 565 | return EXIT_SUCCESS;
|
---|
[1] | 566 | }
|
---|