Changeset 59 in MondoRescue for trunk/mondo/mondo/mondoarchive
- Timestamp:
- Oct 11, 2005, 1:34:31 AM (19 years ago)
- Location:
- trunk/mondo/mondo/mondoarchive
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/mondoarchive/main.c
r30 r59 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : main.c,v 1.14 2004/06/21 20:20:36 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 127 127 128 128 // for CVS 129 //static char cvsid[] = "$Id : main.c,v 1.14 2004/06/21 20:20:36 hugo Exp$";129 //static char cvsid[] = "$Id$"; 130 130 131 131 /************************* external variables *************************/ 132 132 extern void set_signals(int); 133 133 extern int g_current_media_number; 134 extern void register_pid(pid_t, char *);134 extern void register_pid(pid_t, char *); 135 135 extern int g_currentY; 136 136 extern bool g_text_mode; … … 141 141 extern char *g_erase_tmpdir_and_scratchdir; 142 142 extern char *g_cdrw_drive_is_here; 143 static char *g_cdrom_drive_is_here =NULL;144 static char *g_dvd_drive_is_here =NULL;143 static char *g_cdrom_drive_is_here = NULL; 144 static char *g_dvd_drive_is_here = NULL; 145 145 extern double g_kernel_version; 146 146 … … 160 160 void welcome_to_mondoarchive() 161 161 { 162 log_msg (0, "Mondo Archive v%s --- http://www.mondorescue.org", VERSION); 163 log_msg (0, "running on %s architecture",get_architecture()); 164 log_msg (0,"-----------------------------------------------------------"); 165 log_msg (0, "NB: Mondo logs almost everything, so don't panic if you see"); 166 log_msg (0, "some error messages. Please read them carefully before you"); 167 log_msg (0, "decide to break out in a cold sweat. Despite (or perhaps"); 168 log_msg (0, "because of) the wealth of messages. some users are inclined"); 169 log_msg (0, "to stop reading this log. If Mondo stopped for some reason,"); 170 log_msg (0, "chances are it's detailed here. More than likely there's a"); 171 log_msg (0, "message at the very end of this log that will tell you what"); 172 log_msg (0, "is wrong. Please read it! -Devteam"); 173 log_msg (0,"-----------------------------------------------------------"); 174 175 log_msg (0, "Zero..."); 176 log_msg (1, "One..."); 177 log_msg (2, "Two..."); 178 log_msg (3, "Three..."); 179 log_msg (4, "Four..."); 180 log_msg (5, "Five..."); 181 log_msg (6, "Six..."); 182 log_msg (7, "Seven..."); 183 log_msg (8, "Eight..."); 184 printf ("See %s for details of backup run.\n", MONDO_LOGFILE); 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 "-----------------------------------------------------------"); 185 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); 185 196 } 186 197 … … 194 205 void distro_specific_kludges_at_start_of_mondoarchive() 195 206 { 196 log_msg (2, "Unmounting old ramdisks if necessary"); 197 stop_magicdev_if_necessary(); // for RH+Gnome users 198 run_program_and_log_output("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2); 199 unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted 200 // stop_autofs_if_necessary(); // for Xandros users 201 mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions 202 clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way 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 203 215 } 204 216 … … 211 223 { 212 224 // char tmp[500]; 213 log_msg(2, "Restarting magicdev if necessary");214 215 restart_magicdev_if_necessary();// for RH+Gnome users216 217 log_msg(2, "Restarting autofs if necessary");218 219 220 221 log_msg(2, "Restarting supermounts if necessary");222 223 remount_supermounts_if_necessary();// for Mandrake users224 225 log_msg(2, "Unmounting /boot if necessary");226 227 unmount_boot_if_necessary();// for Gentoo users225 log_msg(2, "Restarting magicdev if necessary"); 226 sync(); 227 restart_magicdev_if_necessary(); // for RH+Gnome users 228 229 log_msg(2, "Restarting autofs if necessary"); 230 sync(); 231 // restart_autofs_if_necessary(); // for Xandros users 232 233 log_msg(2, "Restarting supermounts if necessary"); 234 sync(); 235 remount_supermounts_if_necessary(); // for Mandrake users 236 237 log_msg(2, "Unmounting /boot if necessary"); 238 sync(); 239 unmount_boot_if_necessary(); // for Gentoo users 228 240 229 241 // log_msg( 2, "Cleaning up KDE desktop"); … … 240 252 * What did you think it did, anyway? :-) 241 253 */ 242 int 243 main (int argc, char *argv[]) 254 int main(int argc, char *argv[]) 244 255 { 245 246 247 248 256 struct s_bkpinfo *bkpinfo; 257 char *tmp; 258 int res, retval; 259 char *say_at_end; 249 260 250 261 /* Make sure I'm root; abort if not */ 251 if (getuid () != 0) 252 { 253 fprintf (stderr, "Please run as root.\r\n"); 254 exit (127); 255 } 262 if (getuid() != 0) { 263 fprintf(stderr, "Please run as root.\r\n"); 264 exit(127); 265 } 256 266 257 267 /* If -V, -v or --version then echo version no. and quit */ 258 if (argc==2 && (!strcmp(argv[argc-1], "-v") || !strcmp(argv[argc-1], "-V") || !strcmp(argv[argc-1], "--version"))) 259 { printf("mondoarchive v%s\nSee man page for help\n", VERSION); exit(0); } 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 } 260 274 261 275 /* Initialize variables */ 262 276 263 malloc_libmondo_global_strings(); 264 malloc_string(tmp); 265 malloc_string(say_at_end); 266 267 res = 0; 268 retval = 0; 269 diffs = 0; 270 say_at_end[0] = '\0'; 271 unlink("/var/log/partimagehack-debug.log"); 272 printf ("Initializing...\n"); 273 if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) { fatal_error("Cannot malloc bkpinfo"); } 277 malloc_libmondo_global_strings(); 278 malloc_string(tmp); 279 malloc_string(say_at_end); 280 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 } 274 290 275 291 276 292 /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */ 277 strncpy(tmp, getenv("PATH"), MAX_STR_LEN-1); 278 tmp[MAX_STR_LEN-1] = '\0'; 279 if (strlen(tmp)>=MAX_STR_LEN-33) 280 { fatal_error("Your PATH environmental variable is too long. Please shorten it."); } 281 strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin"); 282 setenv("PATH", tmp, 1); 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); 283 301 284 302 /* Add the ARCH environment variable for ia64 purposes */ 285 strncpy(tmp, get_architecture(), MAX_STR_LEN-1);286 tmp[MAX_STR_LEN-1] = '\0';287 288 289 303 strncpy(tmp, get_architecture(), MAX_STR_LEN - 1); 304 tmp[MAX_STR_LEN - 1] = '\0'; 305 setenv("ARCH", tmp, 1); 306 307 unlink(MONDO_LOGFILE); 290 308 291 309 /* Configure the bkpinfo structure, global file paths, etc. */ 292 g_main_pid = getpid(); 293 log_msg(9, "This"); 294 295 register_pid(g_main_pid, "mondo"); 296 set_signals(TRUE); // catch SIGTERM, etc. 297 nice(10); 298 run_program_and_log_output("dmesg -n1", TRUE); 299 300 log_msg(9, "Next"); 301 welcome_to_mondoarchive(); 302 distro_specific_kludges_at_start_of_mondoarchive(); 303 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 304 g_kernel_version = get_kernel_version(); 305 306 if (argc==4 && !strcmp(argv[1], "getfattr")) 307 { 308 g_loglevel = 10; 309 g_text_mode = TRUE; 310 setup_newt_stuff(); 311 if (!strstr(argv[2], "filelist")) 312 { 313 printf("Sorry - filelist goes first\n"); 314 finish(1); 315 } 316 else 317 { 318 finish(get_fattr_list(argv[2], argv[3])); 319 } 320 finish(0); 321 } 322 if (argc==4 && !strcmp(argv[1], "setfattr")) 323 { 324 g_loglevel = 10; 310 g_main_pid = getpid(); 311 log_msg(9, "This"); 312 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); 317 318 log_msg(9, "Next"); 319 welcome_to_mondoarchive(); 320 distro_specific_kludges_at_start_of_mondoarchive(); 321 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 322 bkpinfo->scratchdir); 323 g_kernel_version = get_kernel_version(); 324 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); 336 } 337 if (argc == 4 && !strcmp(argv[1], "setfattr")) { 338 g_loglevel = 10; 325 339 // chdir("/tmp"); 326 g_text_mode = TRUE; 327 setup_newt_stuff(); 328 finish(set_fattr_list(argv[2], argv[3])); 329 } 330 331 if (argc==3 && !strcmp(argv[1], "wildcards")) 332 { 333 g_loglevel = 10; 334 g_text_mode = TRUE; 335 setup_newt_stuff(); 336 turn_wildcard_chars_into_literal_chars(tmp, argv[2]); 337 printf("in=%s; out=%s\n", argv[2], tmp); 338 finish(1); 339 } 340 341 if (argc==4 && !strcmp(argv[1], "getfacl")) 342 { 343 g_loglevel = 10; 344 g_text_mode = TRUE; 345 setup_newt_stuff(); 346 if (!strstr(argv[2], "filelist")) 347 { 348 printf("Sorry - filelist goes first\n"); 349 finish(1); 350 } 351 else 352 { 353 finish(get_acl_list(argv[2], argv[3])); 354 } 355 finish(0); 356 } 357 if (argc==4 && !strcmp(argv[1], "setfacl")) 358 { 359 g_loglevel = 10; 340 g_text_mode = TRUE; 341 setup_newt_stuff(); 342 finish(set_fattr_list(argv[2], argv[3])); 343 } 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); 352 } 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; 360 368 // chdir("/tmp"); 361 g_text_mode = TRUE; 362 setup_newt_stuff(); 363 finish(set_acl_list(argv[2], argv[3])); 364 } 365 366 if (argc>2 && !strcmp(argv[1], "find-cd")) 367 { 368 g_loglevel = 10; 369 g_text_mode = TRUE; 370 setup_newt_stuff(); 371 if (find_cdrw_device(tmp)) 372 { printf("Failed to find CDR-RW drive\n"); } 373 else 374 { printf("CD-RW is at %s\n", tmp); } 375 tmp[0] = '\0'; 376 if (find_cdrom_device(tmp, atoi(argv[2]))) 377 { printf("Failed to find CD-ROM drive\n"); } 378 else 379 { printf("CD-ROM is at %s\n", tmp); } 380 finish(0); 381 } 382 383 if (argc>2 && !strcmp(argv[1], "find-dvd")) 384 { 385 g_loglevel = 10; 386 g_text_mode = TRUE; 387 setup_newt_stuff(); 388 if (find_dvd_device(tmp, atoi(argv[2]))) 389 { printf("Failed to find DVD drive\n"); } 390 else 391 { printf("DVD is at %s\n", tmp); } 392 finish(0); 393 } 394 395 if (argc>2 && !strcmp(argv[1], "disksize")) 396 { 397 printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2])); 398 finish(0); 399 } 400 if (argc>2 && !strcmp(argv[1], "test-dev")) 401 { 402 if (is_dev_an_NTFS_dev(argv[2])) 403 { printf("%s is indeed an NTFS dev\n", argv[2]); } 404 else 405 { printf("%s is _not_ an NTFS dev\n", argv[2]); } 406 finish(0); 407 } 408 409 if (pre_param_configuration(bkpinfo)) { fatal_error("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting..."); } 410 369 g_text_mode = TRUE; 370 setup_newt_stuff(); 371 finish(set_acl_list(argv[2], argv[3])); 372 } 373 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 } 391 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 } 403 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 411 422 /* Process command line, if there is one. If not, ask user for info. */ 412 if (argc==1) 413 { 414 g_text_mode = FALSE; 415 setup_newt_stuff (); 416 res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */ 417 if (res) { fatal_error("Syntax error. Please review the parameters you have supplied and try again."); } 418 } 419 else 420 { 421 res = handle_incoming_parameters (argc, argv, bkpinfo); 422 if (res) { 423 printf("Errors were detected in the command line you supplied.\n"); 424 printf("Please review the log file - " MONDO_LOGFILE "\n"); 425 log_msg(1, "Mondoarchive will now exit."); 426 finish(1); 427 } 428 setup_newt_stuff (); 429 } 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(); 441 } 430 442 431 443 /* Finish configuring global structures */ 432 if (post_param_configuration (bkpinfo)) { fatal_error("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting..."); } 433 434 log_to_screen("BusyBox's sources are available from http://www.busybox.net"); 435 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 436 437 /* If we're meant to backup then backup */ 438 if (bkpinfo->backup_data) 439 { 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 } 448 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); 453 454 /* If we're meant to backup then backup */ 455 if (bkpinfo->backup_data) { 440 456 /* 441 457 log_to_screen("INFERNAL PORPOISES"); … … 444 460 finish(0); 445 461 */ 446 res = backup_data(bkpinfo); 447 retval += res; 448 if (res) 449 { strcat (say_at_end, "Data archived. Please check the logs, just as a precaution. "); } 450 else 451 { strcat (say_at_end, "Data archived OK. "); } 452 } 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 } 453 471 454 472 /* If we're meant to verify then verify */ 455 if (bkpinfo->verify_data) 456 { 457 res = verify_data(bkpinfo); 458 if (res<0) 459 { 460 sprintf(tmp, "%d difference%c found.", -res, (-res != 1) ? 's' : ' '); 461 strcat(say_at_end, tmp); 462 log_to_screen(tmp); 463 res=0; 464 } 465 retval += res; 466 } 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 } 467 484 468 485 /* Offer to write floppy disk images to physical disks */ 469 if (bkpinfo->backup_data && !g_skip_floppies) 470 { 471 res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo); 472 retval += res; 486 if (bkpinfo->backup_data && !g_skip_floppies) { 487 res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo); 488 retval += res; 473 489 // res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo); 474 490 // retval += res; 475 491 } 476 492 477 493 /* Report result of entire operation (success? errors?) */ 478 if (!retval) 479 { 480 mvaddstr_and_log_it (g_currentY++, 0, 481 "Backup and/or verify ran to completion. Everything appears to be fine."); 482 } 483 else 484 { 485 mvaddstr_and_log_it (g_currentY++, 0, 486 "Backup and/or verify ran to completion. However, errors did occur."); 487 } 488 489 if (does_file_exist ("/root/images/mindi/mondorescue.iso")) 490 { 491 log_to_screen ("/root/images/mindi/mondorescue.iso, a boot/utility CD, is available if you want it."); 492 } 493 494 495 if (length_of_file ("/tmp/changed.files") > 2) 496 { 497 if (g_text_mode) { log_to_screen("Type 'less /tmp/changed.files' to see which files don't match the archives"); } 498 else 499 { 500 log_msg (1, "Type 'less /tmp/changed.files' to see which files don't match the archives"); 501 log_msg (2, "Calling popup_changelist_from_file()"); 502 popup_changelist_from_file("/tmp/changed.files"); 503 log_msg (2, "Returned from popup_changelist_from_file()"); 504 } 505 } 506 else 507 { 508 unlink ("/tmp/changed.files"); 509 } 510 log_to_screen (say_at_end); 511 sprintf (tmp, "umount %s/tmpfs", bkpinfo->tmpdir); 512 run_program_and_log_output (tmp, TRUE); 513 run_program_and_log_output (g_erase_tmpdir_and_scratchdir, TRUE); 514 515 run_program_and_log_output("mount", 2); 516 517 if (bkpinfo->please_dont_eject) 518 { 519 log_msg(5, "Not ejecting at end. Fair enough."); 520 } 521 else 522 { 523 log_msg(5, "Ejecting at end."); 524 if (!find_cdrom_device(tmp, FALSE) || !find_dvd_device(tmp, FALSE)) 525 { 526 log_msg(1, "Ejecting %s", tmp); 527 eject_device(tmp); 528 } 529 } 530 531 system("rm -f /var/cache/mondo-archive/last-backup.aborted"); 532 system("rm -Rf /tmp.mondo.* /mondo.scratch.*"); 533 if (!retval) { printf("Mondoarchive ran OK.\n"); } 534 else { printf("Errors occurred during backup. Please check logfile.\n"); } 535 distro_specific_kludges_at_end_of_mondoarchive(); 536 register_pid(0,"mondo"); 537 set_signals(FALSE); 538 chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir 539 system(g_erase_tmpdir_and_scratchdir); 540 free_libmondo_global_strings(); 541 paranoid_free(say_at_end); 542 paranoid_free(tmp); 543 paranoid_free(bkpinfo); 544 545 unlink("/tmp/filelist.full"); 546 unlink("/tmp/filelist.full.gz"); 547 548 if (!g_cdrom_drive_is_here) { log_msg(10, "FYI, g_cdrom_drive_is_here was never used"); } 549 if (!g_dvd_drive_is_here) { log_msg(10, "FYI, g_dvd_drive_is_here was never used"); } 550 551 if (!g_text_mode) 552 { 553 popup_and_OK 554 ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."); 555 log_to_screen("See %s for details of backup run.", MONDO_LOGFILE); 556 finish(retval); 557 } 558 else 559 { 560 printf ("See %s for details of backup run.\n", MONDO_LOGFILE); 561 exit(retval); 562 } 563 564 return EXIT_SUCCESS; 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 } 501 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 } 506 507 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); 526 527 run_program_and_log_output("mount", 2); 528 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 } 537 } 538 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); 555 556 unlink("/tmp/filelist.full"); 557 unlink("/tmp/filelist.full.gz"); 558 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 } 565 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; 565 577 } 566 567 -
trunk/mondo/mondo/mondoarchive/mondo-cli-EXT.h
r30 r59 1 1 /* mondo-cli-EXT.h */ 2 2 3 extern int handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo); 3 extern int handle_incoming_parameters(int argc, char *argv[], 4 struct s_bkpinfo *bkpinfo); 4 5 extern int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 5 extern int process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN], 6 bool flag_set[128]); 7 extern int retrieve_switches_from_command_line (int argc, char *argv[], 8 char flag_val[128][MAX_STR_LEN], 9 bool flag_set[128]); 10 extern void help_screen (); 6 extern int process_switches(struct s_bkpinfo *bkpinfo, 7 char flag_val[128][MAX_STR_LEN], 8 bool flag_set[128]); 9 extern int retrieve_switches_from_command_line(int argc, char *argv[], 10 char 11 flag_val[128][MAX_STR_LEN], 12 bool flag_set[128]); 13 extern void help_screen(); 11 14 extern void terminate_daemon(int sig); 12 15 extern void set_signals(int on); 13 16 extern void termination_in_progress(int sig); 14 -
trunk/mondo/mondo/mondoarchive/mondo-cli.c
r30 r59 7 7 edited by : by Stan Benoit 4/2002 8 8 email : troff@nakedsoul.org 9 cvsid : $Id : mondo-cli.c,v 1.11 2004/06/21 20:20:36 hugo Exp$9 cvsid : $Id$ 10 10 ***************************************************************************/ 11 11 … … 175 175 176 176 177 //static char cvsid[] = "$Id : mondo-cli.c,v 1.11 2004/06/21 20:20:36 hugo Exp$";177 //static char cvsid[] = "$Id$"; 178 178 179 179 extern int g_loglevel; 180 180 extern bool g_text_mode; 181 extern bool g_skip_floppies; 182 extern char g_startdir[MAX_STR_LEN]; 181 extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks 182 extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ????? 183 183 extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN]; 184 184 extern char g_tmpfs_mountpt[MAX_STR_LEN]; … … 195 195 196 196 /*@ bool******** **************************************************/ 197 bool g_debugging = FALSE; 198 bool g_running_live = FALSE; 197 bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup 198 bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup 199 199 extern bool g_cd_recovery; 200 200 … … 220 220 221 221 222 extern char *resolve_softlinks_to_get_to_actual_device_file(char*);222 extern char *resolve_softlinks_to_get_to_actual_device_file(char *); 223 223 224 224 … … 236 236 */ 237 237 int 238 handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo) 238 handle_incoming_parameters(int argc, char *argv[], 239 struct s_bkpinfo *bkpinfo) 239 240 { 240 /*@ int ****/ 241 int res = 0; 242 int retval = 0; 243 int i = 0, j; 244 245 /*@ buffers ****************/ 246 char *tmp; 247 char flag_val[128][MAX_STR_LEN]; 248 bool flag_set[128]; 249 250 malloc_string(tmp); 251 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 252 for (i = 0; i < 128; i++) 253 { 254 flag_val[i][0] = '\0'; 255 flag_set[i] = FALSE; 256 } 257 // strcpy (bkpinfo->tmpdir, "/root/images/mondo"); 258 // strcpy (bkpinfo->scratchdir, "/home"); 259 for(j=1; j<=MAX_NOOF_MEDIA; j++) {bkpinfo->media_size[j] = 650;} /* default */ 260 res = retrieve_switches_from_command_line (argc, argv, flag_val, flag_set); 261 retval += res; 262 if (!retval) 263 { 264 res = process_switches (bkpinfo, flag_val, flag_set); 265 retval += res; 266 } 241 /*@ int *** */ 242 int res = 0; 243 int retval = 0; 244 int i = 0, j; 245 246 /*@ buffers *************** */ 247 char *tmp; 248 char flag_val[128][MAX_STR_LEN]; 249 bool flag_set[128]; 250 251 malloc_string(tmp); 252 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 253 for (i = 0; i < 128; i++) { 254 flag_val[i][0] = '\0'; 255 flag_set[i] = FALSE; 256 } 257 // strcpy (bkpinfo->tmpdir, "/root/images/mondo"); 258 // strcpy (bkpinfo->scratchdir, "/home"); 259 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 260 bkpinfo->media_size[j] = 650; 261 } /* default */ 262 res = 263 retrieve_switches_from_command_line(argc, argv, flag_val, 264 flag_set); 265 retval += res; 266 if (!retval) { 267 res = process_switches(bkpinfo, flag_val, flag_set); 268 retval += res; 269 } 267 270 /* 268 271 if (!retval) 269 272 { 270 273 */ 271 log_msg (3, "Switches:-"); 272 for (i = 0; i < 128; i++) 273 { 274 if (flag_set[i]) 275 { 276 sprintf (tmp, "-%c %s", i, flag_val[i]); 277 log_msg (3, tmp); 278 } 274 log_msg(3, "Switches:-"); 275 for (i = 0; i < 128; i++) { 276 if (flag_set[i]) { 277 sprintf(tmp, "-%c %s", i, flag_val[i]); 278 log_msg(3, tmp); 279 } 279 280 } 280 281 // } 281 sprintf (tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir); 282 paranoid_system (tmp); 283 sprintf (tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 284 paranoid_system (tmp); 285 sprintf (bkpinfo->tmpdir + strlen (bkpinfo->tmpdir), "/tmp.mondo.%ld", 286 random () % 32767); 287 sprintf (bkpinfo->scratchdir + strlen (bkpinfo->scratchdir), 288 "/mondo.scratch.%ld", random () % 32767); 289 sprintf (tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 290 paranoid_system (tmp); 291 sprintf (tmp, "mkdir -p %s", bkpinfo->scratchdir); 292 paranoid_system (tmp); 293 if (bkpinfo->nfs_mount[0] != '\0') 294 { 295 store_nfs_config (bkpinfo); 296 } 297 paranoid_free(tmp); 298 return (retval); 282 sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir); 283 paranoid_system(tmp); 284 sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 285 paranoid_system(tmp); 286 sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld", 287 random() % 32767); 288 sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir), 289 "/mondo.scratch.%ld", random() % 32767); 290 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 291 paranoid_system(tmp); 292 sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir); 293 paranoid_system(tmp); 294 if (bkpinfo->nfs_mount[0] != '\0') { 295 store_nfs_config(bkpinfo); 296 } 297 paranoid_free(tmp); 298 return (retval); 299 299 } 300 300 … … 311 311 int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value) 312 312 { 313 314 315 316 assert(bkpinfo!=NULL);317 assert(value!=NULL);318 319 bkpinfo->media_size[0] = -1;/* dummy value */320 for(j=1, p=value; j<MAX_NOOF_MEDIA && strchr(p,','); j++, p=strchr(p,',')+1) 321 {322 323 *(strchr(tmp,',')) = '\0';324 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);325 sprintf(comment, "media_size[%d] = %ld", j, bkpinfo->media_size[j]); 326 log_msg(3, comment);327 }328 for(; j<=MAX_NOOF_MEDIA; j++) 329 {330 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);313 int j; 314 char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN]; 315 316 assert(bkpinfo != NULL); 317 assert(value != NULL); 318 319 bkpinfo->media_size[0] = -1; /* dummy value */ 320 for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ','); 321 j++, p = strchr(p, ',') + 1) { 322 strncpy(tmp, p, MAX_STR_LEN); 323 *(strchr(tmp, ',')) = '\0'; 324 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp); 325 sprintf(comment, "media_size[%d] = %ld", j, 326 bkpinfo->media_size[j]); 327 log_msg(3, comment); 328 } 329 for (; j <= MAX_NOOF_MEDIA; j++) { 330 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p); 331 331 } 332 332 // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA]; 333 for(j=1; j<=MAX_NOOF_MEDIA; j++) 334 { 335 if (bkpinfo->media_size[j]<=0) { log_msg(1, "You gave media #%d an invalid size\n", j); return(-1); } 336 } 337 return(0); 333 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 334 if (bkpinfo->media_size[j] <= 0) { 335 log_msg(1, "You gave media #%d an invalid size\n", j); 336 return (-1); 337 } 338 } 339 return (0); 338 340 } 339 341 … … 351 353 */ 352 354 int 353 process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN],354 355 process_switches(struct s_bkpinfo *bkpinfo, 356 char flag_val[128][MAX_STR_LEN], bool flag_set[128]) 355 357 { 356 358 357 /*@ ints *** */358 359 360 361 362 /*@ buffers ** */363 364 365 366 367 368 369 370 371 assert(bkpinfo!=NULL);372 assert(flag_val!=NULL);373 assert(flag_set!=NULL);374 375 359 /*@ ints *** */ 360 int i = 0; 361 int retval = 0; 362 int percent = 0; 363 364 /*@ buffers ** */ 365 char *tmp; 366 char *psz; 367 368 long itbs; 369 370 malloc_string(tmp); 371 malloc_string(psz); 372 373 assert(bkpinfo != NULL); 374 assert(flag_val != NULL); 375 assert(flag_set != NULL); 376 377 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 376 378 377 379 /* compulsory */ 378 i = 379 flag_set['c'] + flag_set['i'] + flag_set['n'] + 380 flag_set['t'] + flag_set['u'] + flag_set['r'] + 381 flag_set['w'] + flag_set['C']; 382 if (i == 0) 383 { 384 retval++; 385 log_to_screen( "You must specify the media type\n"); 386 } 387 if (i > 1) 388 { 389 retval++; 390 log_to_screen( "Please specify only one media type\n"); 391 } 392 if (flag_set['K']) 393 { 394 g_loglevel = atoi(flag_val['K']); 395 if (g_loglevel < 3) { g_loglevel = 3; } 396 } 397 if (flag_set['L'] && flag_set['0']) 398 { 399 retval++; 400 log_to_screen( "You cannot have 'no compression' _and_ LZOP.\n"); 401 } 402 bkpinfo->backup_data = flag_set['O']; 403 bkpinfo->verify_data = flag_set['V']; 404 if (flag_set['I'] && !bkpinfo->backup_data) 405 { 406 log_to_screen ("-I switch is ignored if just verifying"); 407 } 408 if (flag_set['E'] && !bkpinfo->backup_data) 409 { 410 log_to_screen ("-E switch is ignored if just verifying"); 411 } 412 413 if (!find_home_of_exe("afio")) 414 { 415 if (find_home_of_exe("star")) 380 i = flag_set['c'] + flag_set['i'] + flag_set['n'] + 381 flag_set['t'] + flag_set['u'] + flag_set['r'] + 382 flag_set['w'] + flag_set['C']; 383 if (i == 0) { 384 retval++; 385 log_to_screen("You must specify the media type\n"); 386 } 387 if (i > 1) { 388 retval++; 389 log_to_screen("Please specify only one media type\n"); 390 } 391 if (flag_set['K']) { 392 g_loglevel = atoi(flag_val['K']); 393 if (g_loglevel < 3) { 394 g_loglevel = 3; 395 } 396 } 397 if (flag_set['L'] && flag_set['0']) { 398 retval++; 399 log_to_screen("You cannot have 'no compression' _and_ LZOP.\n"); 400 } 401 bkpinfo->backup_data = flag_set['O']; 402 bkpinfo->verify_data = flag_set['V']; 403 if (flag_set['I'] && !bkpinfo->backup_data) { 404 log_to_screen("-I switch is ignored if just verifying"); 405 } 406 if (flag_set['E'] && !bkpinfo->backup_data) { 407 log_to_screen("-E switch is ignored if just verifying"); 408 } 409 410 if (!find_home_of_exe("afio")) { 411 if (find_home_of_exe("star")) { 412 flag_set['R'] = TRUE; 413 log_msg(1, "Using star instead of afio"); 414 } else { 415 fatal_error 416 ("Neither afio nor star is installed. Please install at least one."); 417 } 418 } 419 420 if (flag_set['R']) { 421 bkpinfo->use_star = TRUE; 422 if (flag_set['L']) { 423 fatal_error("You may not use star and lzop at the same time."); 424 } 425 if (!find_home_of_exe("star")) { 426 fatal_error 427 ("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); 428 } 429 } 430 if (flag_set['W']) { 431 bkpinfo->nonbootable_backup = TRUE; 432 log_to_screen("Warning - you have opted for non-bootable backup"); 433 if (flag_set['f'] || flag_set['l']) { 434 log_to_screen 435 ("You don't need to specify bootloader or bootdevice"); 436 } 437 } 438 if (flag_set['t'] && flag_set['H']) { 439 fatal_error 440 ("Sorry, you may not nuke w/o warning from tape. Drop -H, please."); 441 } 442 if (flag_set['I']) { 443 if (!strcmp(bkpinfo->include_paths, "/")) { 444 log_msg(2, "'/' is pleonastic."); 445 bkpinfo->include_paths[0] = '\0'; 446 } 447 if (bkpinfo->include_paths[0]) { 448 strcat(bkpinfo->include_paths, " "); 449 } 450 strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths), 451 flag_val['I'], 452 MAX_STR_LEN - strlen(bkpinfo->include_paths)); 453 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths); 454 if (bkpinfo->include_paths[0] == '-') { 455 retval++; 456 log_to_screen("Please supply a sensible value with '-I'\n"); 457 } 458 } 459 460 if (g_kernel_version >= 2.6 && !flag_set['d'] 461 && (flag_set['c'] || flag_set['w'])) { 462 fatal_error 463 ("If you are using the 2.6.x kernel, please specify the CD-R(W) device."); 464 } 465 466 467 if (flag_set['J']) { 468 if (flag_set['I']) { 469 retval++; 470 log_to_screen 471 ("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)"); 472 } 473 bkpinfo->make_filelist = FALSE; 474 strcpy(bkpinfo->include_paths, flag_val['J']); 475 } 476 if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) { 477 if (!flag_set['r'] && g_kernel_version <= 2.5 478 && strstr(flag_val['d'], "/dev/")) { 479 fatal_error 480 ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag."); 481 } 482 if (flag_set['r'] && g_kernel_version <= 2.5 483 && !strstr(flag_val['d'], "/dev/")) { 484 fatal_error 485 ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag."); 486 } 487 if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) { 488 log_to_screen 489 ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."); 490 } 491 492 if (system("which cdrecord > /dev/null 2> /dev/null") 493 && system("which dvdrecord > /dev/null 2> /dev/null")) { 494 fatal_error 495 ("Please install dvdrecord/cdrecord and try again."); 496 } 497 if (flag_set['C']) { 498 bkpinfo->cdrw_speed = 2; 499 if (!flag_set['L']) { 500 log_to_screen 501 ("You must use -L with -C. Therefore I am setting it for you."); 502 flag_set['L'] = 1; 503 flag_val['L'][0] = '\0'; 504 } 505 } else { 506 log_msg(3, "flag_val['c'] = %s", flag_val['c']); 507 log_msg(3, "flag_val['w'] = %s", flag_val['w']); 508 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] ); 509 if (flag_set['c']) { 510 bkpinfo->cdrw_speed = atoi(flag_val['c']); 511 } else if (flag_set['w']) { 512 bkpinfo->cdrw_speed = atoi(flag_val['w']); 513 } else if (flag_set['r']) { 514 bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */ 515 } 516 517 if (bkpinfo->cdrw_speed < 1) { 518 fatal_error 519 ("You specified a silly speed for a CD-R[W] drive"); 520 } 521 } 522 } 523 if (flag_set['t'] && !flag_set['d']) { 524 log_it("Hmm! No tape drive specified. Let's see what we can do."); 525 if (find_tape_device_and_size(flag_val['d'], tmp)) { 526 fatal_error 527 ("Tape device not specified. I couldn't find it either."); 528 } 529 flag_set['d'] = TRUE; 530 sprintf(tmp, 531 "You didn't specify a tape streamer device. I'm assuming %s", 532 flag_val['d']); 533 log_to_screen(tmp); 534 percent = 0; 535 } 536 537 if (flag_set['r']) // DVD 416 538 { 417 flag_set['R'] = TRUE; 418 log_msg(1, "Using star instead of afio"); 419 } 420 else 421 { 422 fatal_error("Neither afio nor star is installed. Please install at least one."); 423 } 424 } 425 426 if (flag_set['R']) 427 { 428 bkpinfo->use_star = TRUE; 429 if (flag_set['L']) 430 { fatal_error ("You may not use star and lzop at the same time."); } 431 if (!find_home_of_exe("star")) 432 { fatal_error ("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); } 433 } 434 if (flag_set['W']) 435 { 436 bkpinfo->nonbootable_backup = TRUE; 437 log_to_screen ("Warning - you have opted for non-bootable backup"); 438 if (flag_set['f'] || flag_set['l']) 439 { 440 log_to_screen ("You don't need to specify bootloader or bootdevice"); 441 } 442 } 443 if (flag_set['t'] && flag_set['H']) 444 { fatal_error("Sorry, you may not nuke w/o warning from tape. Drop -H, please."); } 445 if (flag_set['I']) 446 { 447 if (!strcmp(bkpinfo->include_paths, "/")) 448 { 449 log_msg(2, "'/' is pleonastic."); 450 bkpinfo->include_paths[0] = '\0'; 451 } 452 if (bkpinfo->include_paths[0]) 453 { strcat(bkpinfo->include_paths," "); } 454 strncpy (bkpinfo->include_paths+strlen(bkpinfo->include_paths), flag_val['I'], MAX_STR_LEN - strlen(bkpinfo->include_paths)); 455 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths); 456 if (bkpinfo->include_paths[0] == '-') 457 { 458 retval++; 459 log_to_screen( "Please supply a sensible value with '-I'\n"); 460 } 461 } 462 463 if (g_kernel_version >= 2.6 && !flag_set['d'] && (flag_set['c'] || flag_set['w'])) 464 { 465 fatal_error("If you are using the 2.6.x kernel, please specify the CD-R(W) device."); 466 } 467 468 469 if (flag_set['J']) 470 { 471 if (flag_set['I']) 472 { 473 retval++; 474 log_to_screen( "Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)"); 475 } 476 bkpinfo->make_filelist = FALSE; 477 strcpy(bkpinfo->include_paths, flag_val['J']); 478 } 479 if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) 480 { 481 if (!flag_set['r'] && g_kernel_version <= 2.5 && strstr(flag_val['d'], "/dev/")) 482 { fatal_error("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag."); } 483 if (flag_set['r'] && g_kernel_version <= 2.5 && !strstr(flag_val['d'], "/dev/")) 484 { fatal_error("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag."); } 485 if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) 486 { log_to_screen("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."); } 487 488 if (system ("which cdrecord > /dev/null 2> /dev/null") && system("which dvdrecord > /dev/null 2> /dev/null")) 489 { 490 fatal_error ("Please install dvdrecord/cdrecord and try again."); 491 } 492 if (flag_set['C']) 493 { 494 bkpinfo->cdrw_speed = 2; 495 if (!flag_set['L']) 496 { 497 log_to_screen ("You must use -L with -C. Therefore I am setting it for you."); 498 flag_set['L'] = 1; 499 flag_val['L'][0] = '\0'; 500 } 501 } 502 else 503 { 504 log_msg(3, "flag_val['c'] = %s", flag_val['c'] ); 505 log_msg(3, "flag_val['w'] = %s", flag_val['w'] ); 506 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] ); 507 if (flag_set['c']) { bkpinfo->cdrw_speed = atoi(flag_val['c']); } 508 else 509 if (flag_set['w']) { bkpinfo->cdrw_speed = atoi(flag_val['w']); } 510 else 511 if (flag_set['r']) { bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']);*/ } 512 513 if (bkpinfo->cdrw_speed < 1) 514 { 515 fatal_error ("You specified a silly speed for a CD-R[W] drive"); 516 } 517 } 518 } 519 if (flag_set['t'] && !flag_set['d']) 520 { 521 log_it("Hmm! No tape drive specified. Let's see what we can do."); 522 if (find_tape_device_and_size(flag_val['d'], tmp)) 523 { fatal_error("Tape device not specified. I couldn't find it either."); } 524 flag_set['d'] = TRUE; 525 sprintf(tmp, "You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']); 526 log_to_screen(tmp); 527 percent = 0; 528 } 529 530 if (flag_set['r']) // DVD 531 { 532 if (flag_set['m']) 533 { fatal_error("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); } 534 if (!flag_set['d']) 535 { 536 if (!find_dvd_device(flag_val['d'], FALSE)) 537 { 538 flag_set['d'] = TRUE; 539 log_to_screen("I guess DVD drive is at %s", flag_val['d']); 540 } 541 } 542 if (!find_home_of_exe("growisofs")) 543 { fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); } 544 if (!find_home_of_exe("dvd+rw-format")) 545 { fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); } 546 if (strchr(flag_val['d'], ',')) 547 { fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); } 548 if (!flag_set['s']) 549 { 550 sprintf (flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 551 strcat ( flag_val['s'], "m"); 552 log_to_screen ("You did not specify a size (-s) for DVD. I'm guessing %s.", flag_val['s']); 553 flag_set['s'] = 1; 554 } 539 if (flag_set['m']) { 540 fatal_error 541 ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); 542 } 543 if (!flag_set['d']) { 544 if (!find_dvd_device(flag_val['d'], FALSE)) { 545 flag_set['d'] = TRUE; 546 log_to_screen("I guess DVD drive is at %s", flag_val['d']); 547 } 548 } 549 if (!find_home_of_exe("growisofs")) { 550 fatal_error 551 ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); 552 } 553 if (!find_home_of_exe("dvd+rw-format")) { 554 fatal_error 555 ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); 556 } 557 if (strchr(flag_val['d'], ',')) { 558 fatal_error 559 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 560 } 561 if (!flag_set['s']) { 562 sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 563 strcat(flag_val['s'], "m"); 564 log_to_screen 565 ("You did not specify a size (-s) for DVD. I'm guessing %s.", 566 flag_val['s']); 567 flag_set['s'] = 1; 568 } 555 569 /* 556 570 if (flag_set['Z']) { … … 558 572 } 559 573 */ 560 } 561 562 if (flag_set['t'] || flag_set['u']) 563 { /* tape size */ 564 if (strchr(flag_val['d'], ',')) 565 { fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); } 566 if (flag_set['O']) 574 } 575 576 if (flag_set['t'] || flag_set['u']) { /* tape size */ 577 if (strchr(flag_val['d'], ',')) { 578 fatal_error 579 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 580 } 581 if (flag_set['O']) { 582 if (flag_set['s']) { 583 if (flag_set['t']) { 584 fatal_error 585 ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); 586 } 587 if (process_the_s_switch(bkpinfo, flag_val['s'])) { 588 fatal_error("Bad -s switch"); 589 } 590 } else if (flag_set['u'] || flag_set['t']) { 591 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 592 bkpinfo->media_size[i] = 0; 593 } 594 } else { 595 retval++; 596 log_to_screen("Tape size not specified.\n"); 597 } 598 } 599 } else { /* CD size */ 600 if (flag_set['s']) { 601 if (process_the_s_switch(bkpinfo, flag_val['s'])) { 602 fatal_error("Bad -s switch"); 603 } 604 } 605 if (flag_set['w']) { 606 bkpinfo->wipe_media_first = TRUE; 607 } /* CD-RW */ 608 } 609 if (flag_set['n']) { 610 strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN); 611 if (!flag_set['d']) { 612 strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN); 613 } 614 sprintf(tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3", 615 bkpinfo->nfs_mount); 616 strncpy(bkpinfo->isodir, 617 call_program_and_get_last_line_of_output(tmp), 618 MAX_STR_LEN / 4); 619 if (strlen(bkpinfo->isodir) < 3) { 620 retval++; 621 log_to_screen("NFS share is not mounted. Please mount it.\n"); 622 } 623 log_msg(3, "mount = %s", bkpinfo->nfs_mount); 624 log_msg(3, "isodir= %s", bkpinfo->isodir); 625 } 626 if (flag_set['c']) { 627 bkpinfo->backup_media_type = cdr; 628 } 629 if (flag_set['C']) { 630 bkpinfo->backup_media_type = cdstream; 631 } 632 if (flag_set['i']) { 633 bkpinfo->backup_media_type = iso; 634 } 635 if (flag_set['n']) { 636 bkpinfo->backup_media_type = nfs; 637 } 638 if (flag_set['r']) { 639 bkpinfo->backup_media_type = dvd; 640 } 641 if (flag_set['t']) { 642 bkpinfo->backup_media_type = tape; 643 } 644 if (flag_set['u']) { 645 bkpinfo->backup_media_type = udev; 646 } 647 if (flag_set['w']) { 648 bkpinfo->backup_media_type = cdrw; 649 } 650 651 /* optional, popular */ 652 if (flag_set['g']) { 653 g_text_mode = FALSE; 654 } 655 if (flag_set['E']) { 656 if (bkpinfo->exclude_paths[0]) { 657 strcat(bkpinfo->exclude_paths, " "); 658 } 659 strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths), 660 flag_val['E'], 661 MAX_STR_LEN - strlen(bkpinfo->exclude_paths)); 662 } 663 if (flag_set['e']) { 664 bkpinfo->please_dont_eject = TRUE; 665 } 666 if (flag_set['N']) // exclude NFS mounts & devices 567 667 { 568 if (flag_set['s'])569 {570 if (flag_set['t']) { fatal_error("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); }571 if (process_the_s_switch(bkpinfo, flag_val['s'])) {fatal_error("Bad -s switch");}572 }573 else if (flag_set['u'] || flag_set['t'])574 {575 for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 0; }576 }577 else578 {579 retval++;580 log_to_screen( "Tape size not specified.\n");581 }582 }583 }584 else585 { /* CD size */586 if (flag_set['s'])587 {588 if (process_the_s_switch(bkpinfo, flag_val['s'])) {fatal_error("Bad -s switch");}589 }590 if (flag_set['w'])591 {592 bkpinfo->wipe_media_first = TRUE;593 } /* CD-RW */594 }595 if (flag_set['n'])596 {597 strncpy (bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);598 if (!flag_set['d'])599 {600 strncpy (bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);601 }602 sprintf (tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",603 bkpinfo->nfs_mount);604 strncpy (bkpinfo->isodir,605 call_program_and_get_last_line_of_output (tmp), MAX_STR_LEN/4);606 if (strlen (bkpinfo->isodir) < 3)607 {608 retval++;609 log_to_screen( "NFS share is not mounted. Please mount it.\n");610 }611 log_msg(3, "mount = %s", bkpinfo->nfs_mount);612 log_msg(3, "isodir= %s", bkpinfo->isodir);613 }614 if (flag_set['c']) { bkpinfo->backup_media_type = cdr; }615 if (flag_set['C']) { bkpinfo->backup_media_type = cdstream; }616 if (flag_set['i']) { bkpinfo->backup_media_type = iso; }617 if (flag_set['n']) { bkpinfo->backup_media_type = nfs; }618 if (flag_set['r']) { bkpinfo->backup_media_type = dvd; }619 if (flag_set['t']) { bkpinfo->backup_media_type = tape; }620 if (flag_set['u']) { bkpinfo->backup_media_type = udev; }621 if (flag_set['w']) { bkpinfo->backup_media_type = cdrw; }622 623 /* optional, popular */624 if (flag_set['g'])625 {626 g_text_mode = FALSE;627 }628 if (flag_set['E'])629 {630 if (bkpinfo->exclude_paths[0])631 { strcat(bkpinfo->exclude_paths," "); }632 strncpy (bkpinfo->exclude_paths+strlen(bkpinfo->exclude_paths), flag_val['E'], MAX_STR_LEN - strlen(bkpinfo->exclude_paths));633 }634 if (flag_set['e'])635 {636 bkpinfo->please_dont_eject = TRUE;637 }638 if (flag_set['N']) // exclude NFS mounts & devices639 {640 668 // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN); 641 strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN); 642 if (bkpinfo->exclude_paths[0]) { strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN); } 643 strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN); 644 log_msg(3, "-N means we're now excluding %s", bkpinfo->exclude_paths); 645 } 646 if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) 647 { 648 fatal_error("Your '-E' parameter is too long. Please use '-J'. (See manual.)"); 649 } 650 if (flag_set['b']) 651 { 652 strcpy(psz, flag_val['b']); 653 log_msg(1, "psz = '%s'", psz); 654 if (psz[strlen(psz)-1] == 'k') 655 { psz[strlen(psz)-1] = '\0'; itbs = atol(psz) * 1024L; } 656 else 657 { itbs = atol(psz); } 658 log_msg(1, "'%s' --> %ld", flag_val['b'], itbs); 659 log_msg(1, "Internal tape block size is now %ld bytes", itbs); 660 if (itbs%512!=0 || itbs < 256 || itbs > 1024L*1024) 661 { fatal_error("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); } 662 bkpinfo->internal_tape_block_size = itbs; 663 } 664 if (flag_set['D']) 665 { 666 bkpinfo->differential = 1; 669 strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN); 670 if (bkpinfo->exclude_paths[0]) { 671 strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN); 672 } 673 strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN); 674 log_msg(3, "-N means we're now excluding %s", 675 bkpinfo->exclude_paths); 676 } 677 if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) { 678 fatal_error 679 ("Your '-E' parameter is too long. Please use '-J'. (See manual.)"); 680 } 681 if (flag_set['b']) { 682 strcpy(psz, flag_val['b']); 683 log_msg(1, "psz = '%s'", psz); 684 if (psz[strlen(psz) - 1] == 'k') { 685 psz[strlen(psz) - 1] = '\0'; 686 itbs = atol(psz) * 1024L; 687 } else { 688 itbs = atol(psz); 689 } 690 log_msg(1, "'%s' --> %ld", flag_val['b'], itbs); 691 log_msg(1, "Internal tape block size is now %ld bytes", itbs); 692 if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) { 693 fatal_error 694 ("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); 695 } 696 bkpinfo->internal_tape_block_size = itbs; 697 } 698 if (flag_set['D']) { 699 bkpinfo->differential = 1; 667 700 // bkpinfo->differential = atoi (flag_val['D']); 668 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) 669 { 670 fatal_error ("The D option should be between 1 and 9 inclusive"); 671 } 672 } 673 if (flag_set['x']) 674 { 675 strncpy (bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN/4); 676 if (run_program_and_log_output("which partimagehack", 2)) 677 { fatal_error("Please install partimagehack RPM/tarball."); } 678 } 679 if (flag_set['m']) 680 { 681 bkpinfo->manual_cd_tray = TRUE; 682 } 683 if (flag_set['k']) 684 { 685 strncpy (bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN); 686 if (!strcmp (bkpinfo->kernel_path, "failsafe")) 687 { 688 strcpy (bkpinfo->kernel_path, "FAILSAFE"); 689 } 690 if (strcmp (bkpinfo->kernel_path, "FAILSAFE") 691 && !does_file_exist (bkpinfo->kernel_path)) 692 { 693 retval++; 694 sprintf(tmp, 695 "You specified kernel '%s', which does not exist\n", 696 bkpinfo->kernel_path); 697 log_to_screen(tmp); 698 } 699 } 700 if (flag_set['p']) 701 { 702 strncpy (bkpinfo->prefix, flag_val['p'], MAX_STR_LEN/4); 703 } 704 705 706 if (flag_set['d']) 707 { /* backup directory (if ISO/NFS) */ 708 if (flag_set['i']) 709 { 710 strncpy (bkpinfo->isodir, flag_val['d'], MAX_STR_LEN/4); 711 sprintf(tmp, "ls -l %s", bkpinfo->isodir); 712 if (run_program_and_log_output(tmp, FALSE)) { fatal_error("output folder does not exist - please create it"); } 713 } 714 else if (flag_set['n']) 715 { 716 strncpy (bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); 717 } 718 else /* backup device (if tape/CD-R/CD-RW) */ 719 { 720 strncpy (bkpinfo->media_device, flag_val['d'], MAX_STR_LEN/4); 721 } 722 } 723 724 if (flag_set['n']) 725 { 726 sprintf (tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, bkpinfo->nfs_remote_dir); 727 if (run_program_and_log_output (tmp, FALSE)) 728 { 729 retval++; 730 sprintf (tmp, "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", 731 bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount); 732 log_to_screen (tmp); 733 } 734 } 735 736 if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) 737 { 738 if (g_kernel_version >= 2.6) 739 { 740 if (popup_and_get_string("Device", "Please specify the device", bkpinfo->media_device, MAX_STR_LEN/4)) 741 { 742 retval ++; 743 log_to_screen("User opted to cancel."); 744 } 745 } 746 else if (find_cdrw_device (bkpinfo->media_device)) 747 { 748 retval++; 749 log_to_screen( 750 "Tried and failed to find CD-R[W] drive automatically.\n"); 751 } 752 else 753 { 754 flag_set['d'] = TRUE; 755 strncpy (flag_val['d'], bkpinfo->media_device, MAX_STR_LEN/4); 756 } 757 } 758 759 if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) 760 { 761 retval++; 762 log_to_screen( "Please specify the backup device/directory.\n"); 763 fatal_error("You didn't use -d to specify the backup device/directory."); 764 } 701 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) { 702 fatal_error 703 ("The D option should be between 1 and 9 inclusive"); 704 } 705 } 706 if (flag_set['x']) { 707 strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4); 708 if (run_program_and_log_output("which partimagehack", 2)) { 709 fatal_error("Please install partimagehack RPM/tarball."); 710 } 711 } 712 if (flag_set['m']) { 713 bkpinfo->manual_cd_tray = TRUE; 714 } 715 if (flag_set['k']) { 716 strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN); 717 if (!strcmp(bkpinfo->kernel_path, "failsafe")) { 718 strcpy(bkpinfo->kernel_path, "FAILSAFE"); 719 } 720 if (strcmp(bkpinfo->kernel_path, "FAILSAFE") 721 && !does_file_exist(bkpinfo->kernel_path)) { 722 retval++; 723 sprintf(tmp, 724 "You specified kernel '%s', which does not exist\n", 725 bkpinfo->kernel_path); 726 log_to_screen(tmp); 727 } 728 } 729 if (flag_set['p']) { 730 strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4); 731 } 732 733 734 if (flag_set['d']) { /* backup directory (if ISO/NFS) */ 735 if (flag_set['i']) { 736 strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4); 737 sprintf(tmp, "ls -l %s", bkpinfo->isodir); 738 if (run_program_and_log_output(tmp, FALSE)) { 739 fatal_error 740 ("output folder does not exist - please create it"); 741 } 742 } else if (flag_set['n']) { 743 strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); 744 } else { /* backup device (if tape/CD-R/CD-RW) */ 745 746 strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4); 747 } 748 } 749 750 if (flag_set['n']) { 751 sprintf(tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, 752 bkpinfo->nfs_remote_dir); 753 if (run_program_and_log_output(tmp, FALSE)) { 754 retval++; 755 sprintf(tmp, 756 "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", 757 bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount); 758 log_to_screen(tmp); 759 } 760 } 761 762 if (!flag_set['d'] 763 && (flag_set['c'] || flag_set['w'] || flag_set['C'])) { 764 if (g_kernel_version >= 2.6) { 765 if (popup_and_get_string 766 ("Device", "Please specify the device", 767 bkpinfo->media_device, MAX_STR_LEN / 4)) { 768 retval++; 769 log_to_screen("User opted to cancel."); 770 } 771 } else if (find_cdrw_device(bkpinfo->media_device)) { 772 retval++; 773 log_to_screen 774 ("Tried and failed to find CD-R[W] drive automatically.\n"); 775 } else { 776 flag_set['d'] = TRUE; 777 strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4); 778 } 779 } 780 781 if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) { 782 retval++; 783 log_to_screen("Please specify the backup device/directory.\n"); 784 fatal_error 785 ("You didn't use -d to specify the backup device/directory."); 786 } 765 787 /* optional, obscure */ 766 for (i = '0'; i <= '9'; i++) 767 { 768 if (flag_set[i]) 769 { 770 bkpinfo->compression_level = i - '0'; 771 } /* not '\0' but '0' */ 772 } 773 if (flag_set['S']) 774 { 775 sprintf (bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], 776 random () % 32768); 777 } 778 if (flag_set['T']) 779 { 780 sprintf (bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'], 781 random () % 32768); 782 sprintf(tmp, "touch %s/.foo.dat", flag_val['T']); 783 if (run_program_and_log_output(tmp, 1)) 784 { 785 retval++; 786 log_to_screen( "Please specify a tempdir which I can write to. :)"); 787 fatal_error("I cannot write to the tempdir you specified."); 788 } 789 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'], flag_val['T']); 790 if (run_program_and_log_output(tmp, 1)) 791 { 792 retval++; 793 log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir."); 794 fatal_error("I cannot write to the tempdir you specified."); 795 } 796 } 797 if (flag_set['A']) 798 { 799 strncpy (bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN); 800 } 801 if (flag_set['B']) 802 { 803 strncpy (bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN); 804 } 805 if (flag_set['F']) 806 { 807 g_skip_floppies = TRUE; 808 } 809 if (flag_set['H']) 810 { 811 g_cd_recovery = TRUE; 812 } 813 if (flag_set['l']) 814 { 788 for (i = '0'; i <= '9'; i++) { 789 if (flag_set[i]) { 790 bkpinfo->compression_level = i - '0'; 791 } /* not '\0' but '0' */ 792 } 793 if (flag_set['S']) { 794 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], 795 random() % 32768); 796 } 797 if (flag_set['T']) { 798 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'], 799 random() % 32768); 800 sprintf(tmp, "touch %s/.foo.dat", flag_val['T']); 801 if (run_program_and_log_output(tmp, 1)) { 802 retval++; 803 log_to_screen 804 ("Please specify a tempdir which I can write to. :)"); 805 fatal_error("I cannot write to the tempdir you specified."); 806 } 807 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'], 808 flag_val['T']); 809 if (run_program_and_log_output(tmp, 1)) { 810 retval++; 811 log_to_screen 812 ("Please don't specify a SAMBA or VFAT or NFS tmpdir."); 813 fatal_error("I cannot write to the tempdir you specified."); 814 } 815 } 816 if (flag_set['A']) { 817 strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN); 818 } 819 if (flag_set['B']) { 820 strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN); 821 } 822 if (flag_set['F']) { 823 g_skip_floppies = TRUE; 824 } 825 if (flag_set['H']) { 826 g_cd_recovery = TRUE; 827 } 828 if (flag_set['l']) { 815 829 #ifdef __FreeBSD__ 816 830 # define BOOT_LOADER_CHARS "GLBMR" … … 822 836 # endif 823 837 #endif 824 if (!strchr(BOOT_LOADER_CHARS, (bkpinfo->boot_loader = flag_val['l'][0]))) 825 { 826 log_msg(1, "%c? WTF is %c? I need G, L, E or R.", bkpinfo->boot_loader, bkpinfo->boot_loader); 827 fatal_error("Please specify GRUB, LILO, ELILO or RAW with the -l switch"); 828 } 838 if (!strchr 839 (BOOT_LOADER_CHARS, 840 (bkpinfo->boot_loader = flag_val['l'][0]))) { 841 log_msg(1, "%c? WTF is %c? I need G, L, E or R.", 842 bkpinfo->boot_loader, bkpinfo->boot_loader); 843 fatal_error 844 ("Please specify GRUB, LILO, ELILO or RAW with the -l switch"); 845 } 829 846 #undef BOOT_LOADER_CHARS 830 831 if (flag_set['f']) 832 { 833 strncpy (bkpinfo->boot_device, resolve_softlinks_to_get_to_actual_device_file(flag_val['f']), MAX_STR_LEN/4); 834 } 835 if (flag_set['P']) 836 { 837 strncpy (bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); 838 } 839 if (flag_set['Q']) 840 841 842 843 844 845 846 if (flag_set['L']) 847 { 848 bkpinfo->use_lzo = TRUE; 849 if (run_program_and_log_output ("which lzop", FALSE)) 850 {851 retval++;852 log_to_screen(853 "Please install LZOP. You can't use '-L' until you do.\n");854 } 855 } 856 857 if (!flag_set['o'] && !run_program_and_log_output("cat /etc/issue.net | grep -i suse | grep 64", TRUE)) 858 859 860 log_to_screen("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."); 861 } 862 if (flag_set['o']) 863 864 865 847 } 848 if (flag_set['f']) { 849 strncpy(bkpinfo->boot_device, 850 resolve_softlinks_to_get_to_actual_device_file(flag_val 851 ['f']), 852 MAX_STR_LEN / 4); 853 } 854 if (flag_set['P']) { 855 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); 856 } 857 if (flag_set['Q']) { 858 i = which_boot_loader(tmp); 859 log_msg(3, "boot loader is %c, residing at %s", i, tmp); 860 printf("boot loader is %c, residing at %s\n", i, tmp); 861 finish(0); 862 } 863 if (flag_set['L']) { 864 bkpinfo->use_lzo = TRUE; 865 if (run_program_and_log_output("which lzop", FALSE)) { 866 retval++; 867 log_to_screen 868 ("Please install LZOP. You can't use '-L' until you do.\n"); 869 } 870 } 871 872 if (!flag_set['o'] 873 && 874 !run_program_and_log_output 875 ("cat /etc/issue.net | grep -i suse | grep 64", TRUE)) { 876 bkpinfo->make_cd_use_lilo = TRUE; 877 log_to_screen 878 ("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."); 879 } 880 if (flag_set['o']) { 881 bkpinfo->make_cd_use_lilo = TRUE; 882 } 866 883 #ifndef __FreeBSD__ 867 else 868 { 869 if (!is_this_a_valid_disk_format("vfat")) 870 { 871 bkpinfo->make_cd_use_lilo = TRUE; 872 log_to_screen( "Your kernel appears not to support vfat filesystems. I am therefore"); 873 log_to_screen( "using LILO instead of SYSLINUX as the CD/floppy's boot loader."); 874 } 875 if (run_program_and_log_output("which mkfs.vfat", FALSE)) 876 { 877 bkpinfo->make_cd_use_lilo = TRUE; 884 else { 885 if (!is_this_a_valid_disk_format("vfat")) { 886 bkpinfo->make_cd_use_lilo = TRUE; 887 log_to_screen 888 ("Your kernel appears not to support vfat filesystems. I am therefore"); 889 log_to_screen 890 ("using LILO instead of SYSLINUX as the CD/floppy's boot loader."); 891 } 892 if (run_program_and_log_output("which mkfs.vfat", FALSE)) { 893 bkpinfo->make_cd_use_lilo = TRUE; 878 894 #ifdef __IA32__ 879 log_to_screen( "Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"); 880 log_to_screen( "your boot loader. I shall therefore use LILO instead."); 895 log_to_screen 896 ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"); 897 log_to_screen 898 ("your boot loader. I shall therefore use LILO instead."); 881 899 #endif 882 900 #ifdef __IA64__ 883 log_to_screen( "Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 884 log_to_screen( "environment correctly. Please install it."); 885 fatal_error("Aborting"); 901 log_to_screen 902 ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 903 log_to_screen("environment correctly. Please install it."); 904 fatal_error("Aborting"); 886 905 #endif 887 }906 } 888 907 #ifdef __IA64__ 889 890 908 /* We force ELILO usage on IA64 */ 909 bkpinfo->make_cd_use_lilo = TRUE; 891 910 #endif 892 911 } 893 912 #endif 894 913 895 if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) 896 { 897 paranoid_system("touch /boot/boot.b"); 898 } 899 900 i = flag_set['O'] + flag_set['V']; 901 if (i == 0) 902 { 903 retval++; 904 log_to_screen( "Specify backup (-O), verify (-V) or both (-OV).\n"); 905 } 914 if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) { 915 paranoid_system("touch /boot/boot.b"); 916 } 917 918 i = flag_set['O'] + flag_set['V']; 919 if (i == 0) { 920 retval++; 921 log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n"); 922 } 906 923 907 924 /* and finally... */ 908 925 909 910 paranoid_free(psz); 911 926 paranoid_free(tmp); 927 paranoid_free(psz); 928 return (retval); 912 929 } 913 930 … … 926 943 */ 927 944 int 928 retrieve_switches_from_command_line 929 930 945 retrieve_switches_from_command_line(int argc, char *argv[], 946 char flag_val[128][MAX_STR_LEN], 947 bool flag_set[128]) 931 948 { 932 /*@ ints ***/ 933 int opt = 0; 934 char tmp[MAX_STR_LEN]; 935 int i = 0; 936 int len; 937 938 /*@ bools ****/ 939 bool bad_switches = FALSE; 940 941 assert(flag_val!=NULL); 942 assert(flag_set!=NULL); 943 944 for (i = 0; i < 128; i++) 945 { 946 flag_val[i][0] = '\0'; 947 flag_set[i] = FALSE; 948 } 949 while ((opt = 950 getopt (argc, argv, 951 "0123456789A:B:CDE:FHI:J:K:LNOP:QRS:T:VWb:c:d:ef:gik:l:mn:op:rs:tuw:x:")) != 952 -1) 953 { 954 if (opt == '?') 955 { 956 bad_switches = TRUE; 957 /*log_it("Invalid option: %c\n",optopt); */ 958 } 959 else 960 { 961 if (flag_set[optopt]) 962 { 963 bad_switches = TRUE; 964 sprintf(tmp, "Switch -%c previously defined as %s\n", opt, 965 flag_val[i]); 966 log_to_screen(tmp); 967 } 968 else 969 { 970 flag_set[opt] = TRUE; 971 if (optarg) 972 { 973 len = strlen(optarg); 974 if (optarg[0] != '/' && optarg[len-1] == '/') 975 { 976 optarg[--len] = '\0'; 977 log_to_screen("Warning - param '%s' should not have trailing slash!", optarg); 978 } 979 if (opt=='d') 980 { 981 if (strchr(flag_val[opt], '/') && flag_val[opt][0]!='/') 982 { 983 sprintf(tmp, "-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]); 984 log_to_screen(tmp); 985 bad_switches = TRUE; 986 } 987 } 988 strcpy(flag_val[opt], optarg); 989 } 990 } 991 } 992 } 993 for (i = optind; i < argc; i++) 994 { 995 bad_switches = TRUE; 996 sprintf(tmp, "Invalid arg -- %s\n", argv[i]); 997 log_to_screen(tmp); 998 } 999 return (bad_switches); 949 /*@ ints ** */ 950 int opt = 0; 951 char tmp[MAX_STR_LEN]; 952 int i = 0; 953 int len; 954 955 /*@ bools *** */ 956 bool bad_switches = FALSE; 957 958 assert(flag_val != NULL); 959 assert(flag_set != NULL); 960 961 for (i = 0; i < 128; i++) { 962 flag_val[i][0] = '\0'; 963 flag_set[i] = FALSE; 964 } 965 while ((opt = 966 getopt(argc, argv, 967 "0123456789A:B:CDE:FHI:J:K:LNOP:QRS:T:VWb:c:d:ef:gik:l:mn:op:rs:tuw:x:")) 968 != -1) { 969 if (opt == '?') { 970 bad_switches = TRUE; 971 /*log_it("Invalid option: %c\n",optopt); */ 972 } else { 973 if (flag_set[optopt]) { 974 bad_switches = TRUE; 975 sprintf(tmp, "Switch -%c previously defined as %s\n", opt, 976 flag_val[i]); 977 log_to_screen(tmp); 978 } else { 979 flag_set[opt] = TRUE; 980 if (optarg) { 981 len = strlen(optarg); 982 if (optarg[0] != '/' && optarg[len - 1] == '/') { 983 optarg[--len] = '\0'; 984 log_to_screen 985 ("Warning - param '%s' should not have trailing slash!", 986 optarg); 987 } 988 if (opt == 'd') { 989 if (strchr(flag_val[opt], '/') 990 && flag_val[opt][0] != '/') { 991 sprintf(tmp, 992 "-%c flag --- must be absolute path --- '%s' isn't absolute", 993 opt, flag_val[opt]); 994 log_to_screen(tmp); 995 bad_switches = TRUE; 996 } 997 } 998 strcpy(flag_val[opt], optarg); 999 } 1000 } 1001 } 1002 } 1003 for (i = optind; i < argc; i++) { 1004 bad_switches = TRUE; 1005 sprintf(tmp, "Invalid arg -- %s\n", argv[i]); 1006 log_to_screen(tmp); 1007 } 1008 return (bad_switches); 1000 1009 } 1001 1010 … … 1006 1015 * Print a not-so-helpful help message and exit. 1007 1016 */ 1008 void 1009 help_screen () 1017 void help_screen() 1010 1018 { 1011 log_msg(1,"Type 'man mondo-archive' for more information\n");1012 exit(1);1019 log_msg(1, "Type 'man mondo-archive' for more information\n"); 1020 exit(1); 1013 1021 } 1014 1022 … … 1020 1028 void terminate_daemon(int sig) 1021 1029 { 1022 char tmp[64]; 1023 char tmp2 [MAX_STR_LEN]; 1024 // char command[512]; 1025 // pid_t pid; 1026 1027 switch(sig) 1028 { 1030 char tmp[64]; 1031 char tmp2[MAX_STR_LEN]; 1032 // char command[512]; 1033 // pid_t pid; 1034 1035 switch (sig) { 1029 1036 case SIGINT: 1030 1037 sprintf(tmp, "SIGINT"); … … 1033 1040 case SIGKILL: 1034 1041 sprintf(tmp, "SIGKILL"); 1035 strcpy(tmp2, "I seriously have no clue how this signal even got to me. Something's wrong with your system."); 1042 strcpy(tmp2, 1043 "I seriously have no clue how this signal even got to me. Something's wrong with your system."); 1036 1044 break; 1037 1045 case SIGTERM: 1038 1046 sprintf(tmp, "SIGTERM"); 1039 strcpy 1047 strcpy(tmp2, "Got terminate signal"); 1040 1048 break; 1041 1049 case SIGHUP: 1042 1050 sprintf(tmp, "SIGHUP"); 1043 strcpy 1051 strcpy(tmp2, "Hangup on line"); 1044 1052 break; 1045 1053 case SIGSEGV: 1046 1054 sprintf(tmp, "SIGSEGV"); 1047 strcpy (tmp2, "Internal programming error. Please send a backtrace as well as your log."); 1055 strcpy(tmp2, 1056 "Internal programming error. Please send a backtrace as well as your log."); 1048 1057 break; 1049 1058 case SIGPIPE: 1050 1059 sprintf(tmp, "SIGPIPE"); 1051 strcpy 1060 strcpy(tmp2, "Pipe was broken"); 1052 1061 break; 1053 case SIGABRT: 1054 sprintf (tmp, "SIGABRT"); 1055 sprintf (tmp2, "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."); 1056 break; 1062 case SIGABRT: 1063 sprintf(tmp, "SIGABRT"); 1064 sprintf(tmp2, 1065 "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."); 1066 break; 1057 1067 default: 1058 1068 sprintf(tmp, "(Unknown)"); 1059 } 1060 1061 strcat(tmp, " signal received from OS"); 1062 log_to_screen(tmp); 1063 log_to_screen (tmp2); 1064 if (sig == SIGABRT) { 1065 sleep (10); 1066 } 1067 kill_buffer(); 1068 fatal_error("Mondoarchive is terminating in response to a signal from the OS"); 1069 finish(254); // just in case 1069 } 1070 1071 strcat(tmp, " signal received from OS"); 1072 log_to_screen(tmp); 1073 log_to_screen(tmp2); 1074 if (sig == SIGABRT) { 1075 sleep(10); 1076 } 1077 kill_buffer(); 1078 fatal_error 1079 ("Mondoarchive is terminating in response to a signal from the OS"); 1080 finish(254); // just in case 1070 1081 } 1071 1082 … … 1079 1090 void set_signals(int on) 1080 1091 { 1081 int signals[]= { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1082 int i; 1083 1084 signal(SIGPIPE, sigpipe_occurred); 1085 for (i=0; signals[i]; i++) 1086 { 1087 if (on) 1088 { signal(signals[i], terminate_daemon); } 1089 else 1090 { signal(signals[i], termination_in_progress); } 1091 } 1092 int signals[] = 1093 { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1094 int i; 1095 1096 signal(SIGPIPE, sigpipe_occurred); 1097 for (i = 0; signals[i]; i++) { 1098 if (on) { 1099 signal(signals[i], terminate_daemon); 1100 } else { 1101 signal(signals[i], termination_in_progress); 1102 } 1103 } 1092 1104 } 1093 1105 … … 1101 1113 void termination_in_progress(int sig) 1102 1114 { 1103 1104 1105 1115 log_msg(1, "Termination in progress"); 1116 usleep(1000); 1117 pthread_exit(0); 1106 1118 } 1107 1119 -
trunk/mondo/mondo/mondoarchive/mondo-cli.h
r30 r59 1 1 /* mondo-cli.h 2 * $Id : mondo-cli.h,v 1.2 2004/06/10 15:29:13 hugo Exp$2 * $Id$ 3 3 */ 4 4 5 int handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo); 5 int handle_incoming_parameters(int argc, char *argv[], 6 struct s_bkpinfo *bkpinfo); 6 7 int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 7 int process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN],8 9 int retrieve_switches_from_command_line 10 11 12 void help_screen 8 int process_switches(struct s_bkpinfo *bkpinfo, 9 char flag_val[128][MAX_STR_LEN], bool flag_set[128]); 10 int retrieve_switches_from_command_line(int argc, char *argv[], 11 char flag_val[128][MAX_STR_LEN], 12 bool flag_set[128]); 13 void help_screen(); 13 14 void terminate_daemon(int sig); 14 15 void set_signals(int on); 15 16 void termination_in_progress(int sig); 16 17
Note:
See TracChangeset
for help on using the changeset viewer.