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