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