[1] | 1 | /***************************************************************************
|
---|
| 2 | mondo-cli.c
|
---|
| 3 | -------------------
|
---|
| 4 | begin : Fri Apr 19 16:40:35 EDT 2002
|
---|
| 5 | copyright : (C) 2002 Mondo Hugo Rabson
|
---|
| 6 | email : Hugo Rabson <hugorabson@msn.com>
|
---|
| 7 | edited by : by Stan Benoit 4/2002
|
---|
| 8 | email : troff@nakedsoul.org
|
---|
[116] | 9 | cvsid : $Id: mondo-cli.c 1702 2007-10-23 23:57:41Z bruno $
|
---|
[1] | 10 | ***************************************************************************/
|
---|
| 11 |
|
---|
| 12 | /***************************************************************************
|
---|
| 13 | * *
|
---|
| 14 | * This program is free software; you can redistribute it and/or modify *
|
---|
| 15 | * it under the terms of the GNU General Public License as published by *
|
---|
| 16 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
| 17 | * (at your option) any later version. *
|
---|
| 18 | * *
|
---|
| 19 | ***************************************************************************/
|
---|
| 20 |
|
---|
| 21 | /***************************************************************************
|
---|
| 22 | UPDATE LOG
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | 08/04
|
---|
| 26 | - if user specifies a dumb -T value, abort
|
---|
| 27 |
|
---|
| 28 | 07/22
|
---|
| 29 | - handle -Q sensibly (don't abort if only -Q supplied)
|
---|
| 30 |
|
---|
| 31 | 07/17
|
---|
| 32 | - better checking of NFS dir's validity
|
---|
| 33 |
|
---|
| 34 | 06/19
|
---|
| 35 | - added AUX_VER
|
---|
| 36 |
|
---|
| 37 | 04/17
|
---|
| 38 | - added '-b' support
|
---|
| 39 | 04/03
|
---|
| 40 | - added star support
|
---|
| 41 |
|
---|
| 42 | 02/06
|
---|
| 43 | - fixed "Please give /dev entry" error msg
|
---|
| 44 |
|
---|
| 45 | 01/20/2004
|
---|
| 46 | - added 2.6.x-kernel "device = /dev/...." support to param reader
|
---|
| 47 | - better handling of SCSI and /dev entries
|
---|
| 48 | - touch /boot/boot.b if necessary
|
---|
| 49 |
|
---|
| 50 | 09/26/2003
|
---|
| 51 | - typo in command-line handling of 'r'
|
---|
| 52 |
|
---|
| 53 | 09/25
|
---|
| 54 | - added DVD write support
|
---|
| 55 |
|
---|
| 56 | 09/24
|
---|
| 57 | - if tape backup (-t) but user doesn't specify tape drive then
|
---|
| 58 | make an educated guess using find_tape_device_and_size()
|
---|
| 59 |
|
---|
| 60 | 09/18
|
---|
| 61 | - insist on partimagehack being present if -x found
|
---|
| 62 |
|
---|
| 63 | 09/16
|
---|
| 64 | - added support for multiple -I's and -E's in call to mondoarchive
|
---|
| 65 | - the '-D' flag doesn't take a value now
|
---|
| 66 |
|
---|
| 67 | 07/14
|
---|
| 68 | - fatal error if -E too short
|
---|
| 69 |
|
---|
| 70 | 05/14
|
---|
| 71 | - if 'n' and user doesn't have rights to write to output dir
|
---|
| 72 | then error out
|
---|
| 73 |
|
---|
| 74 | 05/05
|
---|
| 75 | - added Joshua Oreman's FreeBSD patches
|
---|
| 76 |
|
---|
| 77 | 05/04
|
---|
| 78 | - added Herman Kuster's multi-level bkp patch
|
---|
| 79 |
|
---|
| 80 | 05/02
|
---|
| 81 | - write errors to screen, not just to log
|
---|
| 82 |
|
---|
| 83 | 04/25
|
---|
| 84 | - added lots of assert()'s and log_OS_error()'s
|
---|
| 85 |
|
---|
| 86 | 04/21
|
---|
| 87 | - line 570 --- resolve boot device if softlink
|
---|
| 88 |
|
---|
| 89 | 04/08
|
---|
| 90 | - changed a bunch of fprintf(stderr,...)'s to log_it()'s
|
---|
| 91 | - fixed final / removal in retrieve_switches_from_command_line()
|
---|
| 92 |
|
---|
| 93 | 04/04
|
---|
| 94 | - added -e
|
---|
| 95 |
|
---|
| 96 | 03/15
|
---|
| 97 | - reject relative paths if -d flag (Alessandro Polverini)
|
---|
| 98 |
|
---|
| 99 | 01/02/2003
|
---|
| 100 | - added -J flag (to let user specify incoming filelist)
|
---|
| 101 |
|
---|
| 102 | 12/13/2002
|
---|
| 103 | - various strcpy() calls replaced with strncpy() calls
|
---|
| 104 |
|
---|
| 105 | 12/10
|
---|
| 106 | - added g_loglevel
|
---|
| 107 |
|
---|
| 108 | 11/25
|
---|
| 109 | - line 614 --- if commmand-line param ends in '/' then drop that '/'
|
---|
| 110 |
|
---|
| 111 | 11/19
|
---|
| 112 | - rewrote finish() to kill processes more softly
|
---|
| 113 | - if user calls with '-l RAW' then
|
---|
| 114 |
|
---|
| 115 | 09/01 - 09/30
|
---|
| 116 | - added -N to let user exclude all NFS-related mounts and devices
|
---|
| 117 | - run_program_and_log_output() now takes boolean operator to specify
|
---|
| 118 | whether it will log its activities in the event of _success_
|
---|
| 119 |
|
---|
| 120 | 08/01 - 08/31
|
---|
| 121 | - if no device specified when backing up to tape streamer then assume /dev/st0
|
---|
| 122 | - abort if tape user specifies tape size (just for testing porpoises)
|
---|
| 123 | - tape users no longer need to specify tape size
|
---|
| 124 | - added some comments
|
---|
| 125 | - added bkpinfo->backup_media_type
|
---|
| 126 | - renamed from mondo-archive.c to mondo-cli.c
|
---|
| 127 |
|
---|
| 128 | 07/01 - 07/31
|
---|
| 129 | - better check for mkfs.vfat
|
---|
| 130 | - more sanity-checking for -d flag
|
---|
| 131 | - if isodir does not exist then abort
|
---|
| 132 | - removed "the rest are..." comment from log
|
---|
| 133 | - do not permit '-H' and '-t' in the same command line
|
---|
| 134 | - if not '-o' then insist on vfat-friendly kernel
|
---|
| 135 |
|
---|
| 136 | 06/01 - 06/30
|
---|
| 137 | - added signal-trapping
|
---|
| 138 | - added '-W' (won't make bootable CD or floppies) flag
|
---|
| 139 | - added missing 'j++' to -s switch's code
|
---|
| 140 | - expanded -s switch
|
---|
| 141 | - added -u switch
|
---|
| 142 | - if dvdrecord exists and cdrecord doesn't then use
|
---|
| 143 | dvdrecord instead of cdrecord
|
---|
| 144 |
|
---|
| 145 | 04/01 - 04/30
|
---|
| 146 | - if CD-ROM is supermounted then unmount, run, and remount
|
---|
| 147 | - replace MONDO_VERSION #define with VERSION from ../config.h
|
---|
| 148 | - if CD-ROM is mounted at start then abort
|
---|
| 149 | - improved homedir-locating code
|
---|
| 150 | - improved "backup will occupy N CD's" calculation a bit
|
---|
| 151 | - added -m (manual CD tray) flag
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | *******************************************************************/
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * @file
|
---|
| 158 | * Functions for handling command-line arguments passed to mondoarchive.
|
---|
| 159 | */
|
---|
| 160 |
|
---|
| 161 | /** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
|
---|
| 162 |
|
---|
| 163 | #include <pthread.h>
|
---|
| 164 | #include "../common/my-stuff.h"
|
---|
| 165 | #include "../common/mondostructures.h"
|
---|
| 166 | #include "mondo-cli-EXT.h"
|
---|
| 167 | #include "../common/libmondo.h"
|
---|
| 168 |
|
---|
[116] | 169 | //static char cvsid[] = "$Id: mondo-cli.c 1702 2007-10-23 23:57:41Z bruno $";
|
---|
[1] | 170 |
|
---|
| 171 | extern int g_loglevel;
|
---|
| 172 | extern bool g_text_mode;
|
---|
[116] | 173 | extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks
|
---|
| 174 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
|
---|
[1] | 175 | extern char g_tmpfs_mountpt[MAX_STR_LEN];
|
---|
| 176 | extern bool g_sigpipe;
|
---|
| 177 |
|
---|
| 178 | /*@ file pointer **************************************************/
|
---|
| 179 | extern FILE *g_tape_stream;
|
---|
| 180 |
|
---|
| 181 | /*@ long long *****************************************************/
|
---|
| 182 | extern long long g_tape_posK;
|
---|
| 183 |
|
---|
| 184 | /*@ long **********************************************************/
|
---|
| 185 | extern long g_noof_sets;
|
---|
| 186 |
|
---|
| 187 | /*@ bool******** **************************************************/
|
---|
[116] | 188 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
| 189 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
[1] | 190 | extern bool g_cd_recovery;
|
---|
| 191 |
|
---|
[1656] | 192 | extern void setup_tmpdir(char *path);
|
---|
| 193 |
|
---|
[1] | 194 | /**
|
---|
| 195 | * Whether we're restoring from ISOs. Obviously not, since this is the
|
---|
| 196 | * backup program.
|
---|
| 197 | * @note You @b MUST declare this variable somewhere in your program if
|
---|
| 198 | * you use libmondo. Otherwise the link will fail.
|
---|
| 199 | * @ingroup globalGroup
|
---|
| 200 | */
|
---|
| 201 | bool g_ISO_restore_mode = FALSE;
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | extern double g_kernel_version;
|
---|
| 205 | extern int g_current_media_number;
|
---|
| 206 | extern pid_t g_main_pid;
|
---|
[116] | 207 | extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
|
---|
[1] | 208 |
|
---|
[948] | 209 | /* Do we use extended attributes and acl ?
|
---|
| 210 | * By default no, use --acl & --attr options to force their usage */
|
---|
| 211 | char *g_getfacl = NULL;
|
---|
| 212 | char *g_getfattr = NULL;
|
---|
[1] | 213 |
|
---|
[1645] | 214 | /* Reference to global bkpinfo */
|
---|
| 215 | extern struct s_bkpinfo *bkpinfo;
|
---|
| 216 |
|
---|
[1] | 217 | /**
|
---|
| 218 | * @addtogroup cliGroup
|
---|
| 219 | * @{
|
---|
| 220 | */
|
---|
| 221 | /**
|
---|
| 222 | * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv.
|
---|
| 223 | * @param argc The argument count, including the program name; @p argc passed to main().
|
---|
| 224 | * @param argv The argument vector; @p argv passed to main().
|
---|
| 225 | * @param bkpinfo The backup information structure to populate.
|
---|
| 226 | * @return The number of problems with the command line (0 for success).
|
---|
| 227 | */
|
---|
| 228 | int
|
---|
[1645] | 229 | handle_incoming_parameters(int argc, char *argv[])
|
---|
[1] | 230 | {
|
---|
[116] | 231 | /*@ int *** */
|
---|
| 232 | int res = 0;
|
---|
| 233 | int retval = 0;
|
---|
| 234 | int i = 0, j;
|
---|
[1] | 235 |
|
---|
[116] | 236 | /*@ buffers *************** */
|
---|
| 237 | char *tmp;
|
---|
| 238 | char flag_val[128][MAX_STR_LEN];
|
---|
| 239 | bool flag_set[128];
|
---|
[1] | 240 |
|
---|
[1702] | 241 | tmp = malloc(9*MAX_STR_LEN);
|
---|
[1645] | 242 | sensibly_set_tmpdir_and_scratchdir();
|
---|
[116] | 243 | for (i = 0; i < 128; i++) {
|
---|
| 244 | flag_val[i][0] = '\0';
|
---|
| 245 | flag_set[i] = FALSE;
|
---|
| 246 | }
|
---|
[541] | 247 | // strcpy (bkpinfo->scratchdir, "/home");
|
---|
[116] | 248 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 249 | bkpinfo->media_size[j] = 650;
|
---|
| 250 | } /* default */
|
---|
| 251 | res =
|
---|
| 252 | retrieve_switches_from_command_line(argc, argv, flag_val,
|
---|
| 253 | flag_set);
|
---|
| 254 | retval += res;
|
---|
| 255 | if (!retval) {
|
---|
[1645] | 256 | res = process_switches(flag_val, flag_set);
|
---|
[116] | 257 | retval += res;
|
---|
| 258 | }
|
---|
[1] | 259 | /*
|
---|
| 260 | if (!retval)
|
---|
| 261 | {
|
---|
| 262 | */
|
---|
[116] | 263 | log_msg(3, "Switches:-");
|
---|
| 264 | for (i = 0; i < 128; i++) {
|
---|
| 265 | if (flag_set[i]) {
|
---|
| 266 | sprintf(tmp, "-%c %s", i, flag_val[i]);
|
---|
| 267 | log_msg(3, tmp);
|
---|
| 268 | }
|
---|
[1] | 269 | }
|
---|
| 270 | // }
|
---|
[116] | 271 | sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
|
---|
| 272 | paranoid_system(tmp);
|
---|
| 273 | sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
|
---|
| 274 | paranoid_system(tmp);
|
---|
| 275 | sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
|
---|
| 276 | "/mondo.scratch.%ld", random() % 32767);
|
---|
| 277 | sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 278 | paranoid_system(tmp);
|
---|
| 279 | sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
|
---|
| 280 | paranoid_system(tmp);
|
---|
| 281 | paranoid_free(tmp);
|
---|
| 282 | return (retval);
|
---|
[1] | 283 | }
|
---|
| 284 |
|
---|
| 285 |
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | /**
|
---|
| 289 | * Store the sizespec(s) stored in @p value into @p bkpinfo.
|
---|
| 290 | * @param bkpinfo The backup information structure; the @c bkpinfo->media_size field will be populated.
|
---|
| 291 | * @param value The sizespec (e.g. "2g", "40m").
|
---|
| 292 | * @return 0, always.
|
---|
| 293 | * @bug Return code not needed.
|
---|
| 294 | */
|
---|
[1645] | 295 | int process_the_s_switch(char *value)
|
---|
[1] | 296 | {
|
---|
[116] | 297 | int j;
|
---|
| 298 | char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN];
|
---|
[1] | 299 |
|
---|
[116] | 300 | assert(bkpinfo != NULL);
|
---|
| 301 | assert(value != NULL);
|
---|
[1] | 302 |
|
---|
[116] | 303 | bkpinfo->media_size[0] = -1; /* dummy value */
|
---|
| 304 | for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
|
---|
| 305 | j++, p = strchr(p, ',') + 1) {
|
---|
| 306 | strncpy(tmp, p, MAX_STR_LEN);
|
---|
| 307 | *(strchr(tmp, ',')) = '\0';
|
---|
| 308 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
|
---|
| 309 | sprintf(comment, "media_size[%d] = %ld", j,
|
---|
| 310 | bkpinfo->media_size[j]);
|
---|
| 311 | log_msg(3, comment);
|
---|
[1] | 312 | }
|
---|
[116] | 313 | for (; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 314 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
|
---|
[1] | 315 | }
|
---|
| 316 | // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
|
---|
[116] | 317 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 318 | if (bkpinfo->media_size[j] <= 0) {
|
---|
| 319 | log_msg(1, "You gave media #%d an invalid size\n", j);
|
---|
| 320 | return (-1);
|
---|
| 321 | }
|
---|
| 322 | }
|
---|
| 323 | return (0);
|
---|
[1] | 324 | }
|
---|
| 325 |
|
---|
| 326 |
|
---|
| 327 |
|
---|
| 328 | /**
|
---|
| 329 | * Process mondoarchive's command-line switches.
|
---|
| 330 | * @param bkpinfo The backup information structure to populate.
|
---|
| 331 | * @param flag_val An array of the argument passed to each switch (the letter is the index).
|
---|
| 332 | * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
|
---|
| 333 | * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
|
---|
| 334 | * FALSE if it's not.
|
---|
| 335 | * @return The number of problems with the switches, or 0 for success.
|
---|
| 336 | * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
|
---|
| 337 | */
|
---|
| 338 | int
|
---|
[1645] | 339 | process_switches(char flag_val[128][MAX_STR_LEN], bool flag_set[128])
|
---|
[1] | 340 | {
|
---|
| 341 |
|
---|
[116] | 342 | /*@ ints *** */
|
---|
| 343 | int i = 0;
|
---|
| 344 | int retval = 0;
|
---|
| 345 | int percent = 0;
|
---|
[1] | 346 |
|
---|
[116] | 347 | /*@ buffers ** */
|
---|
| 348 | char *tmp;
|
---|
[542] | 349 | char *tmp1;
|
---|
[116] | 350 | char *psz;
|
---|
[603] | 351 | char *p;
|
---|
| 352 | char *q;
|
---|
[1] | 353 |
|
---|
[949] | 354 | long itbs = 0L;
|
---|
[1] | 355 |
|
---|
[289] | 356 | struct stat buf;
|
---|
| 357 |
|
---|
[116] | 358 | malloc_string(tmp);
|
---|
| 359 | malloc_string(psz);
|
---|
[1] | 360 |
|
---|
[116] | 361 | assert(bkpinfo != NULL);
|
---|
| 362 | assert(flag_val != NULL);
|
---|
| 363 | assert(flag_set != NULL);
|
---|
[1] | 364 |
|
---|
[116] | 365 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
[1] | 366 |
|
---|
| 367 | /* compulsory */
|
---|
[116] | 368 | i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
|
---|
| 369 | flag_set['t'] + flag_set['u'] + flag_set['r'] +
|
---|
[1690] | 370 | flag_set['w'] + flag_set['C'] + flag_set['U'];
|
---|
[116] | 371 | if (i == 0) {
|
---|
| 372 | retval++;
|
---|
[541] | 373 | log_to_screen("You must specify the media type\n");
|
---|
[1] | 374 | }
|
---|
[116] | 375 | if (i > 1) {
|
---|
| 376 | retval++;
|
---|
[541] | 377 | log_to_screen("Please specify only one media type\n");
|
---|
[1] | 378 | }
|
---|
[116] | 379 | if (flag_set['K']) {
|
---|
| 380 | g_loglevel = atoi(flag_val['K']);
|
---|
| 381 | if (g_loglevel < 3) {
|
---|
| 382 | g_loglevel = 3;
|
---|
| 383 | }
|
---|
[1] | 384 | }
|
---|
[116] | 385 | if (flag_set['L'] && flag_set['0']) {
|
---|
| 386 | retval++;
|
---|
[541] | 387 | log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
|
---|
[1] | 388 | }
|
---|
[116] | 389 | bkpinfo->backup_data = flag_set['O'];
|
---|
| 390 | bkpinfo->verify_data = flag_set['V'];
|
---|
| 391 | if (flag_set['I'] && !bkpinfo->backup_data) {
|
---|
[541] | 392 | log_to_screen("-I switch is ignored if just verifying");
|
---|
[116] | 393 | }
|
---|
| 394 | if (flag_set['E'] && !bkpinfo->backup_data) {
|
---|
[541] | 395 | log_to_screen("-E switch is ignored if just verifying");
|
---|
[116] | 396 | }
|
---|
[1] | 397 |
|
---|
[116] | 398 | if (!find_home_of_exe("afio")) {
|
---|
| 399 | if (find_home_of_exe("star")) {
|
---|
| 400 | flag_set['R'] = TRUE;
|
---|
| 401 | log_msg(1, "Using star instead of afio");
|
---|
| 402 | } else {
|
---|
| 403 | fatal_error
|
---|
| 404 | ("Neither afio nor star is installed. Please install at least one.");
|
---|
| 405 | }
|
---|
[1] | 406 | }
|
---|
| 407 |
|
---|
[116] | 408 | if (flag_set['R']) {
|
---|
| 409 | bkpinfo->use_star = TRUE;
|
---|
| 410 | if (flag_set['L']) {
|
---|
| 411 | fatal_error("You may not use star and lzop at the same time.");
|
---|
| 412 | }
|
---|
| 413 | if (!find_home_of_exe("star")) {
|
---|
| 414 | fatal_error
|
---|
| 415 | ("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
|
---|
| 416 | }
|
---|
[1] | 417 | }
|
---|
[116] | 418 | if (flag_set['W']) {
|
---|
| 419 | bkpinfo->nonbootable_backup = TRUE;
|
---|
| 420 | log_to_screen("Warning - you have opted for non-bootable backup");
|
---|
| 421 | if (flag_set['f'] || flag_set['l']) {
|
---|
| 422 | log_to_screen
|
---|
[541] | 423 | ("You don't need to specify bootloader or bootdevice");
|
---|
[116] | 424 | }
|
---|
[1] | 425 | }
|
---|
[116] | 426 | if (flag_set['t'] && flag_set['H']) {
|
---|
| 427 | fatal_error
|
---|
| 428 | ("Sorry, you may not nuke w/o warning from tape. Drop -H, please.");
|
---|
| 429 | }
|
---|
| 430 | if (flag_set['I']) {
|
---|
| 431 | if (!strcmp(bkpinfo->include_paths, "/")) {
|
---|
| 432 | log_msg(2, "'/' is pleonastic.");
|
---|
| 433 | bkpinfo->include_paths[0] = '\0';
|
---|
| 434 | }
|
---|
| 435 | if (bkpinfo->include_paths[0]) {
|
---|
| 436 | strcat(bkpinfo->include_paths, " ");
|
---|
| 437 | }
|
---|
[542] | 438 | asprintf(&tmp1, flag_val['I']);
|
---|
[603] | 439 | p = tmp1;
|
---|
| 440 | q = tmp1;
|
---|
[542] | 441 |
|
---|
| 442 | /* Cut the flag_val['I'] in parts containing all paths to test them */
|
---|
| 443 | while (p != NULL) {
|
---|
| 444 | q = strchr(p, ' ');
|
---|
| 445 | if (q != NULL) {
|
---|
| 446 | *q = '\0';
|
---|
| 447 | if (stat(p, &buf) != 0) {
|
---|
| 448 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
| 449 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 450 | }
|
---|
[633] | 451 | p = q+1 ;
|
---|
[542] | 452 | } else {
|
---|
| 453 | if (stat(p, &buf) != 0) {
|
---|
| 454 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
| 455 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 456 | }
|
---|
| 457 | p = NULL;
|
---|
| 458 | }
|
---|
[289] | 459 | }
|
---|
[542] | 460 | paranoid_free(tmp1);
|
---|
| 461 |
|
---|
[116] | 462 | strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
|
---|
| 463 | flag_val['I'],
|
---|
[543] | 464 | 4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
|
---|
[116] | 465 | log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
|
---|
| 466 | if (bkpinfo->include_paths[0] == '-') {
|
---|
| 467 | retval++;
|
---|
[541] | 468 | log_to_screen("Please supply a sensible value with '-I'\n");
|
---|
[116] | 469 | }
|
---|
| 470 | }
|
---|
[1] | 471 |
|
---|
[116] | 472 | if (g_kernel_version >= 2.6 && !flag_set['d']
|
---|
| 473 | && (flag_set['c'] || flag_set['w'])) {
|
---|
| 474 | fatal_error
|
---|
| 475 | ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
|
---|
[1] | 476 | }
|
---|
| 477 |
|
---|
[116] | 478 |
|
---|
| 479 | if (flag_set['J']) {
|
---|
| 480 | if (flag_set['I']) {
|
---|
| 481 | retval++;
|
---|
| 482 | log_to_screen
|
---|
[541] | 483 | ("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. :-)");
|
---|
[116] | 484 | }
|
---|
| 485 | bkpinfo->make_filelist = FALSE;
|
---|
| 486 | strcpy(bkpinfo->include_paths, flag_val['J']);
|
---|
[1] | 487 | }
|
---|
[116] | 488 | if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) {
|
---|
| 489 | if (!flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 490 | && strstr(flag_val['d'], "/dev/")) {
|
---|
| 491 | fatal_error
|
---|
| 492 | ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
|
---|
| 493 | }
|
---|
| 494 | if (flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 495 | && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 496 | fatal_error
|
---|
| 497 | ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
|
---|
| 498 | }
|
---|
| 499 | if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 500 | log_to_screen
|
---|
[541] | 501 | ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
|
---|
[116] | 502 | }
|
---|
| 503 |
|
---|
| 504 | if (system("which cdrecord > /dev/null 2> /dev/null")
|
---|
| 505 | && system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 506 | fatal_error
|
---|
| 507 | ("Please install dvdrecord/cdrecord and try again.");
|
---|
| 508 | }
|
---|
| 509 | if (flag_set['C']) {
|
---|
| 510 | bkpinfo->cdrw_speed = atoi(flag_val['C']);
|
---|
| 511 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 512 | fatal_error
|
---|
| 513 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 514 | }
|
---|
| 515 | if (!flag_set['L']) {
|
---|
| 516 | log_to_screen
|
---|
[541] | 517 | ("You must use -L with -C. Therefore I am setting it for you.");
|
---|
[116] | 518 | flag_set['L'] = 1;
|
---|
| 519 | flag_val['L'][0] = '\0';
|
---|
| 520 | }
|
---|
| 521 | } else {
|
---|
| 522 | log_msg(3, "flag_val['c'] = %s", flag_val['c']);
|
---|
| 523 | log_msg(3, "flag_val['w'] = %s", flag_val['w']);
|
---|
| 524 | // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
|
---|
| 525 | if (flag_set['c']) {
|
---|
| 526 | bkpinfo->cdrw_speed = atoi(flag_val['c']);
|
---|
| 527 | } else if (flag_set['w']) {
|
---|
| 528 | bkpinfo->cdrw_speed = atoi(flag_val['w']);
|
---|
| 529 | } else if (flag_set['r']) {
|
---|
| 530 | bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 534 | fatal_error
|
---|
| 535 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 536 | }
|
---|
| 537 | }
|
---|
[1] | 538 | }
|
---|
[116] | 539 | if (flag_set['t'] && !flag_set['d']) {
|
---|
| 540 | log_it("Hmm! No tape drive specified. Let's see what we can do.");
|
---|
| 541 | if (find_tape_device_and_size(flag_val['d'], tmp)) {
|
---|
| 542 | fatal_error
|
---|
| 543 | ("Tape device not specified. I couldn't find it either.");
|
---|
| 544 | }
|
---|
| 545 | flag_set['d'] = TRUE;
|
---|
| 546 | sprintf(tmp,
|
---|
[541] | 547 | "You didn't specify a tape streamer device. I'm assuming %s",
|
---|
[116] | 548 | flag_val['d']);
|
---|
| 549 | log_to_screen(tmp);
|
---|
| 550 | percent = 0;
|
---|
| 551 | }
|
---|
| 552 |
|
---|
[1687] | 553 | if (flag_set['U']) // USB
|
---|
| 554 | {
|
---|
| 555 | if (! flag_set['d']) {
|
---|
| 556 | fatal_error
|
---|
| 557 | ("You need to specify a device file with -d for bootable USB device creation");
|
---|
| 558 | }
|
---|
| 559 | if (!flag_set['s']) {
|
---|
| 560 | fatal_error("You did not specify a size (-s) for your USB device. Aborting");
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 |
|
---|
[116] | 564 | if (flag_set['r']) // DVD
|
---|
| 565 | {
|
---|
| 566 | if (flag_set['m']) {
|
---|
| 567 | fatal_error
|
---|
| 568 | ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
|
---|
| 569 | }
|
---|
| 570 | if (!flag_set['d']) {
|
---|
| 571 | if (!find_dvd_device(flag_val['d'], FALSE)) {
|
---|
| 572 | flag_set['d'] = TRUE;
|
---|
[541] | 573 | log_to_screen("I guess DVD drive is at %s", flag_val['d']);
|
---|
[116] | 574 | }
|
---|
| 575 | }
|
---|
| 576 | if (!find_home_of_exe("growisofs")) {
|
---|
| 577 | fatal_error
|
---|
| 578 | ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 579 | }
|
---|
| 580 | if (!find_home_of_exe("dvd+rw-format")) {
|
---|
| 581 | fatal_error
|
---|
| 582 | ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 583 | }
|
---|
| 584 | if (strchr(flag_val['d'], ',')) {
|
---|
| 585 | fatal_error
|
---|
| 586 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 587 | }
|
---|
| 588 | if (!flag_set['s']) {
|
---|
| 589 | sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
|
---|
| 590 | strcat(flag_val['s'], "m");
|
---|
| 591 | log_to_screen
|
---|
[541] | 592 | ("You did not specify a size (-s) for DVD. I'm guessing %s.",
|
---|
[116] | 593 | flag_val['s']);
|
---|
| 594 | flag_set['s'] = 1;
|
---|
| 595 | }
|
---|
[1] | 596 | /*
|
---|
| 597 | if (flag_set['Z']) {
|
---|
| 598 | bkpinfo->blank_dvd_first = TRUE;
|
---|
| 599 | }
|
---|
| 600 | */
|
---|
[116] | 601 | }
|
---|
[1] | 602 |
|
---|
[116] | 603 | if (flag_set['t'] || flag_set['u']) { /* tape size */
|
---|
| 604 | if (strchr(flag_val['d'], ',')) {
|
---|
| 605 | fatal_error
|
---|
| 606 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 607 | }
|
---|
| 608 | if (flag_set['O']) {
|
---|
| 609 | if (flag_set['s']) {
|
---|
| 610 | if (flag_set['t']) {
|
---|
| 611 | fatal_error
|
---|
| 612 | ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
|
---|
| 613 | }
|
---|
[1645] | 614 | if (process_the_s_switch(flag_val['s'])) {
|
---|
[116] | 615 | fatal_error("Bad -s switch");
|
---|
| 616 | }
|
---|
| 617 | } else if (flag_set['u'] || flag_set['t']) {
|
---|
| 618 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 619 | bkpinfo->media_size[i] = 0;
|
---|
| 620 | }
|
---|
| 621 | } else {
|
---|
| 622 | retval++;
|
---|
| 623 | log_to_screen("Tape size not specified.\n");
|
---|
| 624 | }
|
---|
| 625 | }
|
---|
[1687] | 626 | } else { /* CD|USB size */
|
---|
[116] | 627 | if (flag_set['s']) {
|
---|
[1645] | 628 | if (process_the_s_switch(flag_val['s'])) {
|
---|
[116] | 629 | fatal_error("Bad -s switch");
|
---|
| 630 | }
|
---|
| 631 | }
|
---|
| 632 | if (flag_set['w']) {
|
---|
| 633 | bkpinfo->wipe_media_first = TRUE;
|
---|
| 634 | } /* CD-RW */
|
---|
[1] | 635 | }
|
---|
[116] | 636 | if (flag_set['n']) {
|
---|
| 637 | strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
|
---|
| 638 | if (!flag_set['d']) {
|
---|
| 639 | strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
|
---|
| 640 | }
|
---|
[910] | 641 | sprintf(tmp, "mount | grep -E \"^%s .*\" | cut -d' ' -f3",
|
---|
[116] | 642 | bkpinfo->nfs_mount);
|
---|
| 643 | strncpy(bkpinfo->isodir,
|
---|
| 644 | call_program_and_get_last_line_of_output(tmp),
|
---|
| 645 | MAX_STR_LEN / 4);
|
---|
| 646 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
| 647 | retval++;
|
---|
[541] | 648 | log_to_screen("NFS share is not mounted. Please mount it.\n");
|
---|
[116] | 649 | }
|
---|
| 650 | log_msg(3, "mount = %s", bkpinfo->nfs_mount);
|
---|
| 651 | log_msg(3, "isodir= %s", bkpinfo->isodir);
|
---|
[1] | 652 | }
|
---|
[116] | 653 | if (flag_set['c']) {
|
---|
| 654 | bkpinfo->backup_media_type = cdr;
|
---|
[1] | 655 | }
|
---|
[116] | 656 | if (flag_set['C']) {
|
---|
| 657 | bkpinfo->backup_media_type = cdstream;
|
---|
[1] | 658 | }
|
---|
[116] | 659 | if (flag_set['i']) {
|
---|
| 660 | bkpinfo->backup_media_type = iso;
|
---|
| 661 | }
|
---|
| 662 | if (flag_set['n']) {
|
---|
| 663 | bkpinfo->backup_media_type = nfs;
|
---|
| 664 | }
|
---|
| 665 | if (flag_set['r']) {
|
---|
| 666 | bkpinfo->backup_media_type = dvd;
|
---|
| 667 | }
|
---|
| 668 | if (flag_set['t']) {
|
---|
| 669 | bkpinfo->backup_media_type = tape;
|
---|
| 670 | }
|
---|
| 671 | if (flag_set['u']) {
|
---|
| 672 | bkpinfo->backup_media_type = udev;
|
---|
| 673 | }
|
---|
| 674 | if (flag_set['w']) {
|
---|
| 675 | bkpinfo->backup_media_type = cdrw;
|
---|
| 676 | }
|
---|
[1687] | 677 | if (flag_set['U']) {
|
---|
| 678 | bkpinfo->backup_media_type = usb;
|
---|
| 679 | }
|
---|
[948] | 680 | if (flag_set['z']) {
|
---|
| 681 | if (find_home_of_exe("getfattr")) {
|
---|
| 682 | asprintf(&g_getfattr,"getfattr");
|
---|
| 683 | }
|
---|
| 684 | if (find_home_of_exe("getfacl")) {
|
---|
| 685 | asprintf(&g_getfacl,"getfacl");
|
---|
| 686 | }
|
---|
| 687 | }
|
---|
[1] | 688 |
|
---|
[805] | 689 | /* optional, popular */
|
---|
[116] | 690 | if (flag_set['g']) {
|
---|
| 691 | g_text_mode = FALSE;
|
---|
| 692 | }
|
---|
[805] | 693 |
|
---|
[116] | 694 | if (flag_set['E']) {
|
---|
| 695 | if (bkpinfo->exclude_paths[0]) {
|
---|
| 696 | strcat(bkpinfo->exclude_paths, " ");
|
---|
| 697 | }
|
---|
[542] | 698 | asprintf(&tmp1, flag_val['E']);
|
---|
[605] | 699 | p = tmp1;
|
---|
| 700 | q = tmp1;
|
---|
[542] | 701 |
|
---|
| 702 | /* Cut the flag_val['E'] in parts containing all paths to test them */
|
---|
| 703 | while (p != NULL) {
|
---|
| 704 | q = strchr(p, ' ');
|
---|
| 705 | if (q != NULL) {
|
---|
| 706 | *q = '\0';
|
---|
[805] | 707 | /* Fix bug 14 where ending / cause a problem later
|
---|
| 708 | * so handled here for the moment */
|
---|
| 709 | q--;
|
---|
[809] | 710 | if (*q == '/') {
|
---|
[805] | 711 | *q = '\0';
|
---|
| 712 | }
|
---|
| 713 | q++;
|
---|
| 714 | /* End of bug fix */
|
---|
[542] | 715 | if (stat(p, &buf) != 0) {
|
---|
| 716 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
| 717 | }
|
---|
[633] | 718 | p = q+1 ;
|
---|
[542] | 719 | } else {
|
---|
| 720 | if (stat(p, &buf) != 0) {
|
---|
| 721 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
| 722 | }
|
---|
| 723 | p = NULL;
|
---|
| 724 | }
|
---|
[289] | 725 | }
|
---|
[542] | 726 | paranoid_free(tmp1);
|
---|
| 727 |
|
---|
[116] | 728 | strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
|
---|
| 729 | flag_val['E'],
|
---|
[543] | 730 | 4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
|
---|
[116] | 731 | }
|
---|
| 732 | if (flag_set['e']) {
|
---|
| 733 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 734 | }
|
---|
| 735 | if (flag_set['N']) // exclude NFS mounts & devices
|
---|
| 736 | {
|
---|
[1] | 737 | // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
|
---|
[116] | 738 | strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN);
|
---|
| 739 | if (bkpinfo->exclude_paths[0]) {
|
---|
[1540] | 740 | strncat(bkpinfo->exclude_paths, " ", 4*MAX_STR_LEN);
|
---|
[116] | 741 | }
|
---|
[1540] | 742 | strncat(bkpinfo->exclude_paths, psz, 4*MAX_STR_LEN);
|
---|
[116] | 743 | log_msg(3, "-N means we're now excluding %s",
|
---|
| 744 | bkpinfo->exclude_paths);
|
---|
| 745 | }
|
---|
[1540] | 746 | if (strlen(bkpinfo->exclude_paths) >= 4*MAX_STR_LEN) {
|
---|
[116] | 747 | fatal_error
|
---|
[1540] | 748 | ("Your '-E' parameter is too long. Increase MAX_STR_LEN");
|
---|
[116] | 749 | }
|
---|
| 750 | if (flag_set['b']) {
|
---|
| 751 | strcpy(psz, flag_val['b']);
|
---|
| 752 | log_msg(1, "psz = '%s'", psz);
|
---|
| 753 | if (psz[strlen(psz) - 1] == 'k') {
|
---|
| 754 | psz[strlen(psz) - 1] = '\0';
|
---|
| 755 | itbs = atol(psz) * 1024L;
|
---|
| 756 | } else {
|
---|
| 757 | itbs = atol(psz);
|
---|
| 758 | }
|
---|
| 759 | log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
|
---|
| 760 | log_msg(1, "Internal tape block size is now %ld bytes", itbs);
|
---|
| 761 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
|
---|
| 762 | fatal_error
|
---|
| 763 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
|
---|
| 764 | }
|
---|
| 765 | bkpinfo->internal_tape_block_size = itbs;
|
---|
| 766 | }
|
---|
| 767 | if (flag_set['D']) {
|
---|
| 768 | bkpinfo->differential = 1;
|
---|
[1] | 769 | // bkpinfo->differential = atoi (flag_val['D']);
|
---|
[116] | 770 | if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
|
---|
| 771 | fatal_error
|
---|
| 772 | ("The D option should be between 1 and 9 inclusive");
|
---|
| 773 | }
|
---|
[1] | 774 | }
|
---|
[116] | 775 | if (flag_set['x']) {
|
---|
| 776 | strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
|
---|
[296] | 777 | if (run_program_and_log_output("which ntfsclone", 2)) {
|
---|
| 778 | fatal_error("Please install ntfsprogs package/tarball.");
|
---|
[116] | 779 | }
|
---|
[1] | 780 | }
|
---|
[116] | 781 | if (flag_set['m']) {
|
---|
| 782 | bkpinfo->manual_cd_tray = TRUE;
|
---|
[1] | 783 | }
|
---|
[116] | 784 | if (flag_set['k']) {
|
---|
| 785 | strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
|
---|
| 786 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
|
---|
| 787 | strcpy(bkpinfo->kernel_path, "FAILSAFE");
|
---|
| 788 | }
|
---|
| 789 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
|
---|
| 790 | && !does_file_exist(bkpinfo->kernel_path)) {
|
---|
| 791 | retval++;
|
---|
| 792 | sprintf(tmp,
|
---|
[541] | 793 | "You specified kernel '%s', which does not exist\n",
|
---|
[116] | 794 | bkpinfo->kernel_path);
|
---|
| 795 | log_to_screen(tmp);
|
---|
| 796 | }
|
---|
| 797 | }
|
---|
| 798 | if (flag_set['p']) {
|
---|
| 799 | strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
|
---|
| 800 | }
|
---|
[1] | 801 |
|
---|
| 802 |
|
---|
[116] | 803 | if (flag_set['d']) { /* backup directory (if ISO/NFS) */
|
---|
| 804 | if (flag_set['i']) {
|
---|
| 805 | strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 806 | sprintf(tmp, "ls -l %s", bkpinfo->isodir);
|
---|
| 807 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
| 808 | fatal_error
|
---|
| 809 | ("output folder does not exist - please create it");
|
---|
| 810 | }
|
---|
| 811 | } else if (flag_set['n']) {
|
---|
| 812 | strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
|
---|
| 813 | } else { /* backup device (if tape/CD-R/CD-RW) */
|
---|
| 814 |
|
---|
| 815 | strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 816 | }
|
---|
[1] | 817 | }
|
---|
[116] | 818 |
|
---|
| 819 | if (flag_set['n']) {
|
---|
| 820 | sprintf(tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
|
---|
| 821 | bkpinfo->nfs_remote_dir);
|
---|
| 822 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
| 823 | retval++;
|
---|
| 824 | sprintf(tmp,
|
---|
[541] | 825 | "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
|
---|
[116] | 826 | bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
|
---|
| 827 | log_to_screen(tmp);
|
---|
| 828 | }
|
---|
[1] | 829 | }
|
---|
| 830 |
|
---|
[116] | 831 | if (!flag_set['d']
|
---|
| 832 | && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
|
---|
| 833 | if (g_kernel_version >= 2.6) {
|
---|
| 834 | if (popup_and_get_string
|
---|
[541] | 835 | ("Device", "Please specify the device",
|
---|
[116] | 836 | bkpinfo->media_device, MAX_STR_LEN / 4)) {
|
---|
| 837 | retval++;
|
---|
[541] | 838 | log_to_screen("User opted to cancel.");
|
---|
[116] | 839 | }
|
---|
| 840 | } else if (find_cdrw_device(bkpinfo->media_device)) {
|
---|
| 841 | retval++;
|
---|
| 842 | log_to_screen
|
---|
[541] | 843 | ("Tried and failed to find CD-R[W] drive automatically.\n");
|
---|
[116] | 844 | } else {
|
---|
| 845 | flag_set['d'] = TRUE;
|
---|
| 846 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
|
---|
| 847 | }
|
---|
[1] | 848 | }
|
---|
| 849 |
|
---|
[116] | 850 | if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) {
|
---|
| 851 | retval++;
|
---|
[541] | 852 | log_to_screen("Please specify the backup device/directory.\n");
|
---|
[116] | 853 | fatal_error
|
---|
| 854 | ("You didn't use -d to specify the backup device/directory.");
|
---|
[1] | 855 | }
|
---|
[116] | 856 | /* optional, obscure */
|
---|
| 857 | for (i = '0'; i <= '9'; i++) {
|
---|
| 858 | if (flag_set[i]) {
|
---|
| 859 | bkpinfo->compression_level = i - '0';
|
---|
| 860 | } /* not '\0' but '0' */
|
---|
[1] | 861 | }
|
---|
[116] | 862 | if (flag_set['S']) {
|
---|
| 863 | sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
|
---|
| 864 | random() % 32768);
|
---|
[1] | 865 | }
|
---|
[116] | 866 | if (flag_set['T']) {
|
---|
[1655] | 867 | setup_tmpdir(flag_val['T']);
|
---|
| 868 | sprintf(tmp, "touch %s/.foo.dat", bkpinfo->tmpdir);
|
---|
[116] | 869 | if (run_program_and_log_output(tmp, 1)) {
|
---|
| 870 | retval++;
|
---|
| 871 | log_to_screen
|
---|
[541] | 872 | ("Please specify a tempdir which I can write to. :)");
|
---|
[116] | 873 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 874 | }
|
---|
[1655] | 875 | sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
|
---|
[116] | 876 | if (run_program_and_log_output(tmp, 1)) {
|
---|
| 877 | retval++;
|
---|
| 878 | log_to_screen
|
---|
[541] | 879 | ("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
|
---|
[116] | 880 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 881 | }
|
---|
[1] | 882 | }
|
---|
[116] | 883 | if (flag_set['A']) {
|
---|
| 884 | strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
|
---|
| 885 | }
|
---|
| 886 | if (flag_set['B']) {
|
---|
| 887 | strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
|
---|
| 888 | }
|
---|
| 889 | if (flag_set['F']) {
|
---|
| 890 | g_skip_floppies = TRUE;
|
---|
| 891 | }
|
---|
| 892 | if (flag_set['H']) {
|
---|
| 893 | g_cd_recovery = TRUE;
|
---|
| 894 | }
|
---|
| 895 | if (flag_set['l']) {
|
---|
[1] | 896 | #ifdef __FreeBSD__
|
---|
| 897 | # define BOOT_LOADER_CHARS "GLBMR"
|
---|
| 898 | #else
|
---|
| 899 | # ifdef __IA64__
|
---|
| 900 | # define BOOT_LOADER_CHARS "GER"
|
---|
| 901 | # else
|
---|
| 902 | # define BOOT_LOADER_CHARS "GLR"
|
---|
| 903 | # endif
|
---|
| 904 | #endif
|
---|
[116] | 905 | if (!strchr
|
---|
| 906 | (BOOT_LOADER_CHARS,
|
---|
| 907 | (bkpinfo->boot_loader = flag_val['l'][0]))) {
|
---|
| 908 | log_msg(1, "%c? WTF is %c? I need G, L, E or R.",
|
---|
| 909 | bkpinfo->boot_loader, bkpinfo->boot_loader);
|
---|
| 910 | fatal_error
|
---|
| 911 | ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
|
---|
| 912 | }
|
---|
[1] | 913 | #undef BOOT_LOADER_CHARS
|
---|
| 914 | }
|
---|
[116] | 915 | if (flag_set['f']) {
|
---|
| 916 | strncpy(bkpinfo->boot_device,
|
---|
| 917 | resolve_softlinks_to_get_to_actual_device_file(flag_val
|
---|
| 918 | ['f']),
|
---|
| 919 | MAX_STR_LEN / 4);
|
---|
| 920 | }
|
---|
| 921 | if (flag_set['P']) {
|
---|
| 922 | strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
|
---|
| 923 | }
|
---|
| 924 | if (flag_set['Q']) {
|
---|
| 925 | i = which_boot_loader(tmp);
|
---|
| 926 | log_msg(3, "boot loader is %c, residing at %s", i, tmp);
|
---|
[541] | 927 | printf("boot loader is %c, residing at %s\n", i, tmp);
|
---|
[116] | 928 | finish(0);
|
---|
| 929 | }
|
---|
| 930 | if (flag_set['L']) {
|
---|
| 931 | bkpinfo->use_lzo = TRUE;
|
---|
| 932 | if (run_program_and_log_output("which lzop", FALSE)) {
|
---|
| 933 | retval++;
|
---|
| 934 | log_to_screen
|
---|
[541] | 935 | ("Please install LZOP. You can't use '-L' until you do.\n");
|
---|
[116] | 936 | }
|
---|
| 937 | }
|
---|
[1] | 938 |
|
---|
[998] | 939 | if (flag_set['G']) {
|
---|
| 940 | bkpinfo->use_gzip = TRUE;
|
---|
| 941 | if (run_program_and_log_output("which gzip", FALSE)) {
|
---|
| 942 | retval++;
|
---|
| 943 | log_to_screen
|
---|
| 944 | ("Please install gzip. You can't use '-G' until you do.\n");
|
---|
| 945 | }
|
---|
| 946 | }
|
---|
| 947 |
|
---|
[116] | 948 | if (!flag_set['o']
|
---|
| 949 | &&
|
---|
| 950 | !run_program_and_log_output
|
---|
[681] | 951 | ("grep -Ei suse /etc/issue.net | grep -E '9.0' | grep 64", TRUE)) {
|
---|
[116] | 952 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 953 | log_to_screen
|
---|
[541] | 954 | ("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary.");
|
---|
[116] | 955 | }
|
---|
| 956 | if (flag_set['o']) {
|
---|
| 957 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 958 | }
|
---|
[1] | 959 | #ifndef __FreeBSD__
|
---|
[116] | 960 | else {
|
---|
| 961 | if (!is_this_a_valid_disk_format("vfat")) {
|
---|
| 962 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 963 | log_to_screen
|
---|
[541] | 964 | ("Your kernel appears not to support vfat filesystems. I am therefore");
|
---|
[116] | 965 | log_to_screen
|
---|
[541] | 966 | ("using LILO instead of SYSLINUX as the CD/floppy's boot loader.");
|
---|
[116] | 967 | }
|
---|
| 968 | if (run_program_and_log_output("which mkfs.vfat", FALSE)) {
|
---|
| 969 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 970 | #ifdef __IA32__
|
---|
[116] | 971 | log_to_screen
|
---|
[541] | 972 | ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
|
---|
[116] | 973 | log_to_screen
|
---|
[541] | 974 | ("your boot loader. I shall therefore use LILO instead.");
|
---|
[1] | 975 | #endif
|
---|
| 976 | #ifdef __IA64__
|
---|
[116] | 977 | log_to_screen
|
---|
[541] | 978 | ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
|
---|
| 979 | log_to_screen("environment correctly. Please install it.");
|
---|
[116] | 980 | fatal_error("Aborting");
|
---|
[1] | 981 | #endif
|
---|
[116] | 982 | }
|
---|
[1] | 983 | #ifdef __IA64__
|
---|
[116] | 984 | /* We force ELILO usage on IA64 */
|
---|
| 985 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 986 | #endif
|
---|
[116] | 987 | }
|
---|
[1] | 988 | #endif
|
---|
| 989 |
|
---|
[116] | 990 | if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) {
|
---|
| 991 | paranoid_system("touch /boot/boot.b");
|
---|
| 992 | }
|
---|
[1] | 993 |
|
---|
[116] | 994 | i = flag_set['O'] + flag_set['V'];
|
---|
| 995 | if (i == 0) {
|
---|
| 996 | retval++;
|
---|
[541] | 997 | log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
|
---|
[116] | 998 | }
|
---|
[1] | 999 |
|
---|
| 1000 | /* and finally... */
|
---|
| 1001 |
|
---|
[116] | 1002 | paranoid_free(tmp);
|
---|
| 1003 | paranoid_free(psz);
|
---|
| 1004 | return (retval);
|
---|
[1] | 1005 | }
|
---|
| 1006 |
|
---|
| 1007 |
|
---|
| 1008 |
|
---|
| 1009 | /**
|
---|
| 1010 | * Get the switches from @p argc and @p argv using getopt() and place them in
|
---|
| 1011 | * @p flag_set and @p flag_val.
|
---|
| 1012 | * @param argc The argument count (@p argc passed to main()).
|
---|
| 1013 | * @param argv The argument vector (@p argv passed to main()).
|
---|
| 1014 | * @param flag_val An array indexed by switch letter - if a switch is set and
|
---|
| 1015 | * has an argument then set flag_val[switch] to that argument.
|
---|
| 1016 | * @param flag_set An array indexed by switch letter - if a switch is set then
|
---|
| 1017 | * set flag_set[switch] to TRUE, else set it to FALSE.
|
---|
| 1018 | * @return The number of problems with the command line (0 for success).
|
---|
| 1019 | */
|
---|
| 1020 | int
|
---|
[116] | 1021 | retrieve_switches_from_command_line(int argc, char *argv[],
|
---|
| 1022 | char flag_val[128][MAX_STR_LEN],
|
---|
| 1023 | bool flag_set[128])
|
---|
[1] | 1024 | {
|
---|
[116] | 1025 | /*@ ints ** */
|
---|
| 1026 | int opt = 0;
|
---|
| 1027 | char tmp[MAX_STR_LEN];
|
---|
| 1028 | int i = 0;
|
---|
| 1029 | int len;
|
---|
[1] | 1030 |
|
---|
[116] | 1031 | /*@ bools *** */
|
---|
| 1032 | bool bad_switches = FALSE;
|
---|
[1] | 1033 |
|
---|
[116] | 1034 | assert(flag_val != NULL);
|
---|
| 1035 | assert(flag_set != NULL);
|
---|
[1] | 1036 |
|
---|
[116] | 1037 | for (i = 0; i < 128; i++) {
|
---|
| 1038 | flag_val[i][0] = '\0';
|
---|
| 1039 | flag_set[i] = FALSE;
|
---|
[1] | 1040 | }
|
---|
[116] | 1041 | while ((opt =
|
---|
| 1042 | getopt(argc, argv,
|
---|
[1687] | 1043 | "0123456789A:B:C:DE:FGHI:J:K:LNOP:QRS:T:UVWb:c:d:ef:gik:l:mn:op:rs:tuw:x:z"))
|
---|
[116] | 1044 | != -1) {
|
---|
| 1045 | if (opt == '?') {
|
---|
| 1046 | bad_switches = TRUE;
|
---|
| 1047 | /*log_it("Invalid option: %c\n",optopt); */
|
---|
| 1048 | } else {
|
---|
| 1049 | if (flag_set[optopt]) {
|
---|
| 1050 | bad_switches = TRUE;
|
---|
[541] | 1051 | sprintf(tmp, "Switch -%c previously defined as %s\n", opt,
|
---|
[116] | 1052 | flag_val[i]);
|
---|
| 1053 | log_to_screen(tmp);
|
---|
| 1054 | } else {
|
---|
| 1055 | flag_set[opt] = TRUE;
|
---|
| 1056 | if (optarg) {
|
---|
| 1057 | len = strlen(optarg);
|
---|
| 1058 | if (optarg[0] != '/' && optarg[len - 1] == '/') {
|
---|
| 1059 | optarg[--len] = '\0';
|
---|
| 1060 | log_to_screen
|
---|
[541] | 1061 | ("Warning - param '%s' should not have trailing slash!",
|
---|
[116] | 1062 | optarg);
|
---|
| 1063 | }
|
---|
| 1064 | if (opt == 'd') {
|
---|
| 1065 | if (strchr(flag_val[opt], '/')
|
---|
| 1066 | && flag_val[opt][0] != '/') {
|
---|
| 1067 | sprintf(tmp,
|
---|
[541] | 1068 | "-%c flag --- must be absolute path --- '%s' isn't absolute",
|
---|
[116] | 1069 | opt, flag_val[opt]);
|
---|
| 1070 | log_to_screen(tmp);
|
---|
| 1071 | bad_switches = TRUE;
|
---|
| 1072 | }
|
---|
| 1073 | }
|
---|
| 1074 | strcpy(flag_val[opt], optarg);
|
---|
| 1075 | }
|
---|
| 1076 | }
|
---|
[1] | 1077 | }
|
---|
| 1078 | }
|
---|
[116] | 1079 | for (i = optind; i < argc; i++) {
|
---|
| 1080 | bad_switches = TRUE;
|
---|
[541] | 1081 | sprintf(tmp, "Invalid arg -- %s\n", argv[i]);
|
---|
[116] | 1082 | log_to_screen(tmp);
|
---|
| 1083 | }
|
---|
| 1084 | return (bad_switches);
|
---|
[1] | 1085 | }
|
---|
| 1086 |
|
---|
| 1087 |
|
---|
| 1088 |
|
---|
| 1089 |
|
---|
| 1090 | /**
|
---|
| 1091 | * Print a not-so-helpful help message and exit.
|
---|
| 1092 | */
|
---|
[116] | 1093 | void help_screen()
|
---|
[1] | 1094 | {
|
---|
[116] | 1095 | log_msg(1, "Type 'man mondo-archive' for more information\n");
|
---|
| 1096 | exit(1);
|
---|
[1] | 1097 | }
|
---|
| 1098 |
|
---|
| 1099 |
|
---|
| 1100 | /**
|
---|
| 1101 | * Terminate Mondo in response to a signal.
|
---|
| 1102 | * @param sig The signal number received.
|
---|
| 1103 | */
|
---|
| 1104 | void terminate_daemon(int sig)
|
---|
| 1105 | {
|
---|
[116] | 1106 | char tmp[64];
|
---|
| 1107 | char tmp2[MAX_STR_LEN];
|
---|
| 1108 | // char command[512];
|
---|
| 1109 | // pid_t pid;
|
---|
[1] | 1110 |
|
---|
[116] | 1111 | switch (sig) {
|
---|
[1] | 1112 | case SIGINT:
|
---|
| 1113 | sprintf(tmp, "SIGINT");
|
---|
[541] | 1114 | strcpy(tmp2, "You interrupted me :-)");
|
---|
[1] | 1115 | break;
|
---|
| 1116 | case SIGKILL:
|
---|
| 1117 | sprintf(tmp, "SIGKILL");
|
---|
[116] | 1118 | strcpy(tmp2,
|
---|
[541] | 1119 | "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
|
---|
[1] | 1120 | break;
|
---|
| 1121 | case SIGTERM:
|
---|
| 1122 | sprintf(tmp, "SIGTERM");
|
---|
[541] | 1123 | strcpy(tmp2, "Got terminate signal");
|
---|
[1] | 1124 | break;
|
---|
| 1125 | case SIGHUP:
|
---|
| 1126 | sprintf(tmp, "SIGHUP");
|
---|
[541] | 1127 | strcpy(tmp2, "Hangup on line");
|
---|
[1] | 1128 | break;
|
---|
| 1129 | case SIGSEGV:
|
---|
| 1130 | sprintf(tmp, "SIGSEGV");
|
---|
[116] | 1131 | strcpy(tmp2,
|
---|
[541] | 1132 | "Internal programming error. Please send a backtrace as well as your log.");
|
---|
[1] | 1133 | break;
|
---|
| 1134 | case SIGPIPE:
|
---|
| 1135 | sprintf(tmp, "SIGPIPE");
|
---|
[541] | 1136 | strcpy(tmp2, "Pipe was broken");
|
---|
[1] | 1137 | break;
|
---|
[116] | 1138 | case SIGABRT:
|
---|
| 1139 | sprintf(tmp, "SIGABRT");
|
---|
| 1140 | sprintf(tmp2,
|
---|
[541] | 1141 | "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
|
---|
[116] | 1142 | break;
|
---|
[1] | 1143 | default:
|
---|
[541] | 1144 | sprintf(tmp, "(Unknown)");
|
---|
[116] | 1145 | }
|
---|
[1] | 1146 |
|
---|
[541] | 1147 | strcat(tmp, " signal received from OS");
|
---|
[116] | 1148 | log_to_screen(tmp);
|
---|
| 1149 | log_to_screen(tmp2);
|
---|
| 1150 | if (sig == SIGABRT) {
|
---|
| 1151 | sleep(10);
|
---|
| 1152 | }
|
---|
| 1153 | kill_buffer();
|
---|
| 1154 | fatal_error
|
---|
| 1155 | ("Mondoarchive is terminating in response to a signal from the OS");
|
---|
| 1156 | finish(254); // just in case
|
---|
[1] | 1157 | }
|
---|
| 1158 |
|
---|
| 1159 |
|
---|
| 1160 |
|
---|
| 1161 |
|
---|
| 1162 | /**
|
---|
| 1163 | * Turn signal-trapping on or off.
|
---|
| 1164 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
|
---|
| 1165 | */
|
---|
| 1166 | void set_signals(int on)
|
---|
| 1167 | {
|
---|
[116] | 1168 | int signals[] =
|
---|
| 1169 | { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
|
---|
| 1170 | int i;
|
---|
| 1171 |
|
---|
| 1172 | signal(SIGPIPE, sigpipe_occurred);
|
---|
| 1173 | for (i = 0; signals[i]; i++) {
|
---|
| 1174 | if (on) {
|
---|
| 1175 | signal(signals[i], terminate_daemon);
|
---|
| 1176 | } else {
|
---|
| 1177 | signal(signals[i], termination_in_progress);
|
---|
| 1178 | }
|
---|
| 1179 | }
|
---|
[1] | 1180 | }
|
---|
| 1181 |
|
---|
| 1182 |
|
---|
| 1183 |
|
---|
| 1184 |
|
---|
| 1185 | /**
|
---|
| 1186 | * Exit immediately without cleaning up.
|
---|
| 1187 | * @param sig The signal we are exiting due to.
|
---|
| 1188 | */
|
---|
| 1189 | void termination_in_progress(int sig)
|
---|
| 1190 | {
|
---|
[116] | 1191 | log_msg(1, "Termination in progress");
|
---|
| 1192 | usleep(1000);
|
---|
| 1193 | pthread_exit(0);
|
---|
[1] | 1194 | }
|
---|
| 1195 |
|
---|
| 1196 | /* @} - end of cliGroup */
|
---|