[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
|
---|
[59] | 7 | cvsid : $Id: main.c 87 2005-10-27 20:03:00Z bcornec $
|
---|
[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"
|
---|
| 119 |
|
---|
| 120 | #ifndef VERSION
|
---|
| 121 | #define VERSION AUX_VER
|
---|
| 122 | #endif
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | char g_version[] = VERSION;
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | // for CVS
|
---|
[59] | 129 | //static char cvsid[] = "$Id: main.c 87 2005-10-27 20:03:00Z bcornec $";
|
---|
[1] | 130 |
|
---|
| 131 | /************************* external variables *************************/
|
---|
| 132 | extern void set_signals(int);
|
---|
| 133 | extern int g_current_media_number;
|
---|
[59] | 134 | extern void register_pid(pid_t, char *);
|
---|
[1] | 135 | extern int g_currentY;
|
---|
| 136 | extern bool g_text_mode;
|
---|
| 137 | extern char *g_boot_mountpt;
|
---|
| 138 | extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
|
---|
| 139 | extern char *g_mondo_home;
|
---|
| 140 | extern char *g_tmpfs_mountpt;
|
---|
| 141 | extern char *g_erase_tmpdir_and_scratchdir;
|
---|
| 142 | extern char *g_cdrw_drive_is_here;
|
---|
[59] | 143 | static char *g_cdrom_drive_is_here = NULL;
|
---|
| 144 | static char *g_dvd_drive_is_here = NULL;
|
---|
[1] | 145 | extern double g_kernel_version;
|
---|
| 146 |
|
---|
| 147 | /***************** global vars, used only by main.c ******************/
|
---|
| 148 | bool g_skip_floppies;
|
---|
| 149 | long diffs;
|
---|
| 150 |
|
---|
| 151 | extern t_bkptype g_backup_media_type;
|
---|
| 152 | extern int g_loglevel;
|
---|
| 153 |
|
---|
| 154 | /****************** subroutines used only by main.c ******************/
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | /**
|
---|
| 158 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
---|
| 159 | */
|
---|
| 160 | void welcome_to_mondoarchive()
|
---|
| 161 | {
|
---|
[59] | 162 | log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
|
---|
| 163 | VERSION);
|
---|
| 164 | log_msg(0, "running on %s architecture", get_architecture());
|
---|
| 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 |
|
---|
[59] | 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 | */
|
---|
| 205 | void distro_specific_kludges_at_start_of_mondoarchive()
|
---|
| 206 | {
|
---|
[59] | 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 | */
|
---|
| 222 | void distro_specific_kludges_at_end_of_mondoarchive()
|
---|
| 223 | {
|
---|
| 224 | // char tmp[500];
|
---|
[59] | 225 | log_msg(2, "Restarting magicdev if necessary");
|
---|
| 226 | sync();
|
---|
| 227 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
---|
[1] | 228 |
|
---|
[59] | 229 | log_msg(2, "Restarting autofs if necessary");
|
---|
| 230 | sync();
|
---|
| 231 | // restart_autofs_if_necessary(); // for Xandros users
|
---|
[1] | 232 |
|
---|
[59] | 233 | log_msg(2, "Restarting supermounts if necessary");
|
---|
| 234 | sync();
|
---|
| 235 | remount_supermounts_if_necessary(); // for Mandrake users
|
---|
[1] | 236 |
|
---|
[59] | 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 |
|
---|
| 245 |
|
---|
| 246 | /*-----------------------------------------------------------*/
|
---|
| 247 |
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 | /**
|
---|
| 251 | * Backup/verify the user's data.
|
---|
| 252 | * What did you think it did, anyway? :-)
|
---|
| 253 | */
|
---|
[59] | 254 | int main(int argc, char *argv[])
|
---|
[1] | 255 | {
|
---|
[59] | 256 | struct s_bkpinfo *bkpinfo;
|
---|
| 257 | char *tmp;
|
---|
| 258 | int res, retval;
|
---|
| 259 | char *say_at_end;
|
---|
[1] | 260 |
|
---|
| 261 | /* Make sure I'm root; abort if not */
|
---|
[59] | 262 | if (getuid() != 0) {
|
---|
| 263 | fprintf(stderr, "Please run as root.\r\n");
|
---|
| 264 | exit(127);
|
---|
| 265 | }
|
---|
[1] | 266 |
|
---|
| 267 | /* If -V, -v or --version then echo version no. and quit */
|
---|
[59] | 268 | if (argc == 2
|
---|
| 269 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
---|
| 270 | || !strcmp(argv[argc - 1], "--version"))) {
|
---|
| 271 | printf("mondoarchive v%s\nSee man page for help\n", VERSION);
|
---|
| 272 | exit(0);
|
---|
| 273 | }
|
---|
[1] | 274 |
|
---|
| 275 | /* Initialize variables */
|
---|
| 276 |
|
---|
[59] | 277 | malloc_libmondo_global_strings();
|
---|
| 278 | malloc_string(tmp);
|
---|
| 279 | malloc_string(say_at_end);
|
---|
[1] | 280 |
|
---|
[59] | 281 | res = 0;
|
---|
| 282 | retval = 0;
|
---|
| 283 | diffs = 0;
|
---|
| 284 | say_at_end[0] = '\0';
|
---|
| 285 | unlink("/var/log/partimagehack-debug.log");
|
---|
| 286 | printf("Initializing...\n");
|
---|
| 287 | if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
|
---|
| 288 | fatal_error("Cannot malloc bkpinfo");
|
---|
| 289 | }
|
---|
[1] | 290 |
|
---|
| 291 |
|
---|
| 292 | /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
|
---|
[59] | 293 | strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
|
---|
| 294 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
| 295 | if (strlen(tmp) >= MAX_STR_LEN - 33) {
|
---|
| 296 | fatal_error
|
---|
| 297 | ("Your PATH environmental variable is too long. Please shorten it.");
|
---|
| 298 | }
|
---|
| 299 | strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
|
---|
| 300 | setenv("PATH", tmp, 1);
|
---|
[1] | 301 |
|
---|
| 302 | /* Add the ARCH environment variable for ia64 purposes */
|
---|
[59] | 303 | strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
|
---|
| 304 | tmp[MAX_STR_LEN - 1] = '\0';
|
---|
| 305 | setenv("ARCH", tmp, 1);
|
---|
[1] | 306 |
|
---|
[59] | 307 | unlink(MONDO_LOGFILE);
|
---|
[1] | 308 |
|
---|
| 309 | /* Configure the bkpinfo structure, global file paths, etc. */
|
---|
[59] | 310 | g_main_pid = getpid();
|
---|
| 311 | log_msg(9, "This");
|
---|
[1] | 312 |
|
---|
[59] | 313 | register_pid(g_main_pid, "mondo");
|
---|
| 314 | set_signals(TRUE); // catch SIGTERM, etc.
|
---|
| 315 | nice(10);
|
---|
| 316 | run_program_and_log_output("dmesg -n1", TRUE);
|
---|
[1] | 317 |
|
---|
[59] | 318 | log_msg(9, "Next");
|
---|
| 319 | welcome_to_mondoarchive();
|
---|
| 320 | distro_specific_kludges_at_start_of_mondoarchive();
|
---|
[87] | 321 | // BERLIOS : too early, bkpinfo is not initialized ??
|
---|
| 322 | //sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
|
---|
[59] | 323 | g_kernel_version = get_kernel_version();
|
---|
[1] | 324 |
|
---|
[59] | 325 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
---|
| 326 | g_loglevel = 10;
|
---|
| 327 | g_text_mode = TRUE;
|
---|
| 328 | setup_newt_stuff();
|
---|
| 329 | if (!strstr(argv[2], "filelist")) {
|
---|
| 330 | printf("Sorry - filelist goes first\n");
|
---|
| 331 | finish(1);
|
---|
| 332 | } else {
|
---|
| 333 | finish(get_fattr_list(argv[2], argv[3]));
|
---|
| 334 | }
|
---|
| 335 | finish(0);
|
---|
[1] | 336 | }
|
---|
[59] | 337 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
---|
| 338 | g_loglevel = 10;
|
---|
[1] | 339 | // chdir("/tmp");
|
---|
[59] | 340 | g_text_mode = TRUE;
|
---|
| 341 | setup_newt_stuff();
|
---|
| 342 | finish(set_fattr_list(argv[2], argv[3]));
|
---|
[1] | 343 | }
|
---|
[59] | 344 |
|
---|
| 345 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
---|
| 346 | g_loglevel = 10;
|
---|
| 347 | g_text_mode = TRUE;
|
---|
| 348 | setup_newt_stuff();
|
---|
| 349 | turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
|
---|
| 350 | printf("in=%s; out=%s\n", argv[2], tmp);
|
---|
| 351 | finish(1);
|
---|
[1] | 352 | }
|
---|
[59] | 353 |
|
---|
| 354 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
---|
| 355 | g_loglevel = 10;
|
---|
| 356 | g_text_mode = TRUE;
|
---|
| 357 | setup_newt_stuff();
|
---|
| 358 | if (!strstr(argv[2], "filelist")) {
|
---|
| 359 | printf("Sorry - filelist goes first\n");
|
---|
| 360 | finish(1);
|
---|
| 361 | } else {
|
---|
| 362 | finish(get_acl_list(argv[2], argv[3]));
|
---|
| 363 | }
|
---|
| 364 | finish(0);
|
---|
| 365 | }
|
---|
| 366 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
---|
| 367 | g_loglevel = 10;
|
---|
[1] | 368 | // chdir("/tmp");
|
---|
[59] | 369 | g_text_mode = TRUE;
|
---|
| 370 | setup_newt_stuff();
|
---|
| 371 | finish(set_acl_list(argv[2], argv[3]));
|
---|
| 372 | }
|
---|
[1] | 373 |
|
---|
[59] | 374 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
---|
| 375 | g_loglevel = 10;
|
---|
| 376 | g_text_mode = TRUE;
|
---|
| 377 | setup_newt_stuff();
|
---|
| 378 | if (find_cdrw_device(tmp)) {
|
---|
| 379 | printf("Failed to find CDR-RW drive\n");
|
---|
| 380 | } else {
|
---|
| 381 | printf("CD-RW is at %s\n", tmp);
|
---|
| 382 | }
|
---|
| 383 | tmp[0] = '\0';
|
---|
| 384 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
---|
| 385 | printf("Failed to find CD-ROM drive\n");
|
---|
| 386 | } else {
|
---|
| 387 | printf("CD-ROM is at %s\n", tmp);
|
---|
| 388 | }
|
---|
| 389 | finish(0);
|
---|
| 390 | }
|
---|
[1] | 391 |
|
---|
[59] | 392 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
---|
| 393 | g_loglevel = 10;
|
---|
| 394 | g_text_mode = TRUE;
|
---|
| 395 | setup_newt_stuff();
|
---|
| 396 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
---|
| 397 | printf("Failed to find DVD drive\n");
|
---|
| 398 | } else {
|
---|
| 399 | printf("DVD is at %s\n", tmp);
|
---|
| 400 | }
|
---|
| 401 | finish(0);
|
---|
| 402 | }
|
---|
[1] | 403 |
|
---|
[59] | 404 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
---|
| 405 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
---|
| 406 | finish(0);
|
---|
| 407 | }
|
---|
| 408 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
---|
| 409 | if (is_dev_an_NTFS_dev(argv[2])) {
|
---|
| 410 | printf("%s is indeed an NTFS dev\n", argv[2]);
|
---|
| 411 | } else {
|
---|
| 412 | printf("%s is _not_ an NTFS dev\n", argv[2]);
|
---|
| 413 | }
|
---|
| 414 | finish(0);
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | if (pre_param_configuration(bkpinfo)) {
|
---|
| 418 | fatal_error
|
---|
| 419 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
---|
| 420 | }
|
---|
| 421 |
|
---|
[1] | 422 | /* Process command line, if there is one. If not, ask user for info. */
|
---|
[59] | 423 | if (argc == 1) {
|
---|
| 424 | g_text_mode = FALSE;
|
---|
| 425 | setup_newt_stuff();
|
---|
| 426 | res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */
|
---|
| 427 | if (res) {
|
---|
| 428 | fatal_error
|
---|
| 429 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
---|
| 430 | }
|
---|
| 431 | } else {
|
---|
| 432 | res = handle_incoming_parameters(argc, argv, bkpinfo);
|
---|
| 433 | if (res) {
|
---|
| 434 | printf
|
---|
| 435 | ("Errors were detected in the command line you supplied.\n");
|
---|
| 436 | printf("Please review the log file - " MONDO_LOGFILE "\n");
|
---|
| 437 | log_msg(1, "Mondoarchive will now exit.");
|
---|
| 438 | finish(1);
|
---|
| 439 | }
|
---|
| 440 | setup_newt_stuff();
|
---|
[1] | 441 | }
|
---|
| 442 |
|
---|
| 443 | /* Finish configuring global structures */
|
---|
[59] | 444 | if (post_param_configuration(bkpinfo)) {
|
---|
| 445 | fatal_error
|
---|
| 446 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
---|
| 447 | }
|
---|
[1] | 448 |
|
---|
[59] | 449 | log_to_screen
|
---|
| 450 | ("BusyBox's sources are available from http://www.busybox.net");
|
---|
| 451 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
---|
| 452 | bkpinfo->scratchdir);
|
---|
[1] | 453 |
|
---|
[59] | 454 | /* If we're meant to backup then backup */
|
---|
| 455 | if (bkpinfo->backup_data) {
|
---|
[1] | 456 | /*
|
---|
| 457 | log_to_screen("INFERNAL PORPOISES");
|
---|
| 458 | res = archive_this_fileset_with_star(bkpinfo, "/tmp/filelist.0", "/tmp/0.star.bz2", 0);
|
---|
| 459 | log_to_screen("atfws returned %d", res);
|
---|
| 460 | finish(0);
|
---|
| 461 | */
|
---|
[59] | 462 | res = backup_data(bkpinfo);
|
---|
| 463 | retval += res;
|
---|
| 464 | if (res) {
|
---|
| 465 | strcat(say_at_end,
|
---|
| 466 | "Data archived. Please check the logs, just as a precaution. ");
|
---|
| 467 | } else {
|
---|
| 468 | strcat(say_at_end, "Data archived OK. ");
|
---|
| 469 | }
|
---|
| 470 | }
|
---|
[1] | 471 |
|
---|
| 472 | /* If we're meant to verify then verify */
|
---|
[59] | 473 | if (bkpinfo->verify_data) {
|
---|
| 474 | res = verify_data(bkpinfo);
|
---|
| 475 | if (res < 0) {
|
---|
| 476 | sprintf(tmp, "%d difference%c found.", -res,
|
---|
| 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 */
|
---|
[59] | 486 | if (bkpinfo->backup_data && !g_skip_floppies) {
|
---|
| 487 | res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
|
---|
| 488 | retval += res;
|
---|
[1] | 489 | // res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo);
|
---|
| 490 | // retval += res;
|
---|
[59] | 491 | }
|
---|
[1] | 492 |
|
---|
| 493 | /* Report result of entire operation (success? errors?) */
|
---|
[59] | 494 | if (!retval) {
|
---|
| 495 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
| 496 | "Backup and/or verify ran to completion. Everything appears to be fine.");
|
---|
| 497 | } else {
|
---|
| 498 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
| 499 | "Backup and/or verify ran to completion. However, errors did occur.");
|
---|
| 500 | }
|
---|
[1] | 501 |
|
---|
[59] | 502 | if (does_file_exist("/root/images/mindi/mondorescue.iso")) {
|
---|
| 503 | log_to_screen
|
---|
| 504 | ("/root/images/mindi/mondorescue.iso, a boot/utility CD, is available if you want it.");
|
---|
| 505 | }
|
---|
[1] | 506 |
|
---|
| 507 |
|
---|
[59] | 508 | if (length_of_file("/tmp/changed.files") > 2) {
|
---|
| 509 | if (g_text_mode) {
|
---|
| 510 | log_to_screen
|
---|
| 511 | ("Type 'less /tmp/changed.files' to see which files don't match the archives");
|
---|
| 512 | } else {
|
---|
| 513 | log_msg(1,
|
---|
| 514 | "Type 'less /tmp/changed.files' to see which files don't match the archives");
|
---|
| 515 | log_msg(2, "Calling popup_changelist_from_file()");
|
---|
| 516 | popup_changelist_from_file("/tmp/changed.files");
|
---|
| 517 | log_msg(2, "Returned from popup_changelist_from_file()");
|
---|
| 518 | }
|
---|
| 519 | } else {
|
---|
| 520 | unlink("/tmp/changed.files");
|
---|
| 521 | }
|
---|
| 522 | log_to_screen(say_at_end);
|
---|
| 523 | sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 524 | run_program_and_log_output(tmp, TRUE);
|
---|
| 525 | run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
|
---|
[1] | 526 |
|
---|
[59] | 527 | run_program_and_log_output("mount", 2);
|
---|
[1] | 528 |
|
---|
[59] | 529 | if (bkpinfo->please_dont_eject) {
|
---|
| 530 | log_msg(5, "Not ejecting at end. Fair enough.");
|
---|
| 531 | } else {
|
---|
| 532 | log_msg(5, "Ejecting at end.");
|
---|
| 533 | if (!find_cdrom_device(tmp, FALSE) || !find_dvd_device(tmp, FALSE)) {
|
---|
| 534 | log_msg(1, "Ejecting %s", tmp);
|
---|
| 535 | eject_device(tmp);
|
---|
| 536 | }
|
---|
[1] | 537 | }
|
---|
| 538 |
|
---|
[59] | 539 | system("rm -f /var/cache/mondo-archive/last-backup.aborted");
|
---|
| 540 | system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
|
---|
| 541 | if (!retval) {
|
---|
| 542 | printf("Mondoarchive ran OK.\n");
|
---|
| 543 | } else {
|
---|
| 544 | printf("Errors occurred during backup. Please check logfile.\n");
|
---|
| 545 | }
|
---|
| 546 | distro_specific_kludges_at_end_of_mondoarchive();
|
---|
| 547 | register_pid(0, "mondo");
|
---|
| 548 | set_signals(FALSE);
|
---|
| 549 | chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir
|
---|
| 550 | system(g_erase_tmpdir_and_scratchdir);
|
---|
| 551 | free_libmondo_global_strings();
|
---|
| 552 | paranoid_free(say_at_end);
|
---|
| 553 | paranoid_free(tmp);
|
---|
| 554 | paranoid_free(bkpinfo);
|
---|
[1] | 555 |
|
---|
[59] | 556 | unlink("/tmp/filelist.full");
|
---|
| 557 | unlink("/tmp/filelist.full.gz");
|
---|
[1] | 558 |
|
---|
[59] | 559 | if (!g_cdrom_drive_is_here) {
|
---|
| 560 | log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
---|
| 561 | }
|
---|
| 562 | if (!g_dvd_drive_is_here) {
|
---|
| 563 | log_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
---|
| 564 | }
|
---|
[1] | 565 |
|
---|
[59] | 566 | if (!g_text_mode) {
|
---|
| 567 | popup_and_OK
|
---|
| 568 | ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
|
---|
| 569 | log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
|
---|
| 570 | finish(retval);
|
---|
| 571 | } else {
|
---|
| 572 | printf("See %s for details of backup run.\n", MONDO_LOGFILE);
|
---|
| 573 | exit(retval);
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | return EXIT_SUCCESS;
|
---|
[1] | 577 | }
|
---|