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