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